Реализовал функцию поиска сертификата
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
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()
|
||||||
|
# )
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
from caddy_worker import CaddyWorker
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
worker = CaddyWorker()
|
||||||
|
|
||||||
|
result = worker.search_cert_caddy(
|
||||||
|
"D:/Work/Programming/Python/CaddyToDSM/TestData/certs",
|
||||||
|
"wud.stadidisk.ru"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Result: {result}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CertInfo:
|
||||||
|
fingerprint: str
|
||||||
|
expires_at: datetime
|
||||||
|
subject: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DSMInfo:
|
||||||
|
certificate_name: str
|
||||||
|
private_key_path: str
|
||||||
|
certificate_pem_path: str
|
||||||
|
private_key_pem_path: str
|
||||||
Reference in New Issue
Block a user