fix: ensure CA certificate and key are created only if they do not exist

This commit is contained in:
2026-03-24 07:42:37 +01:00
parent 5a840f6577
commit 47efc09d18

View File

@@ -9,16 +9,19 @@ CA_DIR="${CA_DIR:-./ca}"
CA_NAME="${CA_NAME:-Azurite Emulator CA}"
STORAGE_ACCOUNT_NAME="${STORAGE_ACCOUNT_NAME:-azuritelocal}"
mkdir -p "$CA_DIR"
openssl req \
-x509 -noenc -text \
-newkey rsa:4096 \
-keyout "${CA_DIR}/ca_key.pem" \
-out "${CA_DIR}/ca_cert.pem" \
-days 3650 \
-subj "/CN=$CA_NAME" \
-addext "basicConstraints=critical,CA:TRUE,pathlen:0"
HASH=$(openssl x509 -in "${CA_DIR}/ca_cert.pem" -noout -hash 2>/dev/null)
ln -sf $(basename "${CA_DIR}/ca_cert.pem") "${CA_DIR}/$HASH.0" # Check it
if [[ ! -f "${CA_DIR}/ca_cert.pem" || ! -f "${CA_DIR}/ca_key.pem" ]]; then
echo "Creating CA certificate and key..."
openssl req \
-x509 -noenc -text \
-newkey rsa:4096 \
-keyout "${CA_DIR}/ca_key.pem" \
-out "${CA_DIR}/ca_cert.pem" \
-days 3650 \
-subj "/CN=$CA_NAME" \
-addext "basicConstraints=critical,CA:TRUE,pathlen:0"
HASH=$(openssl x509 -in "${CA_DIR}/ca_cert.pem" -noout -hash 2>/dev/null)
ln -sf ca_cert.pem "${CA_DIR}/$HASH.0" # Check it
fi
ALTNAMES=()
for endpoint in blob queue table; do
ALTNAMES+=("DNS:${STORAGE_ACCOUNT_NAME}.${endpoint}.core.windows.net")