Changeset - 1f9ad2819335
[Not reviewed]
0 5 0
Branko Majic (branko) - 2 months ago 2024-02-23 22:17:59
branko@majic.rs
GC-45: Upgrade to cryptographyt version 42.0:

- Passing in backend is no longer required/possible.
5 files changed with 10 insertions and 20 deletions:
0 comments (0 inline, 0 general)
gimmecert/crypto.py
Show inline comments
 
@@ -85,13 +85,11 @@ class KeyGenerator:
 

	
 
            private_key = cryptography.hazmat.primitives.asymmetric.rsa.generate_private_key(
 
                public_exponent=rsa_public_exponent,
 
                key_size=self._parameters,
 
                backend=cryptography.hazmat.backends.default_backend()
 
                key_size=self._parameters
 
            )
 
        else:
 
            private_key = cryptography.hazmat.primitives.asymmetric.ec.generate_private_key(
 
                curve=self._parameters,
 
                backend=cryptography.hazmat.backends.default_backend()
 
                curve=self._parameters
 
            )
 

	
 
        return private_key
 
@@ -183,8 +181,7 @@ def issue_certificate(issuer_dn, subject_dn, signing_key, public_key, not_before
 

	
 
    certificate = builder.sign(
 
        private_key=signing_key,
 
        algorithm=cryptography.hazmat.primitives.hashes.SHA256(),
 
        backend=cryptography.hazmat.backends.default_backend()
 
        algorithm=cryptography.hazmat.primitives.hashes.SHA256()
 
    )
 

	
 
    return certificate
 
@@ -434,8 +431,7 @@ def generate_csr(name, private_key):
 

	
 
    csr = builder.sign(
 
        private_key,
 
        cryptography.hazmat.primitives.hashes.SHA256(),
 
        cryptography.hazmat.backends.default_backend()
 
        cryptography.hazmat.primitives.hashes.SHA256()
 
    )
 

	
 
    return csr
gimmecert/storage.py
Show inline comments
 
@@ -171,8 +171,7 @@ def read_private_key(private_key_path):
 
    with open(private_key_path, 'rb') as private_key_file:
 
        private_key = cryptography.hazmat.primitives.serialization.load_pem_private_key(
 
            private_key_file.read(),
 
            None,  # no password
 
            cryptography.hazmat.backends.default_backend()
 
            None  # no password
 
        )
 

	
 
    return private_key
 
@@ -192,8 +191,7 @@ def read_certificate(certificate_path):
 
    """
 
    with open(certificate_path, 'rb') as certificate_file:
 
        certificate = cryptography.x509.load_pem_x509_certificate(
 
            certificate_file.read(),
 
            cryptography.hazmat.backends.default_backend()
 
            certificate_file.read()
 
        )
 

	
 
    return certificate
 
@@ -232,8 +230,7 @@ def read_csr(csr_path):
 

	
 
    with open(csr_path, 'rb') as csr_file:
 
        csr = cryptography.x509.load_pem_x509_csr(
 
            csr_file.read(),
 
            cryptography.hazmat.backends.default_backend()
 
            csr_file.read()
 
        )
 

	
 
    return csr
gimmecert/utils.py
Show inline comments
 
@@ -156,8 +156,7 @@ def csr_from_pem(csr_pem):
 
    """
 

	
 
    csr = cryptography.x509.load_pem_x509_csr(
 
        bytes(csr_pem, encoding='utf8'),
 
        cryptography.hazmat.backends.default_backend()
 
        bytes(csr_pem, encoding='utf8')
 
    )
 

	
 
    return csr
setup.py
Show inline comments
 
@@ -27,7 +27,7 @@ README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
python_requirements = ">=3.8,<3.10"
 

	
 
install_requirements = [
 
    'cryptography>=3.2,<3.3',
 
    'cryptography>=42.0,<42.1',
 
    'python-dateutil>=2.8,<2.9',
 
]
 

	
tests/test_utils.py
Show inline comments
 
@@ -23,7 +23,6 @@ import datetime
 
import io
 

	
 
import cryptography.x509
 
import cryptography.hazmat.backends
 

	
 
import gimmecert.crypto
 
import gimmecert.utils
 
@@ -40,8 +39,7 @@ def test_certificate_to_pem_returns_valid_pem():
 
    certificate_pem = gimmecert.utils.certificate_to_pem(certificate)
 

	
 
    assert isinstance(certificate_pem, str)
 
    certificate_from_pem = cryptography.x509.load_pem_x509_certificate(bytes(certificate_pem, encoding='UTF-8'),
 
                                                                       cryptography.hazmat.backends.default_backend())  # Should not throw
 
    certificate_from_pem = cryptography.x509.load_pem_x509_certificate(bytes(certificate_pem, encoding='UTF-8'))  # Should not throw
 
    assert certificate_from_pem.subject == certificate.subject
 
    assert certificate_from_pem.issuer == certificate.issuer
 

	
0 comments (0 inline, 0 general)