Skip to content

azure-identity | CertificateCredential fails to parse PEM certificate (Error "Failed to deserialize certificate in PEM or PKCS12 format") #24643

Closed

Description

@anishnair-kpmg
  • 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

  1. ghost added
    needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.
    on May 30, 2022
  2. ghost added
    customer-reportedIssues that are reported by GitHub users external to the Azure organization.
    on May 30, 2022
  3. ghost added
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on May 30, 2022
  4. ghost removed
    needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.
    on May 30, 2022
  5. added
    bugThis issue requires a change to an existing behavior in the product in order to be resolved.
    and removed
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    needs-team-triageWorkflow: This issue needs the team to triage.
    on May 31, 2022
  6. ghost added
    needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team
    on May 31, 2022
  7. catalinaperalta commented on May 31, 2022

    @catalinaperalta
    Member

    Thanks for reaching out anishnair-kpmg! We'll investigate asap.

  8. added this to the [2022] July milestone on May 31, 2022
  9. xiangyan99 commented on May 31, 2022

    @xiangyan99
    Member

    anishnair-kpmg Thanks for reporting the issue. Could you help to check the version of cryptography library?

  10. 26 remaining items

  11. anishnair-kpmg commented on Jun 24, 2022

    @anishnair-kpmg
    Author

    /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?

  12. ghost reopened this on Jun 24, 2022
  13. ghost removed
    issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.
    on Jun 24, 2022
  14. ghost added
    needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team
    on Jun 24, 2022
  15. xiangyan99 commented on Jun 24, 2022

    @xiangyan99
    Member

    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.

  16. anishnair-kpmg commented on Jun 24, 2022

    @anishnair-kpmg
    Author

    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 :)

  17. xiangyan99 commented on Jul 5, 2022

    @xiangyan99
    Member

    1.11.0b2 is released with the fix.

  18. ghost removed
    needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team
    on Jul 5, 2022
  19. mohitnmo commented on Jul 8, 2022

    @mohitnmo

    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

  20. ghost closed this as completedon Jul 15, 2022
  21. anishnair-kpmg commented on Jul 18, 2022

    @anishnair-kpmg
    Author

    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.

  22. locked and limited conversation to collaborators on Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.bugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions