Creating Zip With VPN Client Keys and Configuration Files

2013-07-31
#ubuntu #server #vpn #openvpn

Depending on the server configuration, each OpenVPN client needs a configuration file (client.conf for *nix and client.ovpn for Windows), a certificate authority (ca.crt), an [optional] tls-auth file (ta.key), and the user’s crt and key.

A typical OpenVPN client configuration file looks like this (ca and ta files are in the server subdirectory):

 1client
 2remote <vpn server address>
 3port 1194
 4proto udp
 5dev tun
 6dev-type tun
 7ns-cert-type server
 8reneg-sec 86400
 9comp-lzo yes
10verb 3
11ca server/ca.crt
12cert <user crt>
13key <user key>
14tls-auth server/ta.key 1

The following is tested on Ubuntu 12.04, but it will work (maybe with some modifications) in other Linux distributions. Create a new subdirectory key-bundles in the /etc/openvpn/easy-rsa directory. Place the following zip-key script there:

1#!/bin/bash
2NAME=$1
3cd keys
4sed -s "s/^cert .*/cert ${NAME}.crt/g" -i client.conf
5sed -s "s/^key .*/key ${NAME}.key/g" -i client.conf
6cp client.conf client.ovpn
7zip -r ../key-bundles/${NAME}.zip client.conf client.ovpn server ${NAME}.crt ${NAME}.key
8cd -

You may need zip (sudo apt-get install zip) and to make the script executable (sudo chmod +x zip-key). I assume your VPN client configuration file is client.conf, and ta.key and ca.crt are in the /etc/openvpn/easy-rsa/keys/server directory. The first and only script argument is the client key filename.