3
3
import os
4
4
import tempfile
5
5
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
+ )
7
12
8
13
from .base import Entidade
9
14
@@ -56,8 +61,9 @@ def separar_arquivo(self, senha, caminho=False):
56
61
(
57
62
chave ,
58
63
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 ]
61
67
except ValueError as e :
62
68
if "bad decrypt" in str (e ).lower ():
63
69
raise Exception (
@@ -74,7 +80,11 @@ def separar_arquivo(self, senha, caminho=False):
74
80
with tempfile .NamedTemporaryFile (delete = False ) as arqcert :
75
81
arqcert .write (cert .public_bytes (Encoding .PEM ))
76
82
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
+ )
78
88
self .arquivos_temp .append (arqchave .name )
79
89
self .arquivos_temp .append (arqcert .name )
80
90
return arqchave .name , arqcert .name
@@ -86,7 +96,9 @@ def separar_arquivo(self, senha, caminho=False):
86
96
cert = cert .replace ("-----END CERTIFICATE-----" , "" )
87
97
88
98
# 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
+ )
90
102
91
103
return chave , cert
92
104
0 commit comments