Skip to content

Instantly share code, notes, and snippets.

@praseodym
Last active November 13, 2022 13:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save praseodym/8186510 to your computer and use it in GitHub Desktop.
Save praseodym/8186510 to your computer and use it in GitHub Desktop.
#!/bin/bash
# csr.sh: Certificate Signing Request Generator
set -e
if [ $# -lt 1 ]; then
echo "Usage: $0 hostname [alt.hostname1] [alt.hostname2]"
exit 1
fi
LASTUMASK=`umask`
umask 077
HOST=$1
SAN="DNS:${HOST}"
shift
while [ -n "$1" ]; do
SAN="${SAN},DNS:$1"
shift
done
openssl req -new -newkey rsa:2048 -keyout ${HOST}.key -sha512 -nodes -batch -reqexts SAN \
-subj "/C=NL/ST=Zuid-Holland/L=Delft/O=W.I.S.V. \'Christiaan Huygens\'/OU=Beheer/CN=${HOST}/emailAddress=beheer@ch.tudelft.nl" \
-config /dev/stdin > ${HOST}.csr <<EOF
$(cat "$(openssl version -d | cut -d\" -f2)/openssl.cnf")
[SAN]
subjectAltName=$SAN
EOF
umask $LASTUMASK
set -x
openssl req -text -noout -verify -in ${HOST}.csr
cat ${HOST}.csr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment