Last active
January 25, 2017 20:26
-
-
Save berend/4eec35806a7bb562cd4e676c047d7599 to your computer and use it in GitHub Desktop.
Obtain the ssl certificate from a given url and generate the fingerprint for it (SHA1 and SHA256)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from M2Crypto import X509 | |
import ssl | |
def colon(s): | |
return ':'.join(s[i:i+2] for i in range(0, len(s), 2)) | |
addr = ("www.example.com", 443) | |
cert_pem = ssl.get_server_certificate(addr) | |
x509 = X509.load_cert_string(str(cert_pem), X509.FORMAT_PEM) | |
sha1_fingerprint = x509.get_fingerprint('sha1') | |
sha256_fingerprint = x509.get_fingerprint('sha256') | |
print("Address: {}:{}\nSHA1: {}\nSHA256: {}".format( | |
addr[0], addr[1], | |
colon(sha1_fingerprint), | |
colon(sha256_fingerprint)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some notes: