1
0
mirror of https://github.com/vimagick/dockerfiles.git synced 2024-12-12 11:14:57 +02:00
dockerfiles/ocserv/init.sh

90 lines
2.0 KiB
Bash
Raw Normal View History

2016-06-28 22:35:26 +02:00
#!/bin/bash
set -e
if [ -f /etc/ocserv/certs/server-cert.pem ]
then
echo "Initialized!"
exit 0
else
echo "Initializing ..."
fi
mkdir -p /etc/ocserv/certs
cd /etc/ocserv/certs
cat > ca.tmpl <<_EOF_
cn = "ocserv Root CA"
organization = "ocserv"
serial = 1
expiration_days = 3650
ca
signing_key
cert_signing_key
crl_signing_key
_EOF_
cat > server.tmpl <<_EOF_
cn = "${VPN_DOMAIN}"
organization = "ocserv"
serial = 2
expiration_days = 3650
encryption_key
signing_key
tls_www_server
_EOF_
2016-06-29 10:30:45 +02:00
cat > client.tmpl <<_EOF_
cn = "client@${VPN_DOMAIN}"
uid = "client@${VPN_DOMAIN}"
unit = "ocserv"
expiration_days = 3650
signing_key
tls_www_client
_EOF_
# gen ca keys
2016-06-28 22:35:26 +02:00
certtool --generate-privkey \
--outfile ca-key.pem
certtool --generate-self-signed \
--load-privkey /etc/ocserv/certs/ca-key.pem \
--template ca.tmpl \
--outfile ca-cert.pem
2016-06-29 10:30:45 +02:00
# gen server keys
2016-06-28 22:35:26 +02:00
certtool --generate-privkey \
--outfile server-key.pem
certtool --generate-certificate \
--load-privkey server-key.pem \
--load-ca-certificate ca-cert.pem \
--load-ca-privkey ca-key.pem \
--template server.tmpl \
--outfile server-cert.pem
2016-06-29 10:30:45 +02:00
# gen client keys
certtool --generate-privkey \
--outfile client-key.pem
certtool --generate-certificate \
--load-privkey client-key.pem \
--load-ca-certificate ca-cert.pem \
--load-ca-privkey ca-key.pem \
--template client.tmpl \
--outfile client-cert.pem
certtool --to-p12 \
--load-privkey client-key.pem \
--pkcs-cipher 3des-pkcs12 \
--load-certificate client-cert.pem \
--outfile client.p12 \
--outder \
--p12-name "${VPN_USERNAME}" \
--password "${VPN_PASSWORD}"
2016-06-28 22:35:26 +02:00
sed -i -e "s@^ipv4-network =.*@ipv4-network = ${VPN_NETWORK}@" \
-e "s@^ipv4-netmask =.*@ipv4-netmask = ${VPN_NETMASK}@" /etc/ocserv/ocserv.conf
echo "${VPN_PASSWORD}" | ocpasswd -c /etc/ocserv/ocpasswd "${VPN_USERNAME}"