Created
May 17, 2023 01:12
-
-
Save jglenn9k/4ef60cf9e56630cc86c714198d3a86be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import socket | |
import ssl | |
import datetime | |
import pprint | |
now = datetime.datetime.now() | |
# Create an SSL context | |
ssl_context = ssl.create_default_context() | |
# Get the loaded CA certificates | |
ca_certs = ssl_context.get_ca_certs() | |
print("Listing all local certs...") | |
# Extract the 'commonName' and 'organizationName' from the issuer | |
for cert in ca_certs: | |
issuer = {k: v for d in cert['issuer'] for (k, v) in d} | |
common_name = issuer.get('commonName') | |
organization_name = issuer.get('organizationName') | |
not_after = cert['notAfter'] | |
print(f"Common Name: {common_name}") | |
print(f"Organization Name: {organization_name}") | |
print(f"Expiration Date: {not_after}") | |
timestamp = datetime.datetime.strptime(not_after, "%b %d %H:%M:%S %Y %Z") | |
if now > timestamp: | |
print(f"Cert with Common Name = {common_name} and Organization Name = {organization_name} has EXPIRED!") | |
conn = ssl_context.wrap_socket(socket.socket(socket.AF_INET),server_hostname="ssl.com") | |
conn.connect(("ssl.com", 443)) | |
cert = conn.getpeercert() | |
pprint.pprint(cert) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment