From 295135af7fc7203135775c14919c47e8f81d6764 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 30 Aug 2025 12:47:29 +0800 Subject: [PATCH] feat: add tls certificate, but not success --- tls_certificate.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 tls_certificate.py diff --git a/tls_certificate.py b/tls_certificate.py new file mode 100755 index 0000000..0c0e692 --- /dev/null +++ b/tls_certificate.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +import socket +import ssl + +def get_server_certificate(hostname, port=443): + # context = ssl.create_default_context() + context = ssl._create_unverified_context() + + with socket.create_connection((hostname, port)) as sock: + with context.wrap_socket(sock, server_hostname=hostname) as ssock: + cert = ssock.getpeercert() + return cert + +# not success, but why? +if __name__ == "__main__": + certificate = get_server_certificate("hatter.ink") + print(f"Certificate: {certificate}") + for key, value in certificate.items(): + print(f"{key}: {value}") \ No newline at end of file