Skip to content

Commit 7169aae

Browse files
committed
Remove tuf methods from TrustedRoot
Probably makes sense to handle this in ClientTrustConfig only: less code that way. The tests will start passing once staging TUF contains signingconfig (and we have updated our test copies of staging TUF) Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 1bb9029 commit 7169aae

File tree

3 files changed

+13
-49
lines changed

3 files changed

+13
-49
lines changed

sigstore/_internal/trust.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -438,44 +438,6 @@ def from_file(
438438
inner = _TrustedRoot().from_json(Path(path).read_bytes())
439439
return cls(inner)
440440

441-
@classmethod
442-
def from_tuf(
443-
cls,
444-
url: str,
445-
offline: bool = False,
446-
) -> TrustedRoot:
447-
"""Create a new trust root from a TUF repository.
448-
449-
If `offline`, will use trust root in local TUF cache. Otherwise will
450-
update the trust root from remote TUF repository.
451-
"""
452-
path = TrustUpdater(url, offline).get_trusted_root_path()
453-
return cls.from_file(path)
454-
455-
@classmethod
456-
def production(
457-
cls,
458-
offline: bool = False,
459-
) -> TrustedRoot:
460-
"""Create new trust root from Sigstore production TUF repository.
461-
462-
If `offline`, will use trust root in local TUF cache. Otherwise will
463-
update the trust root from remote TUF repository.
464-
"""
465-
return cls.from_tuf(DEFAULT_TUF_URL, offline)
466-
467-
@classmethod
468-
def staging(
469-
cls,
470-
offline: bool = False,
471-
) -> TrustedRoot:
472-
"""Create new trust root from Sigstore staging TUF repository.
473-
474-
If `offline`, will use trust root in local TUF cache. Otherwise will
475-
update the trust root from remote TUF repository.
476-
"""
477-
return cls.from_tuf(STAGING_TUF_URL, offline)
478-
479441
def _get_tlog_keys(
480442
self, tlogs: list[TransparencyLogInstance], purpose: KeyringPurpose
481443
) -> Iterable[_PublicKey]:

sigstore/verify/verifier.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
verify_sct,
4747
)
4848
from sigstore._internal.timestamp import TimestampSource, TimestampVerificationResult
49-
from sigstore._internal.trust import KeyringPurpose, TrustedRoot
49+
from sigstore._internal.trust import ClientTrustConfig, KeyringPurpose, TrustedRoot
5050
from sigstore._utils import base64_encode_pem_cert, sha256_digest
5151
from sigstore.errors import VerificationError
5252
from sigstore.hashes import Hashed
@@ -96,8 +96,9 @@ def production(cls, *, offline: bool = False) -> Verifier:
9696
the verifier uses the Trusted Root in the local TUF cache. If `False`,
9797
a TUF repository refresh is attempted.
9898
"""
99+
config = ClientTrustConfig.production(offline=offline)
99100
return cls(
100-
trusted_root=TrustedRoot.production(offline=offline),
101+
trusted_root=config.trusted_root,
101102
)
102103

103104
@classmethod
@@ -109,8 +110,9 @@ def staging(cls, *, offline: bool = False) -> Verifier:
109110
the verifier uses the Trusted Root in the local TUF cache. If `False`,
110111
a TUF repository refresh is attempted.
111112
"""
113+
config = ClientTrustConfig.staging(offline=offline)
112114
return cls(
113-
trusted_root=TrustedRoot.staging(offline=offline),
115+
trusted_root=config.trusted_root,
114116
)
115117

116118
def _verify_signed_timestamp(

test/unit/internal/test_trust.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_trust_root_tuf_caches_and_requests(mock_staging_tuf, tuf_dirs):
9696
# keep track of requests the TrustUpdater invoked by TrustedRoot makes
9797
reqs, fail_reqs = mock_staging_tuf
9898

99-
trust_root = TrustedRoot.staging()
99+
trust_root = ClientTrustConfig.staging()
100100
# metadata was "downloaded" from staging
101101
expected = [
102102
"root.json",
@@ -126,7 +126,7 @@ def test_trust_root_tuf_caches_and_requests(mock_staging_tuf, tuf_dirs):
126126
assert fail_reqs == expected_fail_reqs
127127

128128
# New trust root (and TrustUpdater instance), same cache dirs
129-
trust_root = TrustedRoot.staging()
129+
trust_root = ClientTrustConfig.staging()
130130

131131
# Expect new timestamp and root requests
132132
expected_requests["timestamp.json"] += 1
@@ -148,7 +148,7 @@ def test_trust_root_tuf_offline(mock_staging_tuf, tuf_dirs):
148148
# keep track of requests the TrustUpdater invoked by TrustedRoot makes
149149
reqs, fail_reqs = mock_staging_tuf
150150

151-
trust_root = TrustedRoot.staging(offline=True)
151+
trust_root = ClientTrustConfig.staging(offline=True)
152152

153153
# local TUF metadata is not initialized, nothing is downloaded
154154
assert not os.path.exists(data_dir)
@@ -217,7 +217,7 @@ def _pem_keys(keys):
217217
]
218218

219219
# Assert that trust root from TUF contains the expected keys/certs
220-
trust_root = TrustedRoot.staging()
220+
trust_root = ClientTrustConfig.staging().trusted_root
221221
assert ctfe_keys[0] in get_public_bytes(
222222
[
223223
k.key
@@ -240,7 +240,7 @@ def _pem_keys(keys):
240240
assert trust_root.get_fulcio_certs() == fulcio_certs
241241

242242
# Assert that trust root from offline TUF contains the expected keys/certs
243-
trust_root = TrustedRoot.staging(offline=True)
243+
trust_root = ClientTrustConfig.staging(offline=True).trust_root
244244
assert ctfe_keys[0] in get_public_bytes(
245245
[
246246
k.key
@@ -289,18 +289,18 @@ def _pem_keys(keys):
289289

290290
def test_trust_root_tuf_instance_error():
291291
with pytest.raises(RootError):
292-
TrustedRoot.from_tuf("foo.bar")
292+
ClientTrustConfig.from_tuf("foo.bar")
293293

294294

295295
def test_trust_root_tuf_ctfe_keys_error(monkeypatch):
296-
trust_root = TrustedRoot.staging(offline=True)
296+
trust_root = ClientTrustConfig.staging(offline=True).trusted_root
297297
monkeypatch.setattr(trust_root._inner, "ctlogs", [])
298298
with pytest.raises(Exception, match="CTFE keys not found in trusted root"):
299299
trust_root.ct_keyring(purpose=KeyringPurpose.VERIFY)
300300

301301

302302
def test_trust_root_fulcio_certs_error(tuf_asset, monkeypatch):
303-
trust_root = TrustedRoot.staging(offline=True)
303+
trust_root = ClientTrustConfig.staging(offline=True).trusted_root
304304
monkeypatch.setattr(trust_root._inner, "certificate_authorities", [])
305305
with pytest.raises(
306306
Exception, match="Fulcio certificates not found in trusted root"

0 commit comments

Comments
 (0)