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: |
Zack Williams | 4da1d15 | 2018-12-14 11:40:36 -0700 | [diff] [blame] | 28 | @echo "Usually you want to run 'make all_certs'" |
Zack Williams | 4b5a971 | 2018-12-13 23:19:51 -0700 | [diff] [blame] | 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 | |
Zack Williams | 4b5a971 | 2018-12-13 23:19:51 -0700 | [diff] [blame] | 47 | clean: |
Zack Williams | 4da1d15 | 2018-12-14 11:40:36 -0700 | [diff] [blame] | 48 | rm -rf root_ca *.pem *.key *.csr |
Zack Williams | 4b5a971 | 2018-12-13 23:19:51 -0700 | [diff] [blame] | 49 | |
| 50 | # CA creation |
| 51 | root_ca: |
| 52 | mkdir -p root_ca/private root_ca/newcerts |
| 53 | chmod 700 root_ca/private |
| 54 | echo 1000 > root_ca/serial |
| 55 | touch root_ca/index.txt |
| 56 | |
| 57 | root_ca/private/ca_root_phrase: root_ca |
| 58 | @echo "TestingXOSRootCAPassPhrase" > root_ca/private/ca_root_phrase |
| 59 | |
| 60 | root_ca/private/ca_key.pem: root_ca root_ca/private/ca_root_phrase |
| 61 | @echo "## Creating CA private key, $@" |
| 62 | openssl genrsa -aes256 \ |
| 63 | -passout file:root_ca/private/ca_root_phrase \ |
| 64 | -out root_ca/private/ca_key.pem $(KEY_SIZE) |
| 65 | |
| 66 | xos-CA.pem: xos-pki.cnf root_ca/private/ca_key.pem |
| 67 | @echo "## Creating self-signed CA public key: $@" |
| 68 | openssl req -config $(OPENSSL_CNF) \ |
| 69 | -new -x509 -days $(EXPIRATION_DAYS) -sha256 \ |
| 70 | -extensions v3_ca \ |
| 71 | -key root_ca/private/ca_key.pem \ |
| 72 | -passin file:root_ca/private/ca_root_phrase \ |
| 73 | -subj "/C=US/ST=California/L=Menlo Park/O=ONF/OU=Testing Only/CN=CORD Test Root CA" \ |
| 74 | -out $@ |
| 75 | |
| 76 | # cert creation |
| 77 | .PRECIOUS: %.key %.csr # don't delete intermediate files |
| 78 | |
| 79 | %.key: |
| 80 | @echo "## Creating server private key: $@" |
| 81 | openssl genrsa -out $@ $(KEY_SIZE) |
| 82 | |
| 83 | %.csr: %.key $(OPENSSL_CNF) |
| 84 | @echo "## Creating signing request $@ from $<" |
| 85 | openssl req -config $(OPENSSL_CNF) \ |
| 86 | -new -sha256 -key $< \ |
| 87 | -subj "/C=US/ST=California/L=Menlo Park/O=ONF/OU=Testing Only/CN=$*" \ |
| 88 | -out $@ |
| 89 | |
| 90 | %.pem: %.csr xos-CA.pem $(OPENSSL_CNF) |
| 91 | @echo "## Signing voltha.csr to create signed public key: voltha.crt" |
| 92 | openssl ca -config $(OPENSSL_CNF) \ |
| 93 | -batch -days $(EXPIRATION_DAYS) -md sha256 \ |
| 94 | -passin file:root_ca/private/ca_root_phrase \ |
| 95 | -extensions $* \ |
| 96 | -in $< \ |
| 97 | -out $@ |