Python Forum
Load X509 Certificate - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Load X509 Certificate (/thread-10013.html)



Load X509 Certificate - paul198204 - May-09-2018

Hi,

I am looking for some help to find out code snippet for loading the SSL certificate from system store. Please help me here.

Thanks,
Paul


RE: Load X509 Certificate - buran - May-09-2018

https://bugs.python.org/issue28547


RE: Load X509 Certificate - paul198204 - May-09-2018

Thank you Buran for your help. I am new to python and unable to find proper api for getting PFX cert from cert store with specific thumbprint and also am looking for constructing cert object from pfx cert data (base64). Here is the power shell script to do the same (get cert data from key vault and construct c in memory cert object)


$returnval = Get-AzureKeyVaultSecret -VaultName $VaultName -SecretName $EncryptionCertName
$kvSecretBytes = [System.Convert]::FromBase64String($returnval.SecretValueText)
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $null)
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($protectedCertificateBytes)

basically what the script does is, get cert data (base64) from key vault (which is cert store in Azure where pfx file is stored) and convert it to byte array and then construct X509Certificate2 object from byte array.

Can you please help me on how can I achieve this in Python.

Thanks,
Praveen V