Zack Williams | 4b5a971 | 2018-12-13 23:19:51 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # XOS pki makefile |
| 16 | # Configuration is also given in xos-pki.cnf |
| 17 | |
| 18 | SHELL = bash -eu -o pipefail |
| 19 | |
| 20 | # parameters |
| 21 | KEY_SIZE ?= 2048 |
| 22 | EXPIRATION_DAYS ?= 366 |
| 23 | OPENSSL_CNF ?= xos-pki.cnf |
| 24 | |
| 25 | # utility/validation targets |
| 26 | |
| 27 | help: |
| 28 | @echo "Usually you want to run 'make helm_xos_pki.yaml'" |
| 29 | |
| 30 | validate: |
| 31 | openssl verify -verbose -purpose sslserver -CAfile xos-CA.pem xos-core.crt |
| 32 | |
| 33 | printca: xos-CA.pem |
| 34 | openssl x509 -in $< -text -noout |
| 35 | |
| 36 | printkey: xos-core.key |
| 37 | openssl rsa -in $< -check |
| 38 | |
| 39 | printcsr: xos-core.csr |
| 40 | openssl req -in $< -text -noout -verify |
| 41 | |
| 42 | printpem: xos-core.pem |
| 43 | openssl x509 -in $< -text -noout |
| 44 | |
| 45 | all_certs: xos-core.pem |
| 46 | |
| 47 | helm_xos_pki.yaml: xos-CA.pem xos-core.pem xos-core.key |
| 48 | @echo "Creating helm compatible YAML file containing certs" |
| 49 | @echo "---" > $@ |
| 50 | @echo "# Certificates can be regenerated with scripts/pki/Makefile" >> $@ |
| 51 | @echo "# Created on: `date -u`, good for $(EXPIRATION_DAYS) days" >> $@ |
| 52 | @echo "ca_cert_chain: |" >> $@ |
| 53 | @cat xos-CA.pem | base64 -b 72 | sed 's/^/ /' >> $@ |
| 54 | @echo "secrets:" >> $@ |
| 55 | @echo " core_api_cert: |" >> $@ |
| 56 | @cat xos-core.pem | base64 -b 72 | sed 's/^/ /' >> $@ |
| 57 | @echo " core_api_key: |" >> $@ |
| 58 | @cat xos-core.key | base64 -b 72 | sed 's/^/ /' >> $@ |
| 59 | |
| 60 | clean: |
| 61 | rm -rf root_ca *.pem *.key *.csr helm_xos_pki.yaml |
| 62 | |
| 63 | # CA creation |
| 64 | root_ca: |
| 65 | mkdir -p root_ca/private root_ca/newcerts |
| 66 | chmod 700 root_ca/private |
| 67 | echo 1000 > root_ca/serial |
| 68 | touch root_ca/index.txt |
| 69 | |
| 70 | root_ca/private/ca_root_phrase: root_ca |
| 71 | @echo "TestingXOSRootCAPassPhrase" > root_ca/private/ca_root_phrase |
| 72 | |
| 73 | root_ca/private/ca_key.pem: root_ca root_ca/private/ca_root_phrase |
| 74 | @echo "## Creating CA private key, $@" |
| 75 | openssl genrsa -aes256 \ |
| 76 | -passout file:root_ca/private/ca_root_phrase \ |
| 77 | -out root_ca/private/ca_key.pem $(KEY_SIZE) |
| 78 | |
| 79 | xos-CA.pem: xos-pki.cnf root_ca/private/ca_key.pem |
| 80 | @echo "## Creating self-signed CA public key: $@" |
| 81 | openssl req -config $(OPENSSL_CNF) \ |
| 82 | -new -x509 -days $(EXPIRATION_DAYS) -sha256 \ |
| 83 | -extensions v3_ca \ |
| 84 | -key root_ca/private/ca_key.pem \ |
| 85 | -passin file:root_ca/private/ca_root_phrase \ |
| 86 | -subj "/C=US/ST=California/L=Menlo Park/O=ONF/OU=Testing Only/CN=CORD Test Root CA" \ |
| 87 | -out $@ |
| 88 | |
| 89 | # cert creation |
| 90 | .PRECIOUS: %.key %.csr # don't delete intermediate files |
| 91 | |
| 92 | %.key: |
| 93 | @echo "## Creating server private key: $@" |
| 94 | openssl genrsa -out $@ $(KEY_SIZE) |
| 95 | |
| 96 | %.csr: %.key $(OPENSSL_CNF) |
| 97 | @echo "## Creating signing request $@ from $<" |
| 98 | openssl req -config $(OPENSSL_CNF) \ |
| 99 | -new -sha256 -key $< \ |
| 100 | -subj "/C=US/ST=California/L=Menlo Park/O=ONF/OU=Testing Only/CN=$*" \ |
| 101 | -out $@ |
| 102 | |
| 103 | %.pem: %.csr xos-CA.pem $(OPENSSL_CNF) |
| 104 | @echo "## Signing voltha.csr to create signed public key: voltha.crt" |
| 105 | openssl ca -config $(OPENSSL_CNF) \ |
| 106 | -batch -days $(EXPIRATION_DAYS) -md sha256 \ |
| 107 | -passin file:root_ca/private/ca_root_phrase \ |
| 108 | -extensions $* \ |
| 109 | -in $< \ |
| 110 | -out $@ |