blob: 6be49ef21ce72e5daa064138db71e6d56ff69ec0 [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, \
Neale Ranns02950402019-12-20 00:54:57 +000012 IpsecTun6HandoffTests, IpsecTun4HandoffTests, \
Filip Tehlarefcad1a2020-02-04 09:36:04 +000013 IpsecTra6ExtTests
Klement Sekerabf613952019-01-29 11:38:08 +010014from vpp_ipsec import VppIpsecSpd, VppIpsecSpdEntry, VppIpsecSA,\
Neale Ranns4f33c802019-04-10 12:39:10 +000015 VppIpsecSpdItfBinding
Neale Ranns311124e2019-01-24 04:52:25 -080016from vpp_ip_route import VppIpRoute, VppRoutePath
17from vpp_ip import DpoProto
Neale Ranns17dcec02019-01-09 21:22:20 -080018from vpp_papi import VppEnum
“mystarrocks”23f0c452017-12-11 07:11:51 -080019
Neale Rannsc87b66c2019-02-07 07:26:12 -080020NUM_PKTS = 67
Filip Tehlarefcad1a2020-02-04 09:36:04 +000021engines_supporting_chain_bufs = ["openssl"]
Neale Rannsc87b66c2019-02-07 07:26:12 -080022
“mystarrocks”23f0c452017-12-11 07:11:51 -080023
Neale Ranns4f33c802019-04-10 12:39:10 +000024class ConfigIpsecESP(TemplateIpsec):
25 encryption_type = ESP
26 tra4_encrypt_node_name = "esp4-encrypt"
27 tra4_decrypt_node_name = "esp4-decrypt"
28 tra6_encrypt_node_name = "esp6-encrypt"
29 tra6_decrypt_node_name = "esp6-decrypt"
30 tun4_encrypt_node_name = "esp4-encrypt"
31 tun4_decrypt_node_name = "esp4-decrypt"
32 tun6_encrypt_node_name = "esp6-encrypt"
33 tun6_decrypt_node_name = "esp6-decrypt"
Neale Ranns53f526b2019-02-25 14:32:02 +000034
Neale Ranns4f33c802019-04-10 12:39:10 +000035 @classmethod
36 def setUpClass(cls):
37 super(ConfigIpsecESP, cls).setUpClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000038
Neale Ranns4f33c802019-04-10 12:39:10 +000039 @classmethod
40 def tearDownClass(cls):
41 super(ConfigIpsecESP, cls).tearDownClass()
Neale Ranns53f526b2019-02-25 14:32:02 +000042
Neale Ranns4f33c802019-04-10 12:39:10 +000043 def setUp(self):
44 super(ConfigIpsecESP, self).setUp()
Neale Ranns53f526b2019-02-25 14:32:02 +000045
Neale Ranns4f33c802019-04-10 12:39:10 +000046 def tearDown(self):
47 super(ConfigIpsecESP, self).tearDown()
48
49 def config_network(self, params):
50 self.net_objs = []
51 self.tun_if = self.pg0
52 self.tra_if = self.pg2
53 self.logger.info(self.vapi.ppcli("show int addr"))
54
55 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
56 self.tra_spd.add_vpp_config()
57 self.net_objs.append(self.tra_spd)
58 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
59 self.tun_spd.add_vpp_config()
60 self.net_objs.append(self.tun_spd)
61
62 b = VppIpsecSpdItfBinding(self, self.tun_spd,
63 self.tun_if)
64 b.add_vpp_config()
65 self.net_objs.append(b)
66
67 b = VppIpsecSpdItfBinding(self, self.tra_spd,
68 self.tra_if)
69 b.add_vpp_config()
70 self.net_objs.append(b)
71
72 for p in params:
73 self.config_esp_tra(p)
74 config_tra_params(p, self.encryption_type)
75 for p in params:
76 self.config_esp_tun(p)
Neale Ranns12989b52019-09-26 16:20:19 +000077 config_tun_params(p, self.encryption_type, self.tun_if)
Neale Ranns4f33c802019-04-10 12:39:10 +000078
79 for p in params:
80 d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4
81 r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
82 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
83 0xffffffff,
Neale Ranns097fa662018-05-01 05:17:55 -070084 proto=d)])
Neale Ranns4f33c802019-04-10 12:39:10 +000085 r.add_vpp_config()
86 self.net_objs.append(r)
87
88 self.logger.info(self.vapi.ppcli("show ipsec all"))
89
90 def unconfig_network(self):
91 for o in reversed(self.net_objs):
92 o.remove_vpp_config()
93 self.net_objs = []
94
95 def config_esp_tun(self, params):
96 addr_type = params.addr_type
97 scapy_tun_sa_id = params.scapy_tun_sa_id
98 scapy_tun_spi = params.scapy_tun_spi
99 vpp_tun_sa_id = params.vpp_tun_sa_id
100 vpp_tun_spi = params.vpp_tun_spi
101 auth_algo_vpp_id = params.auth_algo_vpp_id
102 auth_key = params.auth_key
103 crypt_algo_vpp_id = params.crypt_algo_vpp_id
104 crypt_key = params.crypt_key
105 remote_tun_if_host = params.remote_tun_if_host
106 addr_any = params.addr_any
107 addr_bcast = params.addr_bcast
108 e = VppEnum.vl_api_ipsec_spd_action_t
Neale Ranns49e7ef62019-04-10 17:24:29 +0000109 flags = params.flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000110 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000111 objs = []
112
113 params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi,
114 auth_algo_vpp_id, auth_key,
115 crypt_algo_vpp_id, crypt_key,
116 self.vpp_esp_protocol,
117 self.tun_if.local_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000118 self.tun_if.remote_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000119 flags=flags,
120 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000121 params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi,
122 auth_algo_vpp_id, auth_key,
123 crypt_algo_vpp_id, crypt_key,
124 self.vpp_esp_protocol,
125 self.tun_if.remote_addr[addr_type],
Neale Ranns49e7ef62019-04-10 17:24:29 +0000126 self.tun_if.local_addr[addr_type],
Neale Ranns80f6fd52019-04-16 02:41:34 +0000127 flags=flags,
128 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000129 objs.append(params.tun_sa_in)
130 objs.append(params.tun_sa_out)
131
132 params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd,
133 scapy_tun_sa_id,
134 addr_any, addr_bcast,
135 addr_any, addr_bcast,
136 socket.IPPROTO_ESP)
137 params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd,
138 scapy_tun_sa_id,
139 addr_any, addr_bcast,
140 addr_any, addr_bcast,
141 socket.IPPROTO_ESP,
142 is_outbound=0)
143 objs.append(params.spd_policy_out_any)
144 objs.append(params.spd_policy_in_any)
145
146 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
147 remote_tun_if_host, remote_tun_if_host,
148 self.pg1.remote_addr[addr_type],
149 self.pg1.remote_addr[addr_type],
150 0,
151 priority=10,
152 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
153 is_outbound=0))
154 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
155 self.pg1.remote_addr[addr_type],
156 self.pg1.remote_addr[addr_type],
157 remote_tun_if_host, remote_tun_if_host,
158 0,
159 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
160 priority=10))
161 objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id,
162 remote_tun_if_host, remote_tun_if_host,
163 self.pg0.local_addr[addr_type],
164 self.pg0.local_addr[addr_type],
165 0,
166 priority=20,
167 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
168 is_outbound=0))
169 objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id,
170 self.pg0.local_addr[addr_type],
171 self.pg0.local_addr[addr_type],
172 remote_tun_if_host, remote_tun_if_host,
173 0,
174 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
175 priority=20))
176 for o in objs:
177 o.add_vpp_config()
178 self.net_objs = self.net_objs + objs
179
180 def config_esp_tra(self, params):
181 addr_type = params.addr_type
182 scapy_tra_sa_id = params.scapy_tra_sa_id
183 scapy_tra_spi = params.scapy_tra_spi
184 vpp_tra_sa_id = params.vpp_tra_sa_id
185 vpp_tra_spi = params.vpp_tra_spi
186 auth_algo_vpp_id = params.auth_algo_vpp_id
187 auth_key = params.auth_key
188 crypt_algo_vpp_id = params.crypt_algo_vpp_id
189 crypt_key = params.crypt_key
190 addr_any = params.addr_any
191 addr_bcast = params.addr_bcast
192 flags = (VppEnum.vl_api_ipsec_sad_flags_t.
193 IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY)
194 e = VppEnum.vl_api_ipsec_spd_action_t
195 flags = params.flags | flags
Neale Ranns80f6fd52019-04-16 02:41:34 +0000196 salt = params.salt
Neale Ranns4f33c802019-04-10 12:39:10 +0000197 objs = []
198
199 params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi,
200 auth_algo_vpp_id, auth_key,
201 crypt_algo_vpp_id, crypt_key,
202 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000203 flags=flags,
204 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000205 params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi,
206 auth_algo_vpp_id, auth_key,
207 crypt_algo_vpp_id, crypt_key,
208 self.vpp_esp_protocol,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000209 flags=flags,
210 salt=salt)
Neale Ranns4f33c802019-04-10 12:39:10 +0000211 objs.append(params.tra_sa_in)
212 objs.append(params.tra_sa_out)
213
214 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
215 addr_any, addr_bcast,
216 addr_any, addr_bcast,
217 socket.IPPROTO_ESP))
218 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
219 addr_any, addr_bcast,
220 addr_any, addr_bcast,
221 socket.IPPROTO_ESP,
222 is_outbound=0))
223 objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id,
224 self.tra_if.local_addr[addr_type],
225 self.tra_if.local_addr[addr_type],
226 self.tra_if.remote_addr[addr_type],
227 self.tra_if.remote_addr[addr_type],
228 0, priority=10,
229 policy=e.IPSEC_API_SPD_ACTION_PROTECT,
230 is_outbound=0))
231 objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id,
232 self.tra_if.local_addr[addr_type],
233 self.tra_if.local_addr[addr_type],
234 self.tra_if.remote_addr[addr_type],
235 self.tra_if.remote_addr[addr_type],
236 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT,
237 priority=10))
238 for o in objs:
239 o.add_vpp_config()
240 self.net_objs = self.net_objs + objs
Neale Ranns53f526b2019-02-25 14:32:02 +0000241
242
Neale Ranns4f33c802019-04-10 12:39:10 +0000243class TemplateIpsecEsp(ConfigIpsecESP):
“mystarrocks”23f0c452017-12-11 07:11:51 -0800244 """
245 Basic test for ipsec esp sanity - tunnel and transport modes.
246
247 Below 4 cases are covered as part of this test
248 1) ipsec esp v4 transport basic test - IPv4 Transport mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700249 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800250 2) ipsec esp v4 transport burst test
251 Above test for 257 pkts
252 3) ipsec esp 4o4 tunnel basic test - IPv4 Tunnel mode
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700253 scenario using HMAC-SHA1-96 integrity algo
“mystarrocks”23f0c452017-12-11 07:11:51 -0800254 4) ipsec esp 4o4 tunnel burst test
255 Above test for 257 pkts
256
257 TRANSPORT MODE:
258
259 --- encrypt ---
260 |pg2| <-------> |VPP|
261 --- decrypt ---
262
263 TUNNEL MODE:
264
265 --- encrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200266 |pg0| <------- |VPP| <------ |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800267 --- --- ---
268
269 --- decrypt --- plain ---
Klement Sekera4b089f22018-04-17 18:04:57 +0200270 |pg0| -------> |VPP| ------> |pg1|
“mystarrocks”23f0c452017-12-11 07:11:51 -0800271 --- --- ---
“mystarrocks”23f0c452017-12-11 07:11:51 -0800272 """
273
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700274 @classmethod
275 def setUpClass(cls):
276 super(TemplateIpsecEsp, cls).setUpClass()
277
278 @classmethod
279 def tearDownClass(cls):
280 super(TemplateIpsecEsp, cls).tearDownClass()
281
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800282 def setUp(self):
283 super(TemplateIpsecEsp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000284 self.config_network(self.params.values())
Klement Sekera611864f2018-09-26 11:19:00 +0200285
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800286 def tearDown(self):
Neale Ranns4f33c802019-04-10 12:39:10 +0000287 self.unconfig_network()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800288 super(TemplateIpsecEsp, self).tearDown()
Neale Ranns8e4a89b2019-01-23 08:16:17 -0800289
Klement Sekera611864f2018-09-26 11:19:00 +0200290
Neale Ranns02950402019-12-20 00:54:57 +0000291class TestIpsecEsp1(TemplateIpsecEsp, IpsecTra46Tests,
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000292 IpsecTun46Tests, IpsecTra6ExtTests):
Klement Sekera31da2e32018-06-24 22:49:55 +0200293 """ Ipsec ESP - TUN & TRA tests """
Neale Ranns4f33c802019-04-10 12:39:10 +0000294 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800295
“mystarrocks”23f0c452017-12-11 07:11:51 -0800296
Klement Sekera31da2e32018-06-24 22:49:55 +0200297class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests):
298 """ Ipsec ESP - TCP tests """
299 pass
“mystarrocks”23f0c452017-12-11 07:11:51 -0800300
301
Neale Ranns4a56f4e2019-12-23 04:10:25 +0000302class TestIpsecEspHandoff(TemplateIpsecEsp,
303 IpsecTun6HandoffTests,
304 IpsecTun4HandoffTests):
305 """ Ipsec ESP - handoff tests """
306 pass
307
308
Neale Ranns4f33c802019-04-10 12:39:10 +0000309class TemplateIpsecEspUdp(ConfigIpsecESP):
Neale Ranns53f526b2019-02-25 14:32:02 +0000310 """
311 UDP encapped ESP
312 """
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700313
314 @classmethod
315 def setUpClass(cls):
316 super(TemplateIpsecEspUdp, cls).setUpClass()
317
318 @classmethod
319 def tearDownClass(cls):
320 super(TemplateIpsecEspUdp, cls).tearDownClass()
321
Neale Ranns53f526b2019-02-25 14:32:02 +0000322 def setUp(self):
323 super(TemplateIpsecEspUdp, self).setUp()
Neale Ranns4f33c802019-04-10 12:39:10 +0000324 self.net_objs = []
Neale Ranns53f526b2019-02-25 14:32:02 +0000325 self.tun_if = self.pg0
326 self.tra_if = self.pg2
327 self.logger.info(self.vapi.ppcli("show int addr"))
328
329 p = self.ipv4_params
330 p.flags = (VppEnum.vl_api_ipsec_sad_flags_t.
331 IPSEC_API_SAD_FLAG_UDP_ENCAP)
332 p.nat_header = UDP(sport=5454, dport=4500)
333
334 self.tra_spd = VppIpsecSpd(self, self.tra_spd_id)
335 self.tra_spd.add_vpp_config()
336 VppIpsecSpdItfBinding(self, self.tra_spd,
337 self.tra_if).add_vpp_config()
338
Neale Ranns4f33c802019-04-10 12:39:10 +0000339 self.config_esp_tra(p)
Neale Ranns2ac885c2019-03-20 18:24:43 +0000340 config_tra_params(p, self.encryption_type)
Neale Ranns53f526b2019-02-25 14:32:02 +0000341
342 self.tun_spd = VppIpsecSpd(self, self.tun_spd_id)
343 self.tun_spd.add_vpp_config()
344 VppIpsecSpdItfBinding(self, self.tun_spd,
345 self.tun_if).add_vpp_config()
346
Neale Ranns4f33c802019-04-10 12:39:10 +0000347 self.config_esp_tun(p)
Neale Ranns92e93842019-04-08 07:36:50 +0000348 self.logger.info(self.vapi.ppcli("show ipsec all"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000349
350 d = DpoProto.DPO_PROTO_IP4
351 VppIpRoute(self, p.remote_tun_if_host, p.addr_len,
352 [VppRoutePath(self.tun_if.remote_addr[p.addr_type],
353 0xffffffff,
354 proto=d)]).add_vpp_config()
355
356 def tearDown(self):
357 super(TemplateIpsecEspUdp, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700358
359 def show_commands_at_teardown(self):
360 self.logger.info(self.vapi.cli("show hardware"))
Neale Ranns53f526b2019-02-25 14:32:02 +0000361
362
Neale Ranns49e7ef62019-04-10 17:24:29 +0000363class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests):
Neale Ranns53f526b2019-02-25 14:32:02 +0000364 """ Ipsec NAT-T ESP UDP tests """
Neale Ranns53f526b2019-02-25 14:32:02 +0000365 pass
366
367
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000368class MyParameters():
369 def __init__(self):
370 self.engines = ["ia32", "ipsecmb", "openssl"]
371 flag_esn = VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN
372 self.flags = [0, flag_esn]
Neale Ranns4f33c802019-04-10 12:39:10 +0000373 # foreach crypto algorithm
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000374 self.algos = {
375 'AES-GCM-128/NONE': {
376 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000377 IPSEC_API_CRYPTO_ALG_AES_GCM_128),
378 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
379 IPSEC_API_INTEG_ALG_NONE),
380 'scapy-crypto': "AES-GCM",
381 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200382 'key': b"JPjyOWBeVEQiMe7h",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000383 'salt': 0},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000384 'AES-GCM-192/NONE': {
385 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns80f6fd52019-04-16 02:41:34 +0000386 IPSEC_API_CRYPTO_ALG_AES_GCM_192),
387 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
388 IPSEC_API_INTEG_ALG_NONE),
389 'scapy-crypto': "AES-GCM",
390 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200391 'key': b"JPjyOWBeVEQiMe7h01234567",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000392 'salt': 1010},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000393 'AES-GCM-256/NONE': {
394 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000395 IPSEC_API_CRYPTO_ALG_AES_GCM_256),
396 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
397 IPSEC_API_INTEG_ALG_NONE),
398 'scapy-crypto': "AES-GCM",
399 'scapy-integ': "NULL",
Ole Troan64e978b2019-10-17 21:40:36 +0200400 'key': b"JPjyOWBeVEQiMe7h0123456787654321",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000401 'salt': 2020},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000402 'AES-CBC-128/MD5-96': {
403 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000404 IPSEC_API_CRYPTO_ALG_AES_CBC_128),
405 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400406 IPSEC_API_INTEG_ALG_MD5_96),
Neale Ranns47feb112019-04-11 15:14:07 +0000407 'scapy-crypto': "AES-CBC",
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400408 'scapy-integ': "HMAC-MD5-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000409 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200410 'key': b"JPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000411 'AES-CBC-192/SHA1-96': {
412 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000413 IPSEC_API_CRYPTO_ALG_AES_CBC_192),
414 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
415 IPSEC_API_INTEG_ALG_SHA1_96),
416 'scapy-crypto': "AES-CBC",
417 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000418 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200419 'key': b"JPjyOWBeVEQiMe7hJPjyOWBe"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000420 'AES-CBC-256/SHA1-96': {
421 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns47feb112019-04-11 15:14:07 +0000422 IPSEC_API_CRYPTO_ALG_AES_CBC_256),
423 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
424 IPSEC_API_INTEG_ALG_SHA1_96),
425 'scapy-crypto': "AES-CBC",
426 'scapy-integ': "HMAC-SHA1-96",
Neale Ranns80f6fd52019-04-16 02:41:34 +0000427 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200428 'key': b"JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000429 '3DES-CBC/SHA1-96': {
430 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Vladimir Ratnikovf4805072019-05-17 09:17:59 -0400431 IPSEC_API_CRYPTO_ALG_3DES_CBC),
432 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
433 IPSEC_API_INTEG_ALG_SHA1_96),
434 'scapy-crypto': "3DES",
435 'scapy-integ': "HMAC-SHA1-96",
436 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200437 'key': b"JPjyOWBeVEQiMe7h00112233"},
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000438 'NONE/SHA1-96': {
439 'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t.
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000440 IPSEC_API_CRYPTO_ALG_NONE),
441 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t.
442 IPSEC_API_INTEG_ALG_SHA1_96),
443 'scapy-crypto': "NULL",
444 'scapy-integ': "HMAC-SHA1-96",
445 'salt': 0,
Ole Troan64e978b2019-10-17 21:40:36 +0200446 'key': b"JPjyOWBeVEQiMe7h00112233"}}
Neale Ranns4f33c802019-04-10 12:39:10 +0000447
Neale Ranns4f33c802019-04-10 12:39:10 +0000448
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000449class RunTestIpsecEspAll(ConfigIpsecESP,
450 IpsecTra4, IpsecTra6,
451 IpsecTun4, IpsecTun6):
452 """ Ipsec ESP all Algos """
453
454 def setUp(self):
455 super(RunTestIpsecEspAll, self).setUp()
456 test_args = str.split(self.__doc__, " ")
457
458 params = MyParameters()
459 self.engine = test_args[0]
460 self.flag = params.flags[0]
461 if test_args[1] == 'ESN':
462 self.flag = params.flags[1]
463
464 self.algo = params.algos[test_args[2]]
465
466 def tearDown(self):
467 super(RunTestIpsecEspAll, self).tearDown()
468
469 def run_test(self):
470 self.run_a_test(self.engine, self.flag, self.algo)
471
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000472 def run_a_test(self, engine, flag, algo, payload_size=None):
Neale Ranns00625a62019-07-31 00:13:18 -0700473 self.vapi.cli("set crypto handler all %s" % engine)
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000474
475 self.ipv4_params = IPsecIPv4Params()
476 self.ipv6_params = IPsecIPv6Params()
477
478 self.params = {self.ipv4_params.addr_type:
479 self.ipv4_params,
480 self.ipv6_params.addr_type:
481 self.ipv6_params}
482
483 for _, p in self.params.items():
484 p.auth_algo_vpp_id = algo['vpp-integ']
485 p.crypt_algo_vpp_id = algo['vpp-crypto']
486 p.crypt_algo = algo['scapy-crypto']
487 p.auth_algo = algo['scapy-integ']
488 p.crypt_key = algo['key']
489 p.salt = algo['salt']
490 p.flags = p.flags | flag
491
492 self.reporter.send_keep_alive(self)
493
Neale Ranns4f33c802019-04-10 12:39:10 +0000494 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000495 # configure the SPDs. SAs, etc
Neale Ranns4f33c802019-04-10 12:39:10 +0000496 #
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000497 self.config_network(self.params.values())
Neale Ranns4f33c802019-04-10 12:39:10 +0000498
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000499 #
500 # run some traffic.
501 # An exhautsive 4o6, 6o4 is not necessary
502 # for each algo
503 #
504 self.verify_tra_basic6(count=NUM_PKTS)
505 self.verify_tra_basic4(count=NUM_PKTS)
506 self.verify_tun_66(self.params[socket.AF_INET6],
507 count=NUM_PKTS)
508 self.verify_tun_44(self.params[socket.AF_INET],
509 count=NUM_PKTS)
Neale Ranns4f33c802019-04-10 12:39:10 +0000510
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000511 LARGE_PKT_SZ = [
Filip Tehlare4e8c6b2020-02-13 07:49:30 +0000512 1970, # results in 2 chained buffers entering decrypt node
513 # but leaving as simple buffer due to ICV removal (tra4)
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000514 4010, # ICV ends up splitted accross 2 buffers in esp_decrypt
515 # for transport4; transport6 takes normal path
Filip Tehlarefcad1a2020-02-04 09:36:04 +0000516 4020, # same as above but tra4 and tra6 are switched
517 ]
518 if self.engine in engines_supporting_chain_bufs:
519 for sz in LARGE_PKT_SZ:
520 self.verify_tra_basic4(count=NUM_PKTS, payload_size=sz)
521 self.verify_tra_basic6(count=NUM_PKTS, payload_size=sz)
522 self.verify_tun_66(self.params[socket.AF_INET6],
523 count=NUM_PKTS, payload_size=sz)
524 self.verify_tun_44(self.params[socket.AF_INET],
525 count=NUM_PKTS, payload_size=sz)
526
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000527 #
528 # remove the SPDs, SAs, etc
529 #
530 self.unconfig_network()
Neale Ranns4f33c802019-04-10 12:39:10 +0000531
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000532 #
533 # reconfigure the network and SA to run the
534 # anti replay tests
535 #
536 self.config_network(self.params.values())
537 self.verify_tra_anti_replay()
538 self.unconfig_network()
juraj.linkes11057662019-07-08 10:22:55 +0200539
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000540#
541# To generate test classes, do:
542# grep '# GEN' test_ipsec_esp.py | sed -e 's/# GEN //g' | bash
543#
544# GEN for ENG in ia32 ipsecmb openssl; do \
545# GEN for FLG in noESN ESN; do for ALG in AES-GCM-128/NONE \
546# GEN AES-GCM-192/NONE AES-GCM-256/NONE AES-CBC-128/MD5-96 \
547# GEN AES-CBC-192/SHA1-96 AES-CBC-256/SHA1-96 \
548# GEN 3DES-CBC/SHA1-96 NONE/SHA1-96; do \
Filip Tehlar39cf40a2020-03-25 04:08:55 +0000549# GEN [[ ${FLG} == "ESN" && ${ALG} == *"NONE" ]] && continue
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000550# GEN echo -e "\n\nclass Test_${ENG}_${FLG}_${ALG}(RunTestIpsecEspAll):" |
551# GEN sed -e 's/-/_/g' -e 's#/#_#g' ; \
552# GEN echo ' """'$ENG $FLG $ALG IPSec test'"""' ;
553# GEN echo " def test_ipsec(self):";
554# GEN echo " self.run_test()";
555# GEN done; done; done
Neale Ranns4f33c802019-04-10 12:39:10 +0000556
Neale Ranns4f33c802019-04-10 12:39:10 +0000557
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000558class Test_ia32_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
559 """ia32 noESN AES-GCM-128/NONE IPSec test"""
560 def test_ipsec(self):
561 self.run_test()
Neale Ranns4f33c802019-04-10 12:39:10 +0000562
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000563
564class Test_ia32_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
565 """ia32 noESN AES-GCM-192/NONE IPSec test"""
566 def test_ipsec(self):
567 self.run_test()
568
569
570class Test_ia32_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
571 """ia32 noESN AES-GCM-256/NONE IPSec test"""
572 def test_ipsec(self):
573 self.run_test()
574
575
576class Test_ia32_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
577 """ia32 noESN AES-CBC-128/MD5-96 IPSec test"""
578 def test_ipsec(self):
579 self.run_test()
580
581
582class Test_ia32_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
583 """ia32 noESN AES-CBC-192/SHA1-96 IPSec test"""
584 def test_ipsec(self):
585 self.run_test()
586
587
588class Test_ia32_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
589 """ia32 noESN AES-CBC-256/SHA1-96 IPSec test"""
590 def test_ipsec(self):
591 self.run_test()
592
593
594class Test_ia32_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
595 """ia32 noESN 3DES-CBC/SHA1-96 IPSec test"""
596 def test_ipsec(self):
597 self.run_test()
598
599
600class Test_ia32_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
601 """ia32 noESN NONE/SHA1-96 IPSec test"""
602 def test_ipsec(self):
603 self.run_test()
604
605
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000606class Test_ia32_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
607 """ia32 ESN AES-CBC-128/MD5-96 IPSec test"""
608 def test_ipsec(self):
609 self.run_test()
610
611
612class Test_ia32_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
613 """ia32 ESN AES-CBC-192/SHA1-96 IPSec test"""
614 def test_ipsec(self):
615 self.run_test()
616
617
618class Test_ia32_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
619 """ia32 ESN AES-CBC-256/SHA1-96 IPSec test"""
620 def test_ipsec(self):
621 self.run_test()
622
623
624class Test_ia32_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
625 """ia32 ESN 3DES-CBC/SHA1-96 IPSec test"""
626 def test_ipsec(self):
627 self.run_test()
628
629
630class Test_ia32_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
631 """ia32 ESN NONE/SHA1-96 IPSec test"""
632 def test_ipsec(self):
633 self.run_test()
634
635
636class Test_ipsecmb_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
637 """ipsecmb noESN AES-GCM-128/NONE IPSec test"""
638 def test_ipsec(self):
639 self.run_test()
640
641
642class Test_ipsecmb_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
643 """ipsecmb noESN AES-GCM-192/NONE IPSec test"""
644 def test_ipsec(self):
645 self.run_test()
646
647
648class Test_ipsecmb_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
649 """ipsecmb noESN AES-GCM-256/NONE IPSec test"""
650 def test_ipsec(self):
651 self.run_test()
652
653
654class Test_ipsecmb_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
655 """ipsecmb noESN AES-CBC-128/MD5-96 IPSec test"""
656 def test_ipsec(self):
657 self.run_test()
658
659
660class Test_ipsecmb_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
661 """ipsecmb noESN AES-CBC-192/SHA1-96 IPSec test"""
662 def test_ipsec(self):
663 self.run_test()
664
665
666class Test_ipsecmb_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
667 """ipsecmb noESN AES-CBC-256/SHA1-96 IPSec test"""
668 def test_ipsec(self):
669 self.run_test()
670
671
672class Test_ipsecmb_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
673 """ipsecmb noESN 3DES-CBC/SHA1-96 IPSec test"""
674 def test_ipsec(self):
675 self.run_test()
676
677
678class Test_ipsecmb_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
679 """ipsecmb noESN NONE/SHA1-96 IPSec test"""
680 def test_ipsec(self):
681 self.run_test()
682
683
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000684class Test_ipsecmb_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
685 """ipsecmb ESN AES-CBC-128/MD5-96 IPSec test"""
686 def test_ipsec(self):
687 self.run_test()
688
689
690class Test_ipsecmb_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
691 """ipsecmb ESN AES-CBC-192/SHA1-96 IPSec test"""
692 def test_ipsec(self):
693 self.run_test()
694
695
696class Test_ipsecmb_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
697 """ipsecmb ESN AES-CBC-256/SHA1-96 IPSec test"""
698 def test_ipsec(self):
699 self.run_test()
700
701
702class Test_ipsecmb_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
703 """ipsecmb ESN 3DES-CBC/SHA1-96 IPSec test"""
704 def test_ipsec(self):
705 self.run_test()
706
707
708class Test_ipsecmb_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
709 """ipsecmb ESN NONE/SHA1-96 IPSec test"""
710 def test_ipsec(self):
711 self.run_test()
712
713
714class Test_openssl_noESN_AES_GCM_128_NONE(RunTestIpsecEspAll):
715 """openssl noESN AES-GCM-128/NONE IPSec test"""
716 def test_ipsec(self):
717 self.run_test()
718
719
720class Test_openssl_noESN_AES_GCM_192_NONE(RunTestIpsecEspAll):
721 """openssl noESN AES-GCM-192/NONE IPSec test"""
722 def test_ipsec(self):
723 self.run_test()
724
725
726class Test_openssl_noESN_AES_GCM_256_NONE(RunTestIpsecEspAll):
727 """openssl noESN AES-GCM-256/NONE IPSec test"""
728 def test_ipsec(self):
729 self.run_test()
730
731
732class Test_openssl_noESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
733 """openssl noESN AES-CBC-128/MD5-96 IPSec test"""
734 def test_ipsec(self):
735 self.run_test()
736
737
738class Test_openssl_noESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
739 """openssl noESN AES-CBC-192/SHA1-96 IPSec test"""
740 def test_ipsec(self):
741 self.run_test()
742
743
744class Test_openssl_noESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
745 """openssl noESN AES-CBC-256/SHA1-96 IPSec test"""
746 def test_ipsec(self):
747 self.run_test()
748
749
750class Test_openssl_noESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
751 """openssl noESN 3DES-CBC/SHA1-96 IPSec test"""
752 def test_ipsec(self):
753 self.run_test()
754
755
756class Test_openssl_noESN_NONE_SHA1_96(RunTestIpsecEspAll):
757 """openssl noESN NONE/SHA1-96 IPSec test"""
758 def test_ipsec(self):
759 self.run_test()
760
761
Andrew Yourtchenkofbc38892019-09-09 11:14:59 +0000762class Test_openssl_ESN_AES_CBC_128_MD5_96(RunTestIpsecEspAll):
763 """openssl ESN AES-CBC-128/MD5-96 IPSec test"""
764 def test_ipsec(self):
765 self.run_test()
766
767
768class Test_openssl_ESN_AES_CBC_192_SHA1_96(RunTestIpsecEspAll):
769 """openssl ESN AES-CBC-192/SHA1-96 IPSec test"""
770 def test_ipsec(self):
771 self.run_test()
772
773
774class Test_openssl_ESN_AES_CBC_256_SHA1_96(RunTestIpsecEspAll):
775 """openssl ESN AES-CBC-256/SHA1-96 IPSec test"""
776 def test_ipsec(self):
777 self.run_test()
778
779
780class Test_openssl_ESN_3DES_CBC_SHA1_96(RunTestIpsecEspAll):
781 """openssl ESN 3DES-CBC/SHA1-96 IPSec test"""
782 def test_ipsec(self):
783 self.run_test()
784
785
786class Test_openssl_ESN_NONE_SHA1_96(RunTestIpsecEspAll):
787 """openssl ESN NONE/SHA1-96 IPSec test"""
788 def test_ipsec(self):
789 self.run_test()
Neale Ranns6afaae12019-07-17 15:07:14 +0000790
Neale Ranns4f33c802019-04-10 12:39:10 +0000791
“mystarrocks”23f0c452017-12-11 07:11:51 -0800792if __name__ == '__main__':
793 unittest.main(testRunner=VppTestRunner)