blob: 82346d64708af2c7e4f276f1287c7e2a57b220af [file] [log] [blame]
“mystarrocks”23f0c452017-12-11 07:11:51 -08001import socket
Klement Sekera28fb03f2018-04-17 11:36:55 +02002import unittest
Klement Sekera31da2e32018-06-24 22:49:55 +02003from scapy.layers.ipsec import ESP
Neale Ranns53f526b2019-02-25 14:32:02 +00004from scapy.layers.inet import UDP
“mystarrocks”23f0c452017-12-11 07:11:51 -08005
Neale Ranns00625a62019-07-31 00:13:18 -07006from parameterized import parameterized
juraj.linkes11057662019-07-08 10:22:55 +02007from framework import VppTestRunner
Neale Ranns53f526b2019-02-25 14:32:02 +00008from template_ipsec import IpsecTra46Tests, IpsecTun46Tests, TemplateIpsec, \
Neale Ranns4f33c802019-04-10 12:39:10 +00009 IpsecTcpTests, IpsecTun4Tests, IpsecTra4Tests, config_tra_params, \
Neale Ranns12989b52019-09-26 16:20:19 +000010 config_tun_params, IPsecIPv4Params, IPsecIPv6Params, \
Neale Ranns4a56f4e2019-12-23 04:10:25 +000011 IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6, \
12 IpsecTun6HandoffTests, IpsecTun4HandoffTests
Klement Sekerabf613952019-01-29 11:38:08 +010013from vpp_ipsec import VppIpsecSpd, VppIpsecSpdEntry, VppIpsecSA,\
Neale Ranns4f33c802019-04-10 12:39:10 +000014 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080015from vpp_ip_route import VppIpRoute, VppRoutePath
16from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080017from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080018
Neale Rannsc87b66c2019-02-07 07:26:12 -080019NUM_PKTS = 67
20
“mystarrocks”23f0c452017-12-11 07:11:51 -080021
Neale Ranns4f33c802019-04-10 12:39:10 +000022class ConfigIpsecESP(TemplateIpsec):
23 encryption_type = ESP
24 tra4_encrypt_node_name = "esp4-encrypt"
25 tra4_decrypt_node_name = "esp4-decrypt"
26 tra6_encrypt_node_name = "esp6-encrypt"
27 tra6_decrypt_node_name = "esp6-decrypt"
28 tun4_encrypt_node_name = "esp4-encrypt"
29 tun4_decrypt_node_name = "esp4-decrypt"
30 tun6_encrypt_node_name = "esp6-encrypt"
31 tun6_decrypt_node_name = "esp6-decrypt"
Neale Ranns53f526b2019-02-25 14:32:02 +000032
Neale Ranns4f33c802019-04-10 12:39:10 +000033 @classmethod
34 def setUpClass(cls):
35 super(ConfigIpsecESP, cls).setUpClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000036
Neale Ranns4f33c802019-04-10 12:39:10 +000037 @classmethod
38 def tearDownClass(cls):
39 super(ConfigIpsecESP, cls).tearDownClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000040
Neale Ranns4f33c802019-04-10 12:39:10 +000041 def setUp(self):
42 super(ConfigIpsecESP, self).setUp()
Neale Ranns53f526b2019-02-25 14:32:02 +000043
Neale Ranns4f33c802019-04-10 12:39:10 +000044 def tearDown(self):
45 super(ConfigIpsecESP, self).tearDown()
46
47 def config_network(self, params):
48 self.net_objs = []
49 self.tun_if = self.pg0
50 self.tra_if = self.pg2
51 self.logger.info(self.vapi.ppcli("show int addr"))
52
53 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
54 self.tra_spd.add_vpp_config()
55 self.net_objs.append(self.tra_spd)
56 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
57 self.tun_spd.add_vpp_config()
58 self.net_objs.append(self.tun_spd)
59
60 b = VppIpsecSpdItfBinding(self, self.tun_spd,
61 self.tun_if)
62 b.add_vpp_config()
63 self.net_objs.append(b)
64
65 b = VppIpsecSpdItfBinding(self, self.tra_spd,
66 self.tra_if)
67 b.add_vpp_config()
68 self.net_objs.append(b)
69
70 for p in params:
71 self.config_esp_tra(p)
72 config_tra_params(p, self.encryption_type)
73 for p in params:
74 self.config_esp_tun(p)
Neale Ranns12989b52019-09-26 16:20:19 +000075 config_tun_params(p, self.encryption_type, self.tun_if)
Neale Ranns4f33c802019-04-10 12:39:10 +000076
77 for p in params:
78 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
79 r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
80 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
81 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -070082 proto=d)])
Neale Ranns4f33c802019-04-10 12:39:10 +000083 r.add_vpp_config()
84 self.net_objs.append(r)
85
86 self.logger.info(self.vapi.ppcli("show ipsec all"))
87
88 def unconfig_network(self):
89 for o in reversed(self.net_objs):
90 o.remove_vpp_config()
91 self.net_objs = []
92
93 def config_esp_tun(self, params):
94 addr_type = params.addr_type
95 scapy_tun_sa_id = params.scapy_tun_sa_id
96 scapy_tun_spi = params.scapy_tun_spi
97 vpp_tun_sa_id = params.vpp_tun_sa_id
98 vpp_tun_spi = params.vpp_tun_spi
99 auth_algo_vpp_id = params.auth_algo_vpp_id
100 auth_key = params.auth_key
101 crypt_algo_vpp_id = params.crypt_algo_vpp_id
102 crypt_key = params.crypt_key
103 remote_tun_if_host = params.remote_tun_if_host
104 addr_any = params.addr_any
105 addr_bcast = params.addr_bcast
106 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns49e7ef62019-04-10 17:24:29 +0000107 flags = params.flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000108 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000109 objs = []
110
111 params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
112 auth_algo_vpp_id, auth_key,
113 crypt_algo_vpp_id, crypt_key,
114 self.vpp_esp_protocol,
115 self.tun_if.local_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000116 self.tun_if.remote_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000117 flags=flags,
118 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000119 params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
120 auth_algo_vpp_id, auth_key,
121 crypt_algo_vpp_id, crypt_key,
122 self.vpp_esp_protocol,
123 self.tun_if.remote_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000124 self.tun_if.local_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000125 flags=flags,
126 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000127 objs.append(params.tun_sa_in)
128 objs.append(params.tun_sa_out)
129
130 params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd,
131 scapy_tun_sa_id,
132 addr_any, addr_bcast,
133 addr_any, addr_bcast,
134 socket.IPPROTO_ESP)
135 params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd,
136 scapy_tun_sa_id,
137 addr_any, addr_bcast,
138 addr_any, addr_bcast,
139 socket.IPPROTO_ESP,
140 is_outbound=0)
141 objs.append(params.spd_policy_out_any)
142 objs.append(params.spd_policy_in_any)
143
144 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
145 remote_tun_if_host, remote_tun_if_host,
146 self.pg1.remote_addr[addr_type],
147 self.pg1.remote_addr[addr_type],
148 0,
149 priority=10,
150 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
151 is_outbound=0))
152 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
153 self.pg1.remote_addr[addr_type],
154 self.pg1.remote_addr[addr_type],
155 remote_tun_if_host, remote_tun_if_host,
156 0,
157 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
158 priority=10))
159 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
160 remote_tun_if_host, remote_tun_if_host,
161 self.pg0.local_addr[addr_type],
162 self.pg0.local_addr[addr_type],
163 0,
164 priority=20,
165 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
166 is_outbound=0))
167 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
168 self.pg0.local_addr[addr_type],
169 self.pg0.local_addr[addr_type],
170 remote_tun_if_host, remote_tun_if_host,
171 0,
172 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
173 priority=20))
174 for o in objs:
175 o.add_vpp_config()
176 self.net_objs = self.net_objs + objs
177
178 def config_esp_tra(self, params):
179 addr_type = params.addr_type
180 scapy_tra_sa_id = params.scapy_tra_sa_id
181 scapy_tra_spi = params.scapy_tra_spi
182 vpp_tra_sa_id = params.vpp_tra_sa_id
183 vpp_tra_spi = params.vpp_tra_spi
184 auth_algo_vpp_id = params.auth_algo_vpp_id
185 auth_key = params.auth_key
186 crypt_algo_vpp_id = params.crypt_algo_vpp_id
187 crypt_key = params.crypt_key
188 addr_any = params.addr_any
189 addr_bcast = params.addr_bcast
190 flags = (VppEnum.vl_api_ipsec_sad_flags_t.
191 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
192 e = VppEnum.vl_api_ipsec_spd_action_t
193 flags = params.flags | flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000194 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000195 objs = []
196
197 params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
198 auth_algo_vpp_id, auth_key,
199 crypt_algo_vpp_id, crypt_key,
200 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000201 flags=flags,
202 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000203 params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
204 auth_algo_vpp_id, auth_key,
205 crypt_algo_vpp_id, crypt_key,
206 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000207 flags=flags,
208 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000209 objs.append(params.tra_sa_in)
210 objs.append(params.tra_sa_out)
211
212 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
213 addr_any, addr_bcast,
214 addr_any, addr_bcast,
215 socket.IPPROTO_ESP))
216 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
217 addr_any, addr_bcast,
218 addr_any, addr_bcast,
219 socket.IPPROTO_ESP,
220 is_outbound=0))
221 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
222 self.tra_if.local_addr[addr_type],
223 self.tra_if.local_addr[addr_type],
224 self.tra_if.remote_addr[addr_type],
225 self.tra_if.remote_addr[addr_type],
226 0, priority=10,
227 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
228 is_outbound=0))
229 objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
230 self.tra_if.local_addr[addr_type],
231 self.tra_if.local_addr[addr_type],
232 self.tra_if.remote_addr[addr_type],
233 self.tra_if.remote_addr[addr_type],
234 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
235 priority=10))
236 for o in objs:
237 o.add_vpp_config()
238 self.net_objs = self.net_objs + objs
Neale Ranns53f526b2019-02-25 14:32:02 +0000239
240
Neale Ranns4f33c802019-04-10 12:39:10 +0000241class TemplateIpsecEsp(ConfigIpsecESP):
“mystarrocks”23f0c452017-12-11 07:11:51 -0800242 """
243 Basic test for ipsec esp sanity - tunnel and transport modes.
244
245 Below 4 cases are covered as part of this test
246 1) ipsec esp v4 transport basic test - IPv4 Transport mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700247 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800248 2) ipsec esp v4 transport burst test
249 Above test for 257 pkts
250 3) ipsec esp 4o4 tunnel basic test - IPv4 Tunnel mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700251 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800252 4) ipsec esp 4o4 tunnel burst test
253 Above test for 257 pkts
254
255 TRANSPORT MODE:
256
257 --- encrypt ---
258 |pg2| <-------> |VPP|
259 --- decrypt ---
260
261 TUNNEL MODE:
262
263 --- encrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200264 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800265 --- --- ---
266
267 --- decrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200268 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800269 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -0800270 """
271
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700272 @classmethod
273 def setUpClass(cls):
274 super(TemplateIpsecEsp, cls).setUpClass()
275
276 @classmethod
277 def tearDownClass(cls):
278 super(TemplateIpsecEsp, cls).tearDownClass()
279
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800280 def setUp(self):
281 super(TemplateIpsecEsp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000282 self.config_network(self.params.values())
Klement Sekera611864f2018-09-26 11:19:00 +0200283
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800284 def tearDown(self):
Neale Ranns4f33c802019-04-10 12:39:10 +0000285 self.unconfig_network()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800286 super(TemplateIpsecEsp, self).tearDown()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800287
Klement Sekera611864f2018-09-26 11:19:00 +0200288
Neale Ranns53f526b2019-02-25 14:32:02 +0000289class TestIpsecEsp1(TemplateIpsecEsp, IpsecTra46Tests, IpsecTun46Tests):
Klement Sekera31da2e32018-06-24 22:49:55 +0200290 """ Ipsec ESP - TUN & TRA tests """
Neale Ranns4f33c802019-04-10 12:39:10 +0000291 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800292
“mystarrocks”23f0c452017-12-11 07:11:51 -0800293
Klement Sekera31da2e32018-06-24 22:49:55 +0200294class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests):
295 """ Ipsec ESP - TCP tests """
296 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800297
298
Neale Ranns4a56f4e2019-12-23 04:10:25 +0000299class TestIpsecEspHandoff(TemplateIpsecEsp,
300 IpsecTun6HandoffTests,
301 IpsecTun4HandoffTests):
302 """ Ipsec ESP - handoff tests """
303 pass
304
305
Neale Ranns4f33c802019-04-10 12:39:10 +0000306class TemplateIpsecEspUdp(ConfigIpsecESP):
Neale Ranns53f526b2019-02-25 14:32:02 +0000307 """
308 UDP encapped ESP
309 """
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700310
311 @classmethod
312 def setUpClass(cls):
313 super(TemplateIpsecEspUdp, cls).setUpClass()
314
315 @classmethod
316 def tearDownClass(cls):
317 super(TemplateIpsecEspUdp, cls).tearDownClass()
318
Neale Ranns53f526b2019-02-25 14:32:02 +0000319 def setUp(self):
320 super(TemplateIpsecEspUdp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000321 self.net_objs = []
Neale Ranns53f526b2019-02-25 14:32:02 +0000322 self.tun_if = self.pg0
323 self.tra_if = self.pg2
324 self.logger.info(self.vapi.ppcli("show int addr"))
325
326 p = self.ipv4_params
327 p.flags = (VppEnum.vl_api_ipsec_sad_flags_t.
328 IPSEC_API_SAD_FLAG_UDP_ENCAP)
329 p.nat_header = UDP(sport=5454, dport=4500)
330
331 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
332 self.tra_spd.add_vpp_config()
333 VppIpsecSpdItfBinding(self, self.tra_spd,
334 self.tra_if).add_vpp_config()
335
Neale Ranns4f33c802019-04-10 12:39:10 +0000336 self.config_esp_tra(p)
Neale Ranns2ac885c2019-03-20 18:24:43 +0000337 config_tra_params(p, self.encryption_type)
Neale Ranns53f526b2019-02-25 14:32:02 +0000338
339 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
340 self.tun_spd.add_vpp_config()
341 VppIpsecSpdItfBinding(self, self.tun_spd,
342 self.tun_if).add_vpp_config()
343
Neale Ranns4f33c802019-04-10 12:39:10 +0000344 self.config_esp_tun(p)
Neale Ranns92e93842019-04-08 07:36:50 +0000345 self.logger.info(self.vapi.ppcli("show ipsec all"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000346
347 d = DpoProto.DPO_PROTO_IP4
348 VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
349 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
350 0xffffffff,
351 proto=d)]).add_vpp_config()
352
353 def tearDown(self):
354 super(TemplateIpsecEspUdp, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700355
356 def show_commands_at_teardown(self):
357 self.logger.info(self.vapi.cli("show hardware"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000358
359
Neale Ranns49e7ef62019-04-10 17:24:29 +0000360class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests):
Neale Ranns53f526b2019-02-25 14:32:02 +0000361 """ Ipsec NAT-T ESP UDP tests """
Neale Ranns53f526b2019-02-25 14:32:02 +0000362 pass
363
364
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000365class MyParameters():
366 def __init__(self):
367 self.engines = ["ia32", "ipsecmb", "openssl"]
368 flag_esn = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN
369 self.flags = [0, flag_esn]
Neale Ranns4f33c802019-04-10 12:39:10 +0000370 # foreach crypto algorithm
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000371 self.algos = {
372 'AES-GCM-128/NONE': {
373 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000374 IPSEC_API_CRYPTO_ALG_AES_GCM_128),
375 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
376 IPSEC_API_INTEG_ALG_NONE),
377 'scapy-crypto': "AES-GCM",
378 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200379 'key': b"JPjyOWBeVEQiMe7h",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000380 'salt': 0},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000381 'AES-GCM-192/NONE': {
382 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns80f6fd52019-04-16 02:41:34 +0000383 IPSEC_API_CRYPTO_ALG_AES_GCM_192),
384 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
385 IPSEC_API_INTEG_ALG_NONE),
386 'scapy-crypto': "AES-GCM",
387 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200388 'key': b"JPjyOWBeVEQiMe7h01234567",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000389 'salt': 1010},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000390 'AES-GCM-256/NONE': {
391 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000392 IPSEC_API_CRYPTO_ALG_AES_GCM_256),
393 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
394 IPSEC_API_INTEG_ALG_NONE),
395 'scapy-crypto': "AES-GCM",
396 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200397 'key': b"JPjyOWBeVEQiMe7h0123456787654321",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000398 'salt': 2020},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000399 'AES-CBC-128/MD5-96': {
400 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000401 IPSEC_API_CRYPTO_ALG_AES_CBC_128),
402 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400403 IPSEC_API_INTEG_ALG_MD5_96),
Neale Ranns47feb112019-04-11 15:14:07 +0000404 'scapy-crypto': "AES-CBC",
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400405 'scapy-integ': "HMAC-MD5-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000406 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200407 'key': b"JPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000408 'AES-CBC-192/SHA1-96': {
409 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000410 IPSEC_API_CRYPTO_ALG_AES_CBC_192),
411 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
412 IPSEC_API_INTEG_ALG_SHA1_96),
413 'scapy-crypto': "AES-CBC",
414 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000415 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200416 'key': b"JPjyOWBeVEQiMe7hJPjyOWBe"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000417 'AES-CBC-256/SHA1-96': {
418 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000419 IPSEC_API_CRYPTO_ALG_AES_CBC_256),
420 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
421 IPSEC_API_INTEG_ALG_SHA1_96),
422 'scapy-crypto': "AES-CBC",
423 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000424 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200425 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000426 '3DES-CBC/SHA1-96': {
427 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Vladimir Ratnikovf4805072019-05-17 09:17:59 -0400428 IPSEC_API_CRYPTO_ALG_3DES_CBC),
429 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
430 IPSEC_API_INTEG_ALG_SHA1_96),
431 'scapy-crypto': "3DES",
432 'scapy-integ': "HMAC-SHA1-96",
433 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200434 'key': b"JPjyOWBeVEQiMe7h00112233"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000435 'NONE/SHA1-96': {
436 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000437 IPSEC_API_CRYPTO_ALG_NONE),
438 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
439 IPSEC_API_INTEG_ALG_SHA1_96),
440 'scapy-crypto': "NULL",
441 'scapy-integ': "HMAC-SHA1-96",
442 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200443 'key': b"JPjyOWBeVEQiMe7h00112233"}}
Neale Ranns4f33c802019-04-10 12:39:10 +0000444
Neale Ranns4f33c802019-04-10 12:39:10 +0000445
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000446class RunTestIpsecEspAll(ConfigIpsecESP,
447 IpsecTra4, IpsecTra6,
448 IpsecTun4, IpsecTun6):
449 """ Ipsec ESP all Algos """
450
451 def setUp(self):
452 super(RunTestIpsecEspAll, self).setUp()
453 test_args = str.split(self.__doc__, " ")
454
455 params = MyParameters()
456 self.engine = test_args[0]
457 self.flag = params.flags[0]
458 if test_args[1] == 'ESN':
459 self.flag = params.flags[1]
460
461 self.algo = params.algos[test_args[2]]
462
463 def tearDown(self):
464 super(RunTestIpsecEspAll, self).tearDown()
465
466 def run_test(self):
467 self.run_a_test(self.engine, self.flag, self.algo)
468
469 def run_a_test(self, engine, flag, algo):
Neale Ranns00625a62019-07-31 00:13:18 -0700470 self.vapi.cli("set crypto handler all %s" % engine)
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000471
472 self.ipv4_params = IPsecIPv4Params()
473 self.ipv6_params = IPsecIPv6Params()
474
475 self.params = {self.ipv4_params.addr_type:
476 self.ipv4_params,
477 self.ipv6_params.addr_type:
478 self.ipv6_params}
479
480 for _, p in self.params.items():
481 p.auth_algo_vpp_id = algo['vpp-integ']
482 p.crypt_algo_vpp_id = algo['vpp-crypto']
483 p.crypt_algo = algo['scapy-crypto']
484 p.auth_algo = algo['scapy-integ']
485 p.crypt_key = algo['key']
486 p.salt = algo['salt']
487 p.flags = p.flags | flag
488
489 self.reporter.send_keep_alive(self)
490
Neale Ranns4f33c802019-04-10 12:39:10 +0000491 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000492 # configure the SPDs. SAs, etc
Neale Ranns4f33c802019-04-10 12:39:10 +0000493 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000494 self.config_network(self.params.values())
Neale Ranns4f33c802019-04-10 12:39:10 +0000495
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000496 #
497 # run some traffic.
498 # An exhautsive 4o6, 6o4 is not necessary
499 # for each algo
500 #
501 self.verify_tra_basic6(count=NUM_PKTS)
502 self.verify_tra_basic4(count=NUM_PKTS)
503 self.verify_tun_66(self.params[socket.AF_INET6],
504 count=NUM_PKTS)
505 self.verify_tun_44(self.params[socket.AF_INET],
506 count=NUM_PKTS)
Neale Ranns4f33c802019-04-10 12:39:10 +0000507
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000508 #
509 # remove the SPDs, SAs, etc
510 #
511 self.unconfig_network()
Neale Ranns4f33c802019-04-10 12:39:10 +0000512
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000513 #
514 # reconfigure the network and SA to run the
515 # anti replay tests
516 #
517 self.config_network(self.params.values())
518 self.verify_tra_anti_replay()
519 self.unconfig_network()
juraj.linkes11057662019-07-08 10:22:55 +0200520
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000521#
522# To generate test classes, do:
523# grep '# GEN' test_ipsec_esp.py | sed -e 's/# GEN //g' | bash
524#
525# GEN for ENG in ia32 ipsecmb openssl; do \
526# GEN for FLG in noESN ESN; do for ALG in AES-GCM-128/NONE \
527# GEN AES-GCM-192/NONE AES-GCM-256/NONE AES-CBC-128/MD5-96 \
528# GEN AES-CBC-192/SHA1-96 AES-CBC-256/SHA1-96 \
529# GEN 3DES-CBC/SHA1-96 NONE/SHA1-96; do \
530# GEN echo -e "\n\nclass Test_${ENG}_${FLG}_${ALG}(RunTestIpsecEspAll):" |
531# GEN sed -e 's/-/_/g' -e 's#/#_#g' ; \
532# GEN echo ' """'$ENG $FLG $ALG IPSec test'"""' ;
533# GEN echo " def test_ipsec(self):";
534# GEN echo " self.run_test()";
535# GEN done; done; done
Neale Ranns4f33c802019-04-10 12:39:10 +0000536
Neale Ranns4f33c802019-04-10 12:39:10 +0000537
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000538class Test_ia32_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
539 """ia32 noESN AES-GCM-128/NONE IPSec test"""
540 def test_ipsec(self):
541 self.run_test()
Neale Ranns4f33c802019-04-10 12:39:10 +0000542
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000543
544class Test_ia32_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
545 """ia32 noESN AES-GCM-192/NONE IPSec test"""
546 def test_ipsec(self):
547 self.run_test()
548
549
550class Test_ia32_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
551 """ia32 noESN AES-GCM-256/NONE IPSec test"""
552 def test_ipsec(self):
553 self.run_test()
554
555
556class Test_ia32_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
557 """ia32 noESN AES-CBC-128/MD5-96 IPSec test"""
558 def test_ipsec(self):
559 self.run_test()
560
561
562class Test_ia32_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
563 """ia32 noESN AES-CBC-192/SHA1-96 IPSec test"""
564 def test_ipsec(self):
565 self.run_test()
566
567
568class Test_ia32_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
569 """ia32 noESN AES-CBC-256/SHA1-96 IPSec test"""
570 def test_ipsec(self):
571 self.run_test()
572
573
574class Test_ia32_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
575 """ia32 noESN 3DES-CBC/SHA1-96 IPSec test"""
576 def test_ipsec(self):
577 self.run_test()
578
579
580class Test_ia32_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
581 """ia32 noESN NONE/SHA1-96 IPSec test"""
582 def test_ipsec(self):
583 self.run_test()
584
585
586class Test_ia32_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
587 """ia32 ESN AES-GCM-128/NONE IPSec test"""
588 def test_ipsec(self):
589 self.run_test()
590
591
592class Test_ia32_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
593 """ia32 ESN AES-GCM-192/NONE IPSec test"""
594 def test_ipsec(self):
595 self.run_test()
596
597
598class Test_ia32_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
599 """ia32 ESN AES-GCM-256/NONE IPSec test"""
600 def test_ipsec(self):
601 self.run_test()
602
603
604class Test_ia32_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
605 """ia32 ESN AES-CBC-128/MD5-96 IPSec test"""
606 def test_ipsec(self):
607 self.run_test()
608
609
610class Test_ia32_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
611 """ia32 ESN AES-CBC-192/SHA1-96 IPSec test"""
612 def test_ipsec(self):
613 self.run_test()
614
615
616class Test_ia32_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
617 """ia32 ESN AES-CBC-256/SHA1-96 IPSec test"""
618 def test_ipsec(self):
619 self.run_test()
620
621
622class Test_ia32_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
623 """ia32 ESN 3DES-CBC/SHA1-96 IPSec test"""
624 def test_ipsec(self):
625 self.run_test()
626
627
628class Test_ia32_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
629 """ia32 ESN NONE/SHA1-96 IPSec test"""
630 def test_ipsec(self):
631 self.run_test()
632
633
634class Test_ipsecmb_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
635 """ipsecmb noESN AES-GCM-128/NONE IPSec test"""
636 def test_ipsec(self):
637 self.run_test()
638
639
640class Test_ipsecmb_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
641 """ipsecmb noESN AES-GCM-192/NONE IPSec test"""
642 def test_ipsec(self):
643 self.run_test()
644
645
646class Test_ipsecmb_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
647 """ipsecmb noESN AES-GCM-256/NONE IPSec test"""
648 def test_ipsec(self):
649 self.run_test()
650
651
652class Test_ipsecmb_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
653 """ipsecmb noESN AES-CBC-128/MD5-96 IPSec test"""
654 def test_ipsec(self):
655 self.run_test()
656
657
658class Test_ipsecmb_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
659 """ipsecmb noESN AES-CBC-192/SHA1-96 IPSec test"""
660 def test_ipsec(self):
661 self.run_test()
662
663
664class Test_ipsecmb_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
665 """ipsecmb noESN AES-CBC-256/SHA1-96 IPSec test"""
666 def test_ipsec(self):
667 self.run_test()
668
669
670class Test_ipsecmb_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
671 """ipsecmb noESN 3DES-CBC/SHA1-96 IPSec test"""
672 def test_ipsec(self):
673 self.run_test()
674
675
676class Test_ipsecmb_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
677 """ipsecmb noESN NONE/SHA1-96 IPSec test"""
678 def test_ipsec(self):
679 self.run_test()
680
681
682class Test_ipsecmb_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
683 """ipsecmb ESN AES-GCM-128/NONE IPSec test"""
684 def test_ipsec(self):
685 self.run_test()
686
687
688class Test_ipsecmb_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
689 """ipsecmb ESN AES-GCM-192/NONE IPSec test"""
690 def test_ipsec(self):
691 self.run_test()
692
693
694class Test_ipsecmb_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
695 """ipsecmb ESN AES-GCM-256/NONE IPSec test"""
696 def test_ipsec(self):
697 self.run_test()
698
699
700class Test_ipsecmb_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
701 """ipsecmb ESN AES-CBC-128/MD5-96 IPSec test"""
702 def test_ipsec(self):
703 self.run_test()
704
705
706class Test_ipsecmb_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
707 """ipsecmb ESN AES-CBC-192/SHA1-96 IPSec test"""
708 def test_ipsec(self):
709 self.run_test()
710
711
712class Test_ipsecmb_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
713 """ipsecmb ESN AES-CBC-256/SHA1-96 IPSec test"""
714 def test_ipsec(self):
715 self.run_test()
716
717
718class Test_ipsecmb_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
719 """ipsecmb ESN 3DES-CBC/SHA1-96 IPSec test"""
720 def test_ipsec(self):
721 self.run_test()
722
723
724class Test_ipsecmb_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
725 """ipsecmb ESN NONE/SHA1-96 IPSec test"""
726 def test_ipsec(self):
727 self.run_test()
728
729
730class Test_openssl_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
731 """openssl noESN AES-GCM-128/NONE IPSec test"""
732 def test_ipsec(self):
733 self.run_test()
734
735
736class Test_openssl_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
737 """openssl noESN AES-GCM-192/NONE IPSec test"""
738 def test_ipsec(self):
739 self.run_test()
740
741
742class Test_openssl_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
743 """openssl noESN AES-GCM-256/NONE IPSec test"""
744 def test_ipsec(self):
745 self.run_test()
746
747
748class Test_openssl_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
749 """openssl noESN AES-CBC-128/MD5-96 IPSec test"""
750 def test_ipsec(self):
751 self.run_test()
752
753
754class Test_openssl_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
755 """openssl noESN AES-CBC-192/SHA1-96 IPSec test"""
756 def test_ipsec(self):
757 self.run_test()
758
759
760class Test_openssl_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
761 """openssl noESN AES-CBC-256/SHA1-96 IPSec test"""
762 def test_ipsec(self):
763 self.run_test()
764
765
766class Test_openssl_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
767 """openssl noESN 3DES-CBC/SHA1-96 IPSec test"""
768 def test_ipsec(self):
769 self.run_test()
770
771
772class Test_openssl_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
773 """openssl noESN NONE/SHA1-96 IPSec test"""
774 def test_ipsec(self):
775 self.run_test()
776
777
778class Test_openssl_ESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
779 """openssl ESN AES-GCM-128/NONE IPSec test"""
780 def test_ipsec(self):
781 self.run_test()
782
783
784class Test_openssl_ESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
785 """openssl ESN AES-GCM-192/NONE IPSec test"""
786 def test_ipsec(self):
787 self.run_test()
788
789
790class Test_openssl_ESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
791 """openssl ESN AES-GCM-256/NONE IPSec test"""
792 def test_ipsec(self):
793 self.run_test()
794
795
796class Test_openssl_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
797 """openssl ESN AES-CBC-128/MD5-96 IPSec test"""
798 def test_ipsec(self):
799 self.run_test()
800
801
802class Test_openssl_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
803 """openssl ESN AES-CBC-192/SHA1-96 IPSec test"""
804 def test_ipsec(self):
805 self.run_test()
806
807
808class Test_openssl_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
809 """openssl ESN AES-CBC-256/SHA1-96 IPSec test"""
810 def test_ipsec(self):
811 self.run_test()
812
813
814class Test_openssl_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
815 """openssl ESN 3DES-CBC/SHA1-96 IPSec test"""
816 def test_ipsec(self):
817 self.run_test()
818
819
820class Test_openssl_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
821 """openssl ESN NONE/SHA1-96 IPSec test"""
822 def test_ipsec(self):
823 self.run_test()
Neale Ranns6afaae12019-07-17 15:07:14 +0000824
Neale Ranns4f33c802019-04-10 12:39:10 +0000825
“mystarrocks”23f0c452017-12-11 07:11:51 -0800826if __name__ == '__main__':
827 unittest.main(testRunner=VppTestRunner)