blob: 2b27fe79d29ae1ac7a4bb97385374252c856f996 [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:
Zack Williams4da1d152018-12-14 11:40:36 -070028 @echo "Usually you want to run 'make all_certs'"
Zack Williams4b5a9712018-12-13 23:19:51 -070029
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
Zack Williams4b5a9712018-12-13 23:19:51 -070047clean:
Zack Williams4da1d152018-12-14 11:40:36 -070048 rm -rf root_ca *.pem *.key *.csr
Zack Williams4b5a9712018-12-13 23:19:51 -070049
50# CA creation
51root_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
57root_ca/private/ca_root_phrase: root_ca
58 @echo "TestingXOSRootCAPassPhrase" > root_ca/private/ca_root_phrase
59
60root_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
66xos-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 $@