File size: 2,244 Bytes
636c84f
c431254
 
 
 
 
6c7898d
c431254
6c7898d
 
 
 
29a73fb
6c7898d
29a73fb
 
6c7898d
29a73fb
6c7898d
29a73fb
 
6c7898d
 
 
29a73fb
 
 
6c7898d
 
 
29a73fb
 
 
6c7898d
 
 
 
 
 
 
 
 
 
 
b19261f
6c7898d
c431254
 
 
 
 
 
6c7898d
c431254
 
6c7898d
c431254
 
 
 
 
 
a2075a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
import gradio as gr
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from decode import decode_ssl_certificate

def decode(cert) -> str:
    try:
        # Ensure cert is a byte string
        if isinstance(cert, str):
            cert = cert.encode()

        try:
            decoded_cert = None
            try:
                decoded_cert = x509.load_pem_x509_certificate(cert, default_backend())
            except Exception:
                decoded_cert = x509.load_pem_x509_csr(cert, default_backend())

            if decoded_cert:
                decoded_data = decode_ssl_certificate(decoded_cert)
                response = {
                    "status": "Success",
                    "message": "Certificate decoded successfully.",
                    "data": decoded_data
                }
            else:
                response = {
                    "status": "Failed",
                    "message": "Invalid certificate format.",
                    "data": None
                }
        except Exception as e:
            response = {
                "status": "Failed",
                "message": "Failed to decode certificate. Please upload a valid certificate file.",
                "error": str(e)  # Convert Exception to a string
            }
    except Exception as e:
        response = {
            "status": "Failed",
            "message": "Unexpected error while processing the certificate.",
            "error": str(e)
        }
    print(response)
    return json.dumps(response, indent=4)  # Always return a JSON string

def app():
    with gr.Blocks(title="Project Gatekeeper - Get free SSL Certificates") as webui:
        with gr.Row():
            ssl = gr.Textbox(label="Enter Domains", type="text", interactive=True)
        with gr.Row():
            decoded_data = gr.Textbox(label="Decoded SSL Data", type="text", interactive=False, show_copy_button=True)
        btn = gr.Button(value="Generate SSL Certificate")
        btn.click(decode, inputs=ssl, outputs=decoded_data)
    
    try:
        webui.queue(default_concurrency_limit=15).launch()
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    app()