Created
October 23, 2014 11:43
-
-
Save TheBits/9887f485e753da97d103 to your computer and use it in GitHub Desktop.
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
#FUNCTION x509_get_info(pem character varying) | |
# old | |
from gnutls.crypto import X509Certificate | |
x=X509Certificate(pem.replace('\r ', '\r\n')) | |
subj = dict([f.split('=') for f in x.subject.split(',')]) | |
from datetime import datetime | |
return subj['CN'], datetime.fromtimestamp(x.expiration_time) | |
#new | |
import OpenSSL | |
oc = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, pem) | |
from datetime import datetime | |
return oc.get_subject().commonName, datetime.strptime(oc.get_notAfter(), '%Y%m%d%H%M%SZ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment