28 lines
839 B
Bash
28 lines
839 B
Bash
#!/bin/bash
|
|
|
|
# Arguments: <server address>
|
|
SCRIPT_DIR=$(dirname "$0")
|
|
SCRIPT_DIR=${SCRIPT_DIR:-"."}
|
|
|
|
CA_PATH="${SCRIPT_DIR}/myCA"
|
|
|
|
if [[ ! -f "$CA_PATH.pem" || ! -f "$CA_PATH.key" ]]; then
|
|
echo "CA certificates missing!"
|
|
echo "checked path: $CA_PATH.(pem/key)"
|
|
exit 1
|
|
fi
|
|
|
|
openssl genrsa -out "$SCRIPT_DIR/$1".key 4096
|
|
openssl req -new -key "$1".key -out "$SCRIPT_DIR/in.csr" -subj "/C=US/ST=PRIVATE/L=PRIVATE/O=Success!/OU=Success/CN=$1"
|
|
cat > "$SCRIPT_DIR/extfile" <<EOF
|
|
|
|
authorityKeyIdentifier=keyid,issuer
|
|
basicConstraints=CA:FALSE
|
|
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
|
|
subjectAltName = @alt_names
|
|
|
|
[alt_names]
|
|
DNS.1 = $1
|
|
EOF
|
|
|
|
openssl x509 -req -out "$SCRIPT_DIR/$1.pem" -CA "$SCRIPT_DIR/myCA.pem" -CAkey "$SCRIPT_DIR/myCA.key" -extfile "$SCRIPT_DIR/extfile" -in "$SCRIPT_DIR/in.csr" |