| 1 | // Copyright The gittuf Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package policyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/ |
| 5 | |
| 6 | import ( |
| 7 | "contextscip-go gomod github.com/golang/go/src go1.26.0 context/" |
| 8 | "errorsscip-go gomod github.com/golang/go/src go1.26.0 errors/" |
| 9 | "fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/" |
| 10 | "log/slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/" |
| 11 | "stringsscip-go gomod github.com/golang/go/src go1.26.0 strings/" |
| 12 | |
| 13 | "github.com/gittuf/gittuf/internal/common/setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/" |
| 14 | "github.com/gittuf/gittuf/internal/signerverifier/commonscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/common`/" |
| 15 | "github.com/gittuf/gittuf/internal/signerverifier/dssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/dsse`/" |
| 16 | "github.com/gittuf/gittuf/internal/signerverifier/gpgscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/gpg`/" |
| 17 | "github.com/gittuf/gittuf/internal/signerverifier/sigstorescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/" |
| 18 | sigstoreverifieroptsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/ "github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/" |
| 19 | "github.com/gittuf/gittuf/internal/signerverifier/sshscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/" |
| 20 | sslibdssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/ "github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/" |
| 21 | "github.com/gittuf/gittuf/internal/tufscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/" |
| 22 | "github.com/gittuf/gittuf/pkg/gitinterfacescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/" |
| 23 | ) |
| 24 | |
| 25 | type SignatureVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier# struct { |
| 26 | repositoryscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#repository. *gitinterfacescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/.Repositoryscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Repository# |
| 27 | namescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#name. string |
| 28 | principalsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#principals. []tufscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/.Principalscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal# |
| 29 | thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#threshold. int |
| 30 | verifyExhaustivelyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#verifyExhaustively. bool // verifyExhaustively checks all possible signatures and returns all matched principals, even if threshold is already met |
| 31 | } |
| 32 | |
| 33 | func (v *SignatureVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#) Namescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#Name().() string { |
| 34 | return v.namescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#name. |
| 35 | } |
| 36 | |
| 37 | func (v *SignatureVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#) Thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#Threshold().() int { |
| 38 | return v.thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#threshold. |
| 39 | } |
| 40 | |
| 41 | func (v *SignatureVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#) TrustedPrincipalIDsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#TrustedPrincipalIDs().() *setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/.Setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#[string] { |
| 42 | principalIDs := setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/.NewSetscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/NewSet().[string]() |
| 43 | for _, principal := range v.principalsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#principals. { |
| 44 | principalIDs.Addscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Add().(principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.()) |
| 45 | } |
| 46 | |
| 47 | return principalIDs |
| 48 | } |
| 49 | |
| 50 | // Verify is used to check for a threshold of signatures using the verifier. The |
| 51 | // threshold of signatures may be met using a combination of at most one Git |
| 52 | // signature and signatures embedded in a DSSE envelope. Verify does not inspect |
| 53 | // the envelope's payload, but instead only verifies the signatures. The caller |
| 54 | // must ensure the validity of the envelope's contents. |
| 55 | func (v *SignatureVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#) Verifyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#Verify().(ctx contextscip-go gomod github.com/golang/go/src go1.26.0 context/.Contextscip-go gomod github.com/golang/go/src go1.26.0 context/Context#, gitObjectID gitinterfacescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/.Hashscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Hash#, env *sslibdssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/.Envelopescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#) (*setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/.Setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#[string], error) { |
| 56 | if v.thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#threshold. < 1 || len(v.principalsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#principals.) < 1 { |
| 57 | return nil, ErrInvalidVerifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/ErrInvalidVerifier. |
| 58 | } |
| 59 | |
| 60 | // usedPrincipalIDs is ultimately returned to track the set of principals |
| 61 | // who have been authenticated |
| 62 | usedPrincipalIDs := setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/.NewSetscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/NewSet().[string]() |
| 63 | |
| 64 | // usedKeyIDs is tracked to ensure a key isn't duplicated between two |
| 65 | // principals, allowing two principals to meet a threshold using the same |
| 66 | // key |
| 67 | usedKeyIDs := setscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/.NewSetscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/NewSet().[string]() |
| 68 | |
| 69 | // gitObjectVerified is set to true if the gitObjectID's signature is |
| 70 | // verified |
| 71 | gitObjectVerified := false |
| 72 | |
| 73 | // First, verify the gitObject's signature if one is presented |
| 74 | if gitObjectID != nil && !gitObjectID.IsZeroscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Hash#IsZero().() { |
| 75 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Verifying signature of Git object with ID '%s'...", gitObjectID.Stringscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Hash#String().())) |
| 76 | for _, principal := range v.principalsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#principals. { |
| 77 | // there are multiple keys we must try |
| 78 | keys := principal.Keysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#Keys.() |
| 79 | |
| 80 | for _, key := range keys { |
| 81 | err := v.repositoryscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#repository..VerifySignaturescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Repository#VerifySignature().(ctx, gitObjectID, key) |
| 82 | if err == nil { |
| 83 | // Signature verification succeeded |
| 84 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Public key '%s' belonging to principal '%s' successfully used to verify signature of Git object '%s', counting '%s' towards threshold...", key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID., principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.(), gitObjectID.Stringscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Hash#String().(), principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.())) |
| 85 | usedPrincipalIDs.Addscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Add().(principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.()) |
| 86 | usedKeyIDs.Addscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Add().(key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.) |
| 87 | gitObjectVerified = true |
| 88 | |
| 89 | // No need to try the other keys for this principal, break |
| 90 | break |
| 91 | } |
| 92 | if errorsscip-go gomod github.com/golang/go/src go1.26.0 errors/.Isscip-go gomod github.com/golang/go/src go1.26.0 errors/Is().(err, gitinterfacescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/.ErrUnknownSigningMethodscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/ErrUnknownSigningMethod.) { |
| 93 | // TODO: this should be removed once we have unified signing |
| 94 | // methods across metadata and git signatures |
| 95 | continue |
| 96 | } |
| 97 | if !errorsscip-go gomod github.com/golang/go/src go1.26.0 errors/.Isscip-go gomod github.com/golang/go/src go1.26.0 errors/Is().(err, gitinterfacescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/.ErrIncorrectVerificationKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/ErrIncorrectVerificationKey.) { |
| 98 | return nil, err |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if gitObjectVerified { |
| 103 | // No need to try other principals, break |
| 104 | break |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // If we don't have to verify exhaustively and threshold is 1 and the Git |
| 110 | // signature is verified, we can return |
| 111 | if !v.verifyExhaustivelyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#verifyExhaustively. && v.thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#threshold. == 1 && gitObjectVerified { |
| 112 | return usedPrincipalIDs, nil |
| 113 | } |
| 114 | |
| 115 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().("Proceeding with verification of attestations...") |
| 116 | |
| 117 | if env != nil { |
| 118 | // Second, verify signatures on the envelope |
| 119 | |
| 120 | // We have to verify the envelope independently for each principal |
| 121 | // trusted in the verifier as a principal may have multiple keys |
| 122 | // associated with them. |
| 123 | for _, principal := range v.principalsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#principals. { |
| 124 | if usedPrincipalIDs.Hasscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Has().(principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.()) { |
| 125 | // Do not verify using this principal as they were verified for |
| 126 | // the Git signature |
| 127 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Principal '%s' has already been counted towards the threshold, skipping...", principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.())) |
| 128 | continue |
| 129 | } |
| 130 | |
| 131 | principalVerifiers := []sslibdssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/.Verifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Verifier#{} |
| 132 | |
| 133 | keys := principal.Keysscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#Keys.() |
| 134 | for _, key := range keys { |
| 135 | if usedKeyIDs.Hasscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Has().(key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.) { |
| 136 | // this key has been encountered before, possibly because |
| 137 | // another Principal included this key |
| 138 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Key with ID '%s' has already been used to verify a signature, skipping...", key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.)) |
| 139 | continue |
| 140 | } |
| 141 | |
| 142 | var ( |
| 143 | dsseVerifier sslibdssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/.Verifierscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Verifier# |
| 144 | err error |
| 145 | ) |
| 146 | switch key.KeyTypescip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyType. { |
| 147 | case sshscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/.KeyTypescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/KeyType.: |
| 148 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Found SSH key '%s'...", key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.)) |
| 149 | dsseVerifier, err = sshscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/.NewVerifierFromKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/ssh`/NewVerifierFromKey().(key) |
| 150 | if err != nil { |
| 151 | return nil, err |
| 152 | } |
| 153 | case gpgscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/gpg`/.KeyTypescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/gpg`/KeyType.: |
| 154 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Found GPG key '%s'...", key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.)) |
| 155 | dsseVerifier, err = gpgscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/gpg`/.NewVerifierFromKeyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/gpg`/NewVerifierFromKey().(key) |
| 156 | if err != nil { |
| 157 | return nil, err |
| 158 | } |
| 159 | case sigstorescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/.KeyTypescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/KeyType.: |
| 160 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Found Sigstore key '%s'...", key.KeyIDscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyID.)) |
| 161 | opts := []sigstoreverifieroptsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/.Optionscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/Option#{} |
| 162 | config, err := v.repositoryscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#repository..GetGitConfigscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/pkg/gitinterface`/Repository#GetGitConfig().() |
| 163 | if err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | if rekorURL, has := config[sigstorescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/.GitConfigRekorscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/GitConfigRekor.]; has { |
| 167 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Using '%s' as Rekor server...", rekorURL)) |
| 168 | opts = append(opts, sigstoreverifieroptsscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/.WithRekorURLscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore/options/verifier`/WithRekorURL().(rekorURL)) |
| 169 | } |
| 170 | |
| 171 | dsseVerifier = sigstorescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/.NewVerifierFromIdentityAndIssuerscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/sigstore`/NewVerifierFromIdentityAndIssuer().(key.KeyValscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyVal..Identityscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/KeyVal#Identity., key.KeyValscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/SSLibKey#KeyVal..Issuerscip-go gomod github.com/secure-systems-lab/go-securesystemslib v0.11.0 `github.com/secure-systems-lab/go-securesystemslib/signerverifier`/KeyVal#Issuer., opts...) |
| 172 | default: |
| 173 | return nil, commonscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/common`/.ErrUnknownKeyTypescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/common`/ErrUnknownKeyType. |
| 174 | } |
| 175 | |
| 176 | principalVerifiers = append(principalVerifiers, dsseVerifier) |
| 177 | } |
| 178 | |
| 179 | // We have the principal's verifiers: use that to verify the envelope |
| 180 | if len(principalVerifiers) == 0 { |
| 181 | // TODO: remove this when we have signing method unification |
| 182 | // across git and dsse |
| 183 | continue |
| 184 | } |
| 185 | |
| 186 | // We set threshold to 1 as we only need one of the keys for this |
| 187 | // principal to be matched. If more than one key is matched and |
| 188 | // returned in acceptedKeys, we count this only once towards the |
| 189 | // principal and therefore the verifier's threshold. However, for |
| 190 | // safety, we count both keys. If two principals share keys, this |
| 191 | // can lead to a problem meeting thresholds. Arguably, they |
| 192 | // shouldn't be sharing keys, so this seems reasonable. |
| 193 | acceptedKeys, err := dssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/dsse`/.VerifyEnvelopescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/signerverifier/dsse`/VerifyEnvelope().(ctx, env, principalVerifiers, 1) |
| 194 | if err != nil && !stringsscip-go gomod github.com/golang/go/src go1.26.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.26.0 strings/Contains().(err.Error(), "accepted signatures do not match threshold") { |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | for _, key := range acceptedKeys { |
| 199 | // Mark all accepted keys as used: this doesn't count towards |
| 200 | // the threshold directly, but if another principal has the same |
| 201 | // key, they may not be counted towards the threshold |
| 202 | slogscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.26.0 `log/slog`/Debug().(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("Public key '%s' belonging to principal '%s' successfully used to verify signature of attestation, counting '%s' towards threshold...", key.KeyIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/AcceptedKey#KeyID., principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.(), principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.())) |
| 203 | usedKeyIDs.Addscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Add().(key.KeyIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/AcceptedKey#KeyID.) |
| 204 | usedPrincipalIDs.Addscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Add().(principal.IDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/tuf`/Principal#ID.()) |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if v.verifyExhaustivelyscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#verifyExhaustively. || usedPrincipalIDs.Lenscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/common/set`/Set#Len().() >= v.Thresholdscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/SignatureVerifier#Threshold().() { |
| 210 | // TODO: double check that this is okay! |
| 211 | return usedPrincipalIDs, nil |
| 212 | } |
| 213 | |
| 214 | // Return usedPrincipalIDs so the consumer can decide what to do with the |
| 215 | // principals that were used |
| 216 | return usedPrincipalIDs, ErrVerifierConditionsUnmetscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/policy`/ErrVerifierConditionsUnmet. |
| 217 | } |