-
-
Save urso/cedfdab25b84c8ee3389ff0727d220ad to your computer and use it in GitHub Desktop.
beats SSL certificates+client auth test
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
all: certs/trustchain.cert.pem private/localhost.jks certs/client.localhost.cert.pem certs/trustchain.jks | |
PASS=password | |
OPENSSL=/usr/local/opt/openssl/bin/openssl | |
.PHONY: prepare | |
certs crl newcerts private reqs index.txt serial: | |
mkdir certs crl newcerts private reqs | |
chmod 700 private | |
touch index.txt | |
touch sign-ca-index.txt | |
echo 1000 > serial | |
echo 1000 > sign-ca-serial | |
certs/ca.cert.pem certs/sign-ca.cert.pem certs/trustchain.cert.pem: certs | |
@echo "### make ca" | |
${OPENSSL} req -config openssl.cnf -subj '/CN=ca/C=US/ST=Denial/O=test' -new -x509 -newkey rsa:2048 -keyout private/ca.key.pem -out certs/ca.cert.pem -days 3650 -batch -passout 'pass:${PASS}' | |
@echo "### generate signing ca" | |
${OPENSSL} req -config openssl.cnf -subj '/CN=sign-ca/C=US/ST=Denial/O=test' -new -sha256 -newkey rsa:2048 -keyout private/sign-ca.key.pem -out reqs/sign-ca.cert.pem -days 365 -batch -passout 'pass:${PASS}' | |
@echo "### sign sign-ca.cert with ca.cert" | |
${OPENSSL} ca -config openssl.cnf -key "${PASS}" -batch -extensions v3_intermediate_ca -days 365 -notext -md sha256 -in reqs/sign-ca.cert.pem -out certs/sign-ca.cert.pem -outdir . | |
@echo "### create trustchain" | |
cat certs/sign-ca.cert.pem certs/ca.cert.pem > certs/trustchain.cert.pem | |
chmod 444 certs/trustchain.cert.pem | |
certs/localhost.cert.pem: certs/sign-ca.cert.pem | |
@echo "### generate localhost server certificate" | |
${OPENSSL} req -config sign-openssl.cnf -subj '/CN=localhost/C=US/ST=Denial/O=test' -new -sha256 -nodes -batch -keyout private/localhost.key.pem -out reqs/localhost.cert.pem | |
@echo "### sign server certificate" | |
${OPENSSL} ca -config sign-openssl.cnf -key "${PASS}" -extensions server_cert -batch -days 375 -notext -md sha256 -in reqs/localhost.cert.pem -out certs/localhost.cert.pem | |
certs/client.localhost.cert.pem: certs/sign-ca.cert.pem | |
@echo "### generate localhost client certificate" | |
${OPENSSL} req -config sign-openssl.cnf -subj '/CN=localhost/C=US/ST=Denial/O=client' -new -sha256 -nodes -batch -keyout private/client.localhost.key.pem -out reqs/client.localhost.cert.pem | |
@echo "### sign client certificate" | |
${OPENSSL} ca -config sign-openssl.cnf -key "${PASS}" -extensions usr_cert -batch -days 375 -notext -md sha256 -in reqs/client.localhost.cert.pem -out certs/client.localhost.cert.pem | |
private/localhost.jks: certs/localhost.cert.pem | |
@echo "### create pkcs12 store" | |
${OPENSSL} pkcs12 -export -out private/localhost.pkcs12 -in certs/localhost.cert.pem -inkey private/localhost.key.pem -passout "pass:${PASS}" | |
@echo "### import server key into jks keystore" | |
echo "${PASS}" | keytool -importkeystore -srckeystore private/localhost.pkcs12 -destkeystore private/localhost.jks -srcstoretype pkcs12 -storepass "${PASS}" | |
certs/trustchain.jks: certs/ca.cert.pem certs/sign-ca.cert.pem | |
@echo "### add ca certificate to certs/trustchain.jks" | |
keytool -importcert -file certs/ca.cert.pem -alias ca -noprompt -storepass "${PASS}" -keystore certs/trustchain.jks | |
@echo "### add sign-ca certificate to certs/trustchain.jks" | |
keytool -importcert -file certs/sign-ca.cert.pem -alias 'sign-ca' -noprompt -storepass "${PASS}" -keystore certs/trustchain.jks | |
.PHONY: clean | |
clean: | |
rm -fR certs crl newcerts private reqs | |
rm -f index.txt* | |
rm -f sign-ca-index.txt* | |
rm -f serial* | |
rm -f sign-ca-serial* |
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
[ ca ] | |
# `man ca` | |
default_ca = CA_default | |
[ CA_default ] | |
# Directory and file locations. | |
dir = . | |
certs = $dir/certs | |
crl_dir = $dir/crl | |
new_certs_dir = $dir/newcerts | |
database = $dir/index.txt | |
serial = $dir/serial | |
RANDFILE = $dir/private/.rand | |
# The root key and root certificate. | |
private_key = $dir/private/ca.key.pem | |
certificate = $dir/certs/ca.cert.pem | |
# For certificate revocation lists. | |
crlnumber = $dir/crlnumber | |
crl = $dir/crl/ca.crl.pem | |
crl_extensions = crl_ext | |
default_crl_days = 30 | |
# SHA-1 is deprecated, so use SHA-2 instead. | |
default_md = sha256 | |
name_opt = ca_default | |
cert_opt = ca_default | |
default_days = 375 | |
preserve = no | |
policy = policy_strict | |
[ policy_strict ] | |
# The root CA should only sign intermediate certificates that match. | |
# See the POLICY FORMAT section of `man ca`. | |
countryName = match | |
stateOrProvinceName = match | |
organizationName = match | |
organizationalUnitName = optional | |
commonName = supplied | |
emailAddress = optional | |
[ policy_loose ] | |
# Allow the intermediate CA to sign a more diverse range of certificates. | |
# See the POLICY FORMAT section of the `ca` man page. | |
countryName = optional | |
stateOrProvinceName = optional | |
localityName = optional | |
organizationName = optional | |
organizationalUnitName = optional | |
commonName = supplied | |
emailAddress = optional | |
[ req ] | |
# Options for the `req` tool (`man req`). | |
default_bits = 2048 | |
distinguished_name = req_distinguished_name | |
string_mask = utf8only | |
# SHA-1 is deprecated, so use SHA-2 instead. | |
default_md = sha256 | |
# Extension to add when the -x509 option is used. | |
x509_extensions = v3_ca | |
[ req_distinguished_name ] | |
# 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 | |
# Optionally, specify some defaults. | |
countryName_default = US | |
stateOrProvinceName_default = US | |
localityName_default = local | |
0.organizationName_default = Alice Ltd | |
#organizationalUnitName_default = | |
#emailAddress_default = | |
[ v3_ca ] | |
# Extensions for a typical CA (`man x509v3_config`). | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid:always,issuer | |
basicConstraints = critical, CA:true | |
keyUsage = critical, digitalSignature, cRLSign, keyCertSign | |
[ v3_intermediate_ca ] | |
# Extensions for a typical intermediate CA (`man x509v3_config`). | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid:always,issuer | |
basicConstraints = critical, CA:true, pathlen:0 | |
keyUsage = critical, digitalSignature, cRLSign, keyCertSign | |
[ server_cert ] | |
# Extensions for server certificates (`man x509v3_config`). | |
basicConstraints = CA:FALSE | |
nsCertType = server | |
nsComment = "OpenSSL Generated Server Certificate" | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer:always | |
keyUsage = critical, digitalSignature, keyEncipherment | |
extendedKeyUsage = serverAuth | |
[ usr_cert ] | |
# Extensions for client certificates (`man x509v3_config`). | |
basicConstraints = CA:FALSE | |
nsCertType = client, email | |
nsComment = "OpenSSL Generated Client Certificate" | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer | |
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment | |
extendedKeyUsage = clientAuth, emailProtection | |
[ crl_ext ] | |
# Extension for CRLs (`man x509v3_config`). | |
authorityKeyIdentifier=keyid:always | |
[ ocsp ] | |
# Extension for OCSP signing certificates (`man ocsp`). | |
basicConstraints = CA:FALSE | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer | |
keyUsage = critical, digitalSignature | |
extendedKeyUsage = critical, OCSPSigning |
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
[ ca ] | |
# `man ca` | |
default_ca = CA_default | |
[ CA_default ] | |
# Directory and file locations. | |
dir = . | |
certs = $dir/certs | |
crl_dir = $dir/crl | |
new_certs_dir = $dir/newcerts | |
database = $dir/sign-ca-index.txt | |
serial = $dir/sign-ca-serial | |
RANDFILE = $dir/private/.rand | |
# The root key and root certificate. | |
private_key = $dir/private/sign-ca.key.pem | |
certificate = $dir/certs/sign-ca.cert.pem | |
# For certificate revocation lists. | |
crlnumber = $dir/crlnumber | |
crl = $dir/crl/sign-ca.crl.pem | |
crl_extensions = crl_ext | |
default_crl_days = 30 | |
# SHA-1 is deprecated, so use SHA-2 instead. | |
default_md = sha256 | |
name_opt = ca_default | |
cert_opt = ca_default | |
default_days = 375 | |
preserve = no | |
policy = policy_loose | |
[ policy_strict ] | |
# The root CA should only sign intermediate certificates that match. | |
# See the POLICY FORMAT section of `man ca`. | |
countryName = match | |
stateOrProvinceName = match | |
organizationName = match | |
organizationalUnitName = optional | |
commonName = supplied | |
emailAddress = optional | |
[ policy_loose ] | |
# Allow the intermediate CA to sign a more diverse range of certificates. | |
# See the POLICY FORMAT section of the `ca` man page. | |
countryName = optional | |
stateOrProvinceName = optional | |
localityName = optional | |
organizationName = optional | |
organizationalUnitName = optional | |
commonName = supplied | |
emailAddress = optional | |
[ req ] | |
# Options for the `req` tool (`man req`). | |
default_bits = 2048 | |
distinguished_name = req_distinguished_name | |
string_mask = utf8only | |
# SHA-1 is deprecated, so use SHA-2 instead. | |
default_md = sha256 | |
# Extension to add when the -x509 option is used. | |
x509_extensions = v3_ca | |
[ req_distinguished_name ] | |
# 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 | |
# Optionally, specify some defaults. | |
countryName_default = US | |
stateOrProvinceName_default = US | |
localityName_default = local | |
0.organizationName_default = Alice Ltd | |
#organizationalUnitName_default = | |
#emailAddress_default = | |
[ v3_ca ] | |
# Extensions for a typical CA (`man x509v3_config`). | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid:always,issuer | |
basicConstraints = critical, CA:true | |
keyUsage = critical, digitalSignature, cRLSign, keyCertSign | |
[ v3_intermediate_ca ] | |
# Extensions for a typical intermediate CA (`man x509v3_config`). | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid:always,issuer | |
basicConstraints = critical, CA:true, pathlen:0 | |
keyUsage = critical, digitalSignature, cRLSign, keyCertSign | |
[ server_cert ] | |
# Extensions for server certificates (`man x509v3_config`). | |
basicConstraints = CA:FALSE | |
nsCertType = server | |
nsComment = "OpenSSL Generated Server Certificate" | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer:always | |
keyUsage = critical, digitalSignature, keyEncipherment | |
extendedKeyUsage = serverAuth | |
[ usr_cert ] | |
# Extensions for client certificates (`man x509v3_config`). | |
basicConstraints = CA:FALSE | |
nsCertType = client, email | |
nsComment = "OpenSSL Generated Client Certificate" | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer | |
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment | |
extendedKeyUsage = clientAuth, emailProtection | |
[ crl_ext ] | |
# Extension for CRLs (`man x509v3_config`). | |
authorityKeyIdentifier=keyid:always | |
[ ocsp ] | |
# Extension for OCSP signing certificates (`man ocsp`). | |
basicConstraints = CA:FALSE | |
subjectKeyIdentifier = hash | |
authorityKeyIdentifier = keyid,issuer | |
keyUsage = critical, digitalSignature | |
extendedKeyUsage = critical, OCSPSigning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment