Skip to content

Commit 4d5ff7d

Browse files
authored
Merge pull request #113 from Venafi/pkcs1_support
Adding support for PKCS1 format on private keys
2 parents 4792545 + bd59b97 commit 4d5ff7d

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

tests/test_tpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_tpp_retrieve_non_issued(self):
139139
with self.assertRaises(Exception):
140140
self.tpp_conn.retrieve_cert(self.tpp_zone + "\\devops\\vcert\\test-non-issued.example.com")
141141

142-
def test_tpp_search_by_thumbpint(self):
142+
def test_tpp_search_by_thumbprint(self):
143143
req, cert = simple_enroll(self.tpp_conn, self.tpp_zone)
144144
cert = x509.load_pem_x509_certificate(cert.cert.encode(), default_backend())
145145
fingerprint = binascii.hexlify(cert.fingerprint(hashes.SHA1())).decode()

tests/test_vaas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
log = logger.get_child("test-vaas")
3636

3737

38-
class TestCloudMethods(unittest.TestCase):
38+
class TestVaaSMethods(unittest.TestCase):
3939
def __init__(self, *args, **kwargs):
4040
self.cloud_zone = CLOUD_ZONE
4141
self.cloud_conn = CloudConnection(token=CLOUD_APIKEY, url=CLOUD_URL)
42-
super(TestCloudMethods, self).__init__(*args, **kwargs)
42+
super(TestVaaSMethods, self).__init__(*args, **kwargs)
4343

4444
def test_cloud_enroll(self):
4545
cn = f"{random_word(10)}.venafi.example.com"

vcert/common.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ def __init__(self, cert_id=None,
276276
csr_origin=CSR_ORIGIN_LOCAL,
277277
include_private_key=False,
278278
validity_hours=None,
279-
issuer_hint=IssuerHint.DEFAULT):
279+
issuer_hint=IssuerHint.DEFAULT,
280+
use_legacy_pem=False):
280281
"""
281282
:param str cert_id: Certificate request id. Generating by server.
282283
:param list[str] san_dns: Alternative names for SNI.
@@ -304,6 +305,7 @@ def __init__(self, cert_id=None,
304305
:param bool include_private_key: Indicates if the private key should be returned by the server or not.
305306
:param int validity_hours: time in hours before the certificate expires.
306307
:param IssuerHint issuer_hint: Issuer of the certificate. Ignored when platform is not TPP.
308+
:param bool use_legacy_pem: Flag that indicates the private key must be in PKCS1 format. Default is PKCS8.
307309
"""
308310

309311
self.chain_option = CHAIN_OPTION_LAST # "last"
@@ -340,6 +342,7 @@ def __init__(self, cert_id=None,
340342
self.include_private_key = include_private_key
341343
self.validity_hours = validity_hours
342344
self.issuer_hint = issuer_hint
345+
self.use_legacy_pem = use_legacy_pem
343346

344347
def __setattr__(self, key, value):
345348
if key == "key_password":
@@ -501,9 +504,14 @@ def private_key_pem(self):
501504
else:
502505
encryption = serialization.NoEncryption()
503506

507+
if self.use_legacy_pem:
508+
pk_format = serialization.PrivateFormat.TraditionalOpenSSL
509+
else:
510+
pk_format = serialization.PrivateFormat.PKCS8
511+
504512
return self.private_key.private_bytes(
505513
encoding=serialization.Encoding.PEM,
506-
format=serialization.PrivateFormat.TraditionalOpenSSL,
514+
format=pk_format,
507515
encryption_algorithm=encryption,
508516
).decode()
509517

vcert/connection_tpp_abstract.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ def retrieve_cert(self, cert_request):
182182
log.debug(f"Getting certificate status for id {cert_request.id}")
183183

184184
retrieve_request = dict(CertificateDN=cert_request.id,
185-
Format="base64",
185+
Format="Base64 (PKCS #8)",
186186
IncludeChain=True)
187187

188+
if cert_request.use_legacy_pem:
189+
retrieve_request["Format"] = "base64"
190+
188191
if cert_request.csr_origin == CSR_ORIGIN_SERVICE:
189192
retrieve_request['IncludePrivateKey'] = cert_request.include_private_key
190193
if cert_request.key_password:

0 commit comments

Comments
 (0)