Skip to content

Commit

Permalink
mostra mensagen de WARNING para data de certificados expirados
Browse files Browse the repository at this point in the history
  • Loading branch information
heronbrito committed May 21, 2020
1 parent 86e9379 commit 43bbc0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 117 deletions.
17 changes: 9 additions & 8 deletions pytrustnfe/certificado.py
Expand Up @@ -4,22 +4,24 @@

import tempfile
from OpenSSL import crypto
#import datetime
from datetime import datetime

#temp
import ssl

class Certificado(object):
def __init__(self, pfx, password):
self.pfx = pfx
self.password = password
pfx = crypto.load_pkcs12(pfx, password)

pfx = crypto.load_pkcs12(pfx, password).get_certificate()
cert_date = int(str(pfx.get_notAfter(),'UTF-8').strip('Z'))
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"))
if cert_date < date:
'''
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):
Expand All @@ -34,8 +36,7 @@ def extract_cert_and_key_from_pfx(pfx, password):
try:
pfx = crypto.load_pkcs12(pfx, password)
except:
print("ERROR: Falha ao ler certiticado. Verifique a senha")
exit()
print("WARING: Falha ao ler certiticado. Verifique a senha")
# PEM formatted private key
key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pfx.get_privatekey())
# PEM formatted certificate
Expand Down
108 changes: 0 additions & 108 deletions teste_carioca.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_certificado.py
Expand Up @@ -60,7 +60,7 @@ def test_preparar_pfx(self):

def test_save_pfx(self):
pfx_source = open(os.path.join(self.caminho, "teste.pfx"), "rb").read()
pfx = Certificado(pfx_source, "123")
pfx = Certificado(pfx_source, "123456")
path = pfx.save_pfx()
saved = open(path, "rb").read()
self.assertEqual(
Expand Down

0 comments on commit 43bbc0e

Please sign in to comment.