- •Credits
- •About the Author
- •About the Reviewers
- •www.PacktPub.com
- •Table of Contents
- •Preface
- •Introduction
- •Shortest setup possible
- •OpenVPN secret keys
- •Multiple secret keys
- •Plaintext tunnel
- •Routing
- •Configuration files versus the command-line
- •Complete site-to-site setup
- •3-way routing
- •Introduction
- •Setting up the public and private keys
- •Simple configuration
- •Server-side routing
- •Routing: subnets on both sides
- •Redirecting the default gateway
- •Using an 'ifconfig-pool' block
- •Using the status file
- •Management interface
- •Proxy-arp
- •Introduction
- •Simple configuration—non-bridged
- •Enabling client-to-client traffic
- •Bridging—Linux
- •Bridging—Windows
- •Checking broadcast and non-IP traffic
- •External DHCP server
- •Using the status file
- •Management interface
- •Introduction
- •Certificate generation
- •xCA: a GUI for managing a PKI (Part 1)
- •xCA: a GUI for managing a PKI (Part 2)
- •OpenSSL tricks: x509, pkcs12, verify output
- •Revoking certificates
- •The use of CRLs
- •Checking expired/revoked certificates
- •Intermediary CAs
- •Multiple CAs: stacking, using --capath
- •Introduction
- •Initializing a hardware token
- •Getting a hardware token ID
- •Using a hardware token
- •Selecting a PKCS#11 certificate using the management interface
- •Generating a key on the hardware token
- •Private method for getting a PKCS#11 certificate
- •Pin caching example
- •Introduction
- •Using a client-side up/down script
- •Windows login greeter
- •Using client-connect/client-disconnect scripts
- •Using a 'learn-address' script
- •Using a 'tls-verify' script
- •Using an 'auth-user-pass-verify' script
- •Script order
- •Script security and logging
- •Using the 'down-root' plugin
- •Using the PAM authentication plugin
- •Introduction
- •Cipher mismatches
- •TUN versus TAP mismatches
- •Compression mismatches
- •Key mismatches
- •Troubleshooting MTU and tun-mtu issues
- •Troubleshooting network connectivity
- •How to read the OpenVPN log files
- •Introduction
- •The missing return route
- •Missing return routes when 'iroute' is used
- •Source routing
- •Routing and permissions on Windows
- •Troubleshooting client-to-client traffic routing
- •Understanding the 'MULTI: bad source' warnings
- •Failure when redirecting the default gateway
- •Introduction
- •Optimizing performance using 'ping'
- •OpenSSL cipher speed
- •Compression tests
- •Traffic shaping
- •Tuning UDP-based connections
- •Tuning TCP-based connections
- •Analyzing performance using tcpdump
- •Introduction
- •Linux: using NetworkManager
- •MacOS: using Tunnelblick
- •Windows Vista/7: elevated privileges
- •Windows: using the CryptoAPI store
- •Windows: updating the DNS cache
- •Windows: running OpenVPN as a service
- •Windows: public versus private network adapters
- •Windows: routing methods
- •Introduction
- •Including configuration files in config files
- •Details of ifconfig-pool-persist
- •Connecting using a SOCKS proxy
- •Connecting via an HTTP proxy
- •Connecting via an HTTP proxy with authentication
- •Using dyndns
- •IP-less setups (ifconfig-noexec)
- •Introduction
- •Inline certificates
- •Connection blocks
- •Port sharing with an HTTPS server
- •Routing features: redirect-private, allow-pull-fqdn
- •OCSP support
- •New for 2.2: the 'x509_user_name' parameter
- •Index
PKI, Certificates, and OpenSSL
As a last step, we export the certificate for use with OpenVPN. In the tab Certificates, select the client2 certificate and press Export:
Choose the name as client2.crt and click on OK. Go the Private Keys tab and do the same for the client2 private key. Choose the name client2.key.
How it works...
By selecting our CA certificate and choosing the New certificate, xCA generates a new certificate that is signed by this CA. Before a certificate can be signed, all appropriate X.509 fields such as Key usage and Extended Key usage need to be filled in. This recipe also demonstrates that even with a GUI it is still not trivial to manage a proper Public Key Infrastructure (PKI).
There's more...
The xCA GUI has many more features for the generation of certificates, Certificate Revocation
Lists (CRLs), and other PKI-related subjects, but that is outside the scope of this book.
OpenSSL tricks: x509, pkcs12, verify output
The OpenSSL commands may seem daunting at first, but there are a lot of useful commands in the OpenSSL toolbox for viewing and managing X.509 certificates and private keys. This recipe will show how to use a few of those commands.
112
Chapter 4
Getting ready
Set up the easy-rsa certificate environment using the first recipe from Chapter 2 by sourcing the vars file. This recipe was performed on a computer running Fedora 12 Linux but it can easily be run on Windows or MacOS.
How to do it...
1.To view the subject and expiry date of a given certificate, type: $ cd /etc/openvpn/cookbook/keys
$ openssl x509 -subject -enddate -noout -in openvpnclient1.crt
subject= /C=NL/O=Cookbook/CN=openvpnclient1/emailAddress=[…] notAfter=Jan 30 12:00:09 2013 GMT
2. To export a certificate and private key in PKCS12 format:
$ openssl pkcs12 -export -in openvpnclient1.crt \ -inkey openvpnclient1.key -out openvpnclient1.p12
Enter Export Password:[Choose a strong password]
Verifying - Enter Export Password:[Type the password again] $ chmod 600 openvpnclient1.p12
Note that the chmod 600 ensures that the PKCS12 file is readable only by the user.
3.Verify the purpose of a given certificate:
$ openssl verify -purpose sslclient -CAfile ca.crt \ openvpnclient1.crt
openvpnclient1.crt: OK
4.Notice the error if we select the wrong purpose (sslclient versus sslserver):
$ openssl verify -purpose sslclient -CAfile ca.crt \ openvpnserver.crt
openvpnserver.crt: C = NL, O = Cookbook, CN = openvpnserver, emailAddress = openvpn-ca@cookbook.example.com
error 26 at 0 depth lookup:unsupported certificate purpose OK
5.Change the password (passphrase) of a certificate:
$ openssl rsa -in openvpnclient2.key -aes256 -out newclient.key
Enter pass phrase for keys/openvpnclient2.key:[old password] writing RSA key
Enter PEM pass phrase:[new password]
Verifying - Enter PEM pass phrase:[new password]
113
PKI, Certificates, and OpenSSL
How it works...
The OpenSSL toolkit consists of a wide range of commands to generate, manipulate, and view X.509 certificates and their corresponding private keys. The commands in this chapter are but a small subset of the available commands. On Linux and UNIX systems, you can use openssl -h and the manual pages for x509, pkcs12, and req for more details. The manual pages are also available online at:
http://www.openssl.org/docs/apps/openssl.html
Click on the OpenSSL commands lower down in the list of all commands for direct pointers.
Revoking certificates
A common task when managing a PKI is to revoke certificates that are no longer needed or that have been compromised. This recipe demonstrates how certificates can be revoked
using the easy-rsa script and how OpenVPN can be configured to make use of a Certificate
Revocation List (CRL).
Getting ready
Set up the client and server certificates using the first recipe from Chapter 2. This recipe was performed on a computer running CentOS 5 Linux, but it can easily be run on Windows or Mac OS.
How to do it...
1.First, we generate a certificate: $ cd /etc/openvpn/cookbook $ . ./vars
$ ./build-key client4
[…]
2.Then, we immediately revoke it: $ ./revoke-full client4
Using configuration from /etc/openvpn/cookbook/openssl.cnf Revoking Certificate 08.
Data Base Updated
Using configuration from /etc/openvpn/cookbook/openssl.cnf client4.crt: /C=NL/O=Cookbook/CN=client4/emailAddress=[...] error 23 at 0 depth lookup:certificate revoked
114
Chapter 4
3.This will also update the CRL list. The CRL can be viewed using the command: $ openssl crl –text -noout -in crl.pem
How it works...
A CRL contains a list of certificate serial numbers that have been revoked. Each serial number can be handed out by a CA only once, so this serial number is unique to this particular CA. The CRL is signed using the CA's private key, ensuring that the CRL is indeed issued by the appropriate party.
There's more...
The question "what exactly is needed to revoke a certificate" is often asked, so the following section goes a bit deeper into this.
What is needed to revoke a certificate
In order to revoke a certificate, the certificate subject ("DN") is required as well as the certificate serial number. If a certificate is lost, then it is simply not possible to revoke it. This shows how important it is to do proper PKI management, including backing up the certificates that have been handed out to users.
See also
The next recipe, The Use of CRLs
The last recipe in this chapter, Multiple CA's: stacking, using –capath
115