@@ -25,39 +25,40 @@ const maxAllowedTimestamps = 32
25
25
26
26
// VerifyTimestampAuthority verifies that the given entity has been timestamped
27
27
// by a trusted timestamp authority and that the timestamp is valid.
28
- func VerifyTimestampAuthority (entity SignedEntity , trustedMaterial root.TrustedMaterial ) ([]* root.Timestamp , error ) { //nolint:revive
28
+ func VerifyTimestampAuthority (entity SignedEntity , trustedMaterial root.TrustedMaterial ) ([]* root.Timestamp , [] error , error ) { //nolint:revive
29
29
signedTimestamps , err := entity .Timestamps ()
30
30
if err != nil {
31
- return nil , err
31
+ return nil , nil , err
32
32
}
33
33
34
34
// limit the number of timestamps to prevent DoS
35
35
if len (signedTimestamps ) > maxAllowedTimestamps {
36
- return nil , fmt .Errorf ("too many signed timestamps: %d > %d" , len (signedTimestamps ), maxAllowedTimestamps )
36
+ return nil , nil , fmt .Errorf ("too many signed timestamps: %d > %d" , len (signedTimestamps ), maxAllowedTimestamps )
37
37
}
38
38
sigContent , err := entity .SignatureContent ()
39
39
if err != nil {
40
- return nil , err
40
+ return nil , nil , err
41
41
}
42
42
43
43
signatureBytes := sigContent .Signature ()
44
44
45
45
verifiedTimestamps := []* root.Timestamp {}
46
+ var verificationErrors []error
46
47
for _ , timestamp := range signedTimestamps {
47
48
verifiedSignedTimestamp , err := verifySignedTimestamp (timestamp , signatureBytes , trustedMaterial )
48
49
if err != nil {
50
+ verificationErrors = append (verificationErrors , err )
49
51
continue
50
52
}
51
53
if isDuplicateTSA (verifiedTimestamps , verifiedSignedTimestamp ) {
52
- // TODO: add below error to `errs` when #325 is merged, and continue
53
- // (https://github.com/sigstore/sigstore-go/issues/325)
54
- return verifiedTimestamps , fmt .Errorf ("duplicate timestamps from the same authority, ignoring %s" , verifiedSignedTimestamp .URI )
54
+ verificationErrors = append (verificationErrors , fmt .Errorf ("duplicate timestamps from the same authority, ignoring %s" , verifiedSignedTimestamp .URI ))
55
+ continue
55
56
}
56
57
57
58
verifiedTimestamps = append (verifiedTimestamps , verifiedSignedTimestamp )
58
59
}
59
60
60
- return verifiedTimestamps , nil
61
+ return verifiedTimestamps , verificationErrors , err
61
62
}
62
63
63
64
// isDuplicateTSA checks if the given verified signed timestamp is a duplicate
@@ -79,26 +80,29 @@ func isDuplicateTSA(verifiedTimestamps []*root.Timestamp, verifiedSignedTimestam
79
80
// The threshold parameter is the number of unique timestamps that must be
80
81
// verified.
81
82
func VerifyTimestampAuthorityWithThreshold (entity SignedEntity , trustedMaterial root.TrustedMaterial , threshold int ) ([]* root.Timestamp , error ) { //nolint:revive
82
- verifiedTimestamps , err := VerifyTimestampAuthority (entity , trustedMaterial )
83
+ verifiedTimestamps , verificationErrors , err := VerifyTimestampAuthority (entity , trustedMaterial )
83
84
if err != nil {
84
85
return nil , err
85
86
}
86
87
if len (verifiedTimestamps ) < threshold {
87
- return nil , fmt .Errorf ("threshold not met for verified signed timestamps: %d < %d" , len (verifiedTimestamps ), threshold )
88
+ return nil , fmt .Errorf ("threshold not met for verified signed timestamps: %d < %d; error: %w " , len (verifiedTimestamps ), threshold , errors . Join ( verificationErrors ... ) )
88
89
}
89
90
return verifiedTimestamps , nil
90
91
}
91
92
92
93
func verifySignedTimestamp (signedTimestamp []byte , signatureBytes []byte , trustedMaterial root.TrustedMaterial ) (* root.Timestamp , error ) {
93
94
timestampAuthorities := trustedMaterial .TimestampingAuthorities ()
94
95
96
+ var errs []error
97
+
95
98
// Iterate through TSA certificate authorities to find one that verifies
96
99
for _ , tsa := range timestampAuthorities {
97
100
ts , err := tsa .Verify (signedTimestamp , signatureBytes )
98
101
if err == nil {
99
102
return ts , nil
100
103
}
104
+ errs = append (errs , err )
101
105
}
102
106
103
- return nil , errors . New ("unable to verify signed timestamps" )
107
+ return nil , fmt . Errorf ("unable to verify signed timestamps: %w" , errors . Join ( errs ... ) )
104
108
}
0 commit comments