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 host_id filter for tls_certificates #835

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added
- Add option --optimize migrate-relay-sensors [#827](https://github.com/greenbone/gvmd/pull/827)
- Add host_id filter for tls_certificates [#835](https://github.com/greenbone/gvmd/pull/835)

### Changed
- Extend command line options for managing scanners [#815](https://github.com/greenbone/gvmd/pull/815)
Expand Down
31 changes: 30 additions & 1 deletion src/manage_sql_tls_certificates.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,40 @@ gchar *
tls_certificate_extra_where (const char *filter)
{
GString *ret;
gchar *report_id;
gchar *host_id, *report_id;

ret = g_string_new ("");

host_id = filter_term_value (filter, "host_id");
report_id = filter_term_value (filter, "report_id");

if (host_id)
{
gchar *quoted_id;
quoted_id = sql_quote (host_id);
g_string_append_printf
(ret,
" AND (tls_certificates.id IN"
" (WITH host_idents AS"
" (SELECT source_id AS ident_report_id, value AS ident_ip"
" FROM host_identifiers"
" WHERE host = (SELECT id FROM hosts"
" WHERE uuid='%s')"
" AND name = 'ip')"
" SELECT tls_certificate"
" FROM tls_certificate_sources AS sources"
" JOIN tls_certificate_origins AS origins"
" ON origins.id = sources.origin"
" JOIN tls_certificate_locations AS locations"
" ON locations.id = sources.location"
" JOIN host_idents"
" ON origins.origin_id = host_idents.ident_report_id"
" AND locations.host_ip = host_idents.ident_ip)"
" )",
quoted_id);
g_free (quoted_id);
}

if (report_id)
{
gchar *quoted_id;
Expand All @@ -214,6 +242,7 @@ tls_certificate_extra_where (const char *filter)
g_free (quoted_id);
}

g_free (host_id);
g_free (report_id);

return g_string_free (ret, FALSE);
Expand Down
5 changes: 5 additions & 0 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -22975,6 +22975,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
<type>iso_time</type>
<summary>Most recent time the TLS certificate was imported or found in a scan</summary>
</column>
<option>
<name>host_id</name>
<type>uuid</type>
<summary>UUID of the host asset where the certificate must be found</summary>
</option>
<option>
<name>report_id</name>
<type>uuid</type>
Expand Down