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

- Added checks to every command, removed items from the TODO list.

parent c8fea9fe
No related branches found
No related tags found
No related merge requests found
...@@ -81,4 +81,4 @@ at: https://www.shore.co.il/cgit/. ...@@ -81,4 +81,4 @@ at: https://www.shore.co.il/cgit/.
TODO TODO
---- ----
- Add checks and failure messages to each action. Nothing to see here.
...@@ -40,7 +40,12 @@ usage () { ...@@ -40,7 +40,12 @@ usage () {
init () { init () {
mkdir -p "certs" "keys" mkdir -p "certs" "keys"
if [ -a openssl.cnf ]
then
echo openssl.cnf already exists, skipping generation.
else
echo "$config" > "openssl.cnf" echo "$config" > "openssl.cnf"
fi
openssl genrsa \ openssl genrsa \
-out CA.key -out CA.key
openssl req \ openssl req \
...@@ -52,6 +57,22 @@ init () { ...@@ -52,6 +57,22 @@ init () {
} }
sign_key () { sign_key () {
if [ $# -lt 1 ] || [ "$1" == "" ]
then
echo "No host specified."
exit 1
fi
if [ ! -f CA.crt ] || [ ! -f CA.key ] || [ ! -d keys ] || [ ! -d certs ] ||
[ ! -f openssl.cnf ]
then
echo "CA isn't initialized properly."
exit 1
fi
if [ ! -f "keys/$1" ]
then
echo "Can't find key to sign."
exit 1
fi
csr="$(mktemp -t ssl-ca)" csr="$(mktemp -t ssl-ca)"
export domain="$1.$(basename $PWD)" export domain="$1.$(basename $PWD)"
openssl req \ openssl req \
...@@ -59,7 +80,7 @@ sign_key () { ...@@ -59,7 +80,7 @@ sign_key () {
-new \ -new \
-config openssl.cnf \ -config openssl.cnf \
-out "$csr" -out "$csr"
fqdn="$1.$domain" openssl x509 \ openssl x509 \
-req \ -req \
-in "$csr" \ -in "$csr" \
-out "certs/$1" \ -out "certs/$1" \
...@@ -71,6 +92,21 @@ sign_key () { ...@@ -71,6 +92,21 @@ sign_key () {
} }
gen_key () { gen_key () {
if [ $# -lt 1 ] || [ "$1" == "" ]
then
echo "No host specified."
exit 1
fi
if [ ! -d keys ]
then
echo "keys directory doesn't exists, run ssl-ca init to rectify."
exit 1
fi
if [ -a "keys/$1" ]
then
echo "Key already exists."
exit 1
fi
openssl genrsa -out "keys/$1" openssl genrsa -out "keys/$1"
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment