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

- Cleaned the README a bit.

- Merged the gen-ca command into the init command.
- Fixed a bug.
- Filled all commands (though not everything should be wokring yet).
- Keys and certificates have the subdomain name and the directory the domain.
parent 8513d68e
Branches
No related tags found
No related merge requests found
SSL-CA SSL-CA
###### ######
This is a program (written in POSIX shell) to generate an SSL/TLS certificate This utility automates generating an SSL certificate authority, keys and signed
authority, signed certificates and to sign existing certificates. certificates. The only dependecy is openssl.
Installation Installation
------------ ------------
...@@ -12,62 +12,34 @@ Installation ...@@ -12,62 +12,34 @@ Installation
cd ssl-ca cd ssl-ca
sudo make install sudo make install
The only dependency is openssl.
Usage Usage
----- -----
To start a new CA :: This will generate, inside the new directory, the directory stucture, a starting
configuration for starting work and a new CA key and certificate. ::
$ mkdir mycerts $ mkdir domain.tld
$ cd mycerts $ cd domain.tld
$ ssl-ca init $ ssl-ca init
This will create a new directory with the directory structure and a To generate a new key and certificate for the www host, the key will at
configuration file **Remember to change the configuration in `openssl.cnf`.** ``keys/www`` and the certificate at ``certs/www`` ::
To generate a new CA key and certificate (inside the new directory)::
$ ssl-ca ca-gen
To generate a new key and certificate for the www.example.com domain ::
$ ssl-ca gen www.example.com $ ssl-ca gen www
The key will be at ``keys/www.example.com.key`` and the certificate at To sign existing keys, copy them to the ``keys/`` folder. All keys that don't
``certs/www.example.com.pem``. have a matching certificate under ``certs/`` will be signed when running ::
To sign existing keys, copy them to ``keys/subdomain.domain.tld.key`` and run (this will sign all of keys found under ``keys/``) ::
$ ssl-ca sign $ ssl-ca sign
To resign **ALL** existing keys (overriding existing certificates) :: To resign **ALL** existing keys (regardles of existing certificates) ::
$ ssl-ca resign $ ssl-ca resign
Example config
--------------
::
# This file is sourced by ssl-ca, so comments start with #
# and usual shell evaluation and variables can be used.
# No setting is mandatory and missing setting will be left blank or the
# default value will be used.
keysize=2048
keytype='rsa'
cipher='aes256'
days=365
countrycode='US'
state='Somewhere'
locality='Some other place.'
orgname='Acme'
orgunit='Widgets'
email='hostmaster@example.com'
License License
------- -------
This software is licnesed under the MIT licese (see the LICENSE.txt file). This software is licnesed under the MIT licese (see the ``LICENSE.txt`` file).
Author Author
------ ------
...@@ -77,5 +49,6 @@ Nimrod Adar. ...@@ -77,5 +49,6 @@ Nimrod Adar.
TODO TODO
---- ----
- Write said program.
- Fill out example output in the usage section. - Fill out example output in the usage section.
- Add checks and failure messages to each action.
- Finish openssl configuration.
...@@ -32,29 +32,26 @@ default_bits = 2048" ...@@ -32,29 +32,26 @@ default_bits = 2048"
#orgunit='Widgets' #orgunit='Widgets'
usage () { usage () {
echo "Usage: $0 " echo "Usage: $0 init|gen|sign|resign"
} }
init () { init () {
mkdir "$1/certs" mkdir "certs"
mkdir "$1/keys" mkdir "keys"
echo "$default_config" > "$1/openssl.cnf" openssl genra -out CA.key
openssl req -x509 -new -config openssl.cnf -key CA.key -out CA.crt
echo "$default_config" > "openssl.cnf"
} }
sign_key () { sign_key () {
csr="$(mktemp)" csr="$(mktemp)"
openssl req -new -config openssl.cnf -out $csr openssl req -new -config openssl.cnf -out "$csr"
openssl x509 -req -in $csr -out certs/$1.crt openssl x509 -req -in "$csr" -out "certs/$1.crt"
rm $csr rm "$csr"
} }
gen_key () { gen_key () {
openssl genrsa -out keys/$1.key openssl genrsa -out "keys/$1"
}
ca_gen () {
openssl genra -out CA.key
openssl req -x509 -new -config openssl.cnf -key CA.key -out CA.crt
} }
if [ $# -lt 1 ] if [ $# -lt 1 ]
...@@ -67,26 +64,23 @@ case "$1" in ...@@ -67,26 +64,23 @@ case "$1" in
init) init)
init init
;; ;;
ca-gen)
ca-gen
;;
gen) gen)
gen_key gen_key "$2"
sign_key $key sign_key "$2"
;; ;;
sign) sign)
for key in keys/*.key for key in keys/*
do do
if [ ! -f certs/$key.pem ] if [ ! -f "certs/$(basename $key)" ]
then then
sign_key $key sign_key "$(basename $key)"
fi fi
done done
;; ;;
resign) resign)
for key in keys/* for key in keys/*
do do
sign_key $key sign_key "$(basename $key)"
done done
;; ;;
*) *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment