extracting key and certificate

Hi All,

Trying to extract the private key and certificate from pfx file format using ansible module.Can someone please provide the example.

IIRC PFX are usually binary file that contain ‘everything’, i.e. the private key, the cert and any intermediates.
I would try both

https://docs.ansible.com/ansible/latest/collections/community/crypto/x509_certificate_info_module.html and

https://docs.ansible.com/ansible/latest/collections/community/crypto/openssl_privatekey_info_module.html
and see what that gets me.

Hi,

Trying to extract the private key and certificate from pfx file
format using ansible module.Can someone please provide the example.

PFX files are usually PKCS #12 files
(https://en.wikipedia.org/wiki/PFX), so community.crypto.openssl_pkcs12
(https://docs.ansible.com/ansible/latest/collections/community/crypto/openssl_pkcs12_module.html)
should help you.

Check out the action=parse example, it dumps the contents into a PEM
file, and you can split that one with
https://docs.ansible.com/ansible/latest/collections/community/crypto/split_pem_filter.html).

Cheers,
Felix

Hi All,

I basically wanted to run the below command and create those files using ansible community.crypto module.Its not working as expected

openssl pkcs12 -in test.pfx -nocerts -nodes | sed -ne ‘/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p’ > test.key

openssl pkcs12 -in test.pfx -clcerts -nokeys | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > test.crt

openssl pkcs12 -in test.pfx -cacerts -nokeys -chain | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p’ > cacerts.crt

ansible code:

Hi All,

Anyone has done this before.

This is your chance to become that person!
You did start already, please let us know your findings :slight_smile: