bot: Update ssl parsing
All checks were successful
Build Docker / Build Docker (push) Successful in 15s
All checks were successful
Build Docker / Build Docker (push) Successful in 15s
This commit is contained in:
parent
5c1259c1e2
commit
e9d40a337c
30
bot.py
30
bot.py
@ -9,7 +9,8 @@ import subprocess
|
|||||||
import tempfile
|
import tempfile
|
||||||
import re
|
import re
|
||||||
import binascii
|
import binascii
|
||||||
import ssl
|
from cryptography import x509
|
||||||
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@ -203,22 +204,19 @@ async def ssl(ctx, domain: str):
|
|||||||
|
|
||||||
|
|
||||||
# Get domains
|
# Get domains
|
||||||
x509 = ssl.load_certificate(ssl.PEM_cert_to_DER_cert(cert.encode("utf-8")))
|
cert_obj = x509.load_pem_x509_certificate(cert.encode("utf-8"), default_backend())
|
||||||
|
|
||||||
domains = []
|
domains = []
|
||||||
try:
|
for ext in cert_obj.extensions:
|
||||||
san_list = x509.get_extension_by_oid("subjectAltName")
|
if ext.oid == x509.ExtensionOID.SUBJECT_ALTERNATIVE_NAME:
|
||||||
san_list = san_list._subjectAltNameString().split(", ")
|
san_list = ext.value.get_values_for_type(x509.DNSName)
|
||||||
domains.extend(san_list)
|
domains.extend(san_list)
|
||||||
except Exception as e:
|
|
||||||
print(e, flush=True)
|
# Extract the common name (CN) from the subject
|
||||||
|
common_name = cert_obj.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)
|
||||||
try:
|
if common_name:
|
||||||
subject = x509.get_subject()
|
domains.append(common_name[0].value)
|
||||||
common_name = subject.CN
|
|
||||||
if common_name:
|
|
||||||
domains.append(common_name)
|
|
||||||
except Exception as e:
|
|
||||||
print(e, flush=True)
|
|
||||||
|
|
||||||
if domains:
|
if domains:
|
||||||
message = message + "\n## SSL Domains:\n"
|
message = message + "\n## SSL Domains:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user