Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
karen-avetisyan-mc committed Feb 21, 2024
1 parent 2d25457 commit b34078e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions client_encryption/encryption_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA1, SHA224, SHA256, SHA384, SHA512
#from OpenSSL.crypto import load_certificate, FILETYPE_PEM, FILETYPE_ASN1, Error
from client_encryption.encryption_exception import CertificateError, PrivateKeyError, HashAlgorithmError
from cryptography import x509
from cryptography.hazmat.primitives.serialization import pkcs12
Expand All @@ -26,15 +25,15 @@ def load_encryption_certificate(certificate_path):
raise CertificateError ("Unable to load certificate.")

try:
type = __get_crypto_file_type(certificate)
cert_type = __get_crypto_file_type(certificate)

if type == FileType.FILETYPE_PEM:
if cert_type == FileType.FILETYPE_PEM:
cert = x509.load_pem_x509_certificate(certificate)
return cert, Encoding.PEM
if type == FileType.FILETYPE_ASN1:
if cert_type == FileType.FILETYPE_ASN1:
cert = x509.load_der_x509_certificate(certificate)
return cert, Encoding.DER
if type == FileType.FILETYPE_INVALID:
if cert_type == FileType.FILETYPE_INVALID:
raise CertificateError("Wrong certificate format.")
except ValueError:
raise CertificateError ("Invalid certificate format.")
Expand Down
2 changes: 1 addition & 1 deletion client_encryption/field_level_encryption_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, conf):
if "encryptionCertificate" in json_config:
x509_cert, cert_type = load_encryption_certificate(json_config["encryptionCertificate"])
self._encryption_certificate = x509_cert
#Fixed encoding is required, regardless of initial cerrtificate encoding to ensure correct calcualtion of fingerprint value
# Fixed encoding is required, regardless of initial certificate encoding to ensure correct calculation of fingerprint value
self._encryption_certificate_type = Encoding.DER
self._encryption_key_fingerprint = \
json_config.get("encryptionKeyFingerprint",self.__compute_fingerprint(x509_cert.public_key().public_bytes(Encoding.DER , PublicFormat.SubjectPublicKeyInfo)))
Expand Down
2 changes: 1 addition & 1 deletion client_encryption/jwe_encryption_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, conf):
if "encryptionCertificate" in json_config:
x509_cert, cert_type = load_encryption_certificate(json_config["encryptionCertificate"])
self._encryption_certificate = x509_cert
#Fixed encoding is required, regardless of initial cerrtificate encoding to ensure correct calcualtion of fingerprint value
# Fixed encoding is required, regardless of initial certificate encoding to ensure correct calculation of fingerprint value
self._encryption_certificate_type = Encoding.DER
self._encryption_key_fingerprint = \
json_config.get("encryptionKeyFingerprint",self.__compute_fingerprint(x509_cert.public_key().public_bytes(Encoding.DER, PublicFormat.SubjectPublicKeyInfo)))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
'Topic :: Software Development :: Libraries :: Python Modules'
],
tests_require=['coverage'],
install_requires=['pycryptodome>=3.8.1', 'setuptools>=69.1.0',"cryptography>=42.0.0" ]
install_requires=['pycryptodome>=3.8.1', 'setuptools>=69.1.0', 'cryptography>=42.0.0' ]
)
2 changes: 1 addition & 1 deletion tests/test_api_encryption_jwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import client_encryption.api_encryption as to_test


class ApiEncryptionTest(unittest.TestCase):
class ApiEncryptionJweTest(unittest.TestCase):

def setUp(self):
self._json_config = json.loads(get_mastercard_config_for_test())
Expand Down

0 comments on commit b34078e

Please sign in to comment.