Blame SOURCES/Makefile.certificate

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