bot: Use alt hex reader
All checks were successful
Build Docker / Build Docker (push) Successful in 16s

This commit is contained in:
Nathan Woodburn 2023-09-27 17:44:07 +10:00
parent d3c82b6c05
commit 6cce762dd3
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

36
bot.py
View File

@ -8,6 +8,7 @@ import markdownify
import subprocess
import tempfile
import re
import binascii
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
@ -180,40 +181,21 @@ async def ssl(ctx, domain: str):
if certificates:
cert = certificates[0]
message = message + "\n## Website Certificate:\n`" + cert + "`\n"
message = message + "\n## Website Certificate:\n```\n" + cert + "\n```\n"
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp_cert_file:
temp_cert_file.write(cert)
temp_cert_file.seek(0) # Move back to the beginning of the temporary file
tlsa_command = [
"openssl",
"x509",
"-in",
temp_cert_file.name,
"-pubkey",
"-noout",
"|",
"openssl",
"pkey",
"-pubin",
"-outform",
"der",
"|",
"openssl",
"dgst",
"-sha256",
"-binary",
"|",
"xxd",
"-p",
"-u",
"-c",
"32",
]
tlsa_command = ["openssl","x509","-in",temp_cert_file.name,"-pubkey","-noout","|","openssl","pkey","-pubin","-outform","der","|","openssl","dgst","-sha256","-binary",]
tlsa_process = subprocess.Popen(" ".join(tlsa_command), shell=True, stdout=subprocess.PIPE)
tlsa_output, _ = tlsa_process.communicate()
message = message + "\n## TLSA Record from webserver: `3 1 1 " + tlsa_output.decode("utf-8") + "`\n"
tlsa_hex = binascii.hexlify(tlsa_output).decode("utf-8")
message = message + "\n## TLSA Record from webserver: `3 1 1 " + tlsa_hex + "`\n"
await ctx.response.send_message(message)
else:
ctx.response.send_message(f"No certificate found for {domain}")