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

Function createCustomVerifiers

pkg/cmd/attestation/verification/sigstore.go:103–186  ·  view source on GitHub ↗
(trustedRoot string, noPublicGood bool)

Source from the content-addressed store, hash-verified

101}
102
103func createCustomVerifiers(trustedRoot string, noPublicGood bool) (map[string]*verify.Verifier, error) {
104 customTrustRoots, err := os.ReadFile(trustedRoot)
105 if err != nil {
106 return nil, fmt.Errorf("unable to read file %s: %v", trustedRoot, err)
107 }
108
109 verifiers := make(map[string]*verify.Verifier)
110 reader := bufio.NewReader(bytes.NewReader(customTrustRoots))
111 var line []byte
112 var readError error
113 line, readError = reader.ReadBytes('\n')
114 for readError == nil {
115 // Load each trusted root
116 trustedRoot, err := root.NewTrustedRootFromJSON(line)
117 if err != nil {
118 return nil, fmt.Errorf("failed to create custom verifier: %v", err)
119 }
120
121 // Compare bundle leafCert issuer with trusted root cert authority
122 certAuthorities := trustedRoot.FulcioCertificateAuthorities()
123 for _, certAuthority := range certAuthorities {
124 fulcioCertAuthority, ok := certAuthority.(*root.FulcioCertificateAuthority)
125 if !ok {
126 return nil, fmt.Errorf("trusted root cert authority is not a FulcioCertificateAuthority")
127 }
128 lowestCert, err := getLowestCertInChain(fulcioCertAuthority)
129 if err != nil {
130 return nil, err
131 }
132
133 // if the custom trusted root issuer is not set, skip it
134 if len(lowestCert.Issuer.Organization) == 0 {
135 continue
136 }
137 issuer := lowestCert.Issuer.Organization[0]
138
139 // Determine what policy to use with this trusted root.
140 //
141 // Note that we are *only* inferring the policy with the
142 // issuer. We *must* use the trusted root provided.
143 switch issuer {
144 case PublicGoodIssuerOrg:
145 if noPublicGood {
146 return nil, fmt.Errorf("detected public good instance but requested verification without public good instance")
147 }
148 if _, ok := verifiers[PublicGoodIssuerOrg]; ok {
149 // we have already created a public good verifier with this custom trusted root
150 // so we skip it
151 continue
152 }
153 publicGood, err := newPublicGoodVerifierWithTrustedRoot(trustedRoot)
154 if err != nil {
155 return nil, err
156 }
157 verifiers[PublicGoodIssuerOrg] = publicGood
158 case GitHubIssuerOrg:
159 if _, ok := verifiers[GitHubIssuerOrg]; ok {
160 // we have already created a github verifier with this custom trusted root

Callers 1

NewLiveSigstoreVerifierFunction · 0.85

Calls 5

getLowestCertInChainFunction · 0.85
newCustomVerifierFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected