ca.info
A detailed script to manage an Intermediate Certificate Authority (CA) using OpenSSL, including key generation, CSR creation, certificate issuance, and verification.
ChatGPT has contributed to this document. Therefore, it’s advisable to treat the information here with caution and verify it if necessary.
Let’s break down what this script does in detail. The script is named ca.sh
,
authored by GJS (homelab-alpha), and its purpose is to facilitate the setup and
management of an Intermediate Certificate Authority (CA). The script defines
directory paths, renews database serial numbers, generates ECDSA keys, creates
Certificate Signing Requests (CSRs), issues the intermediate certificate, and
verifies the intermediate CA chain bundle. It ensures the validity and integrity
of the generated keys, CSRs, and certificates.
Script Metadata
- Filename:
ca.sh
- Author: GJS (homelab-alpha)
- Date: February 20, 2025
- Version: 2.6.3
- Description: This script manages an Intermediate Certificate Authority, handling key generation, CSR creation, certificate issuance, and verification processes.
- RAW Script: ca.sh
Detailed Explanation
Before diving into the script, it’s important to know that the script will stop execution on any error using the following line:
Functions
print_cyan: This function is used to print text in cyan color for better readability in the terminal.
generate_random_hex: This function generates a random hexadecimal value, which is used for serial numbers and CRL numbers.
print_section_header: This function prints section headers in cyan to clearly delineate different parts of the script.
check_success: This function checks the success of the last command and exits the script if the command failed.
Main Script Execution
Define Directory Paths
The script defines necessary directory paths for the Intermediate Certificate Authority components.
The following directories are specifically defined for the Intermediate Certificate Authority components:
Renew Database Serial Numbers and CRL
The script renews database serial numbers and CRL by generating random hexadecimal values and writing them to the respective files.
Check if Unique Subject and Intermediate Certificate Authority Exists
The script checks whether the unique_subject
flag is set to yes
in the
index.txt.attr
file, and whether the Intermediate Certificate Authority
(ca.pem
) already exists.
If unique_subject
is enabled and the Intermediate Certificate Authority
exists, the script stops and reports an error. If not, it prompts the user for
confirmation before overwriting the Intermediate Certificate Authority.
Generate ECDSA Key
The script generates an ECDSA key for the Intermediate Certificate Authority using the secp384r1 curve and saves it to the private directory.
Generate Certificate Signing Request (CSR)
A CSR for the Intermediate Certificate Authority is generated using the generated ECDSA key.
Generate Intermediate Certificate Authority
The Intermediate Certificate Authority is generated and signed for a validity of 1826 days (5 years).
Create Intermediate Certificate Authority Chain Bundle
The Intermediate Certificate Authority and Root Certificate Authority are concatenated into a chain bundle.
Verify Certificates
The script verifies the integrity of the certificates using openssl verify
.
Convert Certificate from PEM to CRT Format
The Intermediate Certificate Authority and chain bundle are converted from PEM to CRT format.
Script Completion Message
The script prints a completion message when the process is successfully completed.
Exit
The script exits with a success code (0
).
Conclusion
This comprehensive script ensures that every step in setting up and managing an Intermediate Certificate Authority is performed correctly and securely, from key generation to certificate verification.
Last updated a month ago.