Skip to content

Commit 17f7958

Browse files
fix: fix method for getting leaf certs in Bundle v0.3 (#813)
Followup to slsa-framework/slsa-github-generator#3777 This PR adds a missing modification for getting the leaf certificate in the new Bundle format v0.3. In my original experiments, I did have this method in a dev branch, but neglected to include it in the final PR. - main...verify-sigstore-go-Bundlev3#diff-a9bfffae1bd0d145e950805e7a35b8e65adc7a68affa605b484f4831097b989cR98-R107 - https://github.com/slsa-framework/slsa-verifier/pull/799/files ## Testing - I re-used the same attestation file from a failing workflow for unit tests and manual invocation. - https://github.com/slsa-framework/example-package/actions/runs/11511156484 ## Followup - Finish finding a way to test changes within PRs. - slsa-framework/slsa-github-generator#3777 (comment) - #797 --------- Signed-off-by: Ramon Petgrave <[email protected]>
1 parent 70f3c9a commit 17f7958

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

verifiers/internal/gha/bundle.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,23 @@ func getEnvelopeFromBundleBytes(content []byte) (*dsselib.Envelope, error) {
9999

100100
// getLeafCertFromBundle extracts the signing cert from the Sigstore bundle.
101101
func getLeafCertFromBundle(bundle *bundle_v1.Bundle) (*x509.Certificate, error) {
102+
// Originally, there could be multiple certificates, accessed by `.GetX509CertificateChain().GetCertificates()`.
103+
// As of v0.3 of the protos, only a single certificate is in the Bundle's VerificationMaterial,
104+
// and it's access by the auto-generated `GetCertificate()`
105+
// We keep both methods for backwards compatibility with older bundles.
106+
// See: https://github.com/sigstore/protobuf-specs/pull/191.
107+
108+
// First try the newer method.
109+
if bundleCert := bundle.GetVerificationMaterial().GetCertificate(); bundleCert != nil {
110+
certBytes := bundleCert.GetRawBytes()
111+
return x509.ParseCertificate(certBytes)
112+
}
113+
114+
// Otherwise, try the original method.
102115
certChain := bundle.GetVerificationMaterial().GetX509CertificateChain().GetCertificates()
103116
if len(certChain) == 0 {
104117
return nil, ErrorMissingCertInBundle
105118
}
106-
107119
// The first certificate is the leaf cert: see
108120
// https://github.com/sigstore/protobuf-specs/blob/16541696de137c6281d66d075a4924d9bbd181ff/protos/sigstore_common.proto#L170
109121
certBytes := certChain[0].GetRawBytes()

verifiers/internal/gha/bundle_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ func Test_verifyBundle(t *testing.T) {
3030
expected error
3131
}{
3232
{
33-
name: "valid bundle",
33+
name: "valid bundle: v0.1",
3434
path: "./testdata/bundle/valid.intoto.sigstore",
3535
},
36+
{
37+
name: "valid bundle: v0.3",
38+
path: "./testdata/bundle/valid-v0.3.intoto.sigstore",
39+
},
3640
{
3741
name: "mismatch rekor entry",
3842
path: "./testdata/bundle/mismatch-tlog.intoto.sigstore",

0 commit comments

Comments
 (0)