Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add enhanced error messages for failing verification with TUF targets #2589

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cosign/tlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func VerifyTLogEntryOffline(e *models.LogEntryAnon, rekorPubKeys *TrustedTranspa

pubKey, ok := rekorPubKeys.Keys[payload.LogID]
if !ok {
return errors.New("rekor log public key not found for payload")
return errors.New("rekor log public key not found for payload. Check your TUF root (see cosign initialize) or set a custom key with env var SIGSTORE_REKOR_PUBLIC_KEY")
}
err = VerifySET(payload, []byte(e.Verification.SignedEntryTimestamp), pubKey.PubKey.(*ecdsa.PublicKey))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ func TrustedCert(cert *x509.Certificate, roots *x509.CertPool, intermediates *x5
},
})
if err != nil {
return nil, err
return nil, fmt.Errorf("cert verification failed: %w. Check your TUF root (see cosign initialize) or set a custom root with env var SIGSTORE_ROOT_FILE", err)
}
return chains, nil
}
Expand Down
26 changes: 17 additions & 9 deletions pkg/cosign/verify_sct.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func ContainsSCT(cert []byte) (bool, error) {
return false, nil
}

func getCTPublicKey(sct *ct.SignedCertificateTimestamp,
pubKeys *TrustedTransparencyLogPubKeys) (*TransparencyLogPubKey, error) {
keyID := hex.EncodeToString(sct.LogID.KeyID[:])
pubKeyMetadata, ok := pubKeys.Keys[keyID]
if !ok {
return nil, errors.New("ctfe public key not found for payload. Check your TUF root (see cosign initialize) or set a custom key with env var SIGSTORE_CT_LOG_PUBLIC_KEY_FILE")
}
return &pubKeyMetadata, nil
}

// VerifySCT verifies SCTs against the Fulcio CT log public key.
//
// The SCT is a `Signed Certificate Timestamp`, which promises that
Expand Down Expand Up @@ -92,12 +102,11 @@ func VerifySCT(ctx context.Context, certPEM, chainPEM, rawSCT []byte, pubKeys *T
// check SCT embedded in certificate
if len(embeddedSCTs) != 0 {
for _, sct := range embeddedSCTs {
keyID := hex.EncodeToString(sct.LogID.KeyID[:])
pubKeyMetadata, ok := pubKeys.Keys[keyID]
if !ok {
return errors.New("ctfe public key not found for embedded SCT")
pubKeyMetadata, err := getCTPublicKey(sct, pubKeys)
if err != nil {
return err
}
err := ctutil.VerifySCT(pubKeyMetadata.PubKey, []*ctx509.Certificate{cert, certChain[0]}, sct, true)
err = ctutil.VerifySCT(pubKeyMetadata.PubKey, []*ctx509.Certificate{cert, certChain[0]}, sct, true)
if err != nil {
return fmt.Errorf("error verifying embedded SCT")
}
Expand All @@ -117,10 +126,9 @@ func VerifySCT(ctx context.Context, certPEM, chainPEM, rawSCT []byte, pubKeys *T
if err != nil {
return err
}
keyID := hex.EncodeToString(sct.LogID.KeyID[:])
pubKeyMetadata, ok := pubKeys.Keys[keyID]
if !ok {
return errors.New("ctfe public key not found")
pubKeyMetadata, err := getCTPublicKey(sct, pubKeys)
if err != nil {
return err
}
err = ctutil.VerifySCT(pubKeyMetadata.PubKey, []*ctx509.Certificate{cert}, sct, false)
if err != nil {
Expand Down