|
|
@ -4,12 +4,25 @@ |
|
|
|
|
|
|
|
|
import tempfile |
|
|
import tempfile |
|
|
from OpenSSL import crypto |
|
|
from OpenSSL import crypto |
|
|
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Certificado(object): |
|
|
class Certificado(object): |
|
|
def __init__(self, pfx, password): |
|
|
def __init__(self, pfx, password): |
|
|
self.pfx = pfx |
|
|
self.pfx = pfx |
|
|
self.password = password |
|
|
self.password = password |
|
|
|
|
|
pfx = crypto.load_pkcs12(pfx, password) |
|
|
|
|
|
|
|
|
|
|
|
cert = pfx.get_certificate() |
|
|
|
|
|
cert_date = int(str(cert.get_notAfter(),'UTF-8').strip('Z')) |
|
|
|
|
|
sha1_fingerprint = cert.digest("sha1") |
|
|
|
|
|
now = datetime.now() |
|
|
|
|
|
date = int(now.strftime("%Y%m%d%H%M%S")) |
|
|
|
|
|
''' |
|
|
|
|
|
Exceto certificado de testes |
|
|
|
|
|
''' |
|
|
|
|
|
if cert_date < date or str(sha1_fingerprint,'UTF-8') == "DE:08:15:1E:DA:12:B3:5F:76:BF:5D:4E:56:C1:14:12:8A:85:B6:47": |
|
|
|
|
|
print("WARNING: Certificado expirado") |
|
|
|
|
|
|
|
|
def save_pfx(self): |
|
|
def save_pfx(self): |
|
|
pfx_temp = tempfile.mkstemp()[1] |
|
|
pfx_temp = tempfile.mkstemp()[1] |
|
|
@ -20,7 +33,10 @@ class Certificado(object): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_cert_and_key_from_pfx(pfx, password): |
|
|
def extract_cert_and_key_from_pfx(pfx, password): |
|
|
pfx = crypto.load_pkcs12(pfx, password) |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
pfx = crypto.load_pkcs12(pfx, password) |
|
|
|
|
|
except: |
|
|
|
|
|
print("WARING: Falha ao ler certiticado. Verifique a senha") |
|
|
# PEM formatted private key |
|
|
# PEM formatted private key |
|
|
key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pfx.get_privatekey()) |
|
|
key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pfx.get_privatekey()) |
|
|
# PEM formatted certificate |
|
|
# PEM formatted certificate |
|
|
|