For the complete documentation index, see llms.txt. This page is also available as Markdown.

29.5 OpenSSL

OpenSSL 3 has been included in the base system since FreeBSD 14, introducing the provider module architecture. This section covers self-signed certificate generation (self-signed CA), FIPS compliance configuration (fips_module integrity check and openssl fipsinstall), and loading of deprecated algorithms.

Overview

OpenSSL is a cryptographic toolkit that implements the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) network protocols, and provides a rich set of cryptographic routines.

The openssl program is the command-line entry point to this toolkit, allowing users to invoke various functions of the OpenSSL cryptographic library from the shell, including:

  • Creation and management of private keys, public keys, and parameters

  • Public key cryptographic operations

  • Creation of X.509 certificates, CSRs, and CRLs

  • Computation of message digests and message authentication codes

  • Encryption and decryption using ciphers

  • SSL/TLS client and server testing

  • S/MIME signed or encrypted email processing

  • Timestamp request, generation, and verification

  • Performance testing of cryptographic routines

For more information, refer to the free OpenSSL Cookbook.

Generating Certificates

OpenSSL supports generating certificates that can be submitted to a CA for signing or used independently. Specifically:

Certificate Signing Request Requiring CA Signing

Execute openssl with the following parameters to generate a certificate for CA signing:

Explanation of command options:

Option
Explanation

openssl req

Generate a Certificate Signing Request (CSR)

-new

Create a new certificate signing request

-noenc

Do not set a password for the private key; the generated private key will not be encrypted

-out req.pem

Specify the output filename for the generated certificate signing request file, here req.pem

-keyout cert.key

Specify the output path for the generated private key file, here cert.key

-sha512

Use the SHA-512 hash algorithm for the hash computation of the signing request

-newkey rsa:4096

Generate a new RSA key pair using 4096-bit RSA encryption algorithm

The output should resemble the following:

The above command generates a Certificate Signing Request (CSR), which must be submitted to a CA for signing before a certificate can be obtained.

This command creates two files in the current directory:

Submit the certificate request file req.pem to a CA, which will verify the credentials, sign it, and return the signed certificate;

The other file cert.key is the certificate private key, which must be kept secure. If the private key is leaked, others can impersonate the user or server.

Self-Signed Certificate

If CA signing is not required, you can create a self-signed certificate yourself.

Warning

The following command writes the certificate and private key directly to the /etc/ssl/ system directory. If certificate files already exist at that path, they will be overwritten and cannot be recovered. Please back up existing certificates first.

Execute the following command to generate an X.509 format self-signed certificate:

The output should resemble the following:

This command creates the certificate file cert.crt in the /etc/ssl/certs directory.

Run the following command to verify:

The certificate private key cert.key is located in the /etc/ssl/ directory:

Verify the private key:

If the SHA-256 values match, the private key and certificate are paired.

It is recommended to store the above files in the /etc/ssl/ directory and set permissions using the chmod command: certificates (.crt) are public information and should be set to 0644, while private keys (.key) should be set to 0600.

Configuring the FIPS Provider

OpenSSL 3 has been included in the base system since FreeBSD 14, bringing with it the new concept of provider modules.

In addition to the built-in default provider, the legacy module implements optional and deprecated cryptographic algorithms, while the fips module is strictly limited to the set of cryptographic algorithms permitted by the FIPS standard.

The FIPS-related portions of OpenSSL receive special attention, have a list of known security issues, and undergo periodic FIPS 140 validation process reviews. These measures allow users to ensure FIPS compliance requirements are met.

The fips_module is also protected by additional security mechanisms; it cannot be used without passing an integrity check. The local system administrator can configure this check as needed, and then allow each OpenSSL 3 user to load the module. If configured improperly, the FIPS module will report an error as follows:

The output should resemble the following:

You can configure the integrity check by creating /etc/ssl/fipsmodule.cnf and referencing it in the main OpenSSL configuration file /etc/ssl/openssl.cnf.

You need to install a certified version of OpenSSL via Ports, referring to the FIPS validated version list. Then copy the fips.so library to the appropriate location.

Warning

FIPS Module Cross-Major-Version Mixing Risk: The following operation copies the OpenSSL 3.0 FIPS module from Ports to the base system path, mixing it with the base system's OpenSSL 3.5. This cross-major-version (3.0 to 3.5) mixing carries the following serious risks:

  • ABI Incompatibility: Internal data structures and function interfaces between different major versions of OpenSSL may be incompatible, leading to program crashes or abnormal behavior.

  • FIPS Certification Invalidation: FIPS 140 validation is issued for specific version combinations; cross-major-version mixing renders FIPS compliance invalid both legally and technically.

  • Security Risks: Older FIPS modules may lack security fixes from newer OpenSSL versions; mixing may introduce known vulnerabilities.

To use the FIPS module in compliance, ensure that the FIPS module and OpenSSL library versions strictly match. If you are unsure about version compatibility, do not perform the following operations.

OpenSSL provides openssl fipsinstall to assist with this process. Usage is as follows:

The output should resemble the following (version number depends on the OpenSSL version installed from Ports):

Next, modify /etc/ssl/openssl.cnf to add the following three configurations:

  • Include the generated /etc/ssl/fipsmodule.cnf file,

  • Export the FIPS module for invocation,

  • And explicitly activate the default module.

After completing the above steps, you can confirm that the FIPS module is available and working properly:

The output should resemble the following:

View the current OpenSSL provider status:

In the above output, the default provider version number depends on the OpenSSL version used by the system (base system or Ports), and the FIPS provider version number depends on the OpenSSL version installed from Ports.

When the FIPS module changes (such as after a system update or after the base system OpenSSL applies security fixes), the above process must be repeated.

Exercises

  1. Use the openssl speed command to test the throughput of AES-128-CBC, AES-256-GCM, and ChaCha20-Poly1305 encryption algorithms on a local FreeBSD system, and analyze the reasons for the differences in results.

  2. Use openssl s_client -connect to connect to a public HTTPS website, extract the certificate chain, protocol version, and negotiated cipher suite from the output, and draw the trust chain structure diagram of the certificate.

  3. Use openssl req -x509 to generate a self-signed certificate, then configure Nginx or Apache on FreeBSD to use this certificate to provide HTTPS service.

Last updated