Skip to content

Commit

Permalink
threaded options into policy validation functionary
Browse files Browse the repository at this point in the history
Signed-off-by: chaosinthecrd <[email protected]>
  • Loading branch information
ChaosInTheCRD committed Jan 29, 2024
1 parent f7947b4 commit 3e44fe0
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type verifyOptions struct {
policyTimestampAuthorities []timestamp.TimestampVerifier
policyCARoots []*x509.Certificate
policyCAIntermediates []*x509.Certificate
policyCommonName string
policyDNSNames []string
policyEmails []string
policyOrganizations []string
policyURIs []string
policyEnvelope dsse.Envelope
policyVerifiers []cryptoutil.Verifier
collectionSource source.Sourcer
Expand Down Expand Up @@ -87,6 +92,16 @@ func VerifyWithPolicyCAIntermediates(intermediates []*x509.Certificate) VerifyOp
}
}

func VerifyWithPolicyCertConstraints(commonName string, dnsNames []string, emails []string, organizations []string, uris []string) VerifyOption {
return func(vo *verifyOptions) {
vo.policyCommonName = commonName
vo.policyDNSNames = dnsNames
vo.policyEmails = emails
vo.policyOrganizations = organizations
vo.policyURIs = uris
}
}

// Verify verifies a set of attestations against a provided policy. The set of attestations that satisfy the policy will be returned
// if verifiation is successful.
func Verify(ctx context.Context, policyEnvelope dsse.Envelope, policyVerifiers []cryptoutil.Verifier, opts ...VerifyOption) (map[string][]source.VerifiedCollection, error) {
Expand Down Expand Up @@ -187,8 +202,12 @@ func verifyPolicySignature(ctx context.Context, vo verifyOptions) error {
f = policy.Functionary{
Type: "root",
CertConstraint: policy.CertConstraint{
Roots: rootIDs,
CommonName: "*",
Roots: rootIDs,
CommonName: vo.policyCommonName,
URIs: vo.policyURIs,
Emails: vo.policyEmails,
Organizations: vo.policyOrganizations,
DNSNames: vo.policyDNSNames,
},
}
} else {
Expand All @@ -200,7 +219,7 @@ func verifyPolicySignature(ctx context.Context, vo verifyOptions) error {

err = f.Validate(verifier.Verifier, trustBundle)
if err != nil {
log.Debugf("Policy Verifier %s failed failed to match supplied constraints: %w, continuing...", err, kid)
log.Debugf("Policy Verifier %s failed failed to match supplied constraints: %w, continuing...", kid, err)
continue
}
passed = true
Expand Down

0 comments on commit 3e44fe0

Please sign in to comment.