@@ -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
0 commit comments