From 851d74da3dcab55e9e20eafc047e17d4eb66013c Mon Sep 17 00:00:00 2001 From: kevgliss Date: Wed, 16 Nov 2016 15:05:25 -0800 Subject: [PATCH] Ensuring that private key is in string format before it gets stored (#504) * Ensuring that private key is in string format before it gets stored * Fixing failing test. --- lemur/certificates/service.py | 3 +++ lemur/tests/test_certificates.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py index 9f249e39..2b8ec48e 100644 --- a/lemur/certificates/service.py +++ b/lemur/certificates/service.py @@ -401,6 +401,9 @@ def create_csr(**csr_config): encryption_algorithm=serialization.NoEncryption() ) + if isinstance(private_key, bytes): + private_key = private_key.decode('utf-8') + csr = request.public_bytes( encoding=serialization.Encoding.PEM ) diff --git a/lemur/tests/test_certificates.py b/lemur/tests/test_certificates.py index f38518c7..48827209 100644 --- a/lemur/tests/test_certificates.py +++ b/lemur/tests/test_certificates.py @@ -318,7 +318,6 @@ def test_extended_key_usage_schema(): def test_create_basic_csr(client): from cryptography import x509 from cryptography.hazmat.backends import default_backend - from cryptography.hazmat.primitives import serialization from lemur.certificates.service import create_csr csr_config = dict( common_name='example.com', @@ -332,7 +331,6 @@ def test_create_basic_csr(client): ) csr, pem = create_csr(**csr_config) - private_key = serialization.load_pem_private_key(pem, password=None, backend=default_backend()) csr = x509.load_pem_x509_csr(csr, default_backend()) for name in csr.subject: assert name.value in csr_config.values()