import os import sys import time from genPVTCSR import gen_pvt_csr from tools import get_domains, get_ca_server, get_kid_hmac, extract_subdomains from acme_tools import pg_client, new_account from getTokenCert import get_tokens, verify_tokens from gen_records import txt_recs from dns_cf import add_txt, del_txt def cf_non_wildcard(verification_tokens, email, exchange): tokens = verification_tokens for key, value in tokens.items(): txt_rec = txt_recs(key, exchange) txt_value = value[0].strip() try: del_txt(txt_rec) except Exception as e: print(f"Error deleting TXT records or no TXT records exists: {e}") add_txt(txt_rec, txt_value, ssl_email=email) def cf_wildcard(verification_tokens, email, exchange): tokens = verification_tokens for key, value in tokens.items(): txt_rec = txt_recs(key, exchange) try: del_txt(txt_rec) except Exception as e: print(f"Error deleting TXT records or no TXT records exists: {e}") for txt_value in value: add_txt(txt_rec, txt_value, ssl_email=email) def main(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None, kid=None, hmac=None): domains = get_domains(i_domains) exchange = extract_subdomains(domains=domains) if wildcard: domains = [exchange, f'*.{exchange}'] ca_server_url = get_ca_server(ca_server, key_type) pgk_client = pg_client(ca_server_url, key_type=key_type, key_size=key_size, key_curve=key_curve) if pgk_client is None: exit() nkid, nhmac = get_kid_hmac(ca_server) if nkid == 'Error' or nhmac == 'Error': print("Try with another provider or contact us") sys.exit(1) else: kid = nkid hmac = nhmac account = new_account(pgk_client, email, kid=kid, hmac=hmac) if not account: exit() private_key, csr = gen_pvt_csr(domains=domains, email=email, key_type=key_type, key_curve=key_curve, key_size=key_size) verification_tokens, challs, order = get_tokens(pgk_client, csr, ca_server_url) try: if wildcard: cf_wildcard(verification_tokens, email, exchange) else: cf_non_wildcard(verification_tokens, email, exchange) except: print("Error adding TXT records") sys.exit(1) for i in range(60): print(f"Waiting for {60-i} seconds", end="\r") time.sleep(1) cert = verify_tokens(pgk_client, challs, order) for key, _value in verification_tokens.items(): txt_rec = txt_recs(key, exchange) try: del_txt(txt_rec) print("TXT records deleted successfully") except Exception as e: print(f"Error deleting TXT records or no TXT records exists: {e}") return private_key, csr, cert if __name__ == "__main__": DOMAINS = 'raannakasturi.eu.org' ca_server = "SSL.com" #Let's Encrypt (Testing), Let's Encrypt, Google (Testing), Google, Buypass (Testing), Buypass, ZeroSSL, SSL.com EMAIL = "raannak@mail.com" key_type = "ec" key_curve = "ec384" key_size = None KID = None HMAC = None private_key, csr, cert = main(i_domains=DOMAINS, wildcard=True, email=EMAIL, ca_server=ca_server, key_type=key_type, key_size=key_size,key_curve=key_curve, kid=KID, hmac=HMAC) print("Private Key:") print(private_key.decode('utf-8')) print() print("CSR:") print(csr.decode('utf-8')) print() print("Certificate:") print(cert.decode('utf-8'))