container-openvpn/bin/ovpn_initpki

56 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Initialize the EasyRSA PKI
#
if [ "$DEBUG" == "1" ]; then
set -x
fi
set -e
source "$OPENVPN/ovpn_env.sh"
# Specify "nopass" as arg[2] to make the CA insecure (not recommended!)
nopass=$1
# Download EasyRSA because Ubuntu doesn't have it as a CLI command
2019-06-22 05:22:05 +00:00
wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.6/EasyRSA-unix-v3.0.6.tgz
tar xvf EasyRSA-unix-v3.0.6.tgz
2019-06-22 05:34:34 +00:00
export EASYRSA="EasyRSA-v3.0.6/"
export EASYRSA_SSL_CONF="EasyRSA-v3.0.6/openssl-easyrsa.cnf"
2019-06-22 05:34:11 +00:00
cp -r EasyRSA-v3.0.6/x509-types/ x509-types/
# Provides a sufficient warning before erasing pre-existing files
2019-06-22 05:34:11 +00:00
EasyRSA-v3.0.6/easyrsa init-pki
# CA always has a password for protection in event server is compromised. The
# password is only needed to sign client/server certificates. No password is
# needed for normal OpenVPN operation.
2019-06-22 05:34:11 +00:00
EasyRSA-v3.0.6/easyrsa build-ca $nopass
2019-06-22 05:34:11 +00:00
EasyRSA-v3.0.6/easyrsa gen-dh
2016-06-23 10:20:13 +00:00
openvpn --genkey --secret $EASYRSA_PKI/ta.key
# Was nice to autoset, but probably a bad idea in practice, users should
# have to explicitly specify the common name of their server
#if [ -z "$cn"]; then
# #TODO: Handle IPv6 (when I get a VPS with IPv6)...
# ip4=$(dig +short myip.opendns.com @resolver1.opendns.com)
# ptr=$(dig +short -x $ip4 | sed -e 's:\.$::')
#
# [ -n "$ptr" ] && cn=$ptr || cn=$ip4
#fi
# For a server key with a password, manually init; this is autopilot
2019-06-22 05:34:11 +00:00
EasyRSA-v3.0.6/easyrsa build-server-full "$OVPN_CN" nopass
# Generate the CRL for client/server certificates revocation.
2019-06-22 05:34:11 +00:00
EasyRSA-v3.0.6/easyrsa gen-crl
2019-06-22 03:17:01 +00:00
# Remove EasyRSA files when we're done
2019-06-22 05:34:11 +00:00
rm -r EasyRSA-v3.0.6/
2019-06-22 05:22:05 +00:00
rm EasyRSA-unix-v3.0.6.tgz
2019-06-22 04:55:28 +00:00
rm -r x509-types/