1 AUTHOR: Dirk Kleinschmidt <dirk dot kleinschmidt at gmx dot net>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: Using IPsec under LFS
9 PRIMARY URI: http://www.vinf.de/dirk/
12 This hint describes step-by-step how to install the necessary tools for IPsec (secure IP connections) under LFS and creates a basic configuration file for a simple transport-mode IPsec connection using AH and ESP protocols between two computers.
15 To use this hit you will need a LFS system ready with kernel 2.6.10 and OpenSSL installed.
21 Before you start, make sure you have a running LFS and OpenSSL installed. If you need to install OpenSSL refer to the BLFS book. These installation instructions (especially configuring ipsec) are based on the official IPsec Howto for Linux.
23 1. Reconfiguring the kernel
24 Get the latest linux kernel source archive from www.kernel.org and unpack it in /usr/src
26 $> wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.11.7.tar.bz2 &&
27 $> tar xfj linux-2.6.11.7.tar.bz2
29 Copy your current kernel configuration to /usr/src/linux-2.6.11.7 and reconfigure existing features
30 $> cd /usr/src/linux-2.6.11.7 &&
31 $> cp /boot/config-2.6.11.2 .config &&
34 Now customize the kernel features for IPsec support. Make sure you have selected the following features
37 Networking support (NET) [Y/n/?] y
41 PF_KEY sockets (NET_KEY) [Y/n/m/?] y
42 IP: AH transformation (INET_AH) [Y/n/m/?] y
43 IP: ESP transformation (INET_ESP) [Y/n/m/?] y
44 IP: IPsec user configuration interface (XFRM_USER) [Y/n/m/?] y
46 Cryptographic API (CRYPTO) [Y/n/?] y
47 HMAC support (CRYPTO_HMAC) [Y/n/?] y
48 Null algorithms (CRYPTO_NULL) [Y/n/m/?] y
49 MD5 digest algorithm (CRYPTO_MD5) [Y/n/m/?] y
50 SHA1 digest algorithm (CRYPTO_SHA1) [Y/n/m/?] y
51 DES and Triple DES EDE cipher algorithms (CRYPTO_DES) [Y/n/m/?] y
52 AES cipher algorithms (CRYPTO_AES) [Y/n/m/?] y
54 Compile and install your configured kernel. Reboot after changing your grub config to boot the new kernel.
56 $> make modules_install &&
57 $> cp .config /boot/config-2.6.11.7 &&
58 $> cp arch/i386/boot/bzImage /boot/linux-2.6.11.7 &&
59 $> cp System.map /boot/System.map-2.6.11.7 &&
60 $> vi /boot/grub/menu.lst &&
63 2. Install ipsec-tools
64 download the lastest ipsec-tools source tarball from ipsec-tools.sourceforge.net and unpack it in /usr/src
66 $> wget http://switch.dl.sourceforge.net/sourceforge/ipsec-tools/ipsec-tools-0.5.1.tar.bz2 &&
67 $> tar xfj ipsec-tools-0.5.1.tar.bz2
69 Configure, make and install the ipsec-tools. The ipsec-tools require some kernel headers installed. The LFS book installs them in /usr/include
70 $> cd /usr/src/ipsec-tools-0.5.1 &&
71 $> ./configure --prefix=/usr --with-kernel-headers=/usr/include &&
75 3. Configure ipsec-tools
76 You will need two different configrations, one for each host because IPsec works unidirectional. The example below is using the IPsec ah and esp protocol in transport mode. To be able to reconfigure ipsec quickly after rebooting the rules will be stored in /etc/setkey.conf.
77 $> cat > /etc/setkey.conf << "EOF"
78 $> # Begin 192.168.2.31's setkey.conf
84 $> add 192.168.2.31 192.168.2.32 ah 0x200 -A hmac-md5 0xc0291ff014dccdd03874d9e8e4cdf3e6;
85 $> add 192.168.2.32 192.168.2.31 ah 0x300 -A hmac-md5 0x96358c90783bbfa3d7b196ceabe0536b;
87 $> # ESP SAs using 192 bit long keys (168 + 24 parity)
88 $> add 192.168.2.31 192.168.2.32 esp 0x201 -E 3des-cbc 0x7aeaca3f87d060a12f4a4487d5a5c3355920fae69a96c831;
89 $> add 192.168.2.32 192.168.2.31 esp 0x301 -E 3des-cbc 0xf6ddb555acfd9d77b03ea3843f2653255afe8eb5573965df;
91 $> # Security policies
92 $> spdadd 192.168.2.31 192.168.2.32 any -P out ipsec esp/transport//require ah/transport//require;
93 $> spdadd 192.168.2.32 192.168.2.31 any -P in ipsec esp/transport//require ah/transport//require;
97 $> cat > /etc/setkey.conf << "EOF"
98 $> # Begin 192.168.2.32's setkey.conf
104 $> add 192.168.2.31 192.168.2.32 ah 0x200 -A hmac-md5 0xc0291ff014dccdd03874d9e8e4cdf3e6;
105 $> add 192.168.2.32 192.168.2.31 ah 0x300 -A hmac-md5 0x96358c90783bbfa3d7b196ceabe0536b;
107 $> # ESP SAs using 192 bit long keys (168 + 24 parity)
108 $> add 192.168.2.31 192.168.2.32 esp 0x201 -E 3des-cbc 0x7aeaca3f87d060a12f4a4487d5a5c3355920fae69a96c831;
109 $> add 192.168.2.32 192.168.2.31 esp 0x301 -E 3des-cbc 0xf6ddb555acfd9d77b03ea3843f2653255afe8eb5573965df;
111 $> # Security policies
112 $> spdadd 192.168.2.31 192.168.2.32 any -P in ipsec esp/transport//require ah/transport//require;
113 $> spdadd 192.168.2.32 192.168.2.31 any -P out ipsec esp/transport//require ah/transport//require;
117 Now load your security association and security policy settings into the kernel:
118 $> setkey -f /etc/setkey.conf
120 To create your own secret keys use
121 $> dd if=/dev/random count=16 bs=1| xxd -ps
122 for the md5-hmac key and/or for the 3des keys. Insert your keys in the right position of setkey.conf pairs.
123 $> dd if=/dev/random count=24 bs=1| xxd -ps
125 They generate a random value with each call that may be used with ipsec.
128 You should create some kind of script that loads the contents of setkey.conf into the kernel during each boot. Otherwise the IP traffic will NOT be encrypted/signed after a reboot until a manual load. To check whether your setup works use some tool like tcpdump.