Skip to content

Commit ae54c85

Browse files
committed
Each key applies to signature threshold once
This commit ensures that each key will only count toward the signature threshold once, even if the keys have different keyids. Signed-off-by: marinamoore <[email protected]>
1 parent b265fb9 commit ae54c85

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

tests/test_sig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ def test_verify_count_different_keyids_for_same_key_towards_threshold(self):
436436
tuf.keydb.add_key(key_sha256)
437437
tuf.keydb.add_key(key_sha512)
438438

439-
# Assert that both keys count towards threshold although its the same key
439+
# Assert that the key only counts toward the threshold once
440440
keyids = [key_sha256["keyid"], key_sha512["keyid"]]
441-
self.assertTrue(
441+
self.assertFalse(
442442
tuf.sig.verify(signable, "root", keyids=keyids, threshold=2))
443443

444444
# Clean-up keydb

tuf/sig.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ def verify(signable, role, repository_name='default', threshold=None,
245245
NOTE:
246246
- Signatures with identical authorized keyids only count towards the
247247
threshold once.
248-
- Signatures with different authorized keyids each count towards the
249-
threshold, even if the keyids identify the same key.
248+
- Signatures with the same key only count toward the threshold once.
250249
251250
<Arguments>
252251
signable:
@@ -307,7 +306,12 @@ def verify(signable, role, repository_name='default', threshold=None,
307306
if threshold is None or threshold <= 0: #pragma: no cover
308307
raise securesystemslib.exceptions.Error("Invalid threshold: " + repr(threshold))
309308

310-
return len(set(good_sigs)) >= threshold
309+
unique_keys = set()
310+
for keyid in good_sigs:
311+
key = tuf.keydb.get_key(keyid, repository_name)
312+
unique_keys.add(key['keyval']['public'])
313+
314+
return len(unique_keys) >= threshold
311315

312316

313317

0 commit comments

Comments
 (0)