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

Extend the fields of curl_certificate table #6176

Merged
merged 3 commits into from
Mar 31, 2020

Conversation

kumarak
Copy link
Contributor

@kumarak kumarak commented Jan 16, 2020

The additional columns in the curl_certificate table include the version number, signature algorithm, x509v3 extensions, and the certificate in PEM format. The certificate can be dumped by setting the dump_certificate configuration.

"select * from curl_certificate where hostname = 'google.com'"
"select * from curl_certificate where hostname = 'google.com' and dump_certificate = 1"

An example output:

>> osqueryi --json "select * from curl_certificate where hostname = 'google.com'" --line

                     hostname = google.com
                  common_name = *.google.com
                 organization = Google LLC
            organization_unit = 
                serial_number = A4E0C3B090180813080000000025ECFA
           issuer_common_name = GTS CA 1O1
          issuer_organization = Google Trust Services
     issuer_organization_unit = 
                   valid_from = Dec 20 13:05:43 2019 GMT
                     valid_to = Mar 13 13:05:43 2020 GMT
           sha256_fingerprint = 6d2a6287ba830a6ec7cef5409ca17db1912425f52165db85e0c9109bc9690c25
             sha1_fingerprint = 39c4c9c1ed48830384cd8a3cc67c7f38d4bceace
             ssl_cert_version = 3
      ssl_signature_algorithm = sha256WithRSAEncryption
                ssl_signature = 8d:ba:b0:ab:43:6c:eb:6b:23:a7:95:4a:de:49:d5:c3:e2:29:9b:f1:e7:53:0f:5e:80:02:b1:5a:16:c7:83:fe:e8:80:b3:61:85:d6:95:17:c6:2a:99:a6:86:3e:13:b2:7f:86:c5:e0:2b:f1:ed:00:18:db:f5:f9:95:2b:82:73:b0:0f:2b:b1:03:80:a1:46:e4:9a:92:34:9f:50:ad:6a:4e:00:89:ca:cf:e6:37:99:83:ea:3e:8e:57:1d:09:91:ae:4b:ea:78:0d:f1:81:21:89:f1:22:76:54:68:d9:19:96:e6:a6:47:b4:4f:8d:5b:00:3c:12:01:7b:6b:3e:15:61:89:04:f8:49:eb:91:80:68:7b:95:ae:c1:ee:f0:5b:2b:37:03:16:64:83:eb:df:07:8e:11:3e:09:8d:e5:10:e8:32:62:b8:15:2d:96:5c:7d:de:03:b8:c5:27:59:c1:c9:4c:e8:45:52:1b:18:d4:22:b4:df:c4:15:cf:2e:dc:37:bf:03:f2:aa:74:3a:71:fe:01:82:83:7e:35:0b:0f:de:39:aa:1d:de:0b:d3:c4:92:c0:aa:e1:6b:a0:ed:cd:2c:db:23:99:11:df:ba:4a:0a:fb:e9:f2:4a:c0:ae:9c:f6:e5:b0:50:8e:1c:85:45:76:8e:62:12:a5:b8:06:60
   ssl_subject_key_identifier = C3:3F:18:01:EA:35:DB:C2:19:9A:29:B4:91:7D:6E:31:B8:94:C7:4F
 ssl_authority_key_identifier = keyid:98:D1:F8:6E:10:EB:CF:9B:EC:60:9F:18:90:1B:A0:EB:7D:09:FD:2B
                ssl_key_usage = Digital Signature, Key Encipherment
       ssl_extended_key_usage = TLS Web Server Authentication
     ssl_certificate_policies = Policy: 2.23.140.1.2.2
Policy: 1.3.6.1.4.1.11129.2.5.3
ssl_subject_alternative_names = DNS:*.google.com, DNS:*.android.com, DNS:*.appengine.google.com, DNS:*.cloud.google.com, DNS:*.crowdsource.google.com, DNS:*.g.co, DNS:*.gcp.gvt2.com, DNS:*.gcpcdn.gvt1.com, DNS:*.ggpht.cn, DNS:*.gkecnapps.cn, DNS:*.google-analytics.com, DNS:*.google.ca, DNS:*.google.cl, DNS:*.google.co.in, DNS:*.google.co.jp, DNS:*.google.co.uk, DNS:*.google.com.ar, DNS:*.google.com.au, DNS:*.google.com.br, DNS:*.google.com.co, DNS:*.google.com.mx, DNS:*.google.com.tr, DNS:*.google.com.vn, DNS:*.google.de, DNS:*.google.es, DNS:*.google.fr, DNS:*.google.hu, DNS:*.google.it, DNS:*.google.nl, DNS:*.google.pl, DNS:*.google.pt, DNS:*.googleadapis.com, DNS:*.googleapis.cn, DNS:*.googlecnapps.cn, DNS:*.googlecommerce.com, DNS:*.googlevideo.com, DNS:*.gstatic.cn, DNS:*.gstatic.com, DNS:*.gstaticcnapps.cn, DNS:*.gvt1.com, DNS:*.gvt2.com, DNS:*.metric.gstatic.com, DNS:*.urchin.com, DNS:*.url.google.com, DNS:*.wear.gkecnapps.cn, DNS:*.youtube-nocookie.com, DNS:*.youtube.com, DNS:*.youtubeeducation.com, DNS:*.youtubekids.com, DNS:*.yt.be, DNS:*.ytimg.com, DNS:android.clients.google.com, DNS:android.com, DNS:developer.android.google.cn, DNS:developers.android.google.cn, DNS:g.co, DNS:ggpht.cn, DNS:gkecnapps.cn, DNS:goo.gl, DNS:google-analytics.com, DNS:google.com, DNS:googlecnapps.cn, DNS:googlecommerce.com, DNS:source.android.google.cn, DNS:urchin.com, DNS:www.goo.gl, DNS:youtu.be, DNS:youtube.com, DNS:youtubeeducation.com, DNS:youtubekids.com, DNS:yt.be
 ssl_issuer_alternative_names = 
              ssl_info_access = OCSP - URI:http://ocsp.pki.goog/gts1o1
