Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ All versions prior to 0.9.0 are untracked.
still required.
[#1381](https://github.com/sigstore/sigstore-python/pull/1381)

* Verify: Avoid hard failure if trusted root contains unsupported keytypes (as verification
may succeed without that key).
[#1424](https://github.com/sigstore/sigstore-python/pull/1424)

* CI: Timestamp Authority tests use latest release, not latest tag, of
[sigstore/timestamp-authority](https://github.com/sigstore/timestamp-authority)
[#1377](https://github.com/sigstore/sigstore-python/pull/1377)
Expand Down
10 changes: 8 additions & 2 deletions sigstore/_internal/trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import annotations

import logging
from collections import defaultdict
from collections.abc import Iterable
from dataclasses import dataclass
Expand Down Expand Up @@ -77,6 +78,8 @@
FULCIO_VERSIONS = [1]
OIDC_VERSIONS = [1]

_logger = logging.getLogger(__name__)


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

for public_key in public_keys:
key = Key(public_key)
self._keyring[key.key_id] = key
try:
key = Key(public_key)
self._keyring[key.key_id] = key
except VerificationError as e:
_logger.warning(f"Failed to load a trusted root key: {e}")

def verify(self, *, key_id: KeyID, signature: bytes, data: bytes) -> None:
"""
Expand Down
14 changes: 14 additions & 0 deletions test/assets/trusted_root/trustedroot.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
"logId": {
"keyId": "wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
}
},
{
"baseUrl": "https://example.com/unsupported_key",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "",
"keyDetails": "UNSPECIFIED",
"validFor": {
"start": "2021-01-12T11:53:27.000Z"
}
},
"logId": {
"keyId": "xNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
}
}
],
"certificateAuthorities": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
"logId": {
"keyId": "tAlACZWkUrif9Z9sOIrpk1ak1I8loRNufk79N6l1SNg="
}
},
{
"baseUrl": "https://example.com/unsupported_key",
"hashAlgorithm": "SHA2_256",
"publicKey": {
"rawBytes": "",
"keyDetails": "UNSPECIFIED",
"validFor": {
"start": "2021-01-12T11:53:27.000Z"
}
},
"logId": {
"keyId": "xNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="
}
}
],
"certificateAuthorities": [
Expand Down
10 changes: 6 additions & 4 deletions test/unit/internal/test_trust.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,20 +208,22 @@ class TestTrustedRoot:
)
def test_good(self, asset, file):
"""
Ensures that the trusted_roots are well-formed and that the embedded keys are supported.
Ensures that the trusted_roots are well-formed and that the expected embedded keys are supported.
"""
path = asset(file)
root = TrustedRoot.from_file(path)

assert (
root._inner.media_type == TrustedRoot.TrustedRootType.TRUSTED_ROOT_0_1.value
)
assert len(root._inner.tlogs) == 1
assert len(root._inner.tlogs) == 2
assert len(root._inner.certificate_authorities) == 2
assert len(root._inner.ctlogs) == 2
assert len(root._inner.timestamp_authorities) == 1
assert root.rekor_keyring(KeyringPurpose.VERIFY) is not None
assert root.ct_keyring(KeyringPurpose.VERIFY) is not None

# only one of the two rekor keys is actually supported
assert len(root.rekor_keyring(KeyringPurpose.VERIFY)._keyring) == 1
assert len(root.ct_keyring(KeyringPurpose.VERIFY)._keyring) == 2
assert root.get_fulcio_certs() is not None
assert root.get_timestamp_authorities() is not None

Expand Down