47
47
)
48
48
from sigstore_protobuf_specs .dev .sigstore .trustroot .v1 import (
49
49
Service ,
50
+ ServiceConfiguration ,
50
51
ServiceSelector ,
51
52
TransparencyLogInstance ,
52
53
)
@@ -340,34 +341,27 @@ def __init__(self, inner: _SigningConfig):
340
341
except ValueError :
341
342
raise Error (f"unsupported signing config format: { self ._inner .media_type } " )
342
343
343
- # Create lists of service protos that are valid & supported by this client
344
- # Limit the TSA and tlog lists using the service selector config
345
- tlogs = self ._get_valid_services (self ._inner .rekor_tlog_urls , REKOR_VERSIONS )
346
- if not tlogs :
344
+ # Create lists of service protos that are valid, selected by the service
345
+ # configuration & supported by this client
346
+ self ._tlogs = self ._get_valid_services (
347
+ self ._inner .rekor_tlog_urls , REKOR_VERSIONS , self ._inner .rekor_tlog_config
348
+ )
349
+ if not self ._tlogs :
347
350
raise Error ("No valid Rekor transparency log found in signing config" )
348
- if self ._inner .rekor_tlog_config .selector == ServiceSelector .EXACT :
349
- if len (tlogs ) < self ._inner .rekor_tlog_config .count :
350
- raise Error (
351
- "Not enough Rekor transparency logs found in signing config"
352
- )
353
- self ._tlogs = tlogs [: self ._inner .rekor_tlog_config .count ]
354
- elif self ._inner .rekor_tlog_config .selector == ServiceSelector .ANY :
355
- self ._tlogs = tlogs [:1 ]
356
- else :
357
- self ._tlogs = tlogs
358
351
359
- tsas = self ._get_valid_services (self ._inner .tsa_urls , TSA_VERSIONS )
360
- if self ._inner .tsa_config .selector == ServiceSelector .EXACT :
361
- self ._tsas = tsas [: self ._inner .tsa_config .count ]
362
- elif self ._inner .tsa_config .selector == ServiceSelector .ANY :
363
- self ._tsas = tsas [:1 ]
364
- else :
365
- self ._tsas = tsas
352
+ self ._tsas = self ._get_valid_services (
353
+ self ._inner .tsa_urls , TSA_VERSIONS , self ._inner .tsa_config
354
+ )
366
355
367
- self ._fulcios = self ._get_valid_services (self ._inner .ca_urls , FULCIO_VERSIONS )
356
+ self ._fulcios = self ._get_valid_services (
357
+ self ._inner .ca_urls , FULCIO_VERSIONS , None
358
+ )
368
359
if not self ._fulcios :
369
360
raise Error ("No valid Fulcio CA found in signing config" )
370
- self ._oidcs = self ._get_valid_services (self ._inner .oidc_urls , OIDC_VERSIONS )
361
+
362
+ self ._oidcs = self ._get_valid_services (
363
+ self ._inner .oidc_urls , OIDC_VERSIONS , None
364
+ )
371
365
372
366
@classmethod
373
367
def from_file (
@@ -379,7 +373,10 @@ def from_file(
379
373
return cls (inner )
380
374
381
375
def _get_valid_services (
382
- self , services : list [Service ], valid_versions : list [int ]
376
+ self ,
377
+ services : list [Service ],
378
+ valid_versions : list [int ],
379
+ config : ServiceConfiguration | None ,
383
380
) -> list [Service ]:
384
381
"""Return supported services, taking SigningConfig restrictions into account"""
385
382
@@ -394,7 +391,7 @@ def _get_valid_services(
394
391
395
392
logs_by_operator [service .operator ].append (service )
396
393
397
- # return a list of services but make sure we only return logs of one version per operator
394
+ # build a list of services but make sure we only include logs of one version per operator
398
395
result : list [Service ] = []
399
396
for logs in logs_by_operator .values ():
400
397
logs .sort (key = lambda s : - s .major_api_version )
@@ -403,7 +400,17 @@ def _get_valid_services(
403
400
while logs and logs [- 1 ].major_api_version == max_version :
404
401
result .append (logs .pop ())
405
402
406
- return result
403
+ # limit the list based on ServiceConfiguration
404
+ if not config or config .selector == ServiceSelector .ALL :
405
+ return result
406
+
407
+ count = config .count if config .selector == ServiceSelector .EXACT else 1
408
+ if len (result ) < count :
409
+ raise ValueError (
410
+ f"Expected { count } services in signing config, found { len (result )} "
411
+ )
412
+
413
+ return result [:count ]
407
414
408
415
def get_tlogs (self ) -> list [RekorClient ]:
409
416
"""
0 commit comments