Skip to content

Instantly share code, notes, and snippets.

@pudquick
Last active May 28, 2021 18:13
Show Gist options
  • Save pudquick/ad575cee6bb503d4d193da355d70d3e9 to your computer and use it in GitHub Desktop.
Save pudquick/ad575cee6bb503d4d193da355d70d3e9 to your computer and use it in GitHub Desktop.
Parsing server certificate OIDs for SSL connections with python and pyobjc on macOS / OS X
import ssl, base64, objc
from Foundation import NSBundle
Security = NSBundle.bundleWithIdentifier_('com.apple.security')
S_functions = [
('SecCertificateCreateWithData', '@@@'),
('SecCertificateCopyValues', '@@^@o^@'),
]
objc.loadBundleFunctions(Security, globals(), S_functions)
server_pem = ssl.get_server_certificate(('www.google.com', 443))
pem_lines = server_pem.splitlines()
pem_base64 = ''.join([x for x in pem_lines if 'CERTIFICATE---' not in x])
server_der = base64.b64decode(pem_base64)
server_cert = SecCertificateCreateWithData(None, buffer(server_der))
cert_details, errors = SecCertificateCopyValues(server_cert, None, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment