I would like some help with the openssl command. I need to automate the retrieval of the subject= line in a pkcs12 certificate for a script I'm working on. I've used openssl to view the contents. The official documentation on the community.crypto.opensslpublickey module. Examples ¶ - name: Generate PKCS#12 file community.crypto.opensslpkcs12: action: export path: /opt/certs/ansible.p12 friendlyname: raclette privatekeypath: /opt/certs/keys/key.pem certificatepath: /opt/certs/cert.pem othercertificates: /opt/certs/ca.pem.
If you obtained a certificate and its private key in PEM or another format, you must convert it to PKCS#12 (PFX) format before you can import the certificate into a Windows certificate store on a View server. PKCS#12 (PFX) format is required if you use the Certificate Import wizard in the Windows certificate store.
You might obtain certificate files in one of these ways:
- You obtain a certificate keystore file from a CA.
- You download a certificate and its private key from an intermediate server that is set up in your View deployment.
- Your organization provides you with certificate files.
Certificate files come in various formats. For example, PEM format is often used in a Linux environment. Your files might have a certificate file, key file, and CSR file with the following extensions:
The CRT file contains the SSL certificate that was returned by the CA. The CSR file is the original certificate signing request file and is not needed. The KEY file contains the private key.
- Verify that OpenSSL is installed on the system. You can download openssl from http://www.openssl.org.
- Verify that the root certificate of the SSL certificate that was returned by the CA is also available on the system.
Procedure
- Copy the CRT and KEY files to the OpenSSL installation directory.
- Open a Windows command prompt and, if necessary, navigate to the OpenSSL installation directory.
- Generate a PKCS#12 (PFX) keystore file from the certificate file and your private key. For example: openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt -certfile CACert.crtIn this example, CACert.crt is the name of the root certificate that was returned by the certificate authority.The Windows certificate store also accepts a keystore that is generated with a PFX extension. For example: -out server.pfx
- Type an export password to protect the PKCS#12 (PFX) file.
Note
This plugin is part of the community.crypto collection (version 1.6.1).
To install it use: ansible-galaxycollectioninstallcommunity.crypto
.
To use it in a playbook, specify: community.crypto.openssl_pkcs12
.
This module allows one to (re-)generate PKCS#12.
The below requirements are needed on the host that executes this module.
python-pyOpenSSL
Openssl Pkcs12 Extract Private Key
Parameter | Choices/Defaults | Comments |
---|---|---|
action string |
| export or parse a PKCS#12. |
attributes string | The attributes the resulting file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The = operator is assumed as default, otherwise + or - operators need to be included in the string. | |
backup |
| Create a backup file including a timestamp so you can get the original output file back if you overwrote it with a new one by accident. |
certificate_path path | The path to read certificates and private keys from. | |
force |
| Should the file be regenerated even if it already exists. |
friendly_name string | Specifies the friendly name for the certificate and private key. | |
group | Name of the group that should own the file/directory, as would be fed to chown. | |
iter_size integer | Default: | Number of times to repeat the encryption step. |
maciter_size integer | Default: | Number of times to repeat the MAC step. |
mode raw | The permissions the resulting file or directory should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777 ) or quote it (like '644' or '1777' ) so Ansible receives a string and can do its own conversion from string into number.Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r ). | |
other_certificates list / elements=path | List of other certificates to include. Pre Ansible 2.8 this parameter was called ca_certificates. Assumes there is one PEM-encoded certificate per file. If a file contains multiple PEM certificates, set other_certificates_parse_all to true . | |
other_certificates_parse_all added in 1.4.0 of community.crypto |
| If set to true , assumes that the files mentioned in other_certificates can contain more than one certificate per file (or even none per file). |
owner string | Name of the user that should own the file/directory, as would be fed to chown. | |
passphrase string | ||
path | Filename to write the PKCS#12 file to. | |
privatekey_passphrase string | Passphrase source to decrypt any input private keys with. | |
privatekey_path path | ||
return_content added in 1.0.0 of community.crypto |
| If set to yes , will return the (current or generated) PKCS#12's content as pkcs12. |
selevel string | This is the MLS/MCS attribute, sometimes known as the range .When set to _default , it will use the level portion of the policy if available. | |
serole string | When set to _default , it will use the role portion of the policy if available. | |
setype string | When set to _default , it will use the type portion of the policy if available. | |
seuser string | By default it uses the system policy, where applicable.When set to _default , it will use the user portion of the policy if available. | |
src path | ||
state |
| Whether the file should exist or not. All parameters except path are ignored when state is absent . |
unsafe_writes boolean |
| Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
See also
The official documentation on the community.crypto.x509_certificate module.
The official documentation on the community.crypto.openssl_csr module.
The official documentation on the community.crypto.openssl_dhparam module. Commission invoice.
Openssl Pfx To Pem Private Key
If you obtained a certificate and its private key in PEM or another format, you must convert it to PKCS#12 (PFX) format before you can import the certificate into a Windows certificate store on a View server. PKCS#12 (PFX) format is required if you use the Certificate Import wizard in the Windows certificate store.
You might obtain certificate files in one of these ways:
- You obtain a certificate keystore file from a CA.
- You download a certificate and its private key from an intermediate server that is set up in your View deployment.
- Your organization provides you with certificate files.
Certificate files come in various formats. For example, PEM format is often used in a Linux environment. Your files might have a certificate file, key file, and CSR file with the following extensions:
The CRT file contains the SSL certificate that was returned by the CA. The CSR file is the original certificate signing request file and is not needed. The KEY file contains the private key.
- Verify that OpenSSL is installed on the system. You can download openssl from http://www.openssl.org.
- Verify that the root certificate of the SSL certificate that was returned by the CA is also available on the system.
Procedure
- Copy the CRT and KEY files to the OpenSSL installation directory.
- Open a Windows command prompt and, if necessary, navigate to the OpenSSL installation directory.
- Generate a PKCS#12 (PFX) keystore file from the certificate file and your private key. For example: openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt -certfile CACert.crtIn this example, CACert.crt is the name of the root certificate that was returned by the certificate authority.The Windows certificate store also accepts a keystore that is generated with a PFX extension. For example: -out server.pfx
- Type an export password to protect the PKCS#12 (PFX) file.
Note
This plugin is part of the community.crypto collection (version 1.6.1).
To install it use: ansible-galaxycollectioninstallcommunity.crypto
.
To use it in a playbook, specify: community.crypto.openssl_pkcs12
.
This module allows one to (re-)generate PKCS#12.
The below requirements are needed on the host that executes this module.
python-pyOpenSSL
Openssl Pkcs12 Extract Private Key
Parameter | Choices/Defaults | Comments |
---|---|---|
action string |
| export or parse a PKCS#12. |
attributes string | The attributes the resulting file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The = operator is assumed as default, otherwise + or - operators need to be included in the string. | |
backup |
| Create a backup file including a timestamp so you can get the original output file back if you overwrote it with a new one by accident. |
certificate_path path | The path to read certificates and private keys from. | |
force |
| Should the file be regenerated even if it already exists. |
friendly_name string | Specifies the friendly name for the certificate and private key. | |
group | Name of the group that should own the file/directory, as would be fed to chown. | |
iter_size integer | Default: | Number of times to repeat the encryption step. |
maciter_size integer | Default: | Number of times to repeat the MAC step. |
mode raw | The permissions the resulting file or directory should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like 0644 or 01777 ) or quote it (like '644' or '1777' ) so Ansible receives a string and can do its own conversion from string into number.Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r ). | |
other_certificates list / elements=path | List of other certificates to include. Pre Ansible 2.8 this parameter was called ca_certificates. Assumes there is one PEM-encoded certificate per file. If a file contains multiple PEM certificates, set other_certificates_parse_all to true . | |
other_certificates_parse_all added in 1.4.0 of community.crypto |
| If set to true , assumes that the files mentioned in other_certificates can contain more than one certificate per file (or even none per file). |
owner string | Name of the user that should own the file/directory, as would be fed to chown. | |
passphrase string | ||
path | Filename to write the PKCS#12 file to. | |
privatekey_passphrase string | Passphrase source to decrypt any input private keys with. | |
privatekey_path path | ||
return_content added in 1.0.0 of community.crypto |
| If set to yes , will return the (current or generated) PKCS#12's content as pkcs12. |
selevel string | This is the MLS/MCS attribute, sometimes known as the range .When set to _default , it will use the level portion of the policy if available. | |
serole string | When set to _default , it will use the role portion of the policy if available. | |
setype string | When set to _default , it will use the type portion of the policy if available. | |
seuser string | By default it uses the system policy, where applicable.When set to _default , it will use the user portion of the policy if available. | |
src path | ||
state |
| Whether the file should exist or not. All parameters except path are ignored when state is absent . |
unsafe_writes boolean |
| Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
See also
The official documentation on the community.crypto.x509_certificate module.
The official documentation on the community.crypto.openssl_csr module.
The official documentation on the community.crypto.openssl_dhparam module. Commission invoice.
Openssl Pfx To Pem Private Key
The official documentation on the community.crypto.openssl_privatekey module.
The official documentation on the community.crypto.openssl_publickey module.
Common return values are documented here, the following are the fields unique to this module:
Openssl Pkcs12
Key | Returned | Description |
---|---|---|
backup_file string | changed and if backup is yes | Sample: |
filename | changed or success | Path to the generate PKCS#12 file. /opt/certs/ansible.p12 |
pkcs12 string | if state is present and return_content is yes | The (current or generated) PKCS#12's content Base64 encoded. |
privatekey string | changed or success | Path to the TLS/SSL private key the public key was generated from. /etc/ssl/private/ansible.com.pem |