Search code examples
pythonopensslcertificate

Getting ERROR while uploading certificate of .pfx format


I have a certificate called "MyCert.pfx" with some passphrase say "buggy" and 2 different working server S1 and S2. With S1 uploading and usage of this cert is absolutely fine but While uploading this certificate to S2, I am getting below error: ['asn1 encoding routines', 'ASN1_CHECK_TLEN', 'wrong tag']['asn1 encoding routines', 'asn1_item_embed_d2i', 'nested asn1 error]

Traceback: n File \"/opt/aruba/central/apps/configuration/ENV/local/lib/python2.7/site-packages/OpenSSL/crypto.py\", line 3046, in load_pkcs12 n _raise_current_error() n File \"/opt/aruba/central/apps/configuration/ENV/local/lib/python2.7/site-packages/OpenSSL/_util.py\", line 54, in exception_from_error_queue n raise exception_type(errors) nError: [(\'asn1 encoding routines\', \'asn1_check_tlen\', \'wrong tag\'), (\'asn1 encoding routines\', \'asn1_item_embed_d2i\', \'nested asn1 error\')]'

Any idea why the same certificate is working in one place but not on the other ? When I converted it to .PEM it is working fine at both the places.


Solution

  • In my case it was due to new OpenSSL version vs. old node.js installed on the server.

    I found the solution here:

    Run the following command to fix the key:

    openssl rsa -in key.txt -out key.txt
    

    Where key.txt is the private key file.