Skip to content

Commit 38a3e23

Browse files
committed
Harden verifiy
Signed-off-by: houdini91 <[email protected]>
1 parent 8a23c79 commit 38a3e23

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

dsse/verify.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func (ev *envelopeVerifier) Verify(e *Envelope) ([]AcceptedKeys, error) {
4343
paeEnc := PAE(e.PayloadType, string(body))
4444

4545
// 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)
4748
for _, s := range e.Signatures {
4849
sig, err := b64Decode(s.Sig)
4950
if err != nil {
@@ -74,15 +75,27 @@ func (ev *envelopeVerifier) Verify(e *Envelope) ([]AcceptedKeys, error) {
7475
Sig: s,
7576
}
7677

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)
7885
break
7986
}
8087
}
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))
8396
}
8497

85-
return accepted_keys, nil
98+
return acceptedKeys, nil
8699
}
87100

88101
func NewEnvelopeVerifier(v ...Verifier) (*envelopeVerifier, error) {

0 commit comments

Comments
 (0)