isaacpittman-hitachi / rpms / openssl

Forked from rpms/openssl 2 years ago
Clone

Blame SOURCES/Makefile.certificate

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