Skip to content

Commit

Permalink
Merge pull request #28 from Mastercard/security-issues
Browse files Browse the repository at this point in the history
fixing security issues
  • Loading branch information
karen-avetisyan-mc authored Feb 9, 2024
2 parents 01cb223 + b1782ac commit bd9b5c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions client_encryption/encryption_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA1, SHA224, SHA256, SHA384, SHA512
from OpenSSL.crypto import load_certificate, load_pkcs12, dump_privatekey, FILETYPE_PEM, FILETYPE_ASN1, Error
from OpenSSL.crypto import load_certificate, FILETYPE_PEM, FILETYPE_ASN1, Error
from client_encryption.encryption_exception import CertificateError, PrivateKeyError, HashAlgorithmError

from cryptography.hazmat.primitives.serialization import pkcs12
from cryptography.hazmat.primitives import serialization

_SUPPORTED_HASH = {"SHA1": SHA1, "SHA224": SHA224, "SHA256": SHA256, "SHA384": SHA384, "SHA512": SHA512}

Expand Down Expand Up @@ -40,11 +41,10 @@ def load_decryption_key(key_file_path, decryption_key_password=None):
raise PrivateKeyError("Wrong decryption key format.")


def __load_pkcs12_private_key(pkcs12_key, password):
def __load_pkcs12_private_key(pkcs_file, password):
"""Load a private key in ASN1 format out of a PKCS#12 container."""

pkcs12 = load_pkcs12(pkcs12_key, password.encode("utf-8")).get_privatekey()
return dump_privatekey(FILETYPE_ASN1, pkcs12)
private_key, certs, addcerts = pkcs12.load_key_and_certificates(pkcs_file, password.encode("utf-8"))
return private_key.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.TraditionalOpenSSL, serialization.NoEncryption())


def __get_crypto_file_type(file_content):
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pycryptodome==3.8.1
pyOpenSSL>=22.1.0,<=23.2.0
pycryptodome==3.19.1
pyOpenSSL>=23.3.0
setuptools>=39.0.1
coverage>=4.5.3
cryptography>=39.0.0
cryptography>=42.0.0

0 comments on commit bd9b5c3

Please sign in to comment.