Skip to content

Commit 5d9b210

Browse files
authored
trust: Fail less hard when unsupported keys are seen (#1424)
Currently verification fails immediately if trusted root contains any unsupported keys. I think it makes more sense to warn and continue as it is possible these keys are not required for verification. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 66de675 commit 5d9b210

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ All versions prior to 0.9.0 are untracked.
4343
still required.
4444
[#1381](https://github.com/sigstore/sigstore-python/pull/1381)
4545

46+
* Verify: Avoid hard failure if trusted root contains unsupported keytypes (as verification
47+
may succeed without that key).
48+
[#1424](https://github.com/sigstore/sigstore-python/pull/1424)
49+
4650
* CI: Timestamp Authority tests use latest release, not latest tag, of
4751
[sigstore/timestamp-authority](https://github.com/sigstore/timestamp-authority)
4852
[#1377](https://github.com/sigstore/sigstore-python/pull/1377)

sigstore/_internal/trust.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from __future__ import annotations
2020

21+
import logging
2122
from collections import defaultdict
2223
from collections.abc import Iterable
2324
from dataclasses import dataclass
@@ -77,6 +78,8 @@
7778
FULCIO_VERSIONS = [1]
7879
OIDC_VERSIONS = [1]
7980

81+
_logger = logging.getLogger(__name__)
82+
8083

8184
def _is_timerange_valid(period: TimeRange | None, *, allow_expired: bool) -> bool:
8285
"""
@@ -200,8 +203,11 @@ def __init__(self, public_keys: list[_PublicKey] = []):
200203
self._keyring: dict[KeyID, Key] = {}
201204

202205
for public_key in public_keys:
203-
key = Key(public_key)
204-
self._keyring[key.key_id] = key
206+
try:
207+
key = Key(public_key)
208+
self._keyring[key.key_id] = key
209+
except VerificationError as e:
210+
_logger.warning(f"Failed to load a trusted root key: {e}")
205211

206212
def verify(self, *, key_id: KeyID, signature: bytes, data: bytes) -> None:
207213
"""

test/assets/trusted_root/trustedroot.v1.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
"logId": {
1515
"keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
1616
}
17+
},
18+
{
19+
"baseUrl": "https://example.com/unsupported_key",
20+
"hashAlgorithm": "SHA2_256",
21+
"publicKey": {
22+
"rawBytes": "",
23+
"keyDetails": "UNSPECIFIED",
24+
"validFor": {
25+
"start": "2021-01-12T11:53:27.000Z"
26+
}
27+
},
28+
"logId": {
29+
"keyId": "xNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
30+
}
1731
}
1832
],
1933
"certificateAuthorities": [

test/assets/trusted_root/trustedroot.v1.local_tlog_ed25519_rekor-tiles.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@
1414
"logId": {
1515
"keyId": "tAlACZWkUrif9Z9sOIrpk1ak1I8loRNufk79N6l1SNg="
1616
}
17+
},
18+
{
19+
"baseUrl": "https://example.com/unsupported_key",
20+
"hashAlgorithm": "SHA2_256",
21+
"publicKey": {
22+
"rawBytes": "",
23+
"keyDetails": "UNSPECIFIED",
24+
"validFor": {
25+
"start": "2021-01-12T11:53:27.000Z"
26+
}
27+
},
28+
"logId": {
29+
"keyId": "xNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
30+
}
1731
}
1832
],
1933
"certificateAuthorities": [

test/unit/internal/test_trust.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,22 @@ class TestTrustedRoot:
208208
)
209209
def test_good(self, asset, file):
210210
"""
211-
Ensures that the trusted_roots are well-formed and that the embedded keys are supported.
211+
Ensures that the trusted_roots are well-formed and that the expected embedded keys are supported.
212212
"""
213213
path = asset(file)
214214
root = TrustedRoot.from_file(path)
215215

216216
assert (
217217
root._inner.media_type == TrustedRoot.TrustedRootType.TRUSTED_ROOT_0_1.value
218218
)
219-
assert len(root._inner.tlogs) == 1
219+
assert len(root._inner.tlogs) == 2
220220
assert len(root._inner.certificate_authorities) == 2
221221
assert len(root._inner.ctlogs) == 2
222222
assert len(root._inner.timestamp_authorities) == 1
223-
assert root.rekor_keyring(KeyringPurpose.VERIFY) is not None
224-
assert root.ct_keyring(KeyringPurpose.VERIFY) is not None
223+
224+
# only one of the two rekor keys is actually supported
225+
assert len(root.rekor_keyring(KeyringPurpose.VERIFY)._keyring) == 1
226+
assert len(root.ct_keyring(KeyringPurpose.VERIFY)._keyring) == 2
225227
assert root.get_fulcio_certs() is not None
226228
assert root.get_timestamp_authorities() is not None
227229

0 commit comments

Comments
 (0)