OpenVPN, easy configuration, and that damned ta.key file.

18 April 2017

Now that ISPs not selling information about what you do and what you browse on the Net is pretty much gone, a lot of people are looking into using VPNs - virtual private networks - to add a layer of protection to their everyday activities.  Most of the time there are two big use cases for VPNs: Needing to use them for work, and using them to gain access to Netflix content that isn't licensed where you live.  Now they may as well be a part of everyday carry.

So: Brass tacks.  Here's a quick way to set up your own VPN server, as well as a solution to a problem that frustrated me until very recently.  For starters, unless you're an experienced sysadmin don't try to freestyle the setup.  There is an excellent script on Github called openvpn-install that will do all of the work for you (including adding and deleting users) in less than a minute.  Use it to do the work for you.  Please.  Also, if you build an OpenVPN server, consider going in with a couple of friends on the cost.

Chances are you're running either Windows or Mac OSX (Linux and BSD users, you know what to do) so you'll need an OpenVPN client on the users' end.  This means that you want to run either the Windows version of the OpenVPN client or an OSX client like Tunnelblick.  However, these clients assume that you're just loading an all-in-one configuration file, called an .ovpn file.  If you've never done it before they're remarkably tricky to build but they're basically a copy of the OpenVPN client.conf with all of the crypto keys embedded in special stanzas.  It took me a lot of fumbling and searching but I eventually figured out how to reliably make them.  To save you some time here's a copy of the one I use with all the unique stuff removed from it.  If you open it in a text editor you'll notice a couple of things: First, the very first non-commented line says that it's for the client and not the server.  Second, I have it configured to use TCP and not UDP.  This is so that you don't have to reconfigure the firewall you're behind to get your traffic through.  Keep it simple, trust me on this.  Third, the ca, cert, and key directives are commented out because those keys are embedded at the end of the file.  Fourth, I have tls-auth enabled so that all traffic your server will handle is authenticated for better security.

If you freestyle (that is, build by hand) your OpenVPN server, you'll need to keep in mind the following things:

When you build an OpenVPN server, two files of interest will be created in the /etc/openvpn directory:

  • ca.crt
  • ta.key

Two more files will be created in the /etc/openvpn/easy-rsa/keys directory.  These files will be created for and are unique to every user on that server:

  • .crt
  • .key

The contents of these four files need to be embedded inside four stanzas at the very end of the .ovpn file:

  • ca.crt gets copied into the block
  • .crt gets copied into the block
  • .key gets copied into the block
  • ta.key gets copied into the block

Of course, if you used the openvpn-install script I linked to earlier, it does all of this magick for you.  However, if you're in a situation where you can't use it (say you're building a VPN server for work), you're going to have a hell of a time finding the documentation that actually explains how to this.  So, I hope this is helpful to someone who's working in a constrained environment.