@@ -217,71 +217,69 @@ def __str__(self) -> str:
217
217
return self .value
218
218
219
219
220
- class TrustedRoot (_TrustedRoot ):
221
- """Complete set of trusted entities for a Sigstore client"""
220
+ class TrustedRoot :
221
+ """
222
+ The cryptographic root(s) of trust for a Sigstore instance.
223
+ """
222
224
223
- purpose : KeyringPurpose
225
+ def __init__ (self , inner : _TrustedRoot ):
226
+ self ._inner = inner
224
227
225
228
@classmethod
226
229
def from_file (
227
230
cls ,
228
231
path : str ,
229
- purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
230
232
) -> TrustedRoot :
231
233
"""Create a new trust root from file"""
232
- trusted_root : TrustedRoot = cls ().from_json (Path (path ).read_bytes ())
233
- trusted_root .purpose = purpose
234
- return trusted_root
234
+ inner = _TrustedRoot ().from_json (Path (path ).read_bytes ())
235
+ return cls (inner )
235
236
236
237
@classmethod
237
238
def from_tuf (
238
239
cls ,
239
240
url : str ,
240
241
offline : bool = False ,
241
- purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
242
242
) -> TrustedRoot :
243
243
"""Create a new trust root from a TUF repository.
244
244
245
245
If `offline`, will use trust root in local TUF cache. Otherwise will
246
246
update the trust root from remote TUF repository.
247
247
"""
248
248
path = TrustUpdater (url , offline ).get_trusted_root_path ()
249
- return cls .from_file (path , purpose )
249
+ return cls .from_file (path )
250
250
251
251
@classmethod
252
252
def production (
253
253
cls ,
254
254
offline : bool = False ,
255
- purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
256
255
) -> TrustedRoot :
257
256
"""Create new trust root from Sigstore production TUF repository.
258
257
259
258
If `offline`, will use trust root in local TUF cache. Otherwise will
260
259
update the trust root from remote TUF repository.
261
260
"""
262
- return cls .from_tuf (DEFAULT_TUF_URL , offline , purpose )
261
+ return cls .from_tuf (DEFAULT_TUF_URL , offline )
263
262
264
263
@classmethod
265
264
def staging (
266
265
cls ,
267
266
offline : bool = False ,
268
- purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
269
267
) -> TrustedRoot :
270
268
"""Create new trust root from Sigstore staging TUF repository.
271
269
272
270
If `offline`, will use trust root in local TUF cache. Otherwise will
273
271
update the trust root from remote TUF repository.
274
272
"""
275
- return cls .from_tuf (STAGING_TUF_URL , offline , purpose )
273
+ return cls .from_tuf (STAGING_TUF_URL , offline )
276
274
277
275
def _get_tlog_keys (
278
- self , tlogs : list [TransparencyLogInstance ]
276
+ self , tlogs : list [TransparencyLogInstance ], purpose : KeyringPurpose
279
277
) -> Iterable [_PublicKey ]:
280
278
"""
281
279
Yields an iterator of public keys for transparency log instances that
282
280
are suitable for `purpose`.
283
281
"""
284
- allow_expired = self . purpose is KeyringPurpose .VERIFY
282
+ allow_expired = purpose is KeyringPurpose .VERIFY
285
283
for tlog in tlogs :
286
284
if not _is_timerange_valid (
287
285
tlog .public_key .valid_for , allow_expired = allow_expired
@@ -302,17 +300,17 @@ def _get_ca_keys(
302
300
for cert in ca .cert_chain .certificates :
303
301
yield cert .raw_bytes
304
302
305
- def rekor_keyring (self ) -> RekorKeyring :
303
+ def rekor_keyring (self , purpose : KeyringPurpose ) -> RekorKeyring :
306
304
"""Return keyring with keys for Rekor."""
307
305
308
- keys : list [_PublicKey ] = list (self ._get_tlog_keys (self .tlogs ))
306
+ keys : list [_PublicKey ] = list (self ._get_tlog_keys (self ._inner . tlogs , purpose ))
309
307
if len (keys ) != 1 :
310
308
raise MetadataError ("Did not find one Rekor key in trusted root" )
311
309
return RekorKeyring (Keyring (keys ))
312
310
313
- def ct_keyring (self ) -> CTKeyring :
311
+ def ct_keyring (self , purpose : KeyringPurpose ) -> CTKeyring :
314
312
"""Return keyring with key for CTFE."""
315
- ctfes : list [_PublicKey ] = list (self ._get_tlog_keys (self .ctlogs ))
313
+ ctfes : list [_PublicKey ] = list (self ._get_tlog_keys (self ._inner . ctlogs , purpose ))
316
314
if not ctfes :
317
315
raise MetadataError ("CTFE keys not found in trusted root" )
318
316
return CTKeyring (Keyring (ctfes ))
@@ -326,7 +324,9 @@ def get_fulcio_certs(self) -> list[Certificate]:
326
324
# been active when the certificate was used to sign.
327
325
certs = [
328
326
load_der_x509_certificate (c )
329
- for c in self ._get_ca_keys (self .certificate_authorities , allow_expired = True )
327
+ for c in self ._get_ca_keys (
328
+ self ._inner .certificate_authorities , allow_expired = True
329
+ )
330
330
]
331
331
if not certs :
332
332
raise MetadataError ("Fulcio certificates not found in trusted root" )
0 commit comments