-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
339 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
set -e | ||
CERT_DIR="${1}" | ||
CONTROLLER_ID="${2}" | ||
CA_CERT="root-ca.crt" | ||
CA_KEY="root-ca.key" | ||
CA_CSR="root-csr.pem" | ||
CERT_CONFIG=' | ||
[client] | ||
basicConstraints = CA:FALSE | ||
nsCertType = client, email | ||
nsComment = "Local Test Client Certificate" | ||
subjectKeyIdentifier = hash | ||
authorityKeyIdentifier = keyid,issuer | ||
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment | ||
extendedKeyUsage = clientAuth | ||
' | ||
|
||
mkdir -p ${CERT_DIR} | ||
cd ${CERT_DIR} | ||
if [ ! -f "${CA_CERT}" ]; then | ||
echo "Development CA" | ||
openssl req -newkey rsa -keyout ${CA_KEY} -out ${CA_CSR} -subj "/O=Test/CN=localhost" --nodes | ||
openssl req -x509 -sha256 -new -nodes -key ${CA_KEY} -days 3650 -out ${CA_CERT} -subj '/CN=localhost' | ||
fi | ||
if [ -n "${CONTROLLER_ID}" ]; then | ||
openssl genrsa -out "client.key" 4096 | ||
openssl req -new -key "client.key" -out "client.csr" -sha256 -subj "/CN=${CONTROLLER_ID}" | ||
|
||
openssl x509 -req -days 750 -in "client.csr" -sha256 -CA ${CA_CERT} -CAkey ${CA_KEY} -CAcreateserial -out "client.crt" -extensions client -extfile <(printf ${CERT_CONFIG}) | ||
openssl x509 -in client.crt -issuer_hash -noout > issuer_hash.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
|
||
|
||
class MtlsConfig: | ||
def __init__(self, cert_dir_location): | ||
self.certs_dir= str(cert_dir_location) + "/certs/" | ||
self.ca_cert= self.certs_dir + "root-ca.crt" | ||
self.ca_key= self.certs_dir + "root-ca.key" | ||
self.ca_csr= self.certs_dir + "root-csr.pem" | ||
self.client_cert= self.certs_dir + "client.crt" | ||
self.client_key= self.certs_dir + "client.key" | ||
self.issuer_hash = self. certs_dir + "issuer_hash.txt" | ||
def client_cert_exist(self): | ||
return os.path.isfile(self.client_cert) | ||
|
||
def ca_cert_exist(self): | ||
return os.path.isfile(self.ca_cert) | ||
|
||
def get_issuer_hash(self): | ||
return open(self.issuer_hash, "r").readline().strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.