python - Verify certificates' fingerprints -
i interested in comparing fingerprints of self-signed ssl certifactes. so, thought of:
import ssl, socket m2crypto import x509 cert_pem = ssl.get_server_certificate(addr) x509 = x509.load_cert_string(cert_pem, x509.format_pem) fp = x509.get_fingerprint('sha1') if fp==allowed_fp: s = socket.socket(socket.af_inet,socket.sock_stream) s.connect(addr) but bias see, cert might change between verification , connection. nice use same connection ssl.get_server_certificate uses. there better way compare fingerprints?
use getpeercert after connecting.
Comments
Post a Comment