21
21
# python ./credentials/generate-revocation-set.py --help
22
22
23
23
import base64
24
- import dataclasses
25
24
import json
26
25
import logging
27
26
import os
28
27
import subprocess
29
28
import sys
30
29
import unittest
31
30
from enum import Enum
31
+ import dataclasses
32
32
from typing import Optional
33
33
34
34
import click
53
53
class RevocationType (Enum ):
54
54
CRL = 1
55
55
56
-
57
56
class CertVerificationResult (Enum ):
58
57
SUCCESS = 1
59
58
SKID_NOT_FOUND = 2
@@ -62,7 +61,6 @@ class CertVerificationResult(Enum):
62
61
ISSUER_MISMATCH = 5
63
62
AKID_MISMATCH = 6
64
63
65
-
66
64
@dataclasses .dataclass
67
65
class RevocationPoint :
68
66
vid : int
@@ -79,7 +77,6 @@ class RevocationPoint:
79
77
schemaVersion : int
80
78
crlSignerDelegator : str
81
79
82
-
83
80
@dataclasses .dataclass
84
81
class RevocationSet :
85
82
type : str
@@ -88,10 +85,10 @@ class RevocationSet:
88
85
revoked_serial_numbers : [str ]
89
86
crl_signer_cert : str
90
87
crl_signer_delegator : str = None
91
-
88
+
92
89
def asDict (self ):
93
90
return dataclasses .asdict (self )
94
-
91
+
95
92
96
93
OID_VENDOR_ID = x509 .ObjectIdentifier ("1.3.6.1.4.1.37244.2.1" )
97
94
OID_PRODUCT_ID = x509 .ObjectIdentifier ("1.3.6.1.4.1.37244.2.2" )
@@ -178,8 +175,7 @@ def is_self_signed_certificate(cert: x509.Certificate) -> bool:
178
175
if result == CertVerificationResult .SUCCESS :
179
176
return True
180
177
else :
181
- logging .debug (
182
- f"Certificate with subject: { cert .subject .rfc4514_string ()} is not a valid self-signed certificate. Result: { result .name } " )
178
+ logging .debug (f"Certificate with subject: { cert .subject .rfc4514_string ()} is not a valid self-signed certificate. Result: { result .name } " )
183
179
return False
184
180
185
181
@@ -196,21 +192,18 @@ def validate_cert_chain(crl_signer: x509.Certificate, crl_signer_delegator: x509
196
192
if crl_signer_delegator :
197
193
result_signer = verify_cert (crl_signer , crl_signer_delegator )
198
194
if not result_signer == CertVerificationResult .SUCCESS :
199
- logging .debug (
200
- f"Cannot verify certificate subject: { crl_signer .subject .rfc4514_string ()} issued by certificate subject: { crl_signer_delegator .subject .rfc4514_string ()} . Result: { result_signer .name } " )
195
+ logging .debug (f"Cannot verify certificate subject: { crl_signer .subject .rfc4514_string ()} issued by certificate subject: { crl_signer_delegator .subject .rfc4514_string ()} . Result: { result_signer .name } " )
201
196
return False
202
197
203
198
result_delegator = verify_cert (crl_signer_delegator , paa )
204
199
if not result_delegator == CertVerificationResult .SUCCESS :
205
- logging .debug (
206
- f"Cannot verify certificate subject: { crl_signer_delegator .subject .rfc4514_string ()} issued by certificate subject: { paa .subject .rfc4514_string ()} . Result: { result .name } " )
200
+ logging .debug (f"Cannot verify certificate subject: { crl_signer_delegator .subject .rfc4514_string ()} issued by certificate subject: { paa .subject .rfc4514_string ()} . Result: { result .name } " )
207
201
return False
208
202
return True
209
203
else :
210
204
result = verify_cert (crl_signer , paa )
211
205
if not result == CertVerificationResult .SUCCESS :
212
- logging .debug (
213
- f"Cannot verify certificate subject: { crl_signer .subject .rfc4514_string ()} issued by certificate subject: { paa .subject .rfc4514_string ()} . Result: { result .name } " )
206
+ logging .debug (f"Cannot verify certificate subject: { crl_signer .subject .rfc4514_string ()} issued by certificate subject: { paa .subject .rfc4514_string ()} . Result: { result .name } " )
214
207
return False
215
208
return True
216
209
@@ -359,7 +352,6 @@ def fetch_crl_from_url(url: str, timeout: int) -> x509.CertificateRevocationList
359
352
except Exception as e :
360
353
logging .error ('Failed to fetch a valid CRL' , e )
361
354
362
-
363
355
class DclClientInterface :
364
356
'''
365
357
An interface for interacting with DCLD.
@@ -606,7 +598,7 @@ def get_revocation_points(self) -> list[RevocationPoint]:
606
598
'''
607
599
608
600
response = self .send_get_request (f"{ self .rest_node_url } /dcl/pki/revocation-points" )
609
-
601
+
610
602
return [RevocationPoint (** r ) for r in response ["PkiRevocationDistributionPoint" ]]
611
603
612
604
def get_revocation_points_by_skid (self , issuer_subject_key_id ) -> list [RevocationPoint ]:
@@ -674,8 +666,7 @@ def __init__(self, crls: [], dcl_certificates: [], revocation_points_response_fi
674
666
logging .debug (f"Loading crls from { crls } " )
675
667
logging .debug (f"Loading revocation points response from { revocation_points_response_file } " )
676
668
self .crls = self .get_crls (crls )
677
- self .revocation_points = [RevocationPoint (** r )
678
- for r in json .load (revocation_points_response_file )["PkiRevocationDistributionPoint" ]]
669
+ self .revocation_points = [RevocationPoint (** r ) for r in json .load (revocation_points_response_file )["PkiRevocationDistributionPoint" ]]
679
670
self .authoritative_certs = self .get_authoritative_certificates (dcl_certificates )
680
671
681
672
def get_lookup_key (self , certificate : x509 .Certificate ) -> str :
@@ -851,7 +842,6 @@ def get_crl_file(self,
851
842
return crl
852
843
return None
853
844
854
-
855
845
@click .group ()
856
846
def cli ():
857
847
pass
@@ -995,7 +985,6 @@ def from_dcl(use_main_net_dcld: str, use_test_net_dcld: str, use_main_net_http:
995
985
with open (output , 'w+' ) as outfile :
996
986
json .dump ([revocation .asDict () for revocation in revocation_set ], outfile , indent = 4 )
997
987
998
-
999
988
class TestRevocationSetGeneration (unittest .TestCase ):
1000
989
"""Test class for revocation set generation"""
1001
990
@@ -1062,7 +1051,6 @@ def test_pai_revocation_set(self):
1062
1051
'test/revoked-attestation-certificates/revocation-sets/revocation-set-for-pai.json'
1063
1052
)
1064
1053
1065
-
1066
1054
if __name__ == "__main__" :
1067
1055
if len (sys .argv ) > 1 and sys .argv [1 ] == 'test' :
1068
1056
# Remove the 'test' argument and run tests
0 commit comments