@@ -375,20 +375,6 @@ def _verify_common_signing_cert(
375
375
f"invalid signing cert: expired at time of signing, time via { vts } "
376
376
)
377
377
378
- @staticmethod
379
- def _get_key_details (certificate : Certificate ) -> v1 .PublicKeyDetails :
380
- """Determine PublicKeyDetails from a certificate"""
381
- public_key = certificate .public_key ()
382
- if isinstance (public_key , EllipticCurvePublicKey ):
383
- if public_key .curve .name == "secp256r1" :
384
- return cast (
385
- v1 .PublicKeyDetails ,
386
- v1 .PublicKeyDetails .PKIX_ECDSA_P256_SHA_256 ,
387
- )
388
- # TODO support other keys
389
- raise ValueError (f"Unsupported EC curve: { public_key .curve .name } " )
390
- raise ValueError (f"Unsupported public key type: { type (public_key )} " )
391
-
392
378
def verify_dsse (
393
379
self , bundle : Bundle , policy : VerificationPolicy
394
380
) -> tuple [str , bytes ]:
@@ -440,9 +426,9 @@ def verify_dsse(
440
426
entry ._kind_version .kind == "dsse"
441
427
and entry ._kind_version .version == "0.0.2"
442
428
):
443
- validate_dsse_v002_entry_body (bundle )
429
+ _validate_dsse_v002_entry_body (bundle )
444
430
else :
445
- validate_dsse_v001_entry_body (bundle )
431
+ _validate_dsse_v001_entry_body (bundle )
446
432
447
433
return (envelope ._inner .payload_type , envelope ._inner .payload )
448
434
@@ -491,14 +477,14 @@ def verify_artifact(
491
477
entry ._kind_version .kind == "hashedrekord"
492
478
and entry ._kind_version .version == "0.0.2"
493
479
):
494
- validate_hashedrekord_v002_entry_body (bundle )
480
+ _validate_hashedrekord_v002_entry_body (bundle )
495
481
else :
496
- validate_hashedrekord_v001_entry_body (bundle , hashed_input )
482
+ _validate_hashedrekord_v001_entry_body (bundle , hashed_input )
497
483
498
484
499
- def validate_dsse_v001_entry_body (bundle : Bundle ) -> None :
485
+ def _validate_dsse_v001_entry_body (bundle : Bundle ) -> None :
500
486
"""
501
- Valideate the Entry body for dsse v001.
487
+ Validate the Entry body for dsse v001.
502
488
"""
503
489
entry = bundle .log_entry
504
490
envelope = bundle ._dsse_envelope
@@ -534,9 +520,9 @@ def validate_dsse_v001_entry_body(bundle: Bundle) -> None:
534
520
raise VerificationError ("log entry signatures do not match bundle" )
535
521
536
522
537
- def validate_dsse_v002_entry_body (bundle : Bundle ) -> None :
523
+ def _validate_dsse_v002_entry_body (bundle : Bundle ) -> None :
538
524
"""
539
- Valideate the Entry body for dsse v002.
525
+ Validate Entry body for dsse v002.
540
526
"""
541
527
entry = bundle .log_entry
542
528
envelope = bundle ._dsse_envelope
@@ -562,24 +548,19 @@ def validate_dsse_v002_entry_body(bundle: Bundle) -> None:
562
548
v2_signatures = [
563
549
v2 .Signature (
564
550
content = signature .sig ,
565
- verifier = v2 .Verifier (
566
- x509_certificate = v1 .X509Certificate (
567
- bundle .signing_certificate .public_bytes (
568
- encoding = serialization .Encoding .DER
569
- )
570
- ),
571
- key_details = Verifier ._get_key_details (bundle .signing_certificate ),
572
- ),
551
+ verifier = _v2_verifier_from_certificate (bundle .signing_certificate ),
573
552
)
574
553
for signature in envelope ._inner .signatures
575
554
]
576
555
if v2_signatures != v2_body .spec .dsse_v002 .signatures :
577
556
raise VerificationError ("log entry signatures do not match bundle" )
578
557
579
558
580
- def validate_hashedrekord_v001_entry_body (bundle : Bundle , hashed_input : Hashed ) -> None :
559
+ def _validate_hashedrekord_v001_entry_body (
560
+ bundle : Bundle , hashed_input : Hashed
561
+ ) -> None :
581
562
"""
582
- Valideate the Entry body for hashedrekord v001.
563
+ Validate the Entry body for hashedrekord v001.
583
564
"""
584
565
entry = bundle .log_entry
585
566
expected_body = _hashedrekord_from_parts (
@@ -596,9 +577,9 @@ def validate_hashedrekord_v001_entry_body(bundle: Bundle, hashed_input: Hashed)
596
577
)
597
578
598
579
599
- def validate_hashedrekord_v002_entry_body (bundle : Bundle ) -> None :
580
+ def _validate_hashedrekord_v002_entry_body (bundle : Bundle ) -> None :
600
581
"""
601
- Valideate the Entry body for hashedrekord v002.
582
+ Validate Entry body for hashedrekord v002.
602
583
"""
603
584
entry = bundle .log_entry
604
585
if bundle ._inner .message_signature is None :
@@ -616,16 +597,7 @@ def validate_hashedrekord_v002_entry_body(bundle: Bundle) -> None:
616
597
),
617
598
signature = v2 .Signature (
618
599
content = bundle ._inner .message_signature .signature ,
619
- verifier = v2 .Verifier (
620
- x509_certificate = v1 .X509Certificate (
621
- bundle .signing_certificate .public_bytes (
622
- encoding = serialization .Encoding .DER
623
- )
624
- ),
625
- key_details = Verifier ._get_key_details (
626
- bundle .signing_certificate
627
- ),
628
- ),
600
+ verifier = _v2_verifier_from_certificate (bundle .signing_certificate ),
629
601
),
630
602
)
631
603
),
@@ -635,3 +607,29 @@ def validate_hashedrekord_v002_entry_body(bundle: Bundle) -> None:
635
607
raise VerificationError (
636
608
"transparency log entry is inconsistent with other materials"
637
609
)
610
+
611
+
612
+ def _v2_verifier_from_certificate (certificate : Certificate ) -> v2 .Verifier :
613
+ public_key = certificate .public_key ()
614
+ key_details = None
615
+
616
+ if isinstance (public_key , EllipticCurvePublicKey ):
617
+ if public_key .curve .name == "secp256r1" :
618
+ key_details = cast (
619
+ v1 .PublicKeyDetails ,
620
+ v1 .PublicKeyDetails .PKIX_ECDSA_P256_SHA_256 ,
621
+ )
622
+ else :
623
+ raise ValueError (f"Unsupported EC curve: { public_key .curve .name } " )
624
+
625
+ # TODO support other keys
626
+
627
+ if key_details is None :
628
+ raise ValueError (f"Unsupported public key type: { type (public_key )} " )
629
+
630
+ return v2 .Verifier (
631
+ x509_certificate = v1 .X509Certificate (
632
+ certificate .public_bytes (encoding = serialization .Encoding .DER )
633
+ ),
634
+ key_details = key_details ,
635
+ )
0 commit comments