blob: 70fce4f52a5802a3259fcc9fcf19ab935617034b [file] [log] [blame]
Zack Williams4b5a9712018-12-13 23:19:51 -07001# 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
18SHELL = bash -eu -o pipefail
19
20# parameters
21KEY_SIZE ?= 2048
22EXPIRATION_DAYS ?= 366
23OPENSSL_CNF ?= xos-pki.cnf
24
25# utility/validation targets
26
27help:
28 @echo "Usually you want to run 'make helm_xos_pki.yaml'"
29
30validate:
31 openssl verify -verbose -purpose sslserver -CAfile xos-CA.pem xos-core.crt
32
33printca: xos-CA.pem
34 openssl x509 -in $< -text -noout
35
36printkey: xos-core.key
37 openssl rsa -in $< -check
38
39printcsr: xos-core.csr
40 openssl req -in $< -text -noout -verify
41
42printpem: xos-core.pem
43 openssl x509 -in $< -text -noout
44
45all_certs: xos-core.pem
46
47helm_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: |" >> $@
Zack Williams17e7bc32018-12-14 09:48:08 -070053 @cat xos-CA.pem | base64 | sed 's/^/ /' >> $@
Zack Williams4b5a9712018-12-13 23:19:51 -070054 @echo "secrets:" >> $@
55 @echo " core_api_cert: |" >> $@
Zack Williams17e7bc32018-12-14 09:48:08 -070056 @cat xos-core.pem | base64 | sed 's/^/ /' >> $@
Zack Williams4b5a9712018-12-13 23:19:51 -070057 @echo " core_api_key: |" >> $@
Zack Williams17e7bc32018-12-14 09:48:08 -070058 @cat xos-core.key | base64 | sed 's/^/ /' >> $@
Zack Williams4b5a9712018-12-13 23:19:51 -070059
60clean:
61 rm -rf root_ca *.pem *.key *.csr helm_xos_pki.yaml
62
63# CA creation
64root_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
70root_ca/private/ca_root_phrase: root_ca
71 @echo "TestingXOSRootCAPassPhrase" > root_ca/private/ca_root_phrase
72
73root_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
79xos-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 $@