MCPcopy Create free account
hub / github.com/cli/cli / verifyCertExtensions

Function verifyCertExtensions

pkg/cmd/attestation/verification/extensions.go:43–74  ·  view source on GitHub ↗
(given, expected certificate.Summary)

Source from the content-addressed store, hash-verified

41}
42
43func verifyCertExtensions(given, expected certificate.Summary) error {
44 if !strings.EqualFold(expected.SourceRepositoryOwnerURI, given.SourceRepositoryOwnerURI) {
45 return fmt.Errorf("expected SourceRepositoryOwnerURI to be %s, got %s", expected.SourceRepositoryOwnerURI, given.SourceRepositoryOwnerURI)
46 }
47
48 // if repo is set, compare the SourceRepositoryURI fields
49 if expected.SourceRepositoryURI != "" && !strings.EqualFold(expected.SourceRepositoryURI, given.SourceRepositoryURI) {
50 return fmt.Errorf("expected SourceRepositoryURI to be %s, got %s", expected.SourceRepositoryURI, given.SourceRepositoryURI)
51 }
52
53 // compare the OIDC issuers. If not equal, return an error depending
54 // on if there is a partial match
55 if !strings.EqualFold(expected.Issuer, given.Issuer) {
56 if strings.Index(given.Issuer, expected.Issuer+"/") == 0 {
57 return fmt.Errorf("expected Issuer to be %s, got %s -- if you have a custom OIDC issuer policy for your enterprise, use the --cert-oidc-issuer flag with your expected issuer", expected.Issuer, given.Issuer)
58 }
59 return fmt.Errorf("expected Issuer to be %s, got %s", expected.Issuer, given.Issuer)
60 }
61
62 if expected.BuildSignerDigest != "" && !strings.EqualFold(expected.BuildSignerDigest, given.BuildSignerDigest) {
63 return fmt.Errorf("expected BuildSignerDigest to be %s, got %s", expected.BuildSignerDigest, given.BuildSignerDigest)
64 }
65 if expected.SourceRepositoryDigest != "" && !strings.EqualFold(expected.SourceRepositoryDigest, given.SourceRepositoryDigest) {
66 return fmt.Errorf("expected SourceRepositoryDigest to be %s, got %s", expected.SourceRepositoryDigest, given.SourceRepositoryDigest)
67 }
68 // SourceRepositoryRef must be a case-sensitive comparison
69 if expected.SourceRepositoryRef != "" && expected.SourceRepositoryRef != given.SourceRepositoryRef {
70 return fmt.Errorf("expected SourceRepositoryRef to be %s, got %s", expected.SourceRepositoryRef, given.SourceRepositoryRef)
71 }
72
73 return nil
74}

Callers 1

VerifyCertExtensionsFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected