Skip to content

Instantly share code, notes, and snippets.

@sfunk1x
Last active November 29, 2017 13:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfunk1x/014cfb5c1150a3a67ad708d1b7adbc9a to your computer and use it in GitHub Desktop.
Save sfunk1x/014cfb5c1150a3a67ad708d1b7adbc9a to your computer and use it in GitHub Desktop.
Script to generate an OpenVPN client configuration file in the unified format
#!/bin/sh
##
## Usage: ./ovpn-writer.sh SERVER CA_CERT CLIENT_CERT CLIENT_KEY SHARED_SECRET SERVER_CIPHER HMAC_AUTH_DIGEST > client.ovpn
##
## Example invocation (note it must be run as root since key and cert files are protected
## ./ovpn-writer.sh sub.sub.domain /etc/easy-rsa/pki/ca.crt /etc/easy-rsa/pki/issued/client.crt /etc/easy-rsa/pki/private/client.key /etc/openvpn/ta.key aes-256-cbc sha512 > android.ovpn
##
## Tested and works with OpenVPN for Android 0.6.57 on Android 6.0.1
##
server=${1?"The server address is required"}
cacert=${2?"The path to the ca certificate file is required"}
client_cert=${3?"The path to the client certificate file is required"}
client_key=${4?"The path to the client private key file is required"}
tls_key=${5?"The path to the TLS shared secret file is required"}
server_cipher=${6?"Specifying the server cipher is required"}
hmac_auth_digest=${7?"Specifying the HMAC auth digest is required"}
cat << EOF
client
dev tun
remote ${server} 1194 udp
resolv-retry infinite
nobind
persist-key
persist-tun
verb 3
comp-lzo
remote-cert-tls server
key-direction 1
cipher ${server_cipher}
auth ${hmac_auth_digest}
<ca>
EOF
cat ${cacert}
cat << EOF
</ca>
<cert>
EOF
cat ${client_cert}
cat << EOF
</cert>
<key>
EOF
cat ${client_key}
cat << EOF
</key>
<tls-auth>
EOF
cat ${tls_key}
cat << EOF
</tls-auth>
EOF
@lpvm
Copy link

lpvm commented Apr 28, 2017

How do I find the hmac_auth_digest?
I'm using OpenVPN 2.4.1

@RichardBronosky
Copy link

To convert an existing 4 file (ovpn, ca, key, crt) to a single unified/embedded ovpn file see https://gist.github.com/RichardBronosky/331f975bba6697e5a15217233d280c06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment