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 functionality for scanning OID matchers in a CT log entry #527

Merged

Conversation

linus-sun
Copy link
Collaborator

@linus-sun linus-sun commented Nov 7, 2024

Summary

Per changes outlined in this doc, this PR implements support for scanning asn1.ObjectIdentifier extensions and matching values within a certificate transparency log. A certificate's extensions can be matched on and filtered for specific extension values, (future PRs will handle saving this output and writing to any of various notification platforms).

This PR also refactors functions related to scanning OID extensions and matching on them for specific values.

Release Note

NONE

Documentation

N/A

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 68.46154% with 41 lines in your changes missing coverage. Please review.

Project coverage is 62.81%. Comparing base (d271ec7) to head (be5ee9c).
Report is 168 commits behind head on main.

Files with missing lines Patch % Lines
pkg/identity/identity.go 62.76% 26 Missing and 9 partials ⚠️
pkg/ct/monitor.go 84.21% 2 Missing and 1 partial ⚠️
pkg/ct/test_utils.go 80.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #527      +/-   ##
==========================================
- Coverage   64.02%   62.81%   -1.22%     
==========================================
  Files           4       17      +13     
  Lines         303     1307    +1004     
==========================================
+ Hits          194      821     +627     
- Misses         78      410     +332     
- Partials       31       76      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@linus-sun linus-sun force-pushed the linussun/ct-log-identity-monitoring branch 3 times, most recently from 844c10e to 74be5d5 Compare November 7, 2024 18:43
@linus-sun linus-sun marked this pull request as ready for review November 7, 2024 19:00
@linus-sun linus-sun requested review from haydentherapper and mihaimaruseac and removed request for haydentherapper November 7, 2024 19:01
mihaimaruseac
mihaimaruseac previously approved these changes Nov 7, 2024
subject := logEntry.X509Cert.Subject.String()
foundEntries := []*identity.LogEntry{}
matchedEntries := []*identity.LogEntry{}
for _, monitoredSub := range monitoredSubjects {
regex, err := regexp.Compile(monitoredSub)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is jumping ahead by one PR, but I think you'll want to match on CertificateIdentities rather than Subjects since we'd want to match on issuer as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

going to address this in a follow-up PR

@linus-sun linus-sun force-pushed the linussun/ct-log-identity-monitoring branch 4 times, most recently from 15c7202 to b794951 Compare November 12, 2024 19:19
mihaimaruseac
mihaimaruseac previously approved these changes Nov 13, 2024
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

Just a comment about generic usage! I might be wrong though, so feel free to ping me if this doesn't work.

// if true, it returns the OID extension and extension value that were matched on
func OIDMatchesPolicy[Certificate *x509.Certificate | *google_x509.Certificate](certificate Certificate, oid asn1.ObjectIdentifier, extensionValues []string) (bool, asn1.ObjectIdentifier, string, error) {
switch cert := any(certificate).(type) {
case *x509.Certificate:
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the contents of the two case statements is the same, do you need the two case statements? Or can you just pass cert to getExtension without the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without the switch statement, Golang won't detect that the Certificate generic constraint will always contain an Extensions field; the switch statement in OIDMatchesPolicy is extraneous and can be removed, but getExtension/getDeprecatedExtension both require the cases

return "", nil
case *google_x509.Certificate:
for _, ext := range cert.Extensions {
if !ext.Id.Equal((google_asn1.ObjectIdentifier)(oid)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Like the other comment, it seems like these two case statements are nearly identical, except for this line about comparing OIDs. If we implemented a function that also had a type constraint for either google_asn1.ObjectIdentifier or asn1.ObjectIdentifier, could we use that and then remove the separate case statements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same as above- would it be preferable to have two separate functions for getting extension between asn1/Google or is the switch statement preferable?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is good with me, this duplication is easy to spot then in case there's a later language feature to remove the duplication.

@linus-sun linus-sun force-pushed the linussun/ct-log-identity-monitoring branch from 425f8bd to be5ee9c Compare November 18, 2024 23:15
@haydentherapper haydentherapper merged commit 55f9a4b into sigstore:main Nov 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants