Skip to content
Snippets Groups Projects
Commit b1aca711 authored by nimrod's avatar nimrod
Browse files

- A small refactor of error handling.

parent 82ff83a0
No related branches found
No related tags found
No related merge requests found
#!/bin/sh #!/bin/sh
set -eu set -eu
which openssl >/dev/null || ( echo "Can't find openssl." >&2; exit 1) die () {
echo "$@" >&2
exit 1
}
which openssl >/dev/null || die "Can't find openssl."
#seed="$(hexdump -n10 -e '10/1 "%02o" "\n"' /dev/urandom)" #seed="$(hexdump -n10 -e '10/1 "%02o" "\n"' /dev/urandom)"
config=\ config=\
"[ ca ] "[ ca ]
...@@ -106,19 +111,16 @@ sign_key () { ...@@ -106,19 +111,16 @@ sign_key () {
local csr cn local csr cn
if [ $# -lt 1 ] || [ "$1" = "" ] if [ $# -lt 1 ] || [ "$1" = "" ]
then then
echo "No host specified." >&2 die "No host specified."
exit 1
fi fi
if [ ! -f CA.crt ] || [ ! -f CA.key ] || [ ! -d keys ] || [ ! -d certs ] || if [ ! -f CA.crt ] || [ ! -f CA.key ] || [ ! -d keys ] || [ ! -d certs ] ||
[ ! -f openssl.cnf ] [ ! -f openssl.cnf ]
then then
echo "CA isn't initialized properly." >&2 die "CA isn't initialized properly."
exit 1
fi fi
if [ ! -f "keys/$1" ] if [ ! -f "keys/$1" ]
then then
echo "Can't find key to sign." >&2 die "Can't find key to sign."
exit 1
fi fi
csr="$(mktemp -t ssl-ca-XXXXXXXXX)" csr="$(mktemp -t ssl-ca-XXXXXXXXX)"
cn="$1.$(basename "$PWD")" cn="$1.$(basename "$PWD")"
...@@ -145,18 +147,15 @@ sign_key () { ...@@ -145,18 +147,15 @@ sign_key () {
gen_key () { gen_key () {
if [ $# -lt 1 ] || [ "$1" = "" ] if [ $# -lt 1 ] || [ "$1" = "" ]
then then
echo "No host specified." >&2 die "No host specified."
exit 1
fi fi
if [ ! -d keys ] if [ ! -d keys ]
then then
echo "keys directory doesn't exists, run ssl-ca init to rectify." >&2 die "keys directory doesn't exists, run ssl-ca init to rectify."
exit 1
fi fi
if [ -e "keys/$1" ] if [ -e "keys/$1" ]
then then
echo "Key already exists." >&2 die "Key already exists."
exit 1
fi fi
openssl genrsa -out "keys/$1" 2048 openssl genrsa -out "keys/$1" 2048
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment