Last active
June 23, 2023 14:34
-
-
Save montj2/74c8c2ae666fa7ef98619815ff550c8c to your computer and use it in GitHub Desktop.
SSL Dump
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
import requests | |
import ssl | |
import certifi | |
import logging | |
# Disable SSL verification warning | |
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning) | |
# Configure logging | |
logging.basicConfig(level=logging.INFO) | |
# URL to make the request | |
url = 'https://example.com' | |
# Make the request | |
response = requests.get(url, verify=True) | |
# Get SSL certificate from the response | |
local_certificate = ssl.get_server_certificate((url, 443)) | |
# Get the remote certificate | |
remote_certificate = response.connection.sock.getpeercert(True) | |
# Get the certificates used for verification | |
verification_certificates = ssl.get_default_verify_paths().cafile | |
# Log the certificates | |
logger = logging.getLogger('certificate_logger') | |
logger.info('Local Certificate:\n%s', local_certificate) | |
logger.info('Remote Certificate:\n%s', remote_certificate) | |
logger.info('Verification Certificates:\n%s', verification_certificates) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment