3.11.7. TLS_PrivateKeyFile Previous topic Parent topic Child topic Next topic

When TLS is enabled, this optional parameter specifies the name of the file or other location containing the private key of the certificate configured with TLS_CertificateFile. It is sometimes in the same file as the TLS_CertificateFile. Special formatting characters are supported.
When the private key is stored in a file, the file must be in PEM or DER format, depending on the setting of the TLS_PrivateKeyType parameter, and if not set, TLS_CertificateType parameter. When TLS_PrivateKeyType is not set, the format defaults to the value of TLS_CertificateType.
The private key can be located in the same PEM file as the server certificate in TLS_CertificateFile. With DER format the certificate and private key must be in separate files. If the private key is encrypted, which is usually the case, TLS_PrivateKeyPassword is the key to decrypt it. PEM format is more compatible with encrypted private key files than DER format.
In addition to a file, a private key can be stored in a Hardware Security Module (HSM) or some other storage that is supported by an ENGINE in OpenSSL 3.x and earlier. To use an OpenSSL ENGINE, add the ENGINE specific configuration in OpenSSL configuration and then set the TLS_PrivateKeyType to ENGINE.
Special formatting characters are supported.
# Example 1
# Both the certificate and private key are PEM files
TLS_CertificateType PEM
TLS_CertificateFile %D/server-crt.pem
TLS_PrivateKeyFile %D/server-key.pem

# Example 2
# The certificate is a PEM file and the private key is accessed using a HSM
# Note that % signs that are part of the PKCS11 URL format must be escaped as %%
TLS_CertificateType PEM
TLS_CertificateFile %D/server-crt.pem

TLS_PrivateKeyType ENGINE
TLS_PrivateKeyEngineId pkcs11
TLS_PrivateKeyFile pkcs11:model=SoftHSM%%20v2;...;pin-value=%{GlobalVar:hsm-pin}