2014-06-30 22:43:00 -07:00
|
|
|
#!/bin/bash
|
2014-06-04 11:13:59 -07:00
|
|
|
|
|
|
|
#
|
2014-07-05 21:25:00 -07:00
|
|
|
# Initialize the EasyRSA PKI
|
2014-06-04 11:13:59 -07:00
|
|
|
#
|
|
|
|
|
2015-02-28 02:45:31 -08:00
|
|
|
if [ "$DEBUG" == "1" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
2014-06-04 11:13:59 -07:00
|
|
|
|
2014-07-05 18:51:58 -07:00
|
|
|
source "$OPENVPN/ovpn_env.sh"
|
2014-06-30 22:43:00 -07:00
|
|
|
|
2014-07-05 21:25:00 -07:00
|
|
|
# Specify "nopass" as arg[2] to make the CA insecure (not recommended!)
|
|
|
|
nopass=$1
|
2014-06-04 17:07:07 -07:00
|
|
|
|
2019-06-21 20:12:59 -07:00
|
|
|
# Download EasyRSA because Ubuntu doesn't have it as a CLI command
|
|
|
|
wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.4/EasyRSA-3.0.4.tgz
|
|
|
|
tar xvf EasyRSA-3.0.4.tgz
|
|
|
|
|
2014-06-04 11:13:59 -07:00
|
|
|
# Provides a sufficient warning before erasing pre-existing files
|
2019-06-21 20:12:59 -07:00
|
|
|
~/EasyRSA-3.0.4/easyrsa init-pki
|
2014-06-04 11:13:59 -07:00
|
|
|
|
2014-06-04 17:07:07 -07:00
|
|
|
# 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-21 20:12:59 -07:00
|
|
|
~/EasyRSA-3.0.4/easyrsa build-ca $nopass
|
2014-06-04 11:13:59 -07:00
|
|
|
|
2019-06-21 20:12:59 -07:00
|
|
|
~/EasyRSA-3.0.4/easyrsa gen-dh
|
2016-06-23 12:20:13 +02:00
|
|
|
openvpn --genkey --secret $EASYRSA_PKI/ta.key
|
2014-06-04 11:13:59 -07:00
|
|
|
|
2014-06-04 11:15:43 -07:00
|
|
|
# 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
|
2014-06-04 11:13:59 -07:00
|
|
|
|
2014-06-04 17:07:07 -07:00
|
|
|
# For a server key with a password, manually init; this is autopilot
|
2019-06-21 20:12:59 -07:00
|
|
|
~/EasyRSA-3.0.4/easyrsa build-server-full "$OVPN_CN" nopass
|
2017-05-02 16:42:39 +02:00
|
|
|
|
|
|
|
# Generate the CRL for client/server certificates revocation.
|
2019-06-21 20:12:59 -07:00
|
|
|
~/EasyRSA-3.0.4/easyrsa gen-crl
|
2019-06-21 20:17:01 -07:00
|
|
|
|
2019-06-21 20:19:22 -07:00
|
|
|
# Remove EasyRSA files when we're done
|
2019-06-21 20:17:01 -07:00
|
|
|
rm -r ~/EasyRSA-3.0.4/
|
|
|
|
rm EasyRSA-3.0.4.tgz
|