Skip to content

Commit 9da2d33

Browse files
restyled-commitsbh3000
authored andcommitted
Restyled by autopep8
1 parent 9b0a2fd commit 9da2d33

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

credentials/generate_revocation_set.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import sys
2929
import unittest
3030
from enum import Enum
31-
import dataclasses
31+
import dataclasses
3232
from typing import Optional
3333

3434
import click
@@ -53,6 +53,7 @@
5353
class RevocationType(Enum):
5454
CRL = 1
5555

56+
5657
class CertVerificationResult(Enum):
5758
SUCCESS = 1
5859
SKID_NOT_FOUND = 2
@@ -61,6 +62,7 @@ class CertVerificationResult(Enum):
6162
ISSUER_MISMATCH = 5
6263
AKID_MISMATCH = 6
6364

65+
6466
@dataclasses.dataclass
6567
class RevocationPoint:
6668
vid: int
@@ -77,6 +79,7 @@ class RevocationPoint:
7779
schemaVersion: int
7880
crlSignerDelegator: str
7981

82+
8083
@dataclasses.dataclass
8184
class RevocationSet:
8285
type: str
@@ -85,10 +88,10 @@ class RevocationSet:
8588
revoked_serial_numbers: [str]
8689
crl_signer_cert: str
8790
crl_signer_delegator: str = None
88-
91+
8992
def asDict(self):
9093
return dataclasses.asdict(self)
91-
94+
9295

9396
OID_VENDOR_ID = x509.ObjectIdentifier("1.3.6.1.4.1.37244.2.1")
9497
OID_PRODUCT_ID = x509.ObjectIdentifier("1.3.6.1.4.1.37244.2.2")
@@ -175,7 +178,8 @@ def is_self_signed_certificate(cert: x509.Certificate) -> bool:
175178
if result == CertVerificationResult.SUCCESS:
176179
return True
177180
else:
178-
logging.debug(f"Certificate with subject: {cert.subject.rfc4514_string()} is not a valid self-signed certificate. Result: {result.name}")
181+
logging.debug(
182+
f"Certificate with subject: {cert.subject.rfc4514_string()} is not a valid self-signed certificate. Result: {result.name}")
179183
return False
180184

181185

@@ -192,18 +196,21 @@ def validate_cert_chain(crl_signer: x509.Certificate, crl_signer_delegator: x509
192196
if crl_signer_delegator:
193197
result_signer = verify_cert(crl_signer, crl_signer_delegator)
194198
if not result_signer == CertVerificationResult.SUCCESS:
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}")
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}")
196201
return False
197202

198203
result_delegator = verify_cert(crl_signer_delegator, paa)
199204
if not result_delegator == CertVerificationResult.SUCCESS:
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}")
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}")
201207
return False
202208
return True
203209
else:
204210
result = verify_cert(crl_signer, paa)
205211
if not result == CertVerificationResult.SUCCESS:
206-
logging.debug(f"Cannot verify certificate subject: {crl_signer.subject.rfc4514_string()} issued by certificate subject: {paa.subject.rfc4514_string()}. Result: {result.name}")
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}")
207214
return False
208215
return True
209216

@@ -352,6 +359,7 @@ def fetch_crl_from_url(url: str, timeout: int) -> x509.CertificateRevocationList
352359
except Exception as e:
353360
logging.error('Failed to fetch a valid CRL', e)
354361

362+
355363
class DclClientInterface:
356364
'''
357365
An interface for interacting with DCLD.
@@ -598,7 +606,7 @@ def get_revocation_points(self) -> list[RevocationPoint]:
598606
'''
599607

600608
response = self.send_get_request(f"{self.rest_node_url}/dcl/pki/revocation-points")
601-
609+
602610
return [RevocationPoint(**r) for r in response["PkiRevocationDistributionPoint"]]
603611

604612
def get_revocation_points_by_skid(self, issuer_subject_key_id) -> list[RevocationPoint]:
@@ -666,7 +674,8 @@ def __init__(self, crls: [], dcl_certificates: [], revocation_points_response_fi
666674
logging.debug(f"Loading crls from {crls}")
667675
logging.debug(f"Loading revocation points response from {revocation_points_response_file}")
668676
self.crls = self.get_crls(crls)
669-
self.revocation_points = [RevocationPoint(**r) for r in json.load(revocation_points_response_file)["PkiRevocationDistributionPoint"]]
677+
self.revocation_points = [RevocationPoint(**r)
678+
for r in json.load(revocation_points_response_file)["PkiRevocationDistributionPoint"]]
670679
self.authoritative_certs = self.get_authoritative_certificates(dcl_certificates)
671680

672681
def get_lookup_key(self, certificate: x509.Certificate) -> str:
@@ -842,6 +851,7 @@ def get_crl_file(self,
842851
return crl
843852
return None
844853

854+
845855
@click.group()
846856
def cli():
847857
pass
@@ -985,6 +995,7 @@ def from_dcl(use_main_net_dcld: str, use_test_net_dcld: str, use_main_net_http:
985995
with open(output, 'w+') as outfile:
986996
json.dump([revocation.asDict() for revocation in revocation_set], outfile, indent=4)
987997

998+
988999
class TestRevocationSetGeneration(unittest.TestCase):
9891000
"""Test class for revocation set generation"""
9901001

@@ -1051,6 +1062,7 @@ def test_pai_revocation_set(self):
10511062
'test/revoked-attestation-certificates/revocation-sets/revocation-set-for-pai.json'
10521063
)
10531064

1065+
10541066
if __name__ == "__main__":
10551067
if len(sys.argv) > 1 and sys.argv[1] == 'test':
10561068
# Remove the 'test' argument and run tests

0 commit comments

Comments
 (0)