From 6cce762dd3e87f7b116d1d62d4a6d6c3373e46ad Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 27 Sep 2023 17:44:07 +1000 Subject: [PATCH] bot: Use alt hex reader --- bot.py | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/bot.py b/bot.py index 7663ad5..543c806 100644 --- a/bot.py +++ b/bot.py @@ -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}")