#!/usr/bin/env bash # Script to be used for generating testing certs only - for a production system, # a public CA or an internal CA should be used CLIENT_USAGE=$(cat <] Example: ${0} client -o clienttls EOL ) SERVER_USAGE=$(cat < [-o ] [-r ] [-a ] [-a ] ... Example: ${0} server -o servertls -n notary-server -a DNS:notaryserver \ -a DNS:notary_server -a IP:127.0.0.1 EOL ) if [[ -z "${1}" ]]; then printf "${CLIENT_USAGE}\n\n${SERVER_USAGE}\n\n" exit 1 fi OPENSSLCNF= for path in /etc/openssl/openssl.cnf /etc/ssl/openssl.cnf /usr/local/etc/openssl/openssl.cnf; do if [[ -e ${path} ]]; then OPENSSLCNF=${path} fi done if [[ -z ${OPENSSLCNF} ]]; then printf "Could not find openssl.cnf" exit 1 fi if [[ "${1}" == "client" ]]; then # Generate client keys - ensure that these keys are NOT CA's, otherwise # any client that is compromised can sign any number of other client # certs. OUT="clienttls" while getopts "o:" opt "${@:2}"; do case "${opt}" in o) OUT="${OPTARG}" ;; *) printf "${CLIENT_USAGE}" exit 1 ;; esac done openssl genrsa -out "${OUT}.key" 4096 openssl req -new -key "${OUT}.key" -out "${OUT}.csr" \ -subj '/C=US/ST=CA/L=San Francisco/O=Docker/CN=Notary Testing Client Auth' cat > "${OUT}.cnf" < "${OUT}.cnf" cat >> "${OUT}.cnf" <> "${OUT}.cnf" fi openssl genrsa -out "${OUT}.key" 4096 openssl req -new -nodes -key "${OUT}.key" -out "${OUT}.csr" \ -subj "/C=US/ST=CA/L=San Francisco/O=Docker/CN=${COMMONNAME}" \ -config "${OUT}.cnf" -extensions "v3_req" openssl x509 -req -days 3650 -in "${OUT}.csr" -signkey "${OUT}.key" \ -out "${OUT}.crt" -extensions v3_req -extfile "${OUT}.cnf" fi