50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from structs import CertInfo, DSMInfo
|
|
from pathlib import Path
|
|
|
|
from cryptography import x509
|
|
from cryptography.hazmat.primitives import hashes
|
|
|
|
import logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
class CaddyWorker:
|
|
|
|
def search_cert_caddy(self, path_to_caddy_certs, site_name):
|
|
directory = Path(path_to_caddy_certs)
|
|
|
|
cert_folder = directory / site_name
|
|
|
|
if cert_folder.is_dir():
|
|
logging.info(f"Found certificate folder: {cert_folder}")
|
|
|
|
crt_path = cert_folder / f"{site_name}.crt"
|
|
|
|
if crt_path.is_file():
|
|
logging.info(f"Found certificate file: {crt_path}")
|
|
return crt_path
|
|
|
|
logging.info(f"No certificate file: {cert_folder}")
|
|
return None
|
|
else:
|
|
logging.info(f"No certificate folder: {cert_folder}")
|
|
return None
|
|
|
|
|
|
|
|
# def GetCertInfo(self, pathToCrtFile) -> CertInfo:
|
|
# path = Path(pathToCrtFile)
|
|
#
|
|
# with open(path, "rb") as file:
|
|
# cert_data = file.read()
|
|
#
|
|
# certificate = x509.load_der_x509_certificate(cert_data)
|
|
#
|
|
# fingerprint = certificate.fingerprint(
|
|
# hashes.SHA256()
|
|
# ).hex(":").upper()
|
|
#
|
|
# return CertInfo(
|
|
# fingerprint=fingerprint,
|
|
# expires_at=certificate.not_valid_after_utc,
|
|
# subject=certificate.subject.rfc4514_string()
|
|
# ) |