Skip to content

Instantly share code, notes, and snippets.

@emailandxu
Created September 8, 2022 07:06
Show Gist options
  • Select an option

  • Save emailandxu/a7ee0e52f205f947903e21ce4e052218 to your computer and use it in GitHub Desktop.

Select an option

Save emailandxu/a7ee0e52f205f947903e21ce4e052218 to your computer and use it in GitHub Desktop.
print and validate ssl certificate
import os, ssl, certifi
# adress
host, port = "baidu.com", "443"
# the ca relative path
ca_certs=os.path.relpath(certifi.where())
# Retrieve the server certificate, validate the certificate by specify the ca_certs arg
cert = ssl.get_server_certificate((host, port), ca_certs=ca_certs)
# print the cert
print(cert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment