Last active
May 28, 2021 18:13
-
-
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
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 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