Created
September 29, 2014 14:43
-
-
Save moranned/3bf1e7624938f555f47e to your computer and use it in GitHub Desktop.
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 OpenSSL | |
import sys | |
def parseCert(certFile): | |
cert = open(certFile, 'rb') | |
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert.read()) | |
subject = x509.get_subject() | |
issuer = x509.get_issuer() | |
fingerprint = x509.digest('sha1') | |
subject = x509.get_subject() | |
print '%-25s %s' %('SHA1 Fingerprint:',fingerprint) | |
print '%-25s %s' %('Serial Number:',x509.get_serial_number()) | |
print '%-25s %s' %('Common Name:',subject.CN) | |
print '%-25s %s' %('Organization:',subject.O) | |
print '%-25s %s' %('Issuer CN:',issuer.CN) | |
print '%-25s %s' %('Issuer Org',issuer.O) | |
print '%-25s %s' %('Issue Date:',x509.get_notBefore()) | |
print '%-25s %s' %('Expiration Date:', x509.get_notAfter()) | |
def main(): | |
if len(sys.argv) != 2: | |
print '\nUsage: python ./parseCerts.py [cert file]\n' | |
sys.exit(1) | |
parseCert(sys.argv[1]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment