126f3a4557
* Protect the CA key with a passphrase by default to protect it from a filsystem compromise. An attacker could still steal the other keys stored (ie the server's cert key), but not issue new keys. * This is a good compromise for now.
46 lines
1.1 KiB
Bash
Executable File
46 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
#
|
|
# Initialize the PKI and OpenVPN configs
|
|
#
|
|
|
|
set -ex
|
|
|
|
cn=$1
|
|
|
|
if [ -z "$cn" ]; then
|
|
echo "Common name not specified"
|
|
exit 1
|
|
fi
|
|
|
|
# Specify "nopass" as arg[2] to make the CA insecure
|
|
nopass=$2
|
|
|
|
# Provides a sufficient warning before erasing pre-existing files
|
|
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.
|
|
easyrsa build-ca $nopass
|
|
|
|
easyrsa gen-dh
|
|
openvpn --genkey --secret $OPENVPN/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
|
|
|
|
echo "$cn" > $OPENVPN/servername
|
|
|
|
# For a server key with a password, manually init; this is autopilot
|
|
easyrsa build-server-full $cn nopass
|
|
|
|
ovpn_genconfig "$cn"
|