Initial onfca commit

Updated help target in Makefile
Reworked for IM CAs
Added CRL handling
Added docs/references

Change-Id: I2b1eb541464c157d3626bbe4a6cf7db78c2af533
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8bd7ca5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+# SPDX-FileCopyrightText: © 2022 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+*.pem
+*.csr
+*.key
+*_pki
diff --git a/.reuse/dep5 b/.reuse/dep5
new file mode 100644
index 0000000..a42b189
--- /dev/null
+++ b/.reuse/dep5
@@ -0,0 +1,5 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+
+Files: VERSION README.md
+Copyright: 2022 Open Networking Foundation
+License: Apache-2.0
diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt
new file mode 100644
index 0000000..137069b
--- /dev/null
+++ b/LICENSES/Apache-2.0.txt
@@ -0,0 +1,73 @@
+Apache License
+Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
+
+     (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
+
+     (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
+
+     (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
+
+     (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
+
+     You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!)  The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e1f3d2b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,227 @@
+# onfca Makefile
+#
+# SPDX-FileCopyrightText: © 2022 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+# openssl onfiguration is also given in pki.cnf
+#
+# NOTE: This makefile makes heavy use of Automatic Variables
+#   https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
+
+SHELL = bash -eu -o pipefail
+
+# see bottom for help generation
+.DEFAULT_GOAL := help
+.PHONY: test license help
+
+# common parameters for all options
+KEY_SIZE              ?= 2048
+OPENSSL_CNF           ?= pki.cnf
+
+# base dir
+BASE_DIR               ?= onf_pki
+
+# default CA to use when verifying leaf certs, by default the IM CA
+DEFAULT_CA            ?= im_ca
+
+# root CA
+ROOT_CA_NAME          ?= root_ca
+ROOT_CA_PASSPHRASE    ?= "TestingRootCAPassPhrase"
+ROOT_CA_SUBJECT       ?= /C=US/ST=California/L=Menlo Park/O=ONF/OU=Infra/CN=ONF Test Root CA
+
+# intermediate CA
+IM_CA_NAME            ?= im_ca
+IM_CA_PASSPHRASE      ?= "TestingIMCAPassPhrase"
+IM_CA_SUBJECT         ?= /C=US/ST=California/L=Menlo Park/O=ONF/OU=Infra/CN=ONF Test IM CA
+IM_EXPIRATION_DAYS    ?= 1095
+IM_REVOKE_REASON      ?= CACompromise
+
+# leaf certs
+LEAF_EXPIRATION_DAYS  ?= 730
+LEAF_PURPOSE          ?= server_cert_ext  # alternatively, use client_cert_ext
+LEAF_SUBJECT_PARTIAL  ?= /C=US/ST=California/L=Menlo Park/O=ONF/OU=Infra/CN=
+LEAF_KEYPAIR          ?= core
+LEAF_SAN              ?= DNS:core.example.com,DNS:core.example.net
+LEAF_REVOKE_REASON    ?= keyCompromise
+
+# utility/validation targets
+valid_server: ## Check Server Cert validity (set LEAF_KEYPAIR, DEFAULT_CA)
+	openssl verify -verbose -x509_strict -show_chain \
+	  -purpose sslserver \
+	  -CAfile $(BASE_DIR)/$(DEFAULT_CA)/chain.pem \
+	  -CRLfile $(BASE_DIR)/$(DEFAULT_CA)/ca.crl -crl_check \
+	  $(BASE_DIR)/certout/$(LEAF_KEYPAIR).pem
+
+valid_client: ## Check Client Cert validity (set LEAF_KEYPAIR, DEFAULT_CA)
+	openssl verify -verbose -x509_strict -show_chain \
+	  -purpose sslclient \
+	  -CAfile $(BASE_DIR)/$(DEFAULT_CA)/chain.pem \
+	  -CRLfile $(BASE_DIR)/$(DEFAULT_CA)/ca.crl -crl_check \
+	  $(BASE_DIR)/certout/$(LEAF_KEYPAIR).pem
+
+valid_im: ## Check IM CA validity (set IM_CA_NAME, ROOT_CA_NAME)
+	openssl verify -verbose -x509_strict -purpose any \
+	  -CAfile $(BASE_DIR)/$(ROOT_CA_NAME)/ca.pem \
+	  -CRLfile $(BASE_DIR)/$(ROOT_CA_NAME)/ca.crl -crl_check_all \
+	  $(BASE_DIR)/$(IM_CA_NAME)/ca.pem
+
+printca: $(BASE_DIR)/$(DEFAULT_CA)/ca.pem ## Print CA Public Key (PEM) for DEFAULT_CA
+	openssl x509 -in $< -text -noout
+
+printcrl: $(BASE_DIR)/$(DEFAULT_CA)/ca.crl ## Print CRL (Revoke List) for DEFAULT_CA
+	openssl crl -in $< -text -noout
+
+printkey: ## Print KEY (Private Key) for LEAF_KEYPAIR
+	openssl rsa -in $(BASE_DIR)/certout/$(LEAF_KEYPAIR).key -text -noout -check
+
+printcsr: ## Print CSR (Sign Request) for LEAF_KEYPAIR
+	openssl req -in $(BASE_DIR)/certout/$(LEAF_KEYPAIR).csr -text -noout -verify
+
+printpem: ## Print PEM (Public Key) for LEAF_KEYPAIR
+	openssl x509 -in $(BASE_DIR)/certout/$(LEAF_KEYPAIR).pem -text -noout
+
+revoke_leaf: ## Revoke Leaf Cert (set IM_CA_NAME, LEAF_KEYPAIR, LEAF_REVOKE_REASON)
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl ca \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase \
+	  -revoke $(BASE_DIR)/certout/$(LEAF_KEYPAIR).pem \
+	  -crl_reason $(LEAF_REVOKE_REASON)
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl ca -gencrl \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase \
+	  -out $(BASE_DIR)/$(IM_CA_NAME)/ca.crl
+
+revoke_im: ## Revoke Intermediate CA Cert (set IM_CA_NAME, IM_REVOKE_REASON, ROOT_CA_NAME)
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl ca \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -revoke $(BASE_DIR)/$(IM_CA_NAME)/ca.pem \
+	  -crl_reason $(IM_REVOKE_REASON)
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl ca -gencrl \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -out $(BASE_DIR)/$(ROOT_CA_NAME)/ca.crl
+
+destroy:  ## Delete all certificates and data
+	rm -rf $(BASE_DIR)
+
+# don't delete intermediate files
+.PRECIOUS: ca_passphrase $(BASE_DIR)/certout/%.csr $(BASE_DIR)/certout/%.key
+
+# Generic CA directory creation
+$(BASE_DIR)/%_ca:
+	mkdir -p $@/private $@/db $@/crl/db $@/certs
+	chmod 700 $@/private
+	touch $@/db/ca.db
+	printf "unique_subject = no\ncopy_extensions = copy\n" > $@/db/ca.db.attr
+	echo 01 > $@/db/ca.srl
+	echo 01 > $@/crl/db/ca.crl.srl
+	touch $@/index.txt
+
+# Root CA creation
+$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase: | $(BASE_DIR)/$(ROOT_CA_NAME)
+	@echo $(ROOT_CA_PASSPHRASE) > $@
+
+$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_key.pem: | $(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase
+	@echo "## Creating root CA private key, $@"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl genrsa -aes256 \
+	  -passout file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -out $@ $(KEY_SIZE)
+
+# validity time on root CA is set in the .cnf file
+$(BASE_DIR)/$(ROOT_CA_NAME)/ca.pem: $(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_key.pem
+	@echo "## Creating self-signed root CA cert: $@"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl req -config $(OPENSSL_CNF) \
+	  -extensions root_ca_ext \
+	  -new -x509 -sha256 \
+	  -key $< \
+	  -passin file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -subj "$(ROOT_CA_SUBJECT)" \
+	  -out $@
+	@echo "## Creating root CA revocation list: $(@D)/ca.crl"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl ca -gencrl \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -out $(@D)/ca.crl
+
+# Intermediate CA creation
+$(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase: | $(BASE_DIR)/$(IM_CA_NAME)
+	@echo $(IM_CA_PASSPHRASE) > $@
+
+$(BASE_DIR)/$(IM_CA_NAME)/private/ca_key.pem: $(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase
+	@echo "## Creating intermediate CA private key: $@"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl genrsa -aes256 \
+	  -passout file:$(@D)/ca_passphrase \
+	  -out $@ $(KEY_SIZE)
+
+$(BASE_DIR)/$(IM_CA_NAME)/private/im_ca.csr: $(BASE_DIR)/$(IM_CA_NAME)/private/ca_key.pem
+	@echo "## Creating intermediate CA signing request $@ from $<"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl req -config $(OPENSSL_CNF) \
+	  -new -sha256 \
+	  -key $< \
+	  -passin file:$(@D)/ca_passphrase \
+	  -subj "$(IM_CA_SUBJECT)" \
+	  -out $@
+
+$(BASE_DIR)/$(IM_CA_NAME)/ca.pem: $(BASE_DIR)/$(IM_CA_NAME)/private/im_ca.csr | $(BASE_DIR)/$(ROOT_CA_NAME)/ca.pem
+	@echo "## Signing $< with root CA key to create intermediate CA cert: $@"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(ROOT_CA_NAME) openssl ca -config $(OPENSSL_CNF) \
+	  -extensions im_ca_ext \
+	  -notext -batch -md sha256 \
+	  -days $(IM_EXPIRATION_DAYS) \
+	  -passin file:$(BASE_DIR)/$(ROOT_CA_NAME)/private/ca_passphrase \
+	  -in $< \
+	  -out $@
+	@echo "## Creating chain with Root CA and IM CA: $@"
+	  cat $@ $(BASE_DIR)/$(ROOT_CA_NAME)/ca.pem > $(@D)/chain.pem
+	  openssl crl2pkcs7 -nocrl -certfile $(@D)/chain.pem | openssl pkcs7 -print_certs -noout
+	@echo "## Creating IM CA revocation list: $(@D)/ca.crl"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl ca -gencrl \
+	  -config $(OPENSSL_CNF) \
+	  -passin file:$(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase \
+	  -out $(@D)/ca.crl
+
+# Leaf cert creation
+$(BASE_DIR)/certout:
+	mkdir -p $@
+
+$(BASE_DIR)/certout/%.key: $(BASE_DIR)/certout
+	@echo "## Creating leaf private key: $@"
+	openssl genrsa -out $@ $(KEY_SIZE)
+
+$(BASE_DIR)/certout/%.csr: $(BASE_DIR)/certout/%.key
+	@echo "## Creating signing request $@ from $<"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl req -config $(OPENSSL_CNF) \
+	  -new -sha256 \
+	  -key $< \
+	  -subj "$(LEAF_SUBJECT_PARTIAL)$*" \
+	  -addext "subjectAltName = $(LEAF_SAN)" \
+	  -out $@
+
+$(BASE_DIR)/certout/%.pem: $(BASE_DIR)/certout/%.csr | $(BASE_DIR)/$(IM_CA_NAME)/ca.pem
+	@echo "## Signing $< with IM CA key to create signed leaf cert: $@"
+	BASE_DIR=$(BASE_DIR) CA_NAME=$(IM_CA_NAME) openssl ca -config $(OPENSSL_CNF) \
+	  -extensions $(LEAF_PURPOSE) \
+	  -policy any_pol \
+	  -notext -batch -md sha256 \
+	  -days $(LEAF_EXPIRATION_DAYS) \
+	  -passin file:$(BASE_DIR)/$(IM_CA_NAME)/private/ca_passphrase \
+	  -in $< \
+	  -out $@
+	@echo "## Creating bundle with IM CA and Leaf: $(basename $@)_bundle.pem"
+	  cat $@ $(BASE_DIR)/$(IM_CA_NAME)/ca.pem > $(basename $@)_bundle.pem
+	  openssl crl2pkcs7 -nocrl -certfile $(basename $@)_bundle.pem | openssl pkcs7 -print_certs -noout
+
+# testing and license tasks
+test: license
+
+license: $(VENV_NAME) ## Check license with the reuse tool
+	reuse --version ;\
+  reuse --root . lint
+
+help: ## Print help for each target
+	@echo onfca make targets
+	@echo See README.md for more detailed instructions
+	@echo
+	@grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
+	  | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..adf632d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,76 @@
+# ONF Certificate Generation
+
+Generates certificates and a PKI hierarchy, using a Makefile to drive the
+process.  Please read through the variables at the top of the Makefile to learn
+how to gnerate artifacts.  Also please look at the pki.cnf, which is an OpenSSL
+configuration file used to configure the process.
+
+This Makefile will generate a 3-deep heirarchy of certificates:
+
+    root CA -> intermediate CA -> leaf
+
+Note that also CRLs are generated, as well as "chain" (containing Root CA and
+IM CA) and "bundle" (containing IM CA and Leaf) versions of generated certs.
+
+## Requirements
+
+This repo requires the following tools to work correctly
+
+- GNU `make`
+- `openssl`
+
+## Generating PKI artifacts
+
+Create a root CA Cert:
+
+    ROOT_CA_PASSPHRASE="<password>" make onf_pki/root_ca/ca.pem
+
+Create an IM CA Cert:
+
+    IM_CA_PASSPHRASE="<password>" make onf_pki/im_ca/ca.pem
+
+Create a server leaf cert (issued from IM CA):
+
+    LEAF_SAN="DNS:server.example.com" make onf_pki/certout/server.example.com.pem
+
+Create a client leaf cert (issued from IM CA):
+
+    LEAF_PURPOSE=client_cert_ext LEAF_SAN="email:username@example.com" make onf_pki/certout/username.pem
+
+Test that keys are valid for purpose:
+
+    LEAF_KEYPAIR=server.example.com make valid_server
+    LEAF_KEYPAIR=username make valid_client
+
+Revoking a leaf certificate
+
+    LEAF_KEYPAIR=server.example.com make revoke_leaf
+
+## Testing mTLS against a webserver using curl
+
+This command uses the CA root, client key/cert to connect to a remote webserver
+
+    curl -v --cacert bundle.pem --key client.key --cert client.pem https://server:port/path
+
+If you want to test an IP address that doesn't resolve with DNS but test the
+SAN, use:
+
+    curl -v --cacert ca.pem --key client.key --cert client.pem \
+      --resolve "server:port:<ip address>" https://server:port/path
+
+## References
+
+https://pki-tutorial.readthedocs.io/en/latest/index.html
+https://www.keylength.com/
+
+### Application support
+
+http://nginx.org/en/docs/http/configuring_https_servers.html
+https://ipxe.org/crypto
+
+## ToDo
+
+Implement Eliptic curves:
+
+- https://datatracker.ietf.org/doc/html/draft-moskowitz-ecdsa-pki-10
+- http://safecurves.cr.yp.to/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..0d4d124
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0-dev
diff --git a/pki.cnf b/pki.cnf
new file mode 100644
index 0000000..eb793cf
--- /dev/null
+++ b/pki.cnf
@@ -0,0 +1,117 @@
+# SPDX-FileCopyrightText: © 2022 Open Networking Foundation <support@opennetworking.org>
+#SPDX-License-Identifier: Apache-2.0
+
+
+[ default ]
+ca                   = $ENV::CA_NAME
+dir                  = $ENV::BASE_DIR
+default_ca           = default_ca
+name_opt             = multiline,-esc_msb,utf8  # Display UTF-8 characters
+config_diagnostics   = 1
+
+[ req ]
+default_bits         = 2048
+default_days         = 1825
+default_md           = sha256
+encrypt_key          = yes
+default_md           = sha256
+distinguished_name   = ca_dn
+utf8                 = yes
+string_mask          = utf8only
+
+[ default_ca ]
+certificate          = $dir/$ca/ca.pem
+private_key          = $dir/$ca/private/ca_key.pem
+policy               = match_pol
+name_opt             = $name_opt
+preserve             = no
+email_in_dn          = no
+copy_extensions      = copy
+
+new_certs_dir        = $dir/$ca/certs
+serial               = $dir/$ca/db/ca.srl
+rand_serial          = no
+database             = $dir/$ca/db/ca.db
+
+# crl
+crl_dir              = $dir/$ca/crl
+crlnumber            = $dir/$ca/crl/db/ca.crl.srl
+default_md           = sha256
+default_crl_days     = 365
+crl_extensions       = crl_ext
+
+# Extensions for a typical CA (`man x509v3_config`).
+[ root_ca_ext ]
+subjectKeyIdentifier    = hash
+authorityKeyIdentifier  = keyid:always,issuer
+basicConstraints        = critical, CA:true
+keyUsage                = critical, keyCertSign, cRLSign
+
+# Extensions for a typical intermediate CA (`man x509v3_config`).
+[ im_ca_ext ]
+subjectKeyIdentifier    = hash
+authorityKeyIdentifier  = keyid:always,issuer
+basicConstraints        = critical, CA:true, pathlen:0
+keyUsage                = critical, keyCertSign, cRLSign
+
+# Extensions for server certificates (`man x509v3_config`).
+[ server_cert_ext ]
+subjectKeyIdentifier    = hash
+authorityKeyIdentifier  = keyid,issuer:always
+basicConstraints        = critical, CA:FALSE
+keyUsage                = critical, digitalSignature, keyEncipherment
+extendedKeyUsage        = serverAuth
+
+# Extensions for client certificates (`man x509v3_config`).
+[ client_cert_ext ]
+subjectKeyIdentifier    = hash
+authorityKeyIdentifier  = keyid,issuer:always
+basicConstraints        = critical, CA:FALSE
+keyUsage                = critical, digitalSignature, keyEncipherment, nonRepudiation
+extendedKeyUsage        = clientAuth, emailProtection
+
+[ crl_ext ]
+authorityKeyIdentifier  = keyid:always
+
+# The root CA should only sign intermediate certificates that match.
+# See the POLICY FORMAT section of `man ca`.
+[ match_pol ]
+countryName             = match
+stateOrProvinceName     = match
+localityName            = match
+organizationName        = match
+organizationalUnitName  = optional
+commonName              = supplied
+emailAddress            = optional
+
+# Allow intermediate CA's to sign more types of certs
+[ any_pol ]
+domainComponent         = optional
+countryName             = optional
+stateOrProvinceName     = optional
+localityName            = optional
+organizationName        = optional
+organizationalUnitName  = optional
+commonName              = supplied
+emailAddress            = optional
+
+
+[ ca_dn ]
+# See <https://en.wikipedia.org/wiki/Certificate_signing_request>.
+countryName                     = Country Name (2 letter code)
+stateOrProvinceName             = State or Province Name
+localityName                    = Locality Name
+0.organizationName              = Organization Name
+organizationalUnitName          = Organizational Unit Name
+commonName                      = Common Name
+emailAddress                    = Email Address
+
+# Defaults DN
+countryName_default             = US
+stateOrProvinceName_default     = California
+localityName_default            = Menlo Park
+0.organizationName_default      = ONF
+organizationalUnitName_default  = Infra
+commonName                      = Testing
+emailAddress_default            = do-not-reply@opennetworking.org
+