Repository navigation
azure-identity | CertificateCredential fails to parse PEM certificate (Error "Failed to deserialize certificate in PEM or PKCS12 format") #24643
Description
- Package Name: azure-identity
- Package Version: 1.10.0
- Operating System: Windows 10
- Python Version: 3.10.4
Describe the bug
Getting 'Failed to deserialize certificate in PEM or PKCS12 format' error while using 'CertificateCredential' python module in 'azure.identity' python package. More details error logs below:
Traceback (most recent call last):
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\identity_credentials\certificate.py", line 90, in load_pkcs12_certificate
private_key, cert, additional_certs = pkcs12.load_key_and_certificates(
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\primitives\serialization\pkcs12.py", line 147, in load_key_and_certificates
return ossl.load_key_and_certificates_from_pkcs12(data, password)
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 2134, in load_key_and_certificates_from_pkcs12
pkcs12 = self.load_pkcs12(data, password)
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 2151, in load_pkcs12
raise ValueError("Could not deserialize PKCS12 data")
ValueError: Could not deserialize PKCS12 data
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\userfolder\Downloads\AzureCertificateBasedFileDownload.py", line 51, in
credentials = CertificateCredential(AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_CERTIFICATE_PATH)
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\identity_credentials\certificate.py", line 54, in init
client_credential = get_client_credential(certificate_path, **kwargs)
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\identity_credentials\certificate.py", line 133, in get_client_credential
cert = load_pkcs12_certificate(certificate_data, password)
File "C:\Users\userfolder\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\identity_credentials\certificate.py", line 95, in load_pkcs12_certificate
six.raise_from(ValueError("Failed to deserialize certificate in PEM or PKCS12 format"), ex)
File "", line 3, in raise_from
ValueError: Failed to deserialize certificate in PEM or PKCS12 format
To Reproduce
Steps to reproduce the behavior:
Failure Scenario:
Install ‘azure-identity’ by running pip install azure-identity
Run python script that has "credentials = CertificateCredential(AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_CERTIFICATE_PATH)"
Expected Failure Message: “ValueError: Failed to deserialize certificate in PEM or PKCS12 format”
Expected behavior
To successfully read certificate
Additional context
If I uninstall latest version 'azure-identity' and specifically install azure-identity ==1.4.0 then I'm able to parse the certificate without any issues.
Additionally, I could see that issue was raised before "#21798". However, I could see this particular issue as closed. But I'm facing the same error.
Activity
catalinaperalta commentedon May 31, 2022
Thanks for reaching out anishnair-kpmg! We'll investigate asap.
xiangyan99 commentedon May 31, 2022
anishnair-kpmg Thanks for reporting the issue. Could you help to check the version of cryptography library?
26 remaining items
anishnair-kpmg commentedon Jun 24, 2022
/unresolve
Xiang Yan (@xiangyan99) Thank you so much. I'm glad to hear that it's fixed and changes are merged. Could you please let me know when this is set to release?
xiangyan99 commentedon Jun 24, 2022
It would be available in July's release (which would be a beta release).
You can install the live bits if you want to try it now.
anishnair-kpmg commentedon Jun 24, 2022
Xiang Yan (@xiangyan99) Thank you for quick response. That's helpful. Given that it's working with an older version for now, I'm happy to wait until the release. I will let you know once I validate it using latest release. Once gain thank you for fixing this issue :)
xiangyan99 commentedon Jul 5, 2022
1.11.0b2 is released with the fix.
mohitnmo commentedon Jul 8, 2022
Hi anishnair-kpmg ,
I am also facing same issue, can you provide me the final solution for this!!
python version- 3.10.4 (64 bit)
azure-identity version- 1.10.0
cryptography version- 37.0.2
window 10
Thanks,
Mohit
anishnair-kpmg commentedon Jul 18, 2022
mohitnmo Try with azure-identity version '1.4.0' instead. If you are getting same error as mine, then it should work in this version. Additionally, this issue is fixed in the latest client library version as mentioned by Xiang Yan (@xiangyan99). So I would suggest to use this version as well which is in pre-release phase but available to use:
https://pypi.org/project/azure-identity/1.11.0b2/
I'm yet to try the latest release but I will soon be using this version.