40da137cbd2d38ae31474384a3456830c17335ff
[vpp.git] / docs / usecases / vpp_init_sswan_resp.md
1 VPP as IKEv2 initiator and strongSwan as responder
2 ==================================================
3
4 Prerequisites
5 -------------
6
7 To make the examples easier to configure ``docker`` it is required to pull strongSwan docker image. The networking is done using Linux' veth interfaces and namespaces.
8
9 Setup
10 -----
11
12 First a topology:
13
14 ```
15 192.168.3.2                      192.168.5.2
16      +                           loopback
17      |                                 +
18 +----+----+ 192.168.10.2         +-----+----+
19 |  VPP    |                      |strongSwan|
20 |initiator+----------------------+responder |
21 +---------+                      +----------+
22                      192.168.10.1
23 ```
24
25 Create veth interfaces and namespaces and configure them:
26
27 ```
28 sudo ip link add gw type veth peer name swanif
29 sudo ip link set dev gw up
30
31 sudo ip netns add ns
32 sudo ip link add veth_priv type veth peer name priv
33 sudo ip link set dev priv up
34 sudo ip link set dev veth_priv up netns ns
35
36 sudo ip netns exec ns \
37   bash -c "
38     ip link set dev lo up
39     ip addr add 192.168.3.2/24 dev veth_priv
40     ip route add 192.168.5.0/24 via 192.168.3.1"
41 ```
42
43
44 Create directory with strongswan configs that will be mounted to the docker container
45 ```
46 mkdir /tmp/sswan
47 ```
48
49 Create the ``ipsec.conf`` file in the ``/tmp/sswan`` directory with following content:
50
51 ```
52 config setup
53   strictcrlpolicy=no
54
55 conn initiator
56   mobike=no
57   auto=add
58   type=tunnel
59   keyexchange=ikev2
60   ike=aes256gcm16-prfsha256-modp2048!
61   esp=aes256gcm16-esn!
62
63 # local:
64   leftauth=psk
65   leftid=@sswan.vpn.example.com
66   leftsubnet=192.168.5.0/24
67
68 # remote: (gateway)
69   rightid=@roadwarrior.vpp
70   right=192.168.10.2
71   rightauth=psk
72   rightsubnet=192.168.3.0/24
73 ```
74
75 ``/tmp/sswan/ipsec.secrets``
76 ```
77 : PSK 'Vpp123'
78 ```
79
80 ``/tmp/sswan/strongswan.conf``
81 ```
82 charon {
83   load_modular = yes
84   plugins {
85     include strongswan.d/charon/*.conf
86   }
87   filelog {
88     /tmp/charon.log {
89       time_format = %b %e %T
90       ike_name = yes
91       append = no
92       default = 2
93       flush_line = yes
94     }
95   }
96 }
97 include strongswan.d/*.conf
98 ```
99
100 Start docker container with strongSwan:
101
102 ```
103  docker run --name sswan -d --privileged --rm --net=none \
104   -v /tmp/sswan:/conf -v /tmp/sswan:/etc/ipsec.d philplckthun/strongswan
105 ```
106
107 Finish configuration of initiator's private network:
108
109 ```
110 pid=$(docker inspect --format "{{.State.Pid}}" sswan)
111 sudo ip link set netns $pid dev swanif
112
113 sudo nsenter -t $pid -n ip addr add 192.168.10.1/24 dev swanif
114 sudo nsenter -t $pid -n ip link set dev swanif up
115
116 sudo nsenter -t $pid -n ip addr add 192.168.5.2/32 dev lo
117 sudo nsenter -t $pid -n ip link set dev lo up
118 ```
119
120 Start VPP ...
121
122 ```
123 sudo /usr/bin/vpp unix { \
124       cli-listen /tmp/vpp.sock \
125       gid $(id -g) } \
126       api-segment { prefix vpp } \
127       plugins { plugin dpdk_plugin.so { disable } }
128 ```
129
130 ... and configure it:
131
132 ```
133 create host-interface name gw
134 set interface ip addr host-gw 192.168.10.2/24
135 set interface state host-gw up
136
137 create host-interface name priv
138 set interface ip addr host-priv 192.168.3.1/24
139 set interface state host-priv up
140
141 ikev2 profile add pr1
142 ikev2 profile set pr1 auth shared-key-mic string Vpp123
143 ikev2 profile set pr1 id local fqdn roadwarrior.vpp
144 ikev2 profile set pr1 id remote fqdn sswan.vpn.example.com
145
146 ikev2 profile set pr1 traffic-selector local ip-range 192.168.3.0 - 192.168.3.255 port-range 0 - 65535 protocol 0
147 ikev2 profile set pr1 traffic-selector remote ip-range 192.168.5.0 - 192.168.5.255 port-range 0 - 65535 protocol 0
148
149 ikev2 profile set pr1 responder host-gw 192.168.10.1
150 ikev2 profile set pr1 ike-crypto-alg aes-gcm-16 256 ike-dh modp-2048
151 ikev2 profile set pr1 esp-crypto-alg aes-gcm-16 256
152
153 create ipip tunnel src 192.168.10.2 dst 192.168.10.1
154 ikev2 profile set pr1 tunnel ipip0
155 ip route add 192.168.5.0/24 via 192.168.10.1 ipip0
156 set interface unnumbered ipip0 use host-gw
157 ```
158
159 Initiate the IKEv2 connection:
160
161 ```
162 vpp# ikev2 initiate sa-init pr1
163 ```
164
165 ```
166 vpp# show ikev2 sa details
167  iip 192.168.10.2 ispi f717b0cbd17e27c3 rip 192.168.10.1 rspi e9b7af7fc9b13361
168  encr:aes-gcm-16 prf:hmac-sha2-256  dh-group:modp-2048
169  nonce i:eb0354613b268c6372061bbdaab13deca37c8a625b1f65c073d25df2ecfe672e
170        r:70e1248ac09943047064f6a2135fa2a424778ba03038ab9c4c2af8aba179ed84
171  SK_d    96bd4feb59be2edf1930a12a3a5d22e30195ee9f56ea203c5fb6cba5dd2bb80f
172  SK_e  i:00000000: 5b75b9d808c8467fd00a0923c06efee2a4eb1d033c57532e05f9316ed9c56fe9
173          00000020: c4db9114
174        r:00000000: 95121b63372d20b83558dc3e209b9affef042816cf071c86a53543677b40c15b
175          00000020: f169ab67
176  SK_p  i:fb40d1114c347ddc3228ba004d4759d58f9c1ae6f1746833f908d39444ef92b1
177        r:aa049828240cb242e1d5aa625cd5914dc8f8e980a74de8e06883623d19384902
178  identifier (i) id-type fqdn data roadwarrior.vpp
179  identifier (r) id-type fqdn data sswan.vpn.example.com
180    child sa 0:encr:aes-gcm-16  esn:yes
181     spi(i) 9dffd57a spi(r) c4e0ef53
182     SK_e  i:290c681694f130b33d511335dd257e78721635b7e8aa87930dd77bb1d6dd3f42
183           r:0a09fa18cf1cf65c6324df02b46dcc998b84e5397cf911b63e0c096053946c2e
184     traffic selectors (i):0 type 7 protocol_id 0 addr 192.168.3.0 - 192.168.3.255 port 0 - 65535
185     traffic selectors (r):0 type 7 protocol_id 0 addr 192.168.5.0 - 192.168.5.255 port 0 - 65535
186 ```
187
188 Now we can generate some traffic between responder's and initiator's private networks and see it works.
189
190 ```
191 $ sudo ip netns exec ns ping 192.168.5.2
192 PING 192.168.5.2 (192.168.5.2) 56(84) bytes of data.
193 64 bytes from 192.168.5.2: icmp_seq=1 ttl=63 time=0.450 ms
194 64 bytes from 192.168.5.2: icmp_seq=2 ttl=63 time=0.630 ms
195 ```