IPsec requires a key exchange of a secret. This is mostly done automatically by so called IKE daemons. They also handle the authentication of the peers, either by a common known secret (so called "pre-shared secret") or by RSA keys (which can also be used from X.509 certificates).
Currently, two different IKE daemons are available for Linux, which totally differ in configuration and usage.
I prefer "pluto" from the *S/WAN implementation because of the easier and one-config-only setup.
19.3.1. IKE daemon "racoon"
The IKE daemon "racoon" is taken from the KAME project and ported to Linux. Modern Linux distributions contain this daemon in the package "ipsec-tools". Two executables are required for a proper IPsec setup. Take a look on Linux Advanced Routing & Traffic Control HOWTO / IPSEC, too.
19.3.1.1. Manipulation of the IPsec SA/SP database with the tool "setkey"
"setkey" is important to define the security policy (SP) for the kernel.
File: /etc/racoon/setkey.sh
Example for an end-to-end encrypted connection in transport mode
#!/sbin/setkey -f
flush;
spdflush;
spdadd 2001:db8:1:1::1 2001:db8:2:2::2 any -P out ipsec esp/transport//require;
spdadd 2001:db8:2:2::2 2001:db8:1:1::1 any -P in ipsec esp/transport//require;
Example for a end-to-end encrypted connection in tunnel mode
#!/sbin/setkey -f
flush;
spdflush;
spdadd 2001:db8:1:1::1 2001:db8:2:2::2 any -P out ipsec
� esp/tunnel/2001:db8:1:1::1-2001:db8:2:2::2/require;
spdadd 2001:db8:2:2::2 2001:db8:1:1::1 any -P in ipsec
� esp/tunnel/2001:db8:2:2::2-2001:db8:1:1::1/require;
For the other peer, you have to replace "in" with "out".
19.3.1.2. Configuration of the IKE daemon "racoon"
"racoon" requires a configuration file for proper execution. It includes the related settings to the security policy, which should be set up previously using "setkey".
File: /etc/racoon/racoon.conf
# Racoon IKE daemon configuration file.
# See 'man racoon.conf' for a description of the format and entries.
path include "/etc/racoon";
path pre_shared_key "/etc/racoon/psk.txt";
listen
{
isakmp 2001:db8:1:1::1;
}
remote 2001:db8:2:2::2
{
exchange_mode main;
lifetime time 24 hour;
proposal
{
encryption_algorithm 3des;
hash_algorithm md5;
authentication_method pre_shared_key;
dh_group 2;
}
}
# gateway-to-gateway
sainfo address 2001:db8:1:1::1 any address 2001:db8:2:2::2 any
{
lifetime time 1 hour;
encryption_algorithm 3des;
authentication_algorithm hmac_md5;
compression_algorithm deflate;
}
sainfo address 2001:db8:2:2::2 any address 2001:db8:1:1::1 any
{
lifetime time 1 hour;
encryption_algorithm 3des;
authentication_algorithm hmac_md5;
compression_algorithm deflate;
}
Also set up the pre-shared secret:
File: /etc/racoon/psk.txt
# file for pre-shared keys used for IKE authentication
# format is: 'identifier' 'key'
2001:db8:2:2::2 verysecret
19.3.1.3. Running IPsec with IKE daemon "racoon"
At least the daemon needs to be started. For the first time, use debug and foreground mode. The following example shows a successful IKE phase 1 (ISAKMP-SA) and 2 (IPsec-SA) negotiation:
# racoon -F -v -f /etc/racoon/racoon.conf
Foreground mode.
2005-01-01 20:30:15: INFO: @(#)ipsec-tools 0.3.3 (https://ipsec-tools.sourceforge.net)
2005-01-01 20:30:15: INFO: @(#)This product linked
� OpenSSL 0.9.7a Feb 19 2003 (https://www.openssl.org/)
2005-01-01 20:30:15: INFO: 2001:db8:1:1::1[500] used as isakmp port (fd=7)
2005-01-01 20:31:06: INFO: IPsec-SA request for 2001:db8:2:2::2
� queued due to no phase1 found.
2005-01-01 20:31:06: INFO: initiate new phase 1 negotiation:
� 2001:db8:1:1::1[500]<=>2001:db8:2:2::2[500]
2005-01-01 20:31:06: INFO: begin Identity Protection mode.
2005-01-01 20:31:09: INFO: ISAKMP-SA established
� 2001:db8:1:1::1[500]-2001:db8:2:2::2[500] spi:da3d3693289c9698:ac039a402b2db401
2005-01-01 20:31:09: INFO: initiate new phase 2 negotiation:
� 2001:6f8:900:94::2[0]<=>2001:db8:2:2::2[0]
2005-01-01 20:31:10: INFO: IPsec-SA established:
� ESP/Tunnel 2001:db8:2:2::2->2001:db8:1:1::1 spi=253935531(0xf22bfab)
2005-01-01 20:31:10: INFO: IPsec-SA established:
� ESP/Tunnel 2001:db8:1:1::1->2001:db8:2:2::2 spi=175002564(0xa6e53c4)
Each direction got its own IPsec-SA (like defined in the IPsec standard). With "tcpdump" on the related interface, you will see as result of an IPv6 ping:
The IKE daemon "pluto" is included in distributions of the *S/WAN projects. *S/WAN project starts at the beginning as FreeS/WAN. Unfortunately, the FreeS/WAN project stopped further development in 2004. Because of the slow pace of development in the past, two spin-offs started: strongSwan and Openswan. Today, readily installable packages are available for at least Openswan (included in Fedora Core 3).
A major difference to "racoon", only one configuration file is required. Also, an initscript exists for automatic setup after booting.
19.3.2.1. Configuration of the IKE daemon "pluto"
The configuration is very similar to the IPv4 one, only one important option is necessary.
File: /etc/ipsec.conf
# /etc/ipsec.conf - Openswan IPsec configuration file
#
# Manual: ipsec.conf.5
version 2.0 # conforms to second version of ipsec.conf specification
# basic configuration
config setup
# Debug-logging controls: "none" for (almost) none, "all" for lots.
# klipsdebug=none
# plutodebug="control parsing"
#Disable Opportunistic Encryption
include /etc/ipsec.d/examples/no_oe.conf
conn ipv6-p1-p2
connaddrfamily=ipv6 # Important for IPv6!
left=2001:db8:1:1::1
right=2001:db8:2:2::2
authby=secret
esp=aes128-sha1
ike=aes128-sha-modp1024
type=transport
#type=tunnel
compress=no
#compress=yes
auto=add
#auto=start
Don't forget to define the pre-shared secret here also.
If installation of Openswan was successfully, an initscript should exist for starting IPsec, simply run (on each peer):
# /etc/rc.d/init.d/ipsec start
Afterwards, start this connection on one peer. If you saw the line "IPsec SA established", all worked fine.
# ipsec auto --up ipv6-peer1-peer2
104 "ipv6-p1-p2" #1: STATE_MAIN_I1: initiate
106 "ipv6-p1-p2" #1: STATE_MAIN_I2: sent MI2, expecting MR2
108 "ipv6-p1-p2" #1: STATE_MAIN_I3: sent MI3, expecting MR3
004 "ipv6-p1-p2" #1: STATE_MAIN_I4: ISAKMP SA established
112 "ipv6-p1-p2" #2: STATE_QUICK_I1: initiate
004 "ipv6-p1-p2" #2: STATE_QUICK_I2: sent QI2,
� IPsec SA established {ESP=>0xa98b7710 <0xa51e1f22}
Because *S/WAN and setkey/racoon do use the same IPsec implementation in Linux 2.6.x kernel, "setkey" can be used here too to show current active parameters: