def convert_pfx()

in functions/source/ConvertCertificate/lambda_function.py [0:0]


def convert_pfx(pfx_path, pfx_password):
    ssl_open_pem = OpenSSL.crypto.FILETYPE_PEM
    pfx = open(pfx_path, 'rb').read() # get and open the .pfx file
    p12 = OpenSSL.crypto.load_pkcs12(pfx, pfx_password) # Load the pfx
    privateKey = OpenSSL.crypto.dump_privatekey(ssl_open_pem, p12.get_privatekey()) # get the private key
    certificateKey = OpenSSL.crypto.dump_certificate(ssl_open_pem, p12.get_certificate()) # get the certificate key
    ca = p12.get_ca_certificates() # if there is a CA, get the CA
    if ca is not None:
        for cert in ca:
                certificateChain = OpenSSL.crypto.dump_certificate(ssl_open_pem, cert)
    return [certificateKey, privateKey, certificateChain]