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 sensor relays and OSP sensors #756

Merged
merged 19 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6c6a2ed
Add relay functionality for GMP scanners
timopollmeier Sep 19, 2019
8ff5363
Merge branch 'master' of github.com:greenbone/gvm into sensor-relays
timopollmeier Sep 19, 2019
fd8af5e
Add scanner type "OSP Sensor"
timopollmeier Sep 20, 2019
760cc0e
Merge branch 'master' of github.com:greenbone/gvm into sensor-relays
timopollmeier Sep 23, 2019
6a837e9
Make credential optional in create_scanner
timopollmeier Sep 24, 2019
0bd5d07
Improve credential handling in modify_scanner
timopollmeier Sep 24, 2019
5f65d18
Use client certificate with OSP relays as well
timopollmeier Sep 24, 2019
b03a7c0
Fix adjust doc and logging for --relay-mapper
timopollmeier Sep 24, 2019
6634522
Add CHANGELOG entry for relays and OSP sensor type
timopollmeier Sep 24, 2019
34b3a4a
Merge branch 'master' into sensor-relays
timopollmeier Sep 25, 2019
72268d0
Fix documentation of slave_get_relay
timopollmeier Sep 26, 2019
2efd8bf
Clean up declarations and inits in slave_get_relay
timopollmeier Sep 26, 2019
a268ef5
Fix warnings in osp_connect_with_data
timopollmeier Sep 26, 2019
3f9d765
Clarify --relay-mapper option documentation
timopollmeier Sep 26, 2019
6996e4a
Get system/performance reports list also via OSP
timopollmeier Sep 26, 2019
30bee72
Get performance reports from OSP
timopollmeier Sep 26, 2019
cbd3f82
Free strings in get_osp_performance_string
timopollmeier Sep 26, 2019
fa06038
Remove unused return values from functions
timopollmeier Sep 26, 2019
2486eea
Move comment in get_system_report_types OSP case
timopollmeier Sep 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3446,10 +3446,9 @@ delete_osp_scan (const char *report_id, const char *host, int port,
{
osp_connection_t *connection;

connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv);
connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv);
if (!connection)
{
g_warning ("Couldn't connect to OSP scanner on %s:%d", host, port);
return;
}
osp_delete_scan (connection, report_id);
Expand Down Expand Up @@ -3481,10 +3480,9 @@ get_osp_scan_report (const char *scan_id, const char *host, int port,
int progress;
char *error = NULL;

connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv);
connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv);
if (!connection)
{
g_warning ("Couldn't connect to OSP scanner on %s:%d", host, port);
return -1;
}
progress = osp_get_scan_pop (connection, scan_id, report_xml, details,
Expand Down Expand Up @@ -3523,11 +3521,10 @@ get_osp_scan_status (const char *scan_id, const char *host, int port,
osp_get_scan_status_opts_t get_scan_opts;
osp_scan_status_t status = OSP_SCAN_STATUS_ERROR;

connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv);
connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv);
if (!connection)
{
g_warning ("Couldn't connect to OSP scanner on %s:%d", host, port);
return status;;
return status;
}

get_scan_opts.scan_id = scan_id;
Expand Down Expand Up @@ -4202,7 +4199,8 @@ fork_osp_scan_handler (task_t task, target_t target, char **report_id_return)
reinit_manage_process ();
manage_session_init (current_credentials.uuid);

if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS)
if (scanner_type (task_scanner (task)) == SCANNER_TYPE_OPENVAS
|| scanner_type (task_scanner (task) == SCANNER_TYPE_OSP_SENSOR))
{
rc = launch_osp_openvas_task (task, target, report_id, &error);
}
Expand Down Expand Up @@ -5245,7 +5243,8 @@ run_task (const char *task_id, char **report_id, int from)
return run_gmp_task (task, scanner, from, report_id);

if (scanner_type (scanner) == SCANNER_TYPE_OPENVAS
|| scanner_type (scanner) == SCANNER_TYPE_OSP)
|| scanner_type (scanner) == SCANNER_TYPE_OSP
|| scanner_type (scanner) == SCANNER_TYPE_OSP_SENSOR)
return run_osp_task (task, report_id);

return -1; // Unknown scanner type
Expand Down
8 changes: 8 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ typedef enum scanner_type
SCANNER_TYPE_OPENVAS,
SCANNER_TYPE_CVE,
SCANNER_TYPE_GMP,
SCANNER_TYPE_OSP_SENSOR,
SCANNER_TYPE_MAX,
} scanner_type_t;

Expand Down Expand Up @@ -2829,6 +2830,13 @@ osp_get_version_from_iterator (iterator_t *, char **, char **, char **, char **,
int
osp_get_details_from_iterator (iterator_t *, char **, GSList **);

osp_connection_t *
osp_connect_with_data (const char *,
int,
const char *,
const char *,
const char *);

osp_connection_t *
osp_scanner_connect (scanner_t);

Expand Down
135 changes: 116 additions & 19 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -43755,6 +43755,109 @@ openvas_default_scanner_host ()
SCANNER_UUID_DEFAULT);
}

