|
|
9b88be |
UTF8 := $(shell locale -c LC_CTYPE -k | grep -q charmap.*UTF-8 && echo -utf8)
|
|
|
9b88be |
DAYS=365
|
|
|
9b88be |
KEYLEN=2048
|
|
|
9b88be |
TYPE=rsa:$(KEYLEN)
|
|
|
9b88be |
EXTRA_FLAGS=
|
|
|
9b88be |
ifdef SERIAL
|
|
|
9b88be |
EXTRA_FLAGS+=-set_serial $(SERIAL)
|
|
|
9b88be |
endif
|
|
|
9b88be |
|
|
|
9b88be |
.PHONY: usage
|
|
|
9b88be |
.SUFFIXES: .key .csr .crt .pem
|
|
|
9b88be |
.PRECIOUS: %.key %.csr %.crt %.pem
|
|
|
9b88be |
|
|
|
9b88be |
usage:
|
|
|
9b88be |
@echo "This makefile allows you to create:"
|
|
|
9b88be |
@echo " o public/private key pairs"
|
|
|
9b88be |
@echo " o SSL certificate signing requests (CSRs)"
|
|
|
9b88be |
@echo " o self-signed SSL test certificates"
|
|
|
9b88be |
@echo
|
|
|
9b88be |
@echo "To create a key pair, run \"make SOMETHING.key\"."
|
|
|
9b88be |
@echo "To create a CSR, run \"make SOMETHING.csr\"."
|
|
|
9b88be |
@echo "To create a test certificate, run \"make SOMETHING.crt\"."
|
|
|
9b88be |
@echo "To create a key and a test certificate in one file, run \"make SOMETHING.pem\"."
|
|
|
9b88be |
@echo
|
|
|
9b88be |
@echo "To create a key for use with Apache, run \"make genkey\"."
|
|
|
9b88be |
@echo "To create a CSR for use with Apache, run \"make certreq\"."
|
|
|
9b88be |
@echo "To create a test certificate for use with Apache, run \"make testcert\"."
|
|
|
9b88be |
@echo
|
|
|
9b88be |
@echo "To create a test certificate with serial number other than random, add SERIAL=num"
|
|
|
9b88be |
@echo "You can also specify key length with KEYLEN=n and expiration in days with DAYS=n"
|
|
|
9b88be |
@echo "Any additional options can be passed to openssl req via EXTRA_FLAGS"
|
|
|
9b88be |
@echo
|
|
|
9b88be |
@echo Examples:
|
|
|
9b88be |
@echo " make server.key"
|
|
|
9b88be |
@echo " make server.csr"
|
|
|
9b88be |
@echo " make server.crt"
|
|
|
9b88be |
@echo " make stunnel.pem"
|
|
|
9b88be |
@echo " make genkey"
|
|
|
9b88be |
@echo " make certreq"
|
|
|
9b88be |
@echo " make testcert"
|
|
|
9b88be |
@echo " make server.crt SERIAL=1"
|
|
|
9b88be |
@echo " make stunnel.pem EXTRA_FLAGS=-sha384"
|
|
|
9b88be |
@echo " make testcert DAYS=600"
|
|
|
9b88be |
|
|
|
9b88be |
%.pem:
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
|
|
|
9b88be |
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
|
|
|
9b88be |
/usr/bin/openssl req $(UTF8) -newkey $(TYPE) -keyout $$PEM1 -nodes -x509 -days $(DAYS) -out $$PEM2 $(EXTRA_FLAGS) ; \
|
|
|
9b88be |
cat $$PEM1 > $@ ; \
|
|
|
9b88be |
echo "" >> $@ ; \
|
|
|
9b88be |
cat $$PEM2 >> $@ ; \
|
|
|
9b88be |
$(RM) $$PEM1 $$PEM2
|
|
|
9b88be |
|
|
|
9b88be |
%.key:
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
/usr/bin/openssl genrsa -aes128 $(KEYLEN) > $@
|
|
|
9b88be |
|
|
|
9b88be |
%.csr: %.key
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
/usr/bin/openssl req $(UTF8) -new -key $^ -out $@
|
|
|
9b88be |
|
|
|
9b88be |
%.crt: %.key
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
/usr/bin/openssl req $(UTF8) -new -key $^ -x509 -days $(DAYS) -out $@ $(EXTRA_FLAGS)
|
|
|
9b88be |
|
|
|
9b88be |
TLSROOT=/etc/pki/tls
|
|
|
9b88be |
KEY=$(TLSROOT)/private/localhost.key
|
|
|
9b88be |
CSR=$(TLSROOT)/certs/localhost.csr
|
|
|
9b88be |
CRT=$(TLSROOT)/certs/localhost.crt
|
|
|
9b88be |
|
|
|
9b88be |
genkey: $(KEY)
|
|
|
9b88be |
certreq: $(CSR)
|
|
|
9b88be |
testcert: $(CRT)
|
|
|
9b88be |
|
|
|
9b88be |
$(CSR): $(KEY)
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
/usr/bin/openssl req $(UTF8) -new -key $(KEY) -out $(CSR)
|
|
|
9b88be |
|
|
|
9b88be |
$(CRT): $(KEY)
|
|
|
9b88be |
umask 77 ; \
|
|
|
9b88be |
/usr/bin/openssl req $(UTF8) -new -key $(KEY) -x509 -days $(DAYS) -out $(CRT) $(EXTRA_FLAGS)
|