2013-02-06 16:35:33 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# vi:set filetype=makefile
|
|
|
|
NULL=0 exec make "CALL=$0" "EXE=`which $0`" -f "`which $0`" -- "$@"
|
|
|
|
|
2018-01-11 21:35:43 +01:00
|
|
|
BITS ?= 4096
|
|
|
|
EXE ?= sslmake
|
|
|
|
CALL ?= `which $(EXE)`
|
2013-02-06 16:35:33 +01:00
|
|
|
DEFAULTOPENSSLCNF ?= /etc/ssl/openssl.cnf
|
2018-01-11 21:35:43 +01:00
|
|
|
S ?= .
|
|
|
|
|
2013-02-06 16:35:33 +01:00
|
|
|
OPENSSL ?= /usr/bin/openssl
|
2018-01-11 21:35:43 +01:00
|
|
|
GENRSA ?= $(OPENSSL) genrsa
|
|
|
|
GENDH ?= $(OPENSSL) gendh
|
|
|
|
GENREQ ?= $(OPENSSL) req
|
|
|
|
SIGN ?= $(OPENSSL) x509
|
2013-02-06 16:35:33 +01:00
|
|
|
|
|
|
|
all: help
|
|
|
|
--help -h: help
|
|
|
|
--renew -r: renew
|
|
|
|
--build -b: build
|
|
|
|
|
|
|
|
help:
|
2013-02-06 16:48:20 +01:00
|
|
|
@echo -e "\
|
2013-02-06 16:35:33 +01:00
|
|
|
Creates SSL-keys and -certificate requests named %.key/%.csr (replace % by name)\n\
|
2018-01-11 21:35:43 +01:00
|
|
|
BITS=strength: for setting bit-strength (default $(BITS))\n\
|
2013-02-06 16:35:33 +01:00
|
|
|
--help -h: Display this help message.\n\
|
|
|
|
--renew -r: Renews %.csr for all %.key.\n\
|
|
|
|
--build -b: Builds %.csr and %.key for every %.cnf if doesn't exist.\n\
|
|
|
|
%.cnf: Copies /etc/ssl/openssl.cnf to %.cnf.\n\
|
|
|
|
%.key: Creates %.key.\n\
|
|
|
|
%.csr: Creates %.csr and if doesn't exists %.key."
|
|
|
|
|
|
|
|
renew: $(patsubst %.key,%.csr.new,$(wildcard *.key))
|
|
|
|
build: $(patsubst %.cnf,%csr,$(wildcard *.cnf))
|
|
|
|
|
2013-04-17 10:27:45 +02:00
|
|
|
root.key:
|
|
|
|
@echo "root.crt keeper"
|
|
|
|
root.crt:
|
|
|
|
@echo "root.crt keeper"
|
|
|
|
|
2013-02-06 16:35:33 +01:00
|
|
|
%.del:
|
|
|
|
[ ! -e "$(*)" ] || mv --backup=numbered "$(*)" "$(*).`date +%Y-%m-%d`"
|
|
|
|
|
|
|
|
%.new: %.del
|
|
|
|
$(CALL) "$*"
|
|
|
|
|
|
|
|
%.cnf:
|
|
|
|
cp "$(DEFAULTOPENSSLCNF)" "$(@)"
|
|
|
|
|
|
|
|
%.key:
|
2018-01-11 21:35:43 +01:00
|
|
|
umask 177 ; $(GENRSA) -out "$(@)" $(BITS)
|
|
|
|
|
|
|
|
%.dh:
|
|
|
|
umask 177 ; $(GENDH) -out "$(@)" $(BITS)
|
2013-02-06 16:35:33 +01:00
|
|
|
|
|
|
|
%.csr: %.cnf %.key
|
2018-01-11 21:35:43 +01:00
|
|
|
$(GENREQ) -config "$(*).cnf" -batch -nodes -new -key$$([ -e "$(*).key" ] || echo out ) "$(*).key" -out "$(@)"
|
2013-02-06 16:35:33 +01:00
|
|
|
|
|
|
|
%.crt: %.csr serial root.crt root.key
|
|
|
|
$(SIGN) -req -days 365 -in "$(*).csr" -CA root.crt -CAkey root.key -CAserial "serial" -out "$(@)"
|
|
|
|
|
|
|
|
%.pem: %.crt %.key
|
|
|
|
umask 177 ; cat $(^) > "$(@).bk"
|
|
|
|
mv "$(@).bk" "$(@)"
|
|
|
|
|
2013-02-06 16:48:20 +01:00
|
|
|
.PHONY: all help build renew %.new %.del
|
2013-02-06 16:35:33 +01:00
|
|
|
.PRECIOUS: %.csr %.key %.cnf %.pem
|