From 571025a6092e30d7839d9c78df9b8bf40084319b Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 8 Nov 2013 14:57:01 +0100 Subject: [PATCH] testing: Add ikev2/host2host-transport-nat scenario --- .../host2host-transport-nat/description.txt | 13 +++++++++ .../host2host-transport-nat/evaltest.dat | 12 ++++++++ .../hosts/alice/etc/ipsec.conf | 18 ++++++++++++ .../hosts/sun/etc/ipsec.conf | 18 ++++++++++++ .../hosts/sun/etc/iptables.rules | 28 +++++++++++++++++++ .../hosts/venus/etc/ipsec.conf | 18 ++++++++++++ .../host2host-transport-nat/posttest.dat | 6 ++++ .../ikev2/host2host-transport-nat/pretest.dat | 12 ++++++++ .../ikev2/host2host-transport-nat/test.conf | 21 ++++++++++++++ 9 files changed, 146 insertions(+) create mode 100644 testing/tests/ikev2/host2host-transport-nat/description.txt create mode 100644 testing/tests/ikev2/host2host-transport-nat/evaltest.dat create mode 100644 testing/tests/ikev2/host2host-transport-nat/hosts/alice/etc/ipsec.conf create mode 100644 testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/ipsec.conf create mode 100644 testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/iptables.rules create mode 100644 testing/tests/ikev2/host2host-transport-nat/hosts/venus/etc/ipsec.conf create mode 100644 testing/tests/ikev2/host2host-transport-nat/posttest.dat create mode 100644 testing/tests/ikev2/host2host-transport-nat/pretest.dat create mode 100644 testing/tests/ikev2/host2host-transport-nat/test.conf diff --git a/testing/tests/ikev2/host2host-transport-nat/description.txt b/testing/tests/ikev2/host2host-transport-nat/description.txt new file mode 100644 index 000000000..6f18a88cd --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/description.txt @@ -0,0 +1,13 @@ +An IPsec transport-mode connection between the natted host alice and gateway sun +is successfully set up. leftfirewall=yes automatically inserts iptables-based firewall +rules that let pass the decrypted IP packets. In order to test the host-to-host connection +alice pings sun.
+Note: This scenario also demonstrates two problems with transport-mode and NAT traversal: +
    +
  1. The client venus behind the same NAT as client alice is not able to ping sun +(even with ICMP explicitly allowed there) because the request arrives unencrypted and thus gets +dropped when the IPsec policies are consulted (increases the XfrmInTmplMismatch counter +in /proc/net/xfrm_stat).
  2. +
  3. A similar issue arises when venus also establishes an IPsec transport-mode connection to +sun, due to the conflicting IPsec policies sun declines such a connection.
  4. +
