Created
March 30, 2016 10:05
-
-
Save adlawson/da3f2489d37055ed8447ec724b95a671 to your computer and use it in GitHub Desktop.
Pub/Priv/Cert Makefile with help task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KEY_NAME?=key | |
KEY_LENGTH?=1024 | |
CERT_EXPIRY?=3652 # 10 years | |
all: help | |
.PHONY: clean | |
clean: ## Clean up all generated keys | |
rm -f *.crt *.pkcs12 *.private *.public | |
.PHONY: help | |
help: ## Display this help text | |
@echo "Available commands:\n" | |
@grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\\$$//;s/##//;s/://' | |
@echo "\n\ | |
KEY_NAME=$(KEY_NAME)\n\ | |
KEY_LENGTH=$(KEY_LENGTH)\n\ | |
CERT_EXPIRY=$(CERT_EXPIRY)" | |
.PHONY: key | |
key: ## Generate a valid PKCS8 RSA key pair | |
key: $(KEY_NAME).pkcs12 $(KEY_NAME).private $(KEY_NAME).public $(KEY_NAME).crt | |
.PHONY: $(KEY_NAME)-clean | |
$(KEY_NAME)-clean: | |
rm -f $(KEY_NAME).crt $(KEY_NAME).pkcs12 $(KEY_NAME).private $(KEY_NAME).public | |
$(KEY_NAME).crt: | |
openssl req -x509 -new -key $(KEY_NAME).private -out $(KEY_NAME).crt -days $(CERT_EXPIRY) | |
$(KEY_NAME).pkcs12: | |
openssl genrsa -out $(KEY_NAME).pkcs12 $(KEY_LENGTH) | |
$(KEY_NAME).private: | |
openssl pkcs8 -topk8 -nocrypt -inform pem -outform pem -in $(KEY_NAME).pkcs12 -out $(KEY_NAME).private | |
$(KEY_NAME).public: | |
openssl rsa -in $(KEY_NAME).pkcs12 -pubout > $(KEY_NAME).public |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment