From ec51e68a0b750ceb5737fdb0e62a5721a1acdf7c Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 16 May 2021 22:56:50 +0200 Subject: [PATCH] Started docker-tcp.sh --- static/docker-tcp.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/static/docker-tcp.sh b/static/docker-tcp.sh index 4141187..b1e88a2 100755 --- a/static/docker-tcp.sh +++ b/static/docker-tcp.sh @@ -4,3 +4,40 @@ # Docker API over the internet. +# Defaults +days=365 + + +# Displays how to use the program +function usage() { + echo "This script generates OpenSSL certificate pairs which can be used to expose a Docker API." + echo + echo "Usage: $0 [-h] [-d DAYS] HOST IP" + exit 1 +} + + +while getopts ':hd:' c; do + case $c in + h ) usage ;; + d ) days="$OPTARG" ;; + esac +done +shift $((OPTIND - 1)) + +# Check for correct amount of arguments +[ $# -eq 2 ] || usage + + +# Generate CA key +openssl genrsa -aes256 -out ca-key.pem 4096 +openssl req -new -x509 -days "$DAYS" -key ca-key.pem -sha256 -out ca.pem + +# Generate server key +openssl genrsa -out server-key.pem 4096 +openssl req -subj "/CN=$HOST" -sha256 -new -key server-key.pem -out server.csr + +# Create extfile.cnf + +echo subjectAltName = "DNS:$HOST,IP:$IP,IP:127.0.0.1" > extfile.cnf +echo extendedKeyUsage = serverAuth >> extfile.cnf