Skip to content

Commit

Permalink
Don't fail on TSA signatures we can't verify (#45)
Browse files Browse the repository at this point in the history
For #43

As long as there are enough TSA signatures that do verify to meet the
threshold specified by the verification policy.

---------

Signed-off-by: Zach Steindler <[email protected]>
  • Loading branch information
steiza authored Dec 15, 2023
1 parent 0946840 commit 9a59c7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/verify/tsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
// verified.
func VerifyTimestampAuthority(entity SignedEntity, trustedMaterial root.TrustedMaterial, threshold int) ([]time.Time, error) { //nolint:revive
signedTimestamps, err := entity.Timestamps()
if err != nil {
return nil, err
}

// disallow duplicate timestamps, as a malicious actor could use duplicates to bypass the threshold
for i := 0; i < len(signedTimestamps); i++ {
Expand All @@ -43,10 +46,6 @@ func VerifyTimestampAuthority(entity SignedEntity, trustedMaterial root.TrustedM
}
}

if err != nil || (len(signedTimestamps) < threshold) {
return nil, fmt.Errorf("not enough signed timestamps: %d < %d", len(signedTimestamps), threshold)
}

sigContent, err := entity.SignatureContent()
if err != nil {
return nil, err
Expand All @@ -62,11 +61,19 @@ func VerifyTimestampAuthority(entity SignedEntity, trustedMaterial root.TrustedM
verifiedTimestamps := []time.Time{}
for _, timestamp := range signedTimestamps {
verifiedSignedTimestamp, err := verifySignedTimestamp(timestamp, signatureBytes, trustedMaterial, verificationContent)

// Timestamps from unknown source are okay, but don't count as verified
if err != nil {
return nil, errors.New("unable to verify timestamp")
continue
}

verifiedTimestamps = append(verifiedTimestamps, verifiedSignedTimestamp)
}

if len(verifiedTimestamps) < threshold {
return nil, fmt.Errorf("not enough verified timestamps: %d < %d", len(verifiedTimestamps), threshold)
}

return verifiedTimestamps, nil
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/verify/tsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ func TestTimestampAuthorityVerifier(t *testing.T) {

_, err = verify.VerifyTimestampAuthority(entity, virtualSigstore2, 1)
assert.Error(t, err) // different sigstore instance should fail to verify

untrustedEntity, err := virtualSigstore2.Attest("[email protected]", "issuer", []byte("statement"))
assert.NoError(t, err)

_, err = verify.VerifyTimestampAuthority(&oneTrustedOneUntrustedTimestampEntity{entity, untrustedEntity}, virtualSigstore, 1)
assert.NoError(t, err)

_, err = verify.VerifyTimestampAuthority(&oneTrustedOneUntrustedTimestampEntity{entity, untrustedEntity}, virtualSigstore, 2)
assert.Error(t, err) // only 1 trusted should not meet threshold of 2
}

type oneTrustedOneUntrustedTimestampEntity struct {
*ca.TestEntity
UntrustedTestEntity *ca.TestEntity
}

func (e *oneTrustedOneUntrustedTimestampEntity) Timestamps() ([][]byte, error) {
timestamps, err := e.TestEntity.Timestamps()
if err != nil {
return nil, err
}

untrustedTimestamps, err := e.UntrustedTestEntity.Timestamps()
if err != nil {
return nil, err
}

return append(timestamps, untrustedTimestamps...), nil
}

type dupTimestampEntity struct {
Expand Down

0 comments on commit 9a59c7f

Please sign in to comment.