sslmake/sslmake-openssl

68 lines
1.7 KiB
Text
Raw Normal View History

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`" -- "$@"
BITS ?= 4096
EXE ?= sslmake
CALL ?= `which $(EXE)`
2013-02-06 16:35:33 +01:00
DEFAULTOPENSSLCNF ?= /etc/ssl/openssl.cnf
S ?= .
2013-02-06 16:35:33 +01:00
OPENSSL ?= /usr/bin/openssl
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:
@echo -e "\
2013-02-06 16:35:33 +01:00
Creates SSL-keys and -certificate requests named %.key/%.csr (replace % by name)\n\
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:
umask 177 ; $(GENRSA) -out "$(@)" $(BITS)
%.dh:
umask 177 ; $(GENDH) -out "$(@)" $(BITS)
2013-02-06 16:35:33 +01:00
%.csr: %.cnf %.key
$(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" "$(@)"
.PHONY: all help build renew %.new %.del
2013-02-06 16:35:33 +01:00
.PRECIOUS: %.csr %.key %.cnf %.pem