Skip to content

Instantly share code, notes, and snippets.

@montj2
Last active June 23, 2023 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save montj2/74c8c2ae666fa7ef98619815ff550c8c to your computer and use it in GitHub Desktop.
Save montj2/74c8c2ae666fa7ef98619815ff550c8c to your computer and use it in GitHub Desktop.
SSL Dump
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