VerifyCertExtensions allows us to perform case insensitive comparisons of certificate extensions
(results []*AttestationProcessingResult, ec EnforcementCriteria)
| 15 | |
| 16 | // VerifyCertExtensions allows us to perform case insensitive comparisons of certificate extensions |
| 17 | func VerifyCertExtensions(results []*AttestationProcessingResult, ec EnforcementCriteria) ([]*AttestationProcessingResult, error) { |
| 18 | if len(results) == 0 { |
| 19 | return nil, errors.New("no attestations processing results") |
| 20 | } |
| 21 | |
| 22 | verified := make([]*AttestationProcessingResult, 0, len(results)) |
| 23 | var lastErr error |
| 24 | for _, attestation := range results { |
| 25 | if err := verifyCertExtensions(*attestation.VerificationResult.Signature.Certificate, ec.Certificate); err != nil { |
| 26 | lastErr = err |
| 27 | // move onto the next attestation in the for loop if verification fails |
| 28 | continue |
| 29 | } |
| 30 | // otherwise, add the result to the results slice and increment verifyCount |
| 31 | verified = append(verified, attestation) |
| 32 | } |
| 33 | |
| 34 | // if we have exited the for loop without verifying any attestations, |
| 35 | // return the last error found |
| 36 | if len(verified) == 0 { |
| 37 | return nil, lastErr |
| 38 | } |
| 39 | |
| 40 | return verified, nil |
| 41 | } |
| 42 | |
| 43 | func verifyCertExtensions(given, expected certificate.Summary) error { |
| 44 | if !strings.EqualFold(expected.SourceRepositoryOwnerURI, given.SourceRepositoryOwnerURI) { |