-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck.py
61 lines (50 loc) · 2.07 KB
/
check.py
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
import ssl, socket
from prettytable import PrettyTable
import argparse
import time, json
import streamlit as st
# def check_ssl():
parser = argparse.ArgumentParser(description = 'Check and print SSL certiicate details')
parser.add_argument('--link', type=str)
args = parser.parse_args()
hostname = args.link.split('://')[1]
# print('Verifying SSL certificate details........\n')
# time.sleep(2)
def check_ssl(hostname):
ctx = ssl.create_default_context()
with ctx.wrap_socket(socket.socket(), server_hostname=hostname) as s:
try:
s.connect((hostname, 443))
cert = s.getpeercert()
data = json.dumps(cert, indent=2)
# print(data)
subject = dict(x[0] for x in cert['subject'])
issued_to = subject['commonName']
issuer = dict(x[0] for x in cert['issuer'])
issued_by = issuer['commonName']
subject = list(cert["subjectAltName"])
dns=[]
for i in range(len(subject)):
index = subject[i]
dns.append(index[1])
st.title('SSL Certificate Report')
st.markdown('---')
table = PrettyTable(['Fields', 'Values'])
table.add_row(["version", cert["version"]])
table.add_row(["commonName", issued_to])
for key in issuer.keys():
info = [key, issuer[key]]
table.add_row(info)
table.add_row(["serialNumber", cert["serialNumber"]])
table.add_row(["notBefore", cert["notBefore"]])
table.add_row(["notAfter", cert["notAfter"]])
table.add_row(["OCSP", cert["OCSP"][0]])
table.add_row(["caIssuers", cert["caIssuers"][0]])
table.add_row(["crlDistributionPoints", cert["crlDistributionPoints"][0]])
table.add_row(["DNS", [dns][0][1:4]])
st.json(data)
except:
st.title('SSL Certificate Report')
st.markdown('---')
st.markdown('no **SSL** certificate enabled for this URL!!')
# check_ssl(hostname)