11import base64
22import ssl
33
4- from OpenSSL import crypto
54from jwcrypto import jwk
65
6+ from cryptography .hazmat .primitives import serialization
7+ from cryptography .hazmat .backends import default_backend
8+ from cryptography .hazmat .primitives .serialization import pkcs12
9+
710from authenticationsdk .util .GlobalLabelParameters import *
811
912
@@ -24,24 +27,30 @@ def grab_file(self, mconfig, filepath, filename):
2427
2528 if filename not in self .filecache :
2629
27- p12 = crypto .load_pkcs12 (open (
28- os .path .join (filepath , filename )+ GlobalLabelParameters .P12_PREFIX ,
29- 'rb' ).read (), mconfig .key_password )
30- cert_str = crypto .dump_certificate (crypto .FILETYPE_PEM , p12 .get_certificate ())
31- der_cert_string = base64 .b64encode (ssl .PEM_cert_to_DER_cert (cert_str .decode ("utf-8" )))
32- private_key = crypto .dump_privatekey (crypto .FILETYPE_PEM , p12 .get_privatekey ()).decode ("utf-8" )
30+ private_key , certificate , additional_certificates = pkcs12 .load_key_and_certificates (
31+ open (os .path .join (filepath , filename )+ GlobalLabelParameters .P12_PREFIX ,'rb' ).read () ,
32+ password = (mconfig .key_password ).encode (),
33+ backend = default_backend ()
34+ )
35+
36+ cert_pem = certificate .public_bytes (serialization .Encoding .PEM )
37+ cert_pem_str = cert_pem .decode ('utf-8' )
38+ der_cert_string = base64 .b64encode (ssl .PEM_cert_to_DER_cert (cert_pem_str ))
3339
3440 self .filecache .setdefault (str (filename ), []).append (der_cert_string )
3541 self .filecache .setdefault (str (filename ), []).append (private_key )
3642 self .filecache .setdefault (str (filename ), []).append (file_mod_time )
3743
3844 if file_mod_time != self .filecache [filename ][2 ]:
39- p12 = crypto .load_pkcs12 (open (
40- os .path .join (filepath , filename ) + GlobalLabelParameters .P12_PREFIX ,
41- 'rb' ).read (), mconfig .key_password )
42- cert_str = crypto .dump_certificate (crypto .FILETYPE_PEM , p12 .get_certificate ())
43- der_cert_string = base64 .b64encode (ssl .PEM_cert_to_DER_cert (cert_str .decode ("utf-8" )))
44- private_key = crypto .dump_privatekey (crypto .FILETYPE_PEM , p12 .get_privatekey ()).decode ("utf-8" )
45+ private_key , certificate , additional_certificates = pkcs12 .load_key_and_certificates (
46+ open (os .path .join (filepath , filename )+ GlobalLabelParameters .P12_PREFIX ,'rb' ).read () ,
47+ password = (mconfig .key_password ).encode (),
48+ backend = default_backend ()
49+ )
50+
51+ cert_pem = certificate .public_bytes (serialization .Encoding .PEM )
52+ cert_pem_str = cert_pem .decode ('utf-8' )
53+ der_cert_string = base64 .b64encode (ssl .PEM_cert_to_DER_cert (cert_pem_str ))
4554
4655 self .filecache .setdefault (str (filename ), []).append (der_cert_string )
4756 self .filecache .setdefault (str (filename ), []).append (private_key )
0 commit comments