fix: include CA name in certificate generation for improved clarity
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
function make_ca() {
|
||||
# Use the provided directory argument or default to AZURITE_DIR if not provided
|
||||
local CERT_DIR="$1"
|
||||
local CA_NAME="$2"
|
||||
|
||||
if [[ -z "$CERT_DIR" || ! -d "$CERT_DIR" ]]; then
|
||||
if [[ -z "$CERT_DIR" || -z "$CA_NAME" || ! -d "$CERT_DIR" ]]; then
|
||||
echo "ERROR: Certificate directory $CERT_DIR does not exist."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Generate CA certificate and key if they don't exist
|
||||
if [[ ! -f "$CERT_DIR/ca_cert.pem" || ! -f "$CERT_DIR/ca_key.pem" ]]; then
|
||||
echo "Generating CA certificate and key..."
|
||||
echo "Generating CA certificate '$CA_NAME' and key..."
|
||||
if ! openssl req \
|
||||
-x509 \
|
||||
-newkey rsa:4096 \
|
||||
@@ -17,7 +18,7 @@ function make_ca() {
|
||||
-out "$CERT_DIR/ca_cert.pem" \
|
||||
-days 3650 \
|
||||
-nodes \
|
||||
-subj "/CN=Azurite CA" \
|
||||
-subj "/CN=${CA_NAME}" \
|
||||
-text \
|
||||
-addext "basicConstraints=critical,CA:TRUE,pathlen:0"; then
|
||||
echo "ERROR: Failed to generate CA certificate and key." >&2
|
||||
|
||||
@@ -73,7 +73,7 @@ while [[ $# -gt 0 ]]; do
|
||||
done
|
||||
|
||||
# Ensure certificates are generated before starting Azurite or Caddy.
|
||||
if ! make_ca "$AZURITE_STORAGE"; then
|
||||
if ! make_ca "$AZURITE_STORAGE" "Azurite CA $(date +%Y.%m)"; then
|
||||
echo "Error: Failed to create CA certificate and key." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user