Skip to content

Commit f6578c1

Browse files
committed
Fix encoding type
1 parent 829bcb0 commit f6578c1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pynfe/entidades/certificado.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import os
44
import tempfile
55

6-
from cryptography.hazmat.primitives.serialization import Encoding, pkcs12
6+
from cryptography.hazmat.primitives.serialization import (
7+
Encoding,
8+
NoEncryption,
9+
PrivateFormat,
10+
pkcs12,
11+
)
712

813
from .base import Entidade
914

@@ -56,8 +61,9 @@ def separar_arquivo(self, senha, caminho=False):
5661
(
5762
chave,
5863
cert,
59-
_,
60-
) = pkcs12.load_key_and_certificates(cert_conteudo, str.encode(senha))
64+
) = pkcs12.load_key_and_certificates(
65+
cert_conteudo, str.encode(senha)
66+
)[:2]
6167
except ValueError as e:
6268
if "bad decrypt" in str(e).lower():
6369
raise Exception(
@@ -74,7 +80,11 @@ def separar_arquivo(self, senha, caminho=False):
7480
with tempfile.NamedTemporaryFile(delete=False) as arqcert:
7581
arqcert.write(cert.public_bytes(Encoding.PEM))
7682
with tempfile.NamedTemporaryFile(delete=False) as arqchave:
77-
arqchave.write(chave.private_bytes(Encoding.PEM))
83+
arqchave.write(
84+
chave.private_bytes(
85+
Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption()
86+
)
87+
)
7888
self.arquivos_temp.append(arqchave.name)
7989
self.arquivos_temp.append(arqcert.name)
8090
return arqchave.name, arqcert.name
@@ -86,7 +96,9 @@ def separar_arquivo(self, senha, caminho=False):
8696
cert = cert.replace("-----END CERTIFICATE-----", "")
8797

8898
# Chave, string decodificada da chave privada
89-
chave = chave.private_bytes(Encoding.PEM)
99+
chave = chave.private_bytes(
100+
Encoding.PEM, PrivateFormat.TraditionalOpenSSL, NoEncryption()
101+
)
90102

91103
return chave, cert
92104

0 commit comments

Comments
 (0)