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`" -- "$@"
|
|
|
|
|
|
|
|
EXE ?= sslmake
|
|
|
|
CALL ?= `which $(EXE)`
|
|
|
|
DEFAULTOPENSSLCNF ?= /etc/ssl/openssl.cnf
|
|
|
|
S ?= .
|
|
|
|
OPENSSL ?= /usr/bin/openssl
|
|
|
|
GENRSA = $(OPENSSL) genrsa
|
|
|
|
REQ = $(OPENSSL) req
|
|
|
|
SIGN = $(OPENSSL) x509
|
|
|
|
|
|
|
|
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\
|
|
|
|
--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:
|
|
|
|
umask 177 ; $(GENRSA) -out "$(@)" 4096
|
|
|
|
|
|
|
|
%.csr: %.cnf %.key
|
|
|
|
$(REQ) -config "$(*).cnf" -batch -nodes -new -key$$([ -e "$(*).key" ] || echo out ) "$(*).key" -out "$(@)"
|
|
|
|
|
|
|
|
%.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
|