Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenVPN Cookbook

You're reading from   OpenVPN Cookbook Get the most out of OpenVPN by exploring it's advanced features.

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher
ISBN-13 9781786463128
Length 400 pages
Edition 2nd Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Jan Just Keijser Jan Just Keijser
Author Profile Icon Jan Just Keijser
Jan Just Keijser
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Point-to-Point Networks 2. Client-server IP-only Networks FREE CHAPTER 3. Client-server Ethernet-style Networks 4. PKI, Certificates, and OpenSSL 5. Scripting and Plugins 6. Troubleshooting OpenVPN - Configurations 7. Troubleshooting OpenVPN - Routing 8. Performance Tuning 9. OS Integration 10. Advanced Configuration

OpenVPN secret keys

This recipe uses OpenVPN secret keys to secure the VPN tunnel. It is very similar to the previous recipe, but this time, we will use a shared secret key to encrypt the traffic between the client and the server.

Getting ready

Install OpenVPN 2.3.9 or higher on two computers. Make sure the computers are connected over a network. For this recipe, the server computer was running CentOS 6 Linux and OpenVPN 2.3.9 and the client was running Windows 7 64 bit and OpenVPN 2.3.10.

How to do it...

  1. First, generate a secret key on the server (listener):
              [root@server]# openvpn --genkey --secret secret.key
    
  2. Transfer this key to the client side over a secure channel (for example, using scp).
  3. Next, launch the server-side (listening) OpenVPN process:
              [root@server]# openvpn --ifconfig 10.200.0.1 10.200.0.2 \
                --dev tun --secret secret.key
    
  4. Then, launch the client-side OpenVPN process:
             [WinClient] C:\>"\Program Files\OpenVPN\bin\openvpn.exe" \
               --ifconfig 10.200.0.2 10.200.0.1 \
               --dev tun --secret secret.key \
               --remote openvpnserver.example.com
    

The connection is now established, as shown in the following screenshot:

How to do it...

How it works...

This example works exactly as the first one: the server listens to the incoming connections on UDP port 1194. The client connects to the server on this port. After the initial handshake, the server configures the first available TUN device with the IP address 10.200.0.1 and it expects the remote end (Peer address) to be 10.200.0.2. The client does the opposite.

There's more...

By default, OpenVPN uses two symmetric keys when setting up a point-to-point connection:

  • A cipher key to encrypt the contents of the packets being exchanged.
  • An HMAC key to sign packets. When packets arrive that are not signed using the appropriate HMAC key, they are dropped immediately. This is the first line of defense against a "denial-of-service" attack.
  • The same set of keys are used on both ends and both keys are derived from the file specified using the --secret parameter.

An OpenVPN secret key file is formatted as follows:

# 
# 2048 bit OpenVPN static key 
# 
-----BEGIN OpenVPN Static key V1----- 
<16 lines of random bytes> 
-----END OpenVPN Static key V1----- 

From the random bytes, the OpenVPN Cipher and HMAC keys are derived. Note that these keys are the same for each session.

See also

  • The next recipe, Multiple secret keys, will explain the format of secret keys in detail
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime