Last active
September 8, 2021 06:32
-
-
Save hoogenm/fb0e0113ccbfebcfec7765bab9084494 to your computer and use it in GitHub Desktop.
Certificate check
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
from cryptography import x509 | |
from cryptography.hazmat.backends import default_backend | |
import socket | |
import ssl | |
from datetime import datetime | |
HOST = 'www.rabobank.nl' | |
def check_cert(host): | |
context = ssl.create_default_context() | |
with socket.create_connection((host, 443)) as sock: | |
with context.wrap_socket(sock, server_hostname=HOST) as sslsock: | |
der_cert = sslsock.getpeercert(True) | |
cert = x509.load_der_x509_certificate(der_cert, default_backend()) | |
print("Certificate will expire on ", datetime.strftime(cert.not_valid_after, '%Y-%m-%d %H:%M:%S')) | |
check_cert(HOST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment