Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,83 +4,56 @@ from cryptography import x509
|
|
4 |
from cryptography.hazmat.backends import default_backend
|
5 |
from decode import decode_ssl_certificate
|
6 |
|
7 |
-
def decode(cert) ->
|
8 |
try:
|
9 |
-
cert
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
decoded_cert = x509.load_pem_x509_certificate(cert, default_backend())
|
14 |
-
except:
|
15 |
-
decoded_cert = x509.load_pem_x509_csr(cert, default_backend())
|
16 |
-
if decoded_cert:
|
17 |
-
status = "Success"
|
18 |
-
message = "Certificate decoded successfully."
|
19 |
-
decoded_data = decode_ssl_certificate(decoded_cert)
|
20 |
-
data = {
|
21 |
-
"status": status,
|
22 |
-
"message": message,
|
23 |
-
"data": decoded_data
|
24 |
-
}
|
25 |
-
ssl_out = json.dumps(data, indent = 4)
|
26 |
-
else:
|
27 |
-
data = {
|
28 |
-
"status": status,
|
29 |
-
"message": message,
|
30 |
-
"data": None
|
31 |
-
}
|
32 |
-
ssl_out = json.dumps(data, indent = 4)
|
33 |
-
except Exception as e:
|
34 |
-
status = "Failed"
|
35 |
-
message = "Failed to decode certificate. Please make sure you have uploaded a valid certificate file."
|
36 |
-
data = {
|
37 |
-
"status": status,
|
38 |
-
"message": message,
|
39 |
-
"data": e
|
40 |
-
}
|
41 |
-
except:
|
42 |
-
ssl_out = {}
|
43 |
try:
|
|
|
44 |
try:
|
45 |
decoded_cert = x509.load_pem_x509_certificate(cert, default_backend())
|
46 |
-
except:
|
47 |
decoded_cert = x509.load_pem_x509_csr(cert, default_backend())
|
|
|
48 |
if decoded_cert:
|
49 |
-
status = "Success"
|
50 |
-
message = "Certificate decoded successfully."
|
51 |
decoded_data = decode_ssl_certificate(decoded_cert)
|
52 |
-
|
53 |
-
"status":
|
54 |
-
"message":
|
55 |
"data": decoded_data
|
56 |
}
|
57 |
-
ssl_out = json.dumps(data, indent = 4)
|
58 |
else:
|
59 |
-
|
60 |
-
"status":
|
61 |
-
"message":
|
62 |
"data": None
|
63 |
}
|
64 |
-
ssl_out = json.dumps(data, indent = 4)
|
65 |
except Exception as e:
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
75 |
|
76 |
def app():
|
77 |
with gr.Blocks(title="Project Gatekeeper - Get free SSL Certificates") as webui:
|
78 |
with gr.Row():
|
79 |
ssl = gr.Textbox(label="Enter Domains", type="text", interactive=True)
|
80 |
with gr.Row():
|
81 |
-
decoded_data = gr.Textbox(label="
|
82 |
btn = gr.Button(value="Generate SSL Certificate")
|
83 |
btn.click(decode, inputs=ssl, outputs=decoded_data)
|
|
|
84 |
try:
|
85 |
webui.queue(default_concurrency_limit=15).launch()
|
86 |
except Exception as e:
|
|
|
4 |
from cryptography.hazmat.backends import default_backend
|
5 |
from decode import decode_ssl_certificate
|
6 |
|
7 |
+
def decode(cert) -> str:
|
8 |
try:
|
9 |
+
# Ensure cert is a byte string
|
10 |
+
if isinstance(cert, str):
|
11 |
+
cert = cert.encode()
|
12 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
try:
|
14 |
+
decoded_cert = None
|
15 |
try:
|
16 |
decoded_cert = x509.load_pem_x509_certificate(cert, default_backend())
|
17 |
+
except Exception:
|
18 |
decoded_cert = x509.load_pem_x509_csr(cert, default_backend())
|
19 |
+
|
20 |
if decoded_cert:
|
|
|
|
|
21 |
decoded_data = decode_ssl_certificate(decoded_cert)
|
22 |
+
response = {
|
23 |
+
"status": "Success",
|
24 |
+
"message": "Certificate decoded successfully.",
|
25 |
"data": decoded_data
|
26 |
}
|
|
|
27 |
else:
|
28 |
+
response = {
|
29 |
+
"status": "Failed",
|
30 |
+
"message": "Invalid certificate format.",
|
31 |
"data": None
|
32 |
}
|
|
|
33 |
except Exception as e:
|
34 |
+
response = {
|
35 |
+
"status": "Failed",
|
36 |
+
"message": "Failed to decode certificate. Please upload a valid certificate file.",
|
37 |
+
"error": str(e) # Convert Exception to a string
|
38 |
+
}
|
39 |
+
except Exception as e:
|
40 |
+
response = {
|
41 |
+
"status": "Failed",
|
42 |
+
"message": "Unexpected error while processing the certificate.",
|
43 |
+
"error": str(e)
|
44 |
+
}
|
45 |
+
|
46 |
+
return json.dumps(response, indent=4) # Always return a JSON string
|
47 |
|
48 |
def app():
|
49 |
with gr.Blocks(title="Project Gatekeeper - Get free SSL Certificates") as webui:
|
50 |
with gr.Row():
|
51 |
ssl = gr.Textbox(label="Enter Domains", type="text", interactive=True)
|
52 |
with gr.Row():
|
53 |
+
decoded_data = gr.Textbox(label="Decoded SSL Data", type="text", interactive=False, show_copy_button=True)
|
54 |
btn = gr.Button(value="Generate SSL Certificate")
|
55 |
btn.click(decode, inputs=ssl, outputs=decoded_data)
|
56 |
+
|
57 |
try:
|
58 |
webui.queue(default_concurrency_limit=15).launch()
|
59 |
except Exception as e:
|