Deploying Affordable IPSec VPNs with FreeS/WAN
Finally, we have arrived at the point at which we can rush away from the theoretical aspects and do some hands-on work. The de facto standard for establishing IPSec communication using Linux (kernel 2.4) is a package called FreeS/WAN (http://www.freeswan.org), started by John Gilmore in 1996. The S/WAN part of the name stands for Secure Wide Area Network, a project run among several companies to ensure the interoperability of different IPSec implementations, and the Free part indicates that it is distributed under the GPL. The package supports most of the features you will need for day-to-day VPN operations. Several patches exist to advance FreeS/WAN and make it more customizable. Apparently, an alternative and highly patched solution is called Super FreeS/WAN (http://www.freeswan.ca). We focus on Super FreeS/WAN while guiding you through the installation and configuration process. Whenever we mention FreeS/WAN in the text, we actually address its patched version, Super FreeS/WAN.It is best to view FreeS/WAN as consisting of two parts: KLIPS and Pluto. KLIPS (kernel IP security) is integrated into the Linux kernel and can be compiled as a part of the kernel or as a loadable module. It implements AH, ESP, and packet handling within the kernel. Pluto is responsible for implementing IKE and is used for connection negotiation with other systems.Note
![]() | Several important events have happened since the book was written. The development of the FreeS/WAN project has been stopped and it has re-emerged as the OpenSWAN project, located at http://www.openswan.org. |
FreeS/WAN Compilation
We assume that apart from RPMing or apt-geting, you feel pretty confident at compiling programs from source. In fact, it is possible to get FreeS/WAN as a package, but most likely it will not include support for some of the new "kewl" features you might require.Before you start installing FreeS/WAN, be sure to familiarize yourself with the process of kernel compilation from source. The sources can be obtained from http://www.kernel.org. The stable version at the time of writing is 2.4.24. Make sure the kernel you have compiled has all the necessary features included and that your machine boots and works flawlessly with it.The next step is to obtain the source for FreeS/WAN. The current stable version of FreeS/WAN is 2.00, available from http://www.freeswan.org. The current patched version of Super FreeS/WAN is 1.99.7, available from http://www.freeswan.ca. The version you choose to install is up to you, but we opt for Super FreeS/WAN.Download the latest version of FreeS/WAN into /usr/local/src/ and untar the archive:
Now you are ready to install. The four SuperFreeS/WAN commands you can use to compile are shown in Table 14-1.
arhontus:~#cd /usr/local/src
arhontus:~#tar xvzf super-freeswan-1.99.7.tar.gz
arhontus:~#cd super-freeswan-1.99.7
SuperFreeS/WAN | Kernel |
---|---|
make menugo | make menuconfig |
make xgo | make xconfig |
make ogo | make config |
make oldgo | make oldconfig |
Figure 14.8. Menuconfig IPSec configuration section in the kernel.
[View full size image]

Figure 14.9. Xconfig IPSec configuration section in the kernel.
[View full size image]

Turn this option on if you want IPSec to work; it is a KLIPS part in your kernel.IPSEC: IP-in-IP encapsulation (tunnel mode).
We advise you to turn this option on, unless you do not want to use the tunnel mode.IPSEC: Authentication Header.
If you want to use AH, turn this option on. If you want to use ESP on its own, without additional AH authentication, you can deselect it.HMAC-MD5 authentication algorithm.
Select this option if you want to use the MD5 hashing function.HMAC-SHA1 authentication algorithm.
The SHA1 hashing function is cryptographically stronger than MD5. We recommend turning both options on, especially if you are concerned with interoperability with other IPSec implementations.IPSEC: Encapsulating Security Payload.
By selecting this option you will be able to use IPSec in ESP mode. You should select this option.3DES encryption algorithm.
A standard CPU-intensive cryptographic algorithm. It is a good idea to select this option mainly for interoperability issues.IPSEC Modular Extensions.
Say yes here if you want to use additional features provided by Super FreeS/WAN.HMAC_MD5 auth algorithm (modular alg).
Say no here.HMAC_SHA1 auth algorithm (modular alg).
Say no here as well.HMAC_SHA2 auth algorithm.
SHA2 provides a cryptographically stronger hash function that uses 256- or 512-bit as opposed to 128-bit used by SHA1. We do advise that you use SHA2.3DES encryption algorithm (modular alg).
Say no here.AES encryption algorithm.
AES provides much stronger security than its predecessor, DES. We recommend you use this algorithm, because in our experience it provides one of the best performance/cryptographic strength ratios. On our machines, 256-bit AES encrypts and decrypts data two times faster than 3DES (in software).BLOWFISH encryption algorithm.
This pretty old, free, and reliable 64-bit block algorithm is the predecessor to the TWOFISH cryptographic algorithm.TWOFISH encryption algorithm.
This is one of the AES finalists developed by Bruce Schneier.SERPENT encryption algorithm.
This was another AES finalist. In our opinion, this algorithm is the most secure AES candidate from a mathematical viewpoint. If you do not trust AES to protect your data, SERPENT is the definite choice for encryption.CAST encryption algorithm.
The algorithm is patented for commercial use and was also one of the first-round AES finalists.NULL encryption algorithm.
No encryption. It is unwise to use ESP with no encryption. Unless you have a strange sense of humor, consider using the AH mode.CRYPTOAPI ciphers support.
This provides additional support for using ciphers included with the cryptoapi kernel patch.1DES **INSECURE** encryption algorithm.
This is included for greater interoperability with legacy IPSec implementations.IPSEC: IP Compression.
You might want to experiment with compression to combat the negative impact of the increased overhead. Note that it is rather CPU intensive.IPSEC Debugging Option.
When selected, KLIPS outputs debugging information into syslog. It is a good idea to turn it on, especially when setting up your first VPN.IPSEC NAT-Traversal.
If you plan to run IPSec tunnel when one of the peers is behind the NAT, turn this option on.
In terms of selecting a cryptographic algorithm properly and efficiently, it is best to refer to Chapter 11 for a discussion of each algorithm and its implementations in more details. Understanding applied cryptography is the key to successful VPN deployment.Once the options are selected, go ahead and save the configuration. FreeS/WAN will do the rest, compiling all the utilities and building the kernel. When the compilation process is complete, type cd /usr/src/linux; inform modules_install to install the modules.The next thing you need to do is to copy the newly compiled kernel image into your boot directory and make lilo (or another boot loader) about it. Do the following:
Now open lilo.conf in your favorite editor (vi is our choice):
arhontus:~#cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-ipsec-'kernel version'
Add the following lines:
arhontus:~#vi /etc/lilo.conf
Save the file, quit, and rerun lilo by typing
image = /boot/vmlinuz-ipsec-'kernel version'
root = /dev/'boot_device'
label = Linux-sfswan
read-only
If no errors occurred, reboot the machine, and when presented with the boot loader screen, select new kernel. Cross your fingers, knock on wood, spit three times over your left shoulder, and say a little prayer to Mr. Torvalds, and hopefully you will successfully boot the first time.
arhontus:~#lilo
FreeS/WAN Configuration
We have discussed different types of VPN topologies, but due to space constraints we discuss only two scenarios in more detail: network-to-network and host-to-network using a Road Warrior setup. These types are suitable for protecting wireless point-to-point and point-to-multipoint links. Besides, once you know how to configure these types of VPN topologies, it should not be that difficult for you to configure the rest, if necessary.
Key Generation
The first action you need to perform is generating keys to be used for the IKE initialization. All your keys are stored in /etc/ipsec.secrets. Make sure the permissions are set to 600, and if not, do this:
arhontus:~#chmod 600 /etc/ipsec.secrets
Symmetric Key Generation
The Super FreeS/WAN suite has a built-in symmetric key generation command. To generate a 64-bit key, you have enter the following command:
We have used 64 bits in this example to conserve some space; please use greater sizes when generating keys for a real-life VPN connection.To the right of it add a large ! symbol in the empty space.The pseudorandom number is generated and saved in /tmp/symm.key. Now add the contents of symm.key to /etc/ipsec.secrets, and use the PSK identifier, so the resulting file will look similar to this:
arhontus:~#ipsec ranbits --continouous 64 > /tmp/symm.key
Make sure both of the hosts participating in the communication have matching entries in /etc/ipsec.secrets.
: PSK "0xe687f51034f33f07"
RSA Key Generation
The IPSec suite also allows for RSA public and private key pair generation. In the following example we demonstrate how to generate 64-bit keys. When you generate keys for a real-life situation, please use much larger integers for keys.To generate an RSA key pair, enter the following command:
Now, for IPSec to take advantage of the generated keys, you have to perform some modifications to the generated data. The first step you need to perform is to add ": RSA{" to the beginning and "}" to the end of the file, so that it results in the following format:
# ipsec rsasigkey verbose 64 > /tmp/rsa.key
Make sure that each line in the file is preceded by a tabulation, otherwise FreeS/WAN cannot understand it. Once you have completed editing the file, copy the contents to /etc/ipsec.secrets. It will look similar to this:
: RSA {
output of the rsakeygen
}
It is possible to have multiple keys in ipsec.secrets, but you have to index each one of them independently in the following manner:
: RSA {
# RSA 64 bits dyno Sat May 31 17:08:13 2003
# for signatures only, UNSAFE FOR ENCRYPTION
#pubkey=0sAQNrYsldIB3h4w==
#IN KEY 0x4200 4 1 AQNrYsldIB3h4w==
# (0x4200 = auth-only host-level, 4 = IPSec, 1 = RSA)
Modulus: 0x6b62c95d201de1e3
PublicExponent: 0x03
# everything after this point is secret
PrivateExponent: 0x11e5cc39f8be86f3
Prime1: 0xa889727b
Prime2: 0xa31d45b9
Exponent1: 0x705ba1a7
Exponent2: 0x6cbe2e7b
Coefficient: 0x25a4fd62
}
An additional operation you have to perform is extracting your public key and making it available for other involved parties. The part in the #pubkey= is your public key that can be safely transmitted in the open to others. Later you will have to add it to the ipsec.conf of the involved parties. Remember that your public key is the character sequence and it does not include "#pubkey=".
@vpn1.arhont.com: RSA {
rsasigkey output
}
@vpn2.arhont.com: RSA {
rsasigkey output
}
X.509 Certificate Generation
X.509 certificate creation requires that you have OpenSSL installed and working. First you need to create your own CA, unless you want to send out certificates to be signed by your trusted CA, but that will cost money.The location of the OpenSSL executables will depend on the distribution you are using. Slackware stores OpenSSL files in /etc/ssl/, whereas Debian stores them in /usr/lib/ssl/. In this example we use the Slackware path:
Just press Enter when asked for a file name, then enter information after the prompts. The password you are asked for will be your CA password; make sure you remember it. Then we extend the life of CA to 1,024 days (use a shorter life for security-critical set-ups). Once the process completes, you have the private (cakey.pem) and public (cacert.pem) parts of your CA. Now copy the public part of the CA to the place where SuperFreeS/WAN can find it:
arhontus:~#cd /etc/ssl/misc
arhontus:#./CA.sh -newca
arhontus:#mv ./demoCA/cacert.pem ./demoCA/newca.pem
arhontus:#openssl x509 -in ./demoCA/newca.pem -days 1024 -out ./demoCA/cacert.pem -signkey ./demoCA/private/cakey.pem
arhontus:#rm ./demoCA/newca.pem
As the CA is generated, you have to create two certificates: one for each end of the VPN connection. Both certificates will have a public and private part.The process of creating certificates is described next.
arhontus:~#cp /etc/ssl/misc/demoCA/cacert.pem /etc/ipsec.d/cacerts/
Enter the information required after the prompts, and make sure you remember the password, because it is your FreeS/WAN certificate password to live with. When prompted for a challenge password and an optional company name, press Enter (do not enter anything).Now you have to sign the certificate with your CA. Enter this:
arhontus:~#cd /etc/ssl/misc
arhontus:#./CA.sh -newreq
When prompted for the PEM password, just enter the password for your CA. Your new certificate is created and signed. The public part is located in newcert.pem and the private part is located in newreq.pem. Now let's move these files to the location where FreeS/WAN can recognize them:
arhontus:#./CA.sh -sign
Repeat the procedure for the second pair of certificates. Remember to name the certificates differently this time.Make sure you let FreeS/WAN know about the certificate. Add the following entry to /etc/ipsec/secrets:
arhontus:#mv ./newreq.pem /etc/ipsec.d/private/freeswan-priv.pem
arhontus:#mv ./newcert.pem /etc/ipsec.d/freeswan-cert.pem
Because the password is stored in cleartext and IPSec configuration files are considered to be private information, make sure the permissions for these files are set to disallow group/user read access. Enter the following:
: RSA freeswan-priv.pem "certificate password"
Next we need to generate an empty certificate revocation list (CRL). To do so, enter this:
arhontus:~#chmod 600 /etc/ipsec.secrets
arhontus:~#chmod 644 /etc/ipsec.conf
Your certificates are generated and ready to use.
arhontus:~#openssl ca -gencrl -out /etc/ipsec.d/crls/crl.pem
Ipsec.conf Organization
Before we start configuring FreeS/WAN, it is useful to understand the general organization of the main configuration file. The typical ipsec.conf looks similar to this:
The ipsec.conf is split into two parts, a config part that specifies general configuration options and the conn section defining connection details. Table 14-2 shows some of the relevant parameters and their descriptions.
config setup
interfaces="ipsec0=eth0"
klipsdebug=none
plutodebug=none
plutoload=%search
plutostart=%search
uniqueids=yes
conn %default
keyingtries=0
auth=esp
authby=rsasig
esp=aes128-sha2_256
pfsgroup=modp1536
ike=aes256-md5-modp4096
pfs=yes
compress=no
conn gate1-gate2
left=192.168.50.100
leftid=@vpn1.core.arhont.com
leftnexthop=192.168.50.251
leftsubnet=192.168.10.0/24
leftrsasigkey=0sAQNgvfFH2bGl...
right=192.168.100.150
rightid=@vpn2.core.arhont.com
rightnexthop=192.168.100.251
rightsubnet=192.168.15.0/24
rightrsasigkey=0sAQPFb2ffuPhn...
auto=start
Network-to-Network VPN Topology Setting
First you need to tweak some kernel parameters. To enable forwarding between interfaces, enter this:
Next, you have to generate two sets of keys. The process was explained in the previous section, so we assume you have a set of keys generated. In the following example we show how to use FreeS/WAN to set up the network-to-network tunnel. The sample ipsec.conf is presented here:
# echo 1 > /proc/sys/net/ipv4/ip_forward
Note that we set up a tunnel using ESP and encrypt it with 128-bit AES we defined by the esp=aes128-sha2_256 parameter. If you want a different encryption algorithm, you should check what algorithms are available to Pluto by entering this:
config setup
interfaces="ipsec0=eth0"
klipsdebug=none
plutodebug=none
plutoload=%search
plutostart=%search
uniqueids=yes
conn %default
keyingtries=0
auth=esp
authby=rsasig
esp=aes128-sha2_256
pfsgroup=modp1536
ike=aes256-md5-modp4096
pfs=yes
compress=no
conn gate1-gate2
left=192.168.50.100
leftid=@vpn1.core.arhont.com
leftnexthop=192.168.50.251
leftsubnet=192.168.10.0/24
leftrsasigkey=0sAQNgvfFH2bGl...
right=192.168.100.150
rightid=@vpn2.core.arhont.com
rightnexthop=192.168.100.251
rightsubnet=192.168.15.0/24
rightrsasigkey=0sAQPFb2ffuPhn...
auto=start
arhontus:~#ipsec auto --status | grep alg.*ESP
Host-to-Network VPN Topology Setting
In this type of configuration, we set up the vpn1.core.arhont.com to be the gateway with the wireless host accessing the internal network resources through the VPN. This time we are going to use X.509 certificates for authentication. On the network gateway host, make sure that packet forwarding is enabled by entering the following:
Also check that both public parts of the certificates are located in /etc/ipsec.d/, the private part of the peer certificate is located in /etc/ipsec.d/private/, and the corresponding entry is present in /etc/ipsec.secrets. Thus, the ipsec.conf should look similar to this:
# echo 1 > /proc/sys/net/ipv4/ip_forward
In the current configuration, the authentication is performed using an X.509 certificate. The leftsubnet=0.0.0.0/0 string specifies that the left peer is the default gateway for all traffic. The situation is common when you have wireless hosts on the network that do not only need to communicate with the rest of the LAN, but also have an ability to communicate with the Internet directly.If you have a large number of certificates or often change the certificates' names, it is possible to avoid defining the exact names of these certificates. Instead you can enter the information about the certificate and FreeS/WAN will search through all the available ones until it finds a proper match. A sample setup is shown here:
config setup
interfaces="ipsec0=eth0"
klipsdebug=none
plutodebug=none
plutoload=%search
plutostart=%search
uniqueids=yes
conn %default
keyingtries=0
auth=esp
authby=rsasig
esp=aes128-sha2_256
pfsgroup=modp1536
ike=aes256-md5-modp4096
pfs=yes
compress=no
conn pingo-dyno
left=192.168.50.101
leftsubnet=0.0.0.0/0
leftnexthop=%direct
leftcert=pingo-cert.pem
right=192.168.50.6
rightnexthop=%direct
rightcert=dyno-cert.pem
auto=start
conn pingo-dyno
left=192.168.50.101
leftsubnet=0.0.0.0/0
leftnexthop=%direct
leftcert=pingo-cert.pem
right=192.168.50.6
rightid="C=UK, ST=Some-State, L=Bristol, O=Arhont Ltd, CN=pingo.core.arhont.com,E=info@arhont.com"
rightrsasigkey=%cert
rightnexthop=%direct
auto=start
Windows 2000 Client Setup
Unfortunately, not all of us have the pleasure of using a Linux operating system, so for the less fortunate we guide you through setting up your Windows box for secure communication to a FreeS/WAN-based VPN concentrator. Prepare for a "clicking session."Windows does not understand the *.pem format of OpenSSL, so first you need to convert the certificate using this:
When prompted for a password, enter a password for that specific certificate. Next you will be prompted for an export password. Enter a new password and remember it, as you will be asked for it later when you import the certificate into Windows 2000. Once the files are generated, transfer them in a secure manner to your Windows machine, and make sure to erase them from /tmp.The default Windows installation does not support strong encryption, and you are limited to using DES only. If you have not done so already, fetch the High Encryption Pack for Windows 2000 from the Microsoft Web site (http://www.microsoft.com/WINDOWS2000/downloads/recommended/encryption/default.asp).Once the pack is installed, you have to import the certificates into Windows. To do so, go to the Start menu, click Run, and enter mmc. A window will pop up. In the Console menu, click Add/Remove Snap-in (see Figure 14-10).
arhontus:~#openssl pkcs12 -export -in /etc/ipsec.d/client.pem -inkey /etc/ipsec.d/private/client.pem -certfile /etc/ssl/misc/demoCA/cacert.pem -out /tmp/client.p12
arhontus:~#openssl x509 -in /etc/ipsec.d/freeswan-cert.pem -out /tmp/freeswan-cert.pem
Figure 14.10. Console/Add/Remove snap-in.
[View full size image]

Figure 14.11. Certificates snap-in.
[View full size image]

Figure 14.12. Console computer selection.
[View full size image]

Figure 14.13. Certificate import sequence.
[View full size image]

Figure 14.14. Certificate Import Wizard.
[View full size image]

Figure 14.15. Store selection for certificate.
[View full size image]

Figure 14.16. Cut the imported CA.
[View full size image]

Figure 14.17. Paste the CA in the right place.
[View full size image]

Windows 2000 IPSec Client Configuration
We will not be creating a real VPN connection; rather we will be modifying the properties of the TCP/IP connection by applying a security policy so that the traffic will be always protected. This is the easiest solution when you are accessing your company's LAN over wireless. Besides, you do not incur additional software costs.Like most of the other configuration settings in Windows, the IPSec policies are defined in Control Panel. To create a policy, go to Control Panel, open Administrative Tools, and double-click Local Security Settings.We are going to create our own policy. To do so, click Action and select Create IP Security Policy (see Figure 14-18).
Figure 14.18. Create IP Security Policy.
[View full size image]

Figure 14.19. VPN properties selection.

Figure 14.20. IP filter list creation.

Figure 14.21. IP filter list properties setting.

Figure 14.22. IP filter listTunnel endpoints information.

Figure 14.23. Filter ActionRequire Security.

Figure 14.24. Filter ActionRequire Security properties selection.

Figure 14.25. Tunnel settings.

Figure 14.26. Authentication method selection.

Figure 14.27. Key Exchange settings.

Figure 14.28. Security methods for Key Exchange.

Figure 14.29. Assign your new tunnel.
[View full size image]

Figure 14.30. Restart the IPSEC service.
[View full size image]

Figure 14.31. Assign your IP Security policy to the interface.

The Windows configuration example we provide uses 3DES symmetric block cipher because it is the best available choice in the default Windows IPSec implementation. If you want to go beyond the use of 3DES and employ more robust and secure ciphers, prepare to sacrifice some cash for higher-grade encryption commercial third-party software.
conn pingo-winda
left=192.168.77.6
leftnexthop=%direct
right=192.168.77.66
rightnexthop=%direct
esp=3des
ike=3des-sha
authby=secret
auto=start