-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix cert chain validation for verify-blob in non-experimental mo…
…de (#2256) * fix!: fix cert chain validation for verify-blob in non-experimental mode (#2256) Signed-off-by: Asra Ali <[email protected]>
- Loading branch information
Showing
2 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,7 +434,6 @@ func TestVerifyBlob(t *testing.T) { | |
experimental: false, | ||
shouldErr: true, | ||
}, | ||
|
||
{ | ||
name: "valid signature with expired certificate - experimental good rekor lookup", | ||
blob: blobBytes, | ||
|
@@ -446,7 +445,6 @@ func TestVerifyBlob(t *testing.T) { | |
expiredLeafPem, true), | ||
shouldErr: false, | ||
}, | ||
|
||
{ | ||
name: "valid signature with expired certificate - experimental bad rekor integrated time", | ||
blob: blobBytes, | ||
|
@@ -957,6 +955,166 @@ func TestVerifyBlobCmdWithBundle(t *testing.T) { | |
t.Fatalf("expected error with mismatched issuer, got %v", err) | ||
} | ||
}) | ||
t.Run("Implicit Fulcio chain with bundle in non-experimental mode", func(t *testing.T) { | ||
identity := "[email protected]" | ||
issuer := "issuer" | ||
leafCert, _, leafPemCert, signer := keyless.genLeafCert(t, identity, issuer) | ||
|
||
// Create blob | ||
blob := "someblob" | ||
|
||
// Sign blob with private key | ||
sig, err := signer.SignMessage(bytes.NewReader([]byte(blob))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create bundle | ||
entry := genRekorEntry(t, hashedrekord.KIND, hashedrekord.New().DefaultVersion(), []byte(blob), leafPemCert, sig) | ||
b := createBundle(t, sig, leafPemCert, keyless.rekorLogID, leafCert.NotBefore.Unix()+1, entry) | ||
b.Bundle.SignedEntryTimestamp = keyless.rekorSignPayload(t, b.Bundle.Payload) | ||
bundlePath := writeBundleFile(t, keyless.td, b, "bundle.json") | ||
blobPath := writeBlobFile(t, keyless.td, blob, "blob.txt") | ||
certPath := writeBlobFile(t, keyless.td, string(leafPemCert), "cert.pem") | ||
|
||
// Verify command | ||
err = VerifyBlobCmd(context.Background(), | ||
options.KeyOpts{BundlePath: bundlePath}, | ||
certPath, /*certRef*/ | ||
identity, /*certEmail*/ | ||
issuer, /*certOidcIssuer*/ | ||
"", /*certChain*/ // Chain is fetched from TUF/SIGSTORE_ROOT_FILE | ||
"", /*sigRef*/ // Sig is fetched from bundle | ||
blobPath, /*blobRef*/ | ||
// GitHub identity flags start | ||
"", "", "", "", "", | ||
// GitHub identity flags end | ||
false /*enforceSCT*/) | ||
if err != nil { | ||
t.Fatalf("expected success without specifying the intermediates, got %v", err) | ||
} | ||
}) | ||
t.Run("Explicit Fulcio chain with bundle in non-experimental mode", func(t *testing.T) { | ||
identity := "[email protected]" | ||
issuer := "issuer" | ||
leafCert, _, leafPemCert, signer := keyless.genLeafCert(t, identity, issuer) | ||
|
||
// Create blob | ||
blob := "someblob" | ||
|
||
// Sign blob with private key | ||
sig, err := signer.SignMessage(bytes.NewReader([]byte(blob))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create bundle | ||
entry := genRekorEntry(t, hashedrekord.KIND, hashedrekord.New().DefaultVersion(), []byte(blob), leafPemCert, sig) | ||
b := createBundle(t, sig, leafPemCert, keyless.rekorLogID, leafCert.NotBefore.Unix()+1, entry) | ||
b.Bundle.SignedEntryTimestamp = keyless.rekorSignPayload(t, b.Bundle.Payload) | ||
bundlePath := writeBundleFile(t, keyless.td, b, "bundle.json") | ||
blobPath := writeBlobFile(t, keyless.td, blob, "blob.txt") | ||
|
||
// Verify command | ||
err = VerifyBlobCmd(context.Background(), | ||
options.KeyOpts{BundlePath: bundlePath}, | ||
"", /*certRef*/ | ||
identity, /*certEmail*/ | ||
issuer, /*certOidcIssuer*/ | ||
os.Getenv("SIGSTORE_ROOT_FILE"), /*certChain*/ | ||
"", /*sigRef*/ // Sig is fetched from bundle | ||
blobPath, /*blobRef*/ | ||
// GitHub identity flags start | ||
"", "", "", "", "", | ||
// GitHub identity flags end | ||
false /*enforceSCT*/) | ||
if err != nil { | ||
t.Fatalf("expected success specifying the intermediates, got %v", err) | ||
} | ||
}) | ||
} | ||
|
||
func TestVerifyBlobCmdInvalidRootCA(t *testing.T) { | ||
keyless := newKeylessStack(t) | ||
// Change the keyless stack. | ||
_ = newKeylessStack(t) | ||
t.Run("Invalid certificate root when specifying cert via certRef", func(t *testing.T) { | ||
identity := "[email protected]" | ||
issuer := "issuer" | ||
leafCert, _, leafPemCert, signer := keyless.genLeafCert(t, identity, issuer) | ||
|
||
// Create blob | ||
blob := "someblob" | ||
|
||
// Sign blob with private key | ||
sig, err := signer.SignMessage(bytes.NewReader([]byte(blob))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create bundle | ||
entry := genRekorEntry(t, hashedrekord.KIND, hashedrekord.New().DefaultVersion(), []byte(blob), leafPemCert, sig) | ||
b := createBundle(t, sig, leafPemCert, keyless.rekorLogID, leafCert.NotBefore.Unix()+1, entry) | ||
b.Bundle.SignedEntryTimestamp = keyless.rekorSignPayload(t, b.Bundle.Payload) | ||
bundlePath := writeBundleFile(t, keyless.td, b, "bundle.json") | ||
blobPath := writeBlobFile(t, keyless.td, blob, "blob.txt") | ||
certPath := writeBlobFile(t, keyless.td, string(leafPemCert), "cert.pem") | ||
|
||
// Verify command | ||
err = VerifyBlobCmd(context.Background(), | ||
options.KeyOpts{BundlePath: bundlePath}, | ||
certPath, /*certRef*/ | ||
identity, /*certEmail*/ | ||
issuer, /*certOidcIssuer*/ | ||
"", /*certChain*/ // Chain is fetched from TUF/SIGSTORE_ROOT_FILE | ||
"", /*sigRef*/ // Sig is fetched from bundle | ||
blobPath, /*blobRef*/ | ||
// GitHub identity flags start | ||
"", "", "", "", "", | ||
// GitHub identity flags end | ||
false /*enforceSCT*/) | ||
if err == nil || !strings.Contains(err.Error(), "certificate signed by unknown authority") { | ||
t.Fatalf("expected error with invalid root CA, got %v", err) | ||
} | ||
}) | ||
t.Run("Invalid certificate root when specifying cert in bundle", func(t *testing.T) { | ||
identity := "[email protected]" | ||
issuer := "issuer" | ||
leafCert, _, leafPemCert, signer := keyless.genLeafCert(t, identity, issuer) | ||
|
||
// Create blob | ||
blob := "someblob" | ||
|
||
// Sign blob with private key | ||
sig, err := signer.SignMessage(bytes.NewReader([]byte(blob))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Create bundle | ||
entry := genRekorEntry(t, hashedrekord.KIND, hashedrekord.New().DefaultVersion(), []byte(blob), leafPemCert, sig) | ||
b := createBundle(t, sig, leafPemCert, keyless.rekorLogID, leafCert.NotBefore.Unix()+1, entry) | ||
b.Bundle.SignedEntryTimestamp = keyless.rekorSignPayload(t, b.Bundle.Payload) | ||
bundlePath := writeBundleFile(t, keyless.td, b, "bundle.json") | ||
blobPath := writeBlobFile(t, keyless.td, blob, "blob.txt") | ||
|
||
// Verify command | ||
err = VerifyBlobCmd(context.Background(), | ||
options.KeyOpts{BundlePath: bundlePath}, | ||
"", /*certRef*/ // Fetched from bundle | ||
identity, /*certEmail*/ | ||
issuer, /*certOidcIssuer*/ | ||
"", /*certChain*/ // Chain is fetched from TUF/SIGSTORE_ROOT_FILE | ||
"", /*sigRef*/ // Sig is fetched from bundle | ||
blobPath, /*blobRef*/ | ||
// GitHub identity flags start | ||
"", "", "", "", "", | ||
// GitHub identity flags end | ||
false /*enforceSCT*/) | ||
if err == nil || !strings.Contains(err.Error(), "certificate signed by unknown authority") { | ||
t.Fatalf("expected error with invalid root CA, got %v", err) | ||
} | ||
}) | ||
} | ||
|
||
type keylessStack struct { | ||
|