/**
* @brief Create a new connection to an OSP scanner relay.
*
* @param[in] host Original host name or IP address.
* @param[in] port Original port.
* @param[in] ca_pub Original CA certificate.
*
* @return New connection if success, NULL otherwise.
*/
static osp_connection_t *
osp_scanner_relay_connect (const char *host, int port, const char *ca_pub)
{
int ret, new_port;
gchar *new_host, *new_ca_pub;
osp_connection_t *connection;

new_host = NULL;
new_ca_pub = NULL;
new_port = 0;

ret = slave_get_relay (host,
port,
ca_pub,
"OSP",
&new_host,
&new_port,
&new_ca_pub);

switch (ret)
{
case 0:
break;
case 1:
g_warning ("No relay found for Scanner at %s:%d", host, port);
return NULL;
default:
g_warning ("%s: Error getting relay for Scanner at %s:%d",
__FUNCTION__, host, port);
return NULL;
}

connection
= osp_connection_new (new_host, new_port, new_ca_pub, NULL, NULL);

if (connection == NULL)
{
if (new_port)
g_warning ("Could not connect to relay at %s:%d"
" for Scanner at %s:%d",
new_host, new_port, host, port);
else
g_warning ("Could not connect to relay at %s"
" for Scanner at %s:%d",
new_host, host, port);
}

g_free (new_host);
g_free (new_ca_pub);

return connection;
}

/**
* @brief Create a new connection to an OSP scanner using the scanner data.
*
* @param[in] host Host name or IP address.
* @param[in] port Port.
* @param[in] ca_pub CA certificate.
* @param[in] key_pub Public key.
* @param[in] key_priv Private key.
*
* @return New connection if success, NULL otherwise.
*/
osp_connection_t *
osp_connect_with_data (const char *host,
int port,
const char *ca_pub,
const char *key_pub,
const char *key_priv)
{
osp_connection_t *connection;
int is_unix_socket = (host && *host == '/') ? 1 : 0;

if (is_unix_socket == 0
&& get_relay_mapper_path ())
{
connection = osp_scanner_relay_connect (host, port, ca_pub);
}
else
{
connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv);

if (connection == NULL)
{
if (is_unix_socket)
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
g_warning ("Could not connect to Scanner at %s:%d", host, port);
else
g_warning ("Could not connect to Scanner at %s", host);
}
}
return connection;
}

/**
* @brief Create a new connection to an OSP scanner.
*
Expand Down Expand Up @@ -43785,15 +43888,8 @@ osp_scanner_connect (scanner_t scanner)
key_pub = scanner_key_pub (scanner);
key_priv = scanner_key_priv (scanner);
}
connection = osp_connection_new (host, port, ca_pub, key_pub, key_priv);

if (connection == NULL)
{
if (port)
g_warning ("Could not connect to Scanner at %s:%d", host, port);
else
g_warning ("Could not connect to Scanner at %s", host);
}
connection = osp_connect_with_data (host, port, ca_pub, key_pub, key_priv);

g_free (host);
g_free (ca_pub);
Expand Down Expand Up @@ -43823,11 +43919,11 @@ osp_get_version_from_iterator (iterator_t *iterator, char **s_name,
osp_connection_t *connection;

assert (iterator);
connection = osp_connection_new (scanner_iterator_host (iterator),
scanner_iterator_port (iterator),
scanner_iterator_ca_pub (iterator),
scanner_iterator_key_pub (iterator),
scanner_iterator_key_priv (iterator));
connection = osp_connect_with_data (scanner_iterator_host (iterator),
scanner_iterator_port (iterator),
scanner_iterator_ca_pub (iterator),
scanner_iterator_key_pub (iterator),
scanner_iterator_key_priv (iterator));
if (!connection)
return 1;
if (osp_get_version (connection, s_name, s_ver, d_name, d_ver, p_name, p_ver))
Expand All @@ -43852,11 +43948,11 @@ osp_get_details_from_iterator (iterator_t *iterator, char **desc,
osp_connection_t *connection;

assert (iterator);
connection = osp_connection_new (scanner_iterator_host (iterator),
scanner_iterator_port (iterator),
scanner_iterator_ca_pub (iterator),
scanner_iterator_key_pub (iterator),
scanner_iterator_key_priv (iterator));
connection = osp_connect_with_data (scanner_iterator_host (iterator),
scanner_iterator_port (iterator),
scanner_iterator_ca_pub (iterator),
scanner_iterator_key_pub (iterator),
scanner_iterator_key_priv (iterator));
if (!connection)
return 1;
if (osp_get_scanner_details (connection, desc, params))
Expand Down Expand Up @@ -44015,7 +44111,8 @@ verify_scanner (const char *scanner_id, char **version)
return 0;
}
else if (scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP
|| scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS)
|| scanner_iterator_type (&scanner) == SCANNER_TYPE_OPENVAS
|| scanner_iterator_type (&scanner) == SCANNER_TYPE_OSP_SENSOR)
{
int ret = osp_get_version_from_iterator (&scanner, NULL, version, NULL,
NULL, NULL, NULL);
Expand Down