@@ -43,7 +43,8 @@ func (ev *envelopeVerifier) Verify(e *Envelope) ([]AcceptedKeys, error) {
43
43
paeEnc := PAE (e .PayloadType , string (body ))
44
44
45
45
// If *any* signature is found to be incorrect, it is skipped
46
- var accepted_keys []AcceptedKeys
46
+ var acceptedKeys []AcceptedKeys
47
+ usedKeyids := make (map [string ]string )
47
48
for _ , s := range e .Signatures {
48
49
sig , err := b64Decode (s .Sig )
49
50
if err != nil {
@@ -74,15 +75,27 @@ func (ev *envelopeVerifier) Verify(e *Envelope) ([]AcceptedKeys, error) {
74
75
Sig : s ,
75
76
}
76
77
77
- accepted_keys = append (accepted_keys , acceptedKey )
78
+ // See https://github.com/in-toto/in-toto/pull/251
79
+ if val , ok := usedKeyids [keyID ]; ok {
80
+ fmt .Printf ("Found envelope signed by different subkeys of the same main key, Only one of them is counted towards the step threshold, KeyID=%s\n " , val )
81
+ }
82
+
83
+ usedKeyids [keyID ] = ""
84
+ acceptedKeys = append (acceptedKeys , acceptedKey )
78
85
break
79
86
}
80
87
}
81
- if len (accepted_keys ) < ev .threshold {
82
- return accepted_keys , errors .New (fmt .Sprintf ("Accepted signitures do not match threshold, Found: %d, Expected %d" , len (accepted_keys ), ev .threshold ))
88
+
89
+ // Sanity if with some reflect magic this happens.
90
+ if ev .threshold <= 0 || ev .threshold > len (ev .providers ) {
91
+ return nil , errors .New ("Invalid threshold" )
92
+ }
93
+
94
+ if len (usedKeyids ) < ev .threshold {
95
+ return acceptedKeys , errors .New (fmt .Sprintf ("Accepted signitures do not match threshold, Found: %d, Expected %d" , len (acceptedKeys ), ev .threshold ))
83
96
}
84
97
85
- return accepted_keys , nil
98
+ return acceptedKeys , nil
86
99
}
87
100
88
101
func NewEnvelopeVerifier (v ... Verifier ) (* envelopeVerifier , error ) {
0 commit comments