diff --git a/src/cl_sii/libs/crypto_utils.py b/src/cl_sii/libs/crypto_utils.py index a82d4dd3..776cd8a4 100644 --- a/src/cl_sii/libs/crypto_utils.py +++ b/src/cl_sii/libs/crypto_utils.py @@ -46,9 +46,9 @@ import base64 from typing import Union +import cryptography.hazmat.backends.openssl.backend as _crypto_x509_backend import cryptography.x509 import signxml.util -from cryptography.hazmat.backends.openssl import backend as _crypto_x509_backend from cryptography.x509 import Certificate as X509Cert from OpenSSL.crypto import X509 as _X509CertOpenSsl diff --git a/src/cl_sii/rut/crypto_utils.py b/src/cl_sii/rut/crypto_utils.py index d8f03c8a..df98a9c7 100644 --- a/src/cl_sii/rut/crypto_utils.py +++ b/src/cl_sii/rut/crypto_utils.py @@ -2,9 +2,9 @@ from typing import Optional import cryptography +import cryptography.hazmat.backends.openssl.backend as crypto_x509_backend +import cryptography.hazmat.primitives.serialization.pkcs12 import cryptography.x509 -from cryptography.hazmat.backends.openssl import backend as crypto_x509_backend -from cryptography.hazmat.primitives.serialization import pkcs12 from . import Rut, constants @@ -22,7 +22,7 @@ def get_subject_rut_from_certificate_pfx(pfx_file_bytes: bytes, password: Option private_key, x509_cert, additional_certs, - ) = pkcs12.load_key_and_certificates( + ) = cryptography.hazmat.primitives.serialization.pkcs12.load_key_and_certificates( data=pfx_file_bytes, password=password.encode() if password is not None else None, backend=crypto_x509_backend, diff --git a/src/tests/test_rut_crypto_utils.py b/src/tests/test_rut_crypto_utils.py index 810894cc..c485d53b 100644 --- a/src/tests/test_rut_crypto_utils.py +++ b/src/tests/test_rut_crypto_utils.py @@ -1,8 +1,8 @@ import unittest from unittest.mock import Mock, patch +import cryptography.hazmat.primitives.serialization.pkcs12 import cryptography.x509 -from cryptography.hazmat.primitives.serialization import pkcs12 from cl_sii import rut from cl_sii.libs.crypto_utils import load_der_x509_cert @@ -19,7 +19,7 @@ def test_get_subject_rut_from_certificate_pfx_ok(self) -> None: x509_cert = load_der_x509_cert(cert_der_bytes) with patch.object( - pkcs12, + cryptography.hazmat.primitives.serialization.pkcs12, 'load_key_and_certificates', Mock(return_value=(None, x509_cert, None)), ): @@ -40,7 +40,7 @@ def test_get_subject_rut_from_certificate_pfx_fails_if_rut_info_is_missing(self) x509_cert = load_der_x509_cert(cert_der_bytes) with patch.object( - pkcs12, + cryptography.hazmat.primitives.serialization.pkcs12, 'load_key_and_certificates', Mock(return_value=(None, x509_cert, None)), ): @@ -81,7 +81,7 @@ def test_get_subject_rut_from_certificate_pfx_does_not_throw_attribute_error_if_ ) with patch.object( - pkcs12, + cryptography.hazmat.primitives.serialization.pkcs12, 'load_key_and_certificates', Mock(return_value=(None, x509_cert, None)), ), patch.object(