Spaces:
Sleeping
Sleeping
Commit ·
43737a5
1
Parent(s): f74c8dc
Refactor imports in acme_tools.py and app.py
Browse files- acme_tools.py +0 -1
- app.py +1 -12
- dns_cf.py +1 -0
- main.py +11 -4
- requirements.txt +2 -1
- send_mail.py +83 -0
- tools.py +0 -13
- verify_txt.py +1 -0
acme_tools.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import sys
|
| 2 |
import josepy as jose
|
| 3 |
from acme import messages, jose
|
| 4 |
from acme import client, messages
|
|
|
|
|
|
|
| 1 |
import josepy as jose
|
| 2 |
from acme import messages, jose
|
| 3 |
from acme import client, messages
|
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
import sys
|
| 3 |
import gradio as gr
|
| 4 |
from main import main
|
| 5 |
-
from tools import write_file
|
| 6 |
|
| 7 |
def gen_ssl(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None):
|
| 8 |
if key_type == "rsa":
|
|
@@ -14,17 +13,7 @@ def gen_ssl(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_
|
|
| 14 |
if key_size is not None:
|
| 15 |
key_size = int(key_size)
|
| 16 |
pvt, csr, cert = main(i_domains, wildcard, email, ca_server, key_type, key_size, key_curve)
|
| 17 |
-
|
| 18 |
-
path = "error"
|
| 19 |
-
else:
|
| 20 |
-
path = email.split("@")[0]
|
| 21 |
-
try:
|
| 22 |
-
os.makedirs(path, exist_ok=True)
|
| 23 |
-
except:
|
| 24 |
-
print("Error creating directory")
|
| 25 |
-
write_file(f"{path}/private.pem", pvt)
|
| 26 |
-
write_file(f"{path}/domain.csr", csr)
|
| 27 |
-
write_file(f"{path}/cert.pem", cert)
|
| 28 |
try:
|
| 29 |
return pvt.decode('utf-8'), csr.decode('utf-8'), cert.decode('utf-8')
|
| 30 |
except:
|
|
|
|
| 2 |
import sys
|
| 3 |
import gradio as gr
|
| 4 |
from main import main
|
|
|
|
| 5 |
|
| 6 |
def gen_ssl(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None):
|
| 7 |
if key_type == "rsa":
|
|
|
|
| 13 |
if key_size is not None:
|
| 14 |
key_size = int(key_size)
|
| 15 |
pvt, csr, cert = main(i_domains, wildcard, email, ca_server, key_type, key_size, key_curve)
|
| 16 |
+
print("SSL Certificate generated successfully")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
try:
|
| 18 |
return pvt.decode('utf-8'), csr.decode('utf-8'), cert.decode('utf-8')
|
| 19 |
except:
|
dns_cf.py
CHANGED
|
@@ -51,6 +51,7 @@ def del_txt(txt_name):
|
|
| 51 |
for record_id, record_name in zip(record_ids, record_names):
|
| 52 |
if record_name.startswith(txt_name):
|
| 53 |
try:
|
|
|
|
| 54 |
cf_endpoint = f"zones/{cf_zone_id}/dns_records/{record_id}"
|
| 55 |
url = f"{cf_api}{cf_endpoint}"
|
| 56 |
requests.request("DELETE", url, headers=headers)
|
|
|
|
| 51 |
for record_id, record_name in zip(record_ids, record_names):
|
| 52 |
if record_name.startswith(txt_name):
|
| 53 |
try:
|
| 54 |
+
print(f"Deleting record {record_name}")
|
| 55 |
cf_endpoint = f"zones/{cf_zone_id}/dns_records/{record_id}"
|
| 56 |
url = f"{cf_api}{cf_endpoint}"
|
| 57 |
requests.request("DELETE", url, headers=headers)
|
main.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import re
|
| 2 |
-
import sys
|
| 3 |
import time
|
| 4 |
from genPVTCSR import gen_pvt_csr
|
| 5 |
from tools import get_domains, get_ca_server, get_kid_hmac, extract_subdomains
|
|
@@ -8,6 +7,7 @@ from getTokenCert import get_tokens, verify_tokens
|
|
| 8 |
from gen_records import txt_recs
|
| 9 |
from dns_cf import add_txt, del_txt
|
| 10 |
from verify_txt import verify_txt
|
|
|
|
| 11 |
|
| 12 |
def cf_non_wildcard(verification_tokens, email, exchange):
|
| 13 |
tokens = verification_tokens
|
|
@@ -24,6 +24,7 @@ def cf_wildcard(verification_tokens, email, exchange):
|
|
| 24 |
tokens = verification_tokens
|
| 25 |
for key, value in tokens.items():
|
| 26 |
txt_rec = txt_recs(key, exchange)
|
|
|
|
| 27 |
try:
|
| 28 |
del_txt(txt_rec)
|
| 29 |
except Exception as e:
|
|
@@ -125,12 +126,9 @@ def main(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_cur
|
|
| 125 |
cf_non_wildcard(verification_tokens, email, exchange)
|
| 126 |
except Exception as e:
|
| 127 |
print(f"Error adding TXT records: {e}")
|
| 128 |
-
# verify TXT
|
| 129 |
-
'''
|
| 130 |
for i in range(60):
|
| 131 |
print(f"Waiting for {60-i} seconds", end="\r")
|
| 132 |
time.sleep(1)
|
| 133 |
-
'''
|
| 134 |
while not verify_txt_records(verification_tokens, exchange):
|
| 135 |
print("TXT records not verified yet")
|
| 136 |
time.sleep(5)
|
|
@@ -145,6 +143,15 @@ def main(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_cur
|
|
| 145 |
private_key = private_key.decode("utf-8")
|
| 146 |
csr = csr.decode("utf-8")
|
| 147 |
cert = cert.decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
return private_key, csr, cert
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import re
|
|
|
|
| 2 |
import time
|
| 3 |
from genPVTCSR import gen_pvt_csr
|
| 4 |
from tools import get_domains, get_ca_server, get_kid_hmac, extract_subdomains
|
|
|
|
| 7 |
from gen_records import txt_recs
|
| 8 |
from dns_cf import add_txt, del_txt
|
| 9 |
from verify_txt import verify_txt
|
| 10 |
+
from send_mail import send_email
|
| 11 |
|
| 12 |
def cf_non_wildcard(verification_tokens, email, exchange):
|
| 13 |
tokens = verification_tokens
|
|
|
|
| 24 |
tokens = verification_tokens
|
| 25 |
for key, value in tokens.items():
|
| 26 |
txt_rec = txt_recs(key, exchange)
|
| 27 |
+
print("\nTXT record:", txt_rec, "\n")
|
| 28 |
try:
|
| 29 |
del_txt(txt_rec)
|
| 30 |
except Exception as e:
|
|
|
|
| 126 |
cf_non_wildcard(verification_tokens, email, exchange)
|
| 127 |
except Exception as e:
|
| 128 |
print(f"Error adding TXT records: {e}")
|
|
|
|
|
|
|
| 129 |
for i in range(60):
|
| 130 |
print(f"Waiting for {60-i} seconds", end="\r")
|
| 131 |
time.sleep(1)
|
|
|
|
| 132 |
while not verify_txt_records(verification_tokens, exchange):
|
| 133 |
print("TXT records not verified yet")
|
| 134 |
time.sleep(5)
|
|
|
|
| 143 |
private_key = private_key.decode("utf-8")
|
| 144 |
csr = csr.decode("utf-8")
|
| 145 |
cert = cert.decode("utf-8")
|
| 146 |
+
generation_details = f"""
|
| 147 |
+
SSL Certificate for {i_domains} were generated successfully, using Project Gatekeeper, a free SSL Certificate creator tool.
|
| 148 |
+
SSL Provider = {ca_server}
|
| 149 |
+
Key Type = {key_type}
|
| 150 |
+
Key Curve = {key_curve}
|
| 151 |
+
Key Size = {key_size}
|
| 152 |
+
For more details, visit: https://projectgatekeeper.vercel.app/tool/decode.html
|
| 153 |
+
"""
|
| 154 |
+
send_email(email, private_key, csr, cert, generation_details)
|
| 155 |
return private_key, csr, cert
|
| 156 |
|
| 157 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -3,4 +3,5 @@ python-dotenv
|
|
| 3 |
acme==2.11.0
|
| 4 |
google-cloud-public-ca==0.3.9
|
| 5 |
gradio==4.41.0
|
| 6 |
-
dnspython==2.6.1
|
|
|
|
|
|
| 3 |
acme==2.11.0
|
| 4 |
google-cloud-public-ca==0.3.9
|
| 5 |
gradio==4.41.0
|
| 6 |
+
dnspython==2.6.1
|
| 7 |
+
sib-api-v3-sdk==7.6.0
|
send_mail.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import smtplib
|
| 3 |
+
from email.mime.text import MIMEText
|
| 4 |
+
from email.mime.multipart import MIMEMultipart
|
| 5 |
+
from email.mime.base import MIMEBase
|
| 6 |
+
from email import encoders
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
smtp_port = os.getenv("PORT")
|
| 11 |
+
smtp_server = os.getenv("SERVER")
|
| 12 |
+
smtp_login = os.getenv("LOGIN")
|
| 13 |
+
smtp_passwd = os.getenv("PASSWD")
|
| 14 |
+
|
| 15 |
+
def mail_body(email, generation_details):
|
| 16 |
+
body = f"""
|
| 17 |
+
Hello {email},
|
| 18 |
+
Thankyou for using Project Gatekeeper to generate your SSL certificate.
|
| 19 |
+
Your SSL certificate has been generated and is attached to this email.
|
| 20 |
+
Please find the attached file for your SSL certificate.
|
| 21 |
+
|
| 22 |
+
{generation_details}
|
| 23 |
+
|
| 24 |
+
Regards,
|
| 25 |
+
Nayan Kasturi (Raanna),
|
| 26 |
+
Developer & Maintainer,
|
| 27 |
+
Project Gatekeeper.
|
| 28 |
+
"""
|
| 29 |
+
return body
|
| 30 |
+
|
| 31 |
+
def make_attachment(private_key, csr, cert):
|
| 32 |
+
pvt = perpare_pvt(private_key)
|
| 33 |
+
csr = perpare_csr(csr)
|
| 34 |
+
ssl = perpare_ssl(cert)
|
| 35 |
+
return pvt, csr, ssl
|
| 36 |
+
|
| 37 |
+
def perpare_pvt(pvt):
|
| 38 |
+
filename = "private_key.key"
|
| 39 |
+
pvt= pvt.encode('utf-8')
|
| 40 |
+
pvtkey = MIMEBase('application', 'octet-stream')
|
| 41 |
+
pvtkey.set_payload(pvt)
|
| 42 |
+
encoders.encode_base64(pvtkey)
|
| 43 |
+
pvtkey.add_header('Content-Disposition', "attachment; filename= " + filename)
|
| 44 |
+
return pvtkey
|
| 45 |
+
|
| 46 |
+
def perpare_csr(csr):
|
| 47 |
+
filename = "domain.csr"
|
| 48 |
+
csr= csr.encode('utf-8')
|
| 49 |
+
domaincsr = MIMEBase('application', 'octet-stream')
|
| 50 |
+
domaincsr.set_payload(csr)
|
| 51 |
+
encoders.encode_base64(domaincsr)
|
| 52 |
+
domaincsr.add_header('Content-Disposition', "attachment; filename= " + filename)
|
| 53 |
+
return domaincsr
|
| 54 |
+
|
| 55 |
+
def perpare_ssl(ssl):
|
| 56 |
+
filename = "ssl_certificate.crt"
|
| 57 |
+
ssl= ssl.encode('utf-8')
|
| 58 |
+
sslcrt = MIMEBase('application', 'octet-stream')
|
| 59 |
+
sslcrt.set_payload(ssl)
|
| 60 |
+
encoders.encode_base64(sslcrt)
|
| 61 |
+
sslcrt.add_header('Content-Disposition', "attachment; filename= " + filename)
|
| 62 |
+
return sslcrt
|
| 63 |
+
|
| 64 |
+
def prepare_email(email, private_key, csr, cert, generation_details):
|
| 65 |
+
body = mail_body(email, generation_details)
|
| 66 |
+
msg = MIMEMultipart()
|
| 67 |
+
msg['From'] = "Project Gatekeeper <{}>".format(smtp_login)
|
| 68 |
+
msg['To'] = email
|
| 69 |
+
msg['Subject'] = "Project Gatekeeper - Your SSL Certificate is ready!"
|
| 70 |
+
msg.attach(MIMEText(body, 'plain'))
|
| 71 |
+
p, c, s = make_attachment(private_key, csr, cert)
|
| 72 |
+
for attachment_package in [p, c, s]:
|
| 73 |
+
msg.attach(attachment_package)
|
| 74 |
+
text = msg.as_string()
|
| 75 |
+
return text
|
| 76 |
+
|
| 77 |
+
def send_email(email, private_key, csr, cert, generation_details):
|
| 78 |
+
data = prepare_email(email, private_key, csr, cert, generation_details)
|
| 79 |
+
TIE_server = smtplib.SMTP(smtp_server, smtp_port)
|
| 80 |
+
TIE_server.starttls()
|
| 81 |
+
TIE_server.login(smtp_login, smtp_passwd)
|
| 82 |
+
TIE_server.sendmail(from_addr=smtp_login, to_addrs=email, msg=data)
|
| 83 |
+
TIE_server.quit()
|
tools.py
CHANGED
|
@@ -59,16 +59,3 @@ def get_kid_hmac(server):
|
|
| 59 |
return kid, hmac
|
| 60 |
else:
|
| 61 |
return None, None
|
| 62 |
-
|
| 63 |
-
def write_file(filename, data):
|
| 64 |
-
try:
|
| 65 |
-
try:
|
| 66 |
-
with open(filename, 'wb') as f:
|
| 67 |
-
f.write(data)
|
| 68 |
-
except:
|
| 69 |
-
with open(filename, 'w') as f:
|
| 70 |
-
f.write(data)
|
| 71 |
-
print(filename, " successfully written")
|
| 72 |
-
except Exception as e:
|
| 73 |
-
print("Error writing file: ", filename)
|
| 74 |
-
print(e)
|
|
|
|
| 59 |
return kid, hmac
|
| 60 |
else:
|
| 61 |
return None, None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify_txt.py
CHANGED
|
@@ -10,6 +10,7 @@ def get_txt(rec):
|
|
| 10 |
redirect_domain = txt_record.split('.')[-1]
|
| 11 |
else:
|
| 12 |
redirect_domain = txt_record
|
|
|
|
| 13 |
return redirect_domain.strip('"').strip('.')
|
| 14 |
except Exception as e:
|
| 15 |
print(f"An error occurred while resolving {rec}: {e}")
|
|
|
|
| 10 |
redirect_domain = txt_record.split('.')[-1]
|
| 11 |
else:
|
| 12 |
redirect_domain = txt_record
|
| 13 |
+
print(f"Resolved {rec} to {redirect_domain.strip('.')}")
|
| 14 |
return redirect_domain.strip('"').strip('.')
|
| 15 |
except Exception as e:
|
| 16 |
print(f"An error occurred while resolving {rec}: {e}")
|