Skip to content

Commit f4eb001

Browse files
authored
Merge pull request #1091 from mnm678/check-key-uniqueness
Each key applies to signature threshold once
2 parents 0c07311 + ae54c85 commit f4eb001

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)