22#
33# SPDX-License-Identifier: Apache-2.0
44
5+ import argparse
56import sys
67import time
8+
79import requests
8- import argparse
910from cryptography import x509
1011from cryptography .hazmat .backends import default_backend
1112from cryptography .hazmat .primitives import serialization
@@ -28,24 +29,29 @@ def get_logs(self, count: int = 100):
2829 url = f"{ BASE_URL } /?q={ self .domain } &output=json&limit={ count } "
2930 response = requests .get (url )
3031 return response .json ()
31-
32+
3233 def check_one_log (self , log : object ):
3334 log_id = log ["id" ]
3435 cert_url = f"{ BASE_URL } /?d={ log_id } "
3536 cert_data = requests .get (cert_url ).text
3637 # Extract PEM-encoded certificate
3738 import re
38- pem_match = re .search (r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----' , cert_data , re .DOTALL )
39+
40+ pem_match = re .search (
41+ r"-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----" ,
42+ cert_data ,
43+ re .DOTALL ,
44+ )
3945 if pem_match :
4046 pem_cert = pem_match .group (0 )
41-
47+
4248 # Parse PEM certificate
4349 cert = x509 .load_pem_x509_certificate (pem_cert .encode (), default_backend ())
4450 # Extract the public key
4551 public_key = cert .public_key ()
4652 pem_public_key = public_key .public_bytes (
4753 encoding = serialization .Encoding .PEM ,
48- format = serialization .PublicFormat .SubjectPublicKeyInfo
54+ format = serialization .PublicFormat .SubjectPublicKeyInfo ,
4955 )
5056 print ("Public Key:" )
5157 print (pem_public_key .hex ())
@@ -65,11 +71,11 @@ def check_new_logs(self):
6571 logs = self .get_logs (count = 10000 )
6672 print ("num logs" , len (logs ))
6773 for log in logs :
68- print (f"log id={ log ["id" ]} " )
74+ print (f"log id={ log ['id' ]} " )
6975 if log ["id" ] <= (self .last_checked or 0 ):
7076 break
7177 self .check_one_log (log )
72- print (' next' )
78+ print (" next" )
7379 if len (logs ) > 0 :
7480 self .last_checked = logs [0 ]["id" ]
7581
@@ -92,7 +98,7 @@ def validate_domain(domain: str):
9298
9399 # Regular expression for validating domain names
94100 domain_regex = re .compile (
95- r' ^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$'
101+ r" ^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$"
96102 )
97103
98104 if not domain_regex .match (domain ):
@@ -102,7 +108,9 @@ def validate_domain(domain: str):
102108
103109
104110def main ():
105- parser = argparse .ArgumentParser (description = "Monitor certificate transparency logs" )
111+ parser = argparse .ArgumentParser (
112+ description = "Monitor certificate transparency logs"
113+ )
106114 parser .add_argument ("-d" , "--domain" , help = "The domain to monitor" )
107115 args = parser .parse_args ()
108116 monitor = Monitor (args .domain )
0 commit comments