CA Issuers - URI:http://pki.goog/gsr2/GTS1O1.crt
      ssl_subject_info_access = 
          ssl_policy_mappings = 
              ssl_has_expired = 0
             basic_constraint = CA:FALSE
             name_constraints = 
           policy_constraints = 
                 ssl_cert_pem = 

Copy link
Member

@theopolis theopolis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Also remember to check the formatting with make format_check, the Linux builds will fail if the code is not formatted correctly.

osquery/tables/networking/curl_certificate.cpp Outdated Show resolved Hide resolved
osquery/tables/networking/curl_certificate.cpp Outdated Show resolved Hide resolved
osquery/tables/networking/curl_certificate.cpp Outdated Show resolved Hide resolved
@theopolis
Copy link
Member

Looks good, sorry for the follow up, but I think we can drop the “ssl_” prefix to the column names, thoughts?

@kumarak
Copy link
Contributor Author

kumarak commented Jan 27, 2020

Thanks, Teddy for the review. I will fix the field name changes.

Copy link
Member

@theopolis theopolis left a comment

Choose a reason for hiding this comment

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

Thanks for bearing with me on the nitpicks. I have a final round then we can merge ASAP!

}

static std::string signature(X509* cert) {
X509_ALGOR* algo;
Copy link
Member

Choose a reason for hiding this comment

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

= nullptr

Column("info_access", TEXT, "Authority Information Access"),
Column("subject_info_access", TEXT, "Subject Information Access"),
Column("policy_mappings", TEXT, "Policy Mappings"),
Column("certificate_has_expired", INTEGER, "Boolean value if certificate expired"),
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind updating the description to 1 if the certificate has expired, otherwise 0

}

Status getTLSCertificate(std::string hostname, QueryData& results) {
Status getTLSCertificate(std::string hostname,
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this hostname should be passed by const reference const std::string& hostname. Do you mind making this change while you're improving the table in this PR?

auto length = bio_buf->length;
if (bio_buf->data[length - 1] == '\n' ||
bio_buf->data[length - 1] == '\r') {
bio_buf->data[length - 1] = (char)0;
Copy link
Member

Choose a reason for hiding this comment

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

Why not \0;

}

if (bio_buf->data[length] == '\n' || bio_buf->data[length] == '\r') {
bio_buf->data[length] = (char)0;
Copy link
Member

Choose a reason for hiding this comment

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

Why not \0;

kumarak and others added 3 commits March 13, 2020 22:40
Add certificate in pem format to table

Add new extension to the table

Add algorithm signature to the table

Add condition to dump certificate

fix leaking bio_out
@Smjert
Copy link
Member

Smjert commented Mar 14, 2020

@theopolis thanks for the review!
I have rebased this on the latest master, addressed your review and also did some other small cleanups.

@Smjert Smjert closed this Mar 14, 2020
@Smjert Smjert reopened this Mar 14, 2020
@Smjert
Copy link
Member

Smjert commented Mar 27, 2020

@theopolis thanks!
This has been hit by a temporary Azure bug that was not triggering the build for PRs, closing and reopening to re-trigger.

@Smjert Smjert closed this Mar 27, 2020
@Smjert Smjert reopened this Mar 27, 2020
@theopolis theopolis merged commit 58d0671 into osquery:master Mar 31, 2020
@kumarak kumarak deleted the kumarak/curl_certificate branch August 3, 2020 19:17
aikuchin pushed a commit to aikuchin/osquery that referenced this pull request Jul 11, 2023
… to master

* commit '8c13dd6bd206f2909a4baea5bcfbc91d5e3f502b': (159 commits)
  release: updating changelog for 4.3.0 release (osquery#6387)
  Build hvci_status table with CMake (osquery#6378)
  Change calls to debug log to verbose (osquery#6369)
  iokit: Fix race when accessing port_ (osquery#6380)
  Check extensions are registered with osquery core (osquery#6374)
  First steps to remove the Buck build system (osquery#6361)
  Return error detaching table, only use primary database (osquery#6373)
  Copy the parent environment when launching worker
  Change process table log errors to info and fix typo (osquery#6370)
  Ensure the extension uuid is never 0 (osquery#6377)
  Remove errors when converting empty numeric rows (osquery#6371)
  Do not force a specific path to install osquery on Windows (osquery#6379)
  Fix readFile API doing blocking I/O with a non-blocking handle (osquery#6368)
  magic: Check return from magic_file (osquery#6363)
  macos: Use -1 for missing ppid in process_events (osquery#6339)
  Update OpenSSL to version 1.1.1f and fix build (osquery#6359)
  Simplify how third party libraries formula work (osquery#6303)
  Add socket_events table for socket auditing in MacOS (osquery#6028)
  Extend the fields of curl_certificate table (osquery#6176)
  add status column to deb_packages table (osquery#6341)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants