Skip to content

Commit a314bbc

Browse files
committed
Rename CustomTrustedRoot to TrustedRoot
All other modules should be using our customized version so the rename should be ok: only trustroot module needs a single "import as" shenanigan. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 650a857 commit a314bbc

File tree

7 files changed

+37
-35
lines changed

7 files changed

+37
-35
lines changed

sigstore/_cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
RekorClient,
4141
RekorKeyring,
4242
)
43-
from sigstore._internal.trustroot import CustomTrustedRoot
43+
from sigstore._internal.trustroot import TrustedRoot
4444
from sigstore._utils import PEMCert
4545
from sigstore.errors import Error
4646
from sigstore.oidc import (
@@ -651,7 +651,7 @@ def _sign(args: argparse.Namespace) -> None:
651651
signing_ctx = SigningContext.production()
652652
else:
653653
# Assume "production" trust root if no keys are given as arguments
654-
trusted_root = CustomTrustedRoot.production()
654+
trusted_root = TrustedRoot.production()
655655
if args.ctfe_pem is not None:
656656
ctfe_keys = [args.ctfe_pem.read()]
657657
else:
@@ -828,7 +828,7 @@ def _collect_verification_state(
828828
if args.rekor_root_pubkey is not None:
829829
rekor_keys = [args.rekor_root_pubkey.read()]
830830
else:
831-
trusted_root = CustomTrustedRoot.production()
831+
trusted_root = TrustedRoot.production()
832832
rekor_keys = trusted_root.get_rekor_keys()
833833

834834
verifier = Verifier(

sigstore/_internal/rekor/client.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from sigstore._internal.ctfe import CTKeyring
3131
from sigstore._internal.keyring import Keyring
32-
from sigstore._internal.trustroot import CustomTrustedRoot
32+
from sigstore._internal.trustroot import TrustedRoot
3333
from sigstore.transparency import LogEntry
3434

3535
logger = logging.getLogger(__name__)
@@ -232,11 +232,11 @@ def __del__(self) -> None:
232232
self.session.close()
233233

234234
@classmethod
235-
def production(cls, trust_root: CustomTrustedRoot) -> RekorClient:
235+
def production(cls, trust_root: TrustedRoot) -> RekorClient:
236236
"""
237237
Returns a `RekorClient` populated with the default Rekor production instance.
238238
239-
trust_root must be a `CustomTrustedRoot` for the production TUF repository.
239+
trust_root must be a `TrustedRoot` for the production TUF repository.
240240
"""
241241
rekor_keys = trust_root.get_rekor_keys()
242242
ctfe_keys = trust_root.get_ctfe_keys()
@@ -248,11 +248,11 @@ def production(cls, trust_root: CustomTrustedRoot) -> RekorClient:
248248
)
249249

250250
@classmethod
251-
def staging(cls, trust_root: CustomTrustedRoot) -> RekorClient:
251+
def staging(cls, trust_root: TrustedRoot) -> RekorClient:
252252
"""
253253
Returns a `RekorClient` populated with the default Rekor staging instance.
254254
255-
trust_root must be a `CustomTrustedRoot` for the staging TUF repository.
255+
trust_root must be a `TrustedRoot` for the staging TUF repository.
256256
"""
257257
rekor_keys = trust_root.get_rekor_keys()
258258
ctfe_keys = trust_root.get_ctfe_keys()

sigstore/_internal/trustroot.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
from sigstore_protobuf_specs.dev.sigstore.trustroot.v1 import (
2828
CertificateAuthority,
2929
TransparencyLogInstance,
30-
TrustedRoot,
30+
)
31+
from sigstore_protobuf_specs.dev.sigstore.trustroot.v1 import (
32+
TrustedRoot as _TrustedRoot,
3133
)
3234

3335
from sigstore._internal.tuf import DEFAULT_TUF_URL, STAGING_TUF_URL, TrustUpdater
@@ -56,17 +58,17 @@ def _is_timerange_valid(period: TimeRange | None, *, allow_expired: bool) -> boo
5658
return allow_expired or (period.end is None or now <= period.end)
5759

5860

59-
class CustomTrustedRoot(TrustedRoot):
61+
class TrustedRoot(_TrustedRoot):
6062
"""Complete set of trusted entities for a Sigstore client"""
6163

6264
@classmethod
63-
def from_file(cls, path: str) -> "CustomTrustedRoot":
65+
def from_file(cls, path: str) -> "TrustedRoot":
6466
"""Create a new trust root from file"""
65-
tr: CustomTrustedRoot = cls().from_json(Path(path).read_bytes())
67+
tr: TrustedRoot = cls().from_json(Path(path).read_bytes())
6668
return tr
6769

6870
@classmethod
69-
def from_tuf(cls, url: str, offline: bool = False) -> "CustomTrustedRoot":
71+
def from_tuf(cls, url: str, offline: bool = False) -> "TrustedRoot":
7072
"""Create a new trust root from a TUF repository.
7173
7274
If `offline`, will use trust root in local TUF cache. Otherwise will
@@ -76,7 +78,7 @@ def from_tuf(cls, url: str, offline: bool = False) -> "CustomTrustedRoot":
7678
return cls.from_file(path)
7779

7880
@classmethod
79-
def production(cls, offline: bool = False) -> "CustomTrustedRoot":
81+
def production(cls, offline: bool = False) -> "TrustedRoot":
8082
"""Create new trust root from Sigstore production TUF repository.
8183
8284
If `offline`, will use trust root in local TUF cache. Otherwise will
@@ -85,7 +87,7 @@ def production(cls, offline: bool = False) -> "CustomTrustedRoot":
8587
return cls.from_tuf(DEFAULT_TUF_URL, offline)
8688

8789
@classmethod
88-
def staging(cls, offline: bool = False) -> "CustomTrustedRoot":
90+
def staging(cls, offline: bool = False) -> "TrustedRoot":
8991
"""Create new trust root from Sigstore staging TUF repository.
9092
9193
If `offline`, will use trust root in local TUF cache. Otherwise will

sigstore/sign.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
)
8080
from sigstore._internal.rekor.client import RekorClient
8181
from sigstore._internal.sct import verify_sct
82-
from sigstore._internal.trustroot import CustomTrustedRoot
82+
from sigstore._internal.trustroot import TrustedRoot
8383
from sigstore._utils import B64Str, HexStr, PEMCert, sha256_streaming
8484
from sigstore.oidc import ExpiredIdentity, IdentityToken
8585
from sigstore.transparency import LogEntry
@@ -271,7 +271,7 @@ def production(cls) -> SigningContext:
271271
"""
272272
Return a `SigningContext` instance configured against Sigstore's production-level services.
273273
"""
274-
trust_root = CustomTrustedRoot.production()
274+
trust_root = TrustedRoot.production()
275275
rekor = RekorClient.production(trust_root)
276276
return cls(
277277
fulcio=FulcioClient.production(),
@@ -283,7 +283,7 @@ def staging(cls) -> SigningContext:
283283
"""
284284
Return a `SignerContext` instance configured against Sigstore's staging-level services.
285285
"""
286-
trust_root = CustomTrustedRoot.staging()
286+
trust_root = TrustedRoot.staging()
287287
rekor = RekorClient.staging(trust_root)
288288
return cls(
289289
fulcio=FulcioClient.staging(),

sigstore/verify/verifier.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
)
4848
from sigstore._internal.rekor.client import RekorClient
4949
from sigstore._internal.set import InvalidSETError, verify_set
50-
from sigstore._internal.trustroot import CustomTrustedRoot
50+
from sigstore._internal.trustroot import TrustedRoot
5151
from sigstore._utils import B64Str, HexStr
5252
from sigstore.verify.models import InvalidRekorEntry as InvalidRekorEntryError
5353
from sigstore.verify.models import RekorEntryMissing as RekorEntryMissingError
@@ -126,7 +126,7 @@ def production(cls) -> Verifier:
126126
"""
127127
Return a `Verifier` instance configured against Sigstore's production-level services.
128128
"""
129-
trust_root = CustomTrustedRoot.production()
129+
trust_root = TrustedRoot.production()
130130
return cls(
131131
rekor=RekorClient.production(trust_root),
132132
fulcio_certificate_chain=trust_root.get_fulcio_certs(),
@@ -137,7 +137,7 @@ def staging(cls) -> Verifier:
137137
"""
138138
Return a `Verifier` instance configured against Sigstore's staging-level services.
139139
"""
140-
trust_root = CustomTrustedRoot.staging()
140+
trust_root = TrustedRoot.staging()
141141
return cls(
142142
rekor=RekorClient.staging(trust_root),
143143
fulcio_certificate_chain=trust_root.get_fulcio_certs(),

test/unit/internal/test_trust_root.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from cryptography.x509 import load_pem_x509_certificate
2222
from sigstore_protobuf_specs.dev.sigstore.common.v1 import TimeRange
2323

24-
from sigstore._internal.trustroot import CustomTrustedRoot, _is_timerange_valid
24+
from sigstore._internal.trustroot import TrustedRoot, _is_timerange_valid
2525
from sigstore._utils import load_der_public_key, load_pem_public_key
2626
from sigstore.errors import RootError
2727

@@ -30,10 +30,10 @@ def test_trust_root_tuf_caches_and_requests(mock_staging_tuf, tuf_dirs):
3030
# start with empty target cache, empty local metadata dir
3131
data_dir, cache_dir = tuf_dirs
3232

33-
# keep track of requests the TrustUpdater in CustomTrustedRoot makes
33+
# keep track of requests the TrustUpdater invoked by TrustedRoot makes
3434
reqs, fail_reqs = mock_staging_tuf
3535

36-
trust_root = CustomTrustedRoot.staging()
36+
trust_root = TrustedRoot.staging()
3737
# metadata was "downloaded" from staging
3838
expected = ["root.json", "snapshot.json", "targets.json", "timestamp.json"]
3939
assert sorted(os.listdir(data_dir)) == expected
@@ -58,7 +58,7 @@ def test_trust_root_tuf_caches_and_requests(mock_staging_tuf, tuf_dirs):
5858
assert fail_reqs == expected_fail_reqs
5959

6060
# New trust root (and TrustUpdater instance), same cache dirs
61-
trust_root = CustomTrustedRoot.staging()
61+
trust_root = TrustedRoot.staging()
6262

6363
# Expect new timestamp and root requests
6464
expected_requests["timestamp.json"] += 1
@@ -77,10 +77,10 @@ def test_trust_root_tuf_offline(mock_staging_tuf, tuf_dirs):
7777
# start with empty target cache, empty local metadata dir
7878
data_dir, cache_dir = tuf_dirs
7979

80-
# keep track of requests the TrustUpdater in CustomTrustedRoot makes
80+
# keep track of requests the TrustUpdater invoked by TrustedRoot makes
8181
reqs, fail_reqs = mock_staging_tuf
8282

83-
trust_root = CustomTrustedRoot.staging(offline=True)
83+
trust_root = TrustedRoot.staging(offline=True)
8484

8585
# Only the embedded root is in local TUF metadata, nothing is downloaded
8686
expected = ["root.json"]
@@ -161,39 +161,39 @@ def _pem_keys(keys):
161161
]
162162

163163
# Assert that trust root from TUF contains the expected keys/certs
164-
trust_root = CustomTrustedRoot.staging()
164+
trust_root = TrustedRoot.staging()
165165
assert _der_keys(trust_root.get_ctfe_keys()) == ctfe_keys
166166
assert _der_keys(trust_root.get_rekor_keys()) == rekor_keys
167167
assert trust_root.get_fulcio_certs() == fulcio_certs
168168

169169
# Assert that trust root from offline TUF contains the expected keys/certs
170-
trust_root = CustomTrustedRoot.staging(offline=True)
170+
trust_root = TrustedRoot.staging(offline=True)
171171
assert _der_keys(trust_root.get_ctfe_keys()) == ctfe_keys
172172
assert _der_keys(trust_root.get_rekor_keys()) == rekor_keys
173173
assert trust_root.get_fulcio_certs() == fulcio_certs
174174

175175
# Assert that trust root from file contains the expected keys/certs
176176
path = tuf_asset.target_path("trusted_root.json")
177-
trust_root = CustomTrustedRoot.from_file(path)
177+
trust_root = TrustedRoot.from_file(path)
178178
assert _der_keys(trust_root.get_ctfe_keys()) == ctfe_keys
179179
assert _der_keys(trust_root.get_rekor_keys()) == rekor_keys
180180
assert trust_root.get_fulcio_certs() == fulcio_certs
181181

182182

183183
def test_trust_root_tuf_instance_error():
184184
with pytest.raises(RootError):
185-
CustomTrustedRoot.from_tuf("foo.bar")
185+
TrustedRoot.from_tuf("foo.bar")
186186

187187

188188
def test_trust_root_tuf_ctfe_keys_error(monkeypatch):
189-
trust_root = CustomTrustedRoot.staging(offline=True)
189+
trust_root = TrustedRoot.staging(offline=True)
190190
monkeypatch.setattr(trust_root, "ctlogs", [])
191191
with pytest.raises(Exception, match="Active CTFE keys not found in trusted root"):
192192
trust_root.get_ctfe_keys()
193193

194194

195195
def test_trust_root_fulcio_certs_error(tuf_asset, monkeypatch):
196-
trust_root = CustomTrustedRoot.staging(offline=True)
196+
trust_root = TrustedRoot.staging(offline=True)
197197
monkeypatch.setattr(trust_root, "certificate_authorities", [])
198198
with pytest.raises(
199199
Exception, match="Fulcio certificates not found in trusted root"

test/unit/verify/test_models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import pytest
1717

1818
from sigstore._internal.rekor.client import RekorClient
19-
from sigstore._internal.trustroot import CustomTrustedRoot
19+
from sigstore._internal.trustroot import TrustedRoot
2020
from sigstore.verify.models import (
2121
InvalidMaterials,
2222
InvalidRekorEntry,
@@ -45,7 +45,7 @@ def test_verification_materials_retrieves_rekor_entry(self, signing_materials):
4545
materials = signing_materials("a.txt")
4646
assert materials._rekor_entry is None
4747

48-
trust_root = CustomTrustedRoot.staging()
48+
trust_root = TrustedRoot.staging()
4949
client = RekorClient.staging(trust_root)
5050
entry = materials.rekor_entry(client)
5151
assert entry is not None

0 commit comments

Comments
 (0)