#!/bin/sh # Reissue one leaf from the existing lab CA. Does not print the key. # Args: name cn eku san # Optional env: NOT_BEFORE, NOT_AFTER as YYYYMMDDHHMMSSZ set -eu apk add --no-cache openssl >/dev/null cd /work name="$1" cn="$2" eku="$3" san="$4" test -f ca.key test -f ca.crt cat > "/tmp/${name}.cnf" </dev/null 2>&1 if [ -n "${NOT_BEFORE:-}" ] || [ -n "${NOT_AFTER:-}" ]; then mkdir -p /tmp/newcerts : > /tmp/index.txt echo 1000 > /tmp/serial cat > /tmp/ca.cnf </dev/null 2>&1 else openssl x509 -req -in "/tmp/${name}.csr" -CA ca.crt -CAkey ca.key -CAcreateserial \ -out "${name}.crt" -days 7 -extfile "/tmp/${name}.cnf" -extensions ext >/dev/null 2>&1 fi cat "${name}.crt" "${name}.key" > "${name}.pem" chmod 644 "${name}.key" "${name}.pem" if [ "$name" = "lb-client" ]; then openssl x509 -in lb-client.crt -outform DER | openssl dgst -sha256 -r | awk '{print $1}' > allowed-lb.sha256 fi if [ "$name" = "api-client" ]; then openssl x509 -in api-client.crt -noout -serial | awk -F= '{print tolower($2)}' > allowed-api.serial fi if [ "$name" = "worker-client" ]; then openssl x509 -in worker-client.crt -noout -serial | awk -F= '{print tolower($2)}' > allowed-worker.serial fi echo "reissued $name"