Skip to content

Commit 5023302

Browse files
committed
fix vulnerability for pyopenssl
1 parent cba7d06 commit 5023302

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

authenticationsdk/util/Cache.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import base64
22
import ssl
33

4-
from OpenSSL import crypto
54
from 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+
710
from 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)

generator/cybersource-python-template/requirements.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
certifi
22
pycryptodome
33
PyJWT
4-
pyOpenSSL<=23.2.0
54
DateTime
65
setuptools
76
six

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
certifi
22
pycryptodome
33
PyJWT
4-
pyOpenSSL<=23.2.0
54
DateTime
65
setuptools
76
six

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"certifi",
2424
"pycryptodome",
2525
"PyJWT",
26-
"pyOpenSSL<=23.2.0",
2726
"DateTime",
2827
"setuptools",
2928
"six",

0 commit comments

Comments
 (0)