Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OSP Sensor type to GSA #1646

Merged
merged 8 commits into from
Sep 30, 2019
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]

### Added
- Added OSP Sensor type to GSA [#1646](https://github.com/greenbone/gsa/pull/1646)
- Added TLS certificate filter type [#1630](https://github.com/greenbone/gsa/pull/1630)
- Added change method to Field and TextArea component, removed withChangeHandler [#1625](https://github.com/greenbone/gsa/pull/1625)
- Added custom page title to all pages [#1623](https://github.com/greenbone/gsa/pull/1623/files)
Expand Down
13 changes: 11 additions & 2 deletions gsa/src/gmp/models/__tests__/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Scanner, {
OPENVAS_SCANNER_TYPE,
OSP_SCANNER_TYPE,
GMP_SCANNER_TYPE,
OSP_SENSOR_SCANNER_TYPE,
} from 'gmp/models/scanner';
import {testModel} from 'gmp/models/testing';

Expand Down Expand Up @@ -187,33 +188,39 @@ describe('Scanner model tests', () => {
const elem2 = {type: OPENVAS_SCANNER_TYPE};
const elem3 = {type: GMP_SCANNER_TYPE};
const elem4 = {type: OSP_SCANNER_TYPE};
const elem5 = {type: OSP_SENSOR_SCANNER_TYPE};

const scanner1 = new Scanner(elem1);
const scanner2 = new Scanner(elem2);
const scanner3 = new Scanner(elem3);
const scanner4 = new Scanner(elem4);
const scanner5 = new Scanner(elem5);

expect(scanner1.isClonable()).toEqual(false);
expect(scanner2.isClonable()).toEqual(false);
expect(scanner3.isClonable()).toEqual(true);
expect(scanner4.isClonable()).toEqual(true);
expect(scanner5.isClonable()).toEqual(true);
});

test('isWritable() should return correct true/false', () => {
const elem1 = {type: CVE_SCANNER_TYPE};
const elem2 = {type: OPENVAS_SCANNER_TYPE};
const elem3 = {type: GMP_SCANNER_TYPE};
const elem4 = {type: OSP_SCANNER_TYPE};
const elem5 = {type: OSP_SENSOR_SCANNER_TYPE};

const scanner1 = new Scanner(elem1);
const scanner2 = new Scanner(elem2);
const scanner3 = new Scanner(elem3);
const scanner4 = new Scanner(elem4);
const scanner5 = new Scanner(elem5);

expect(scanner1.isClonable()).toEqual(false);
expect(scanner2.isClonable()).toEqual(false);
expect(scanner3.isClonable()).toEqual(true);
expect(scanner4.isClonable()).toEqual(true);
expect(scanner5.isClonable()).toEqual(true);
});

test('hasUnixSocket() should return correct true/false', () => {
Expand All @@ -233,13 +240,15 @@ describe('Scanner model function tests', () => {
const type2 = scannerTypeName(OPENVAS_SCANNER_TYPE);
const type3 = scannerTypeName(CVE_SCANNER_TYPE);
const type4 = scannerTypeName(GMP_SCANNER_TYPE);
const type5 = scannerTypeName(42);
const type5 = scannerTypeName(OSP_SENSOR_SCANNER_TYPE);
const type6 = scannerTypeName(42);

expect(type1).toEqual('OSP Scanner');
expect(type2).toEqual('OpenVAS Scanner');
expect(type3).toEqual('CVE Scanner');
expect(type4).toEqual('GMP Scanner');
expect(type5).toEqual('Unknown type (42)');
expect(type5).toEqual('OSP Sensor');
expect(type6).toEqual('Unknown type (42)');
});

test('openVasScannersFilter should return filter with correct true/false', () => {
Expand Down
3 changes: 3 additions & 0 deletions gsa/src/gmp/models/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const OSP_SCANNER_TYPE = 1;
export const OPENVAS_SCANNER_TYPE = 2;
export const CVE_SCANNER_TYPE = 3;
export const GMP_SCANNER_TYPE = 4;
export const OSP_SENSOR_SCANNER_TYPE = 5;

export const OPENVAS_DEFAULT_SCANNER_ID =
'08b69003-5fc2-4037-a479-93b440211c73';
Expand All @@ -55,6 +56,8 @@ export function scannerTypeName(scannerType) {
return _('CVE Scanner');
} else if (scannerType === GMP_SCANNER_TYPE) {
return _('GMP Scanner');
} else if (scannerType === OSP_SENSOR_SCANNER_TYPE) {
return _('OSP Sensor');
}
return _('Unknown type ({{type}})', {type: scannerType});
}
Expand Down
8 changes: 5 additions & 3 deletions gsa/src/web/pages/performance/performancepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {isDefined} from 'gmp/utils/identity';

import date from 'gmp/models/date';
import Filter from 'gmp/models/filter';
import {GMP_SCANNER_TYPE} from 'gmp/models/scanner';
import {GMP_SCANNER_TYPE, OSP_SENSOR_SCANNER_TYPE} from 'gmp/models/scanner';

import FormGroup from 'web/components/form/formgroup';
import Select from 'web/components/form/select';
Expand Down Expand Up @@ -162,7 +162,9 @@ const Selector = withClickHandler()(styled.span`
}}
`);

const SLAVE_SCANNER_FILTER = Filter.fromString('type=' + GMP_SCANNER_TYPE);
const SLAVE_SCANNER_FILTER = Filter.fromString(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we could rename this variable in another PR. Something like SENSOR_SCANNERS_FILTER

'type=' + GMP_SCANNER_TYPE + ' type=' + OSP_SENSOR_SCANNER_TYPE,
);

class PerformancePage extends React.Component {
constructor(...args) {
Expand Down Expand Up @@ -328,7 +330,7 @@ class PerformancePage extends React.Component {
</Divider>
</FormGroup>

<FormGroup title={_('Report for GMP Scanner')}>
<FormGroup title={_('Report for GMP Scanner or OSP Sensor')}>
<Select
name="scannerId"
value={sensorId}
Expand Down
64 changes: 39 additions & 25 deletions gsa/src/web/pages/scanners/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {getTimezone} from 'web/store/usersettings/selectors';
import {
OSP_SCANNER_TYPE,
GMP_SCANNER_TYPE,
OSP_SENSOR_SCANNER_TYPE,
scannerTypeName,
} from 'gmp/models/scanner';

Expand All @@ -62,7 +63,11 @@ import {
USERNAME_PASSWORD_CREDENTIAL_TYPE,
} from 'gmp/models/credential';

const SCANNER_TYPES = [GMP_SCANNER_TYPE, OSP_SCANNER_TYPE];
const SCANNER_TYPES = [
GMP_SCANNER_TYPE,
OSP_SCANNER_TYPE,
OSP_SENSOR_SCANNER_TYPE,
];

const client_cert_credentials_filter = credential => {
return credential.credential_type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE;
Expand Down Expand Up @@ -143,10 +148,9 @@ class ScannerDialog extends React.Component {

render() {
const {
ca_pub,
comment = '',
scanner,
credential_id,
ca_pub,
credentials,
host = 'localhost',
id,
Expand All @@ -161,6 +165,8 @@ class ScannerDialog extends React.Component {
onSave,
} = this.props;

let {credential_id} = this.props;

const data = {
ca_pub,
comment,
Expand All @@ -182,8 +188,14 @@ class ScannerDialog extends React.Component {
const show_cred_info =
isDefined(scanner) &&
isDefined(scanner.credential) &&
scanner.credential.type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE;
const isGmpScannerType = type === GMP_SCANNER_TYPE;
scanner.credential.credential_type === CLIENT_CERTIFICATE_CREDENTIAL_TYPE;

const isOspSensorType = type === OSP_SENSOR_SCANNER_TYPE;
const isOspScannerType = type === OSP_SCANNER_TYPE;

if (isOspSensorType) {
credential_id = '';
saberlynx marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<SaveDialog
Expand Down Expand Up @@ -239,7 +251,7 @@ class ScannerDialog extends React.Component {
/>
</FormGroup>

{!isGmpScannerType && (
{isOspScannerType && (
<React.Fragment>
<FormGroup title={_('Port')}>
<TextField
Expand Down Expand Up @@ -295,26 +307,28 @@ class ScannerDialog extends React.Component {
</React.Fragment>
)}

<FormGroup title={_('Credential')} flex="column">
<Divider>
<Select
name="credential_id"
items={renderSelectItems(scanner_credentials)}
value={credential_id}
onChange={onCredentialChange}
/>
<Layout>
<NewIcon
value={type}
title={_('Create a new Credential')}
onClick={onNewCredentialClick}
{!isOspSensorType && (
<FormGroup title={_('Credential')} flex="column">
<Divider>
<Select
name="credential_id"
items={renderSelectItems(scanner_credentials)}
value={credential_id}
onChange={onCredentialChange}
/>
</Layout>
</Divider>
{show_cred_info && (
<CertStatus info={scanner.credential.certificate_info} />
)}
</FormGroup>
<Layout>
<NewIcon
value={type}
title={_('Create a new Credential')}
onClick={onNewCredentialClick}
/>
</Layout>
</Divider>
{show_cred_info && (
<CertStatus info={scanner.credential.certificate_info} />
)}
</FormGroup>
)}
</Layout>
);
}}
Expand Down
5 changes: 4 additions & 1 deletion gsa/src/web/pages/tasks/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
OSP_SCANNER_TYPE,
GMP_SCANNER_TYPE,
OPENVAS_DEFAULT_SCANNER_ID,
OSP_SENSOR_SCANNER_TYPE,
} from 'gmp/models/scanner';

import {
Expand Down Expand Up @@ -305,7 +306,9 @@ const TaskDialog = ({

const use_openvas_scan_config =
state.scanner_type === OPENVAS_SCANNER_TYPE ||
state.scanner_type === GMP_SCANNER_TYPE;
state.scanner_type === GMP_SCANNER_TYPE ||
state.scanner_type === OSP_SENSOR_SCANNER_TYPE;

return (
<Layout flex="column">
<FormGroup title={_('Name')}>
Expand Down
3 changes: 1 addition & 2 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10084,7 +10084,6 @@ create_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials,
CHECK_VARIABLE_INVALID (type, "Create Scanner");
if (params_given (params, "ca_pub"))
CHECK_VARIABLE_INVALID (ca_pub, "Create Scanner");
CHECK_VARIABLE_INVALID (credential_id, "Create Scanner");

if (ca_pub)
ret = gmpf (connection, credentials, &response, &entity, response_data,
Expand All @@ -10102,7 +10101,7 @@ create_scanner_gmp (gvm_connection_t *connection, credentials_t *credentials,
"<host>%s</host><port>%s</port><type>%s</type>"
"<credential id=\"%s\"/>"
"</create_scanner>",
name, comment, host, port, type, credential_id);
name, comment, host, port, type, credential_id ? credential_id : "");
switch (ret)
{
case 0:
Expand Down