diff --git a/testing/tests/ikev2/host2host-transport-nat/evaltest.dat b/testing/tests/ikev2/host2host-transport-nat/evaltest.dat new file mode 100644 index 000000000..faa9fb265 --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/evaltest.dat @@ -0,0 +1,12 @@ +alice::ipsec status 2> /dev/null::nat-t.*ESTABLISHED.*alice@strongswan.org.*sun.strongswan.org::YES +sun:: ipsec status 2> /dev/null::nat-t.*ESTABLISHED.*sun.strongswan.org.*alice@strongswan.org::YES +alice::ipsec status 2> /dev/null::nat-t.*INSTALLED, TRANSPORT::YES +sun:: ipsec status 2> /dev/null::nat-t.*INSTALLED, TRANSPORT::YES +alice::ping -c 1 PH_IP_SUN::64 bytes from PH_IP_SUN: icmp_req=1::YES +venus::ping -c 1 -W 1 PH_IP_SUN::64 bytes from PH_IP_SUN: icmp_req=1::NO +venus::ipsec up nat-t::received TS_UNACCEPTABLE notify::YES +sun::cat /var/log/daemon.log::unable to install policy::YES +sun::tcpdump::IP moon.strongswan.org.* > sun.strongswan.org.*: UDP::YES +sun::tcpdump::IP sun.strongswan.org.* > moon.strongswan.org.*: UDP::YES +sun::tcpdump::IP moon.strongswan.org > sun.strongswan.org: ICMP echo request::YES +sun::tcpdump::IP sun.strongswan.org > moon.strongswan.org: ICMP echo reply::NO diff --git a/testing/tests/ikev2/host2host-transport-nat/hosts/alice/etc/ipsec.conf b/testing/tests/ikev2/host2host-transport-nat/hosts/alice/etc/ipsec.conf new file mode 100644 index 000000000..8679a23a4 --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/hosts/alice/etc/ipsec.conf @@ -0,0 +1,18 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + +conn nat-t + leftcert=aliceCert.pem + leftid=alice@strongswan.org + leftfirewall=yes + right=192.168.0.2 + rightid=@sun.strongswan.org + type=transport + auto=add diff --git a/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/ipsec.conf b/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/ipsec.conf new file mode 100644 index 000000000..11b0b2db9 --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/ipsec.conf @@ -0,0 +1,18 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + left=192.168.0.2 + leftcert=sunCert.pem + leftid=@sun.strongswan.org + leftfirewall=yes + +conn nat-t + right=%any + type=transport + auto=add diff --git a/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/iptables.rules b/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/iptables.rules new file mode 100644 index 000000000..0a2cd80b8 --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/hosts/sun/etc/iptables.rules @@ -0,0 +1,28 @@ +*filter + +# default policy is DROP +-P INPUT DROP +-P OUTPUT DROP +-P FORWARD DROP + +# allow IKE +-A INPUT -i eth0 -p udp --dport 500 -j ACCEPT +-A OUTPUT -o eth0 -p udp --sport 500 -j ACCEPT + +# allow MobIKE +-A INPUT -i eth0 -p udp --dport 4500 -j ACCEPT +-A OUTPUT -o eth0 -p udp --sport 4500 -j ACCEPT + +# allow ssh +-A INPUT -p tcp --dport 22 -j ACCEPT +-A OUTPUT -p tcp --sport 22 -j ACCEPT + +# allow crl fetch from winnetou +-A INPUT -i eth0 -p tcp --sport 80 -s PH_IP_WINNETOU -j ACCEPT +-A OUTPUT -o eth0 -p tcp --dport 80 -d PH_IP_WINNETOU -j ACCEPT + +# allow ICMP +-A INPUT -i eth0 -p icmp -j ACCEPT +-A OUTPUT -o eth0 -p icmp -j ACCEPT + +COMMIT diff --git a/testing/tests/ikev2/host2host-transport-nat/hosts/venus/etc/ipsec.conf b/testing/tests/ikev2/host2host-transport-nat/hosts/venus/etc/ipsec.conf new file mode 100644 index 000000000..b416b30b8 --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/hosts/venus/etc/ipsec.conf @@ -0,0 +1,18 @@ +# /etc/ipsec.conf - strongSwan IPsec configuration file + +config setup + +conn %default + ikelifetime=60m + keylife=20m + rekeymargin=3m + keyingtries=1 + +conn nat-t + leftcert=venusCert.pem + leftid=venus@strongswan.org + leftfirewall=yes + right=192.168.0.2 + rightid=@sun.strongswan.org + type=transport + auto=add diff --git a/testing/tests/ikev2/host2host-transport-nat/posttest.dat b/testing/tests/ikev2/host2host-transport-nat/posttest.dat new file mode 100644 index 000000000..80a3c7b7d --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/posttest.dat @@ -0,0 +1,6 @@ +alice::ipsec stop +venus::ipsec stop +sun::ipsec stop +alice::iptables-restore < /etc/iptables.flush +moon::iptables-restore < /etc/iptables.flush +sun::iptables-restore < /etc/iptables.flush diff --git a/testing/tests/ikev2/host2host-transport-nat/pretest.dat b/testing/tests/ikev2/host2host-transport-nat/pretest.dat new file mode 100644 index 000000000..fe0f17d3d --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/pretest.dat @@ -0,0 +1,12 @@ +alice::iptables-restore < /etc/iptables.rules +moon::iptables-restore < /etc/iptables.rules +sun::iptables-restore < /etc/iptables.rules +moon::iptables -t nat -A POSTROUTING -o eth0 -s 10.1.0.0/16 -j MASQUERADE +moon::iptables -A FORWARD -i eth1 -o eth0 -s 10.1.0.0/16 -j ACCEPT +moon::iptables -A FORWARD -i eth0 -o eth1 -d 10.1.0.0/16 -j ACCEPT +alice::ipsec start +venus::ipsec start +sun::ipsec start +alice::expect-connection nat-t +venus::expect-connection nat-t +alice::ipsec up nat-t diff --git a/testing/tests/ikev2/host2host-transport-nat/test.conf b/testing/tests/ikev2/host2host-transport-nat/test.conf new file mode 100644 index 000000000..8c2facefd --- /dev/null +++ b/testing/tests/ikev2/host2host-transport-nat/test.conf @@ -0,0 +1,21 @@ +#!/bin/bash +# +# This configuration file provides information on the +# guest instances used for this test + +# All guest instances that are required for this test +# +VIRTHOSTS="alice moon winnetou sun" + +# Corresponding block diagram +# +DIAGRAM="a-m-w-s-b.png" + +# Guest instances on which tcpdump is to be started +# +TCPDUMPHOSTS="sun alice venus moon" + +# Guest instances on which IPsec is started +# Used for IPsec logging purposes +# +IPSECHOSTS="alice venus sun"