“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 1 | import socket |
Klement Sekera | 28fb03f | 2018-04-17 11:36:55 +0200 | [diff] [blame] | 2 | import unittest |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3 | from scapy.layers.ipsec import ESP |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 4 | from scapy.layers.inet import UDP |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 5 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 6 | from parameterized import parameterized |
juraj.linkes | 1105766 | 2019-07-08 10:22:55 +0200 | [diff] [blame] | 7 | from framework import VppTestRunner |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 8 | from template_ipsec import IpsecTra46Tests, IpsecTun46Tests, TemplateIpsec, \ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 9 | IpsecTcpTests, IpsecTun4Tests, IpsecTra4Tests, config_tra_params, \ |
| 10 | IPsecIPv4Params, IPsecIPv6Params, \ |
| 11 | IpsecTra4, IpsecTun4, IpsecTra6, IpsecTun6 |
Klement Sekera | bf61395 | 2019-01-29 11:38:08 +0100 | [diff] [blame] | 12 | from vpp_ipsec import VppIpsecSpd, VppIpsecSpdEntry, VppIpsecSA,\ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 13 | VppIpsecSpdItfBinding |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 14 | from vpp_ip_route import VppIpRoute, VppRoutePath |
| 15 | from vpp_ip import DpoProto |
Neale Ranns | 17dcec0 | 2019-01-09 21:22:20 -0800 | [diff] [blame] | 16 | from vpp_papi import VppEnum |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 17 | |
Neale Ranns | c87b66c | 2019-02-07 07:26:12 -0800 | [diff] [blame] | 18 | NUM_PKTS = 67 |
| 19 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 20 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 21 | class ConfigIpsecESP(TemplateIpsec): |
| 22 | encryption_type = ESP |
| 23 | tra4_encrypt_node_name = "esp4-encrypt" |
| 24 | tra4_decrypt_node_name = "esp4-decrypt" |
| 25 | tra6_encrypt_node_name = "esp6-encrypt" |
| 26 | tra6_decrypt_node_name = "esp6-decrypt" |
| 27 | tun4_encrypt_node_name = "esp4-encrypt" |
| 28 | tun4_decrypt_node_name = "esp4-decrypt" |
| 29 | tun6_encrypt_node_name = "esp6-encrypt" |
| 30 | tun6_decrypt_node_name = "esp6-decrypt" |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 31 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 32 | @classmethod |
| 33 | def setUpClass(cls): |
| 34 | super(ConfigIpsecESP, cls).setUpClass() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 35 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 36 | @classmethod |
| 37 | def tearDownClass(cls): |
| 38 | super(ConfigIpsecESP, cls).tearDownClass() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 39 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 40 | def setUp(self): |
| 41 | super(ConfigIpsecESP, self).setUp() |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 42 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 43 | def tearDown(self): |
| 44 | super(ConfigIpsecESP, self).tearDown() |
| 45 | |
| 46 | def config_network(self, params): |
| 47 | self.net_objs = [] |
| 48 | self.tun_if = self.pg0 |
| 49 | self.tra_if = self.pg2 |
| 50 | self.logger.info(self.vapi.ppcli("show int addr")) |
| 51 | |
| 52 | self.tra_spd = VppIpsecSpd(self, self.tra_spd_id) |
| 53 | self.tra_spd.add_vpp_config() |
| 54 | self.net_objs.append(self.tra_spd) |
| 55 | self.tun_spd = VppIpsecSpd(self, self.tun_spd_id) |
| 56 | self.tun_spd.add_vpp_config() |
| 57 | self.net_objs.append(self.tun_spd) |
| 58 | |
| 59 | b = VppIpsecSpdItfBinding(self, self.tun_spd, |
| 60 | self.tun_if) |
| 61 | b.add_vpp_config() |
| 62 | self.net_objs.append(b) |
| 63 | |
| 64 | b = VppIpsecSpdItfBinding(self, self.tra_spd, |
| 65 | self.tra_if) |
| 66 | b.add_vpp_config() |
| 67 | self.net_objs.append(b) |
| 68 | |
| 69 | for p in params: |
| 70 | self.config_esp_tra(p) |
| 71 | config_tra_params(p, self.encryption_type) |
| 72 | for p in params: |
| 73 | self.config_esp_tun(p) |
| 74 | |
| 75 | for p in params: |
| 76 | d = DpoProto.DPO_PROTO_IP6 if p.is_ipv6 else DpoProto.DPO_PROTO_IP4 |
| 77 | r = VppIpRoute(self, p.remote_tun_if_host, p.addr_len, |
| 78 | [VppRoutePath(self.tun_if.remote_addr[p.addr_type], |
| 79 | 0xffffffff, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 80 | proto=d)]) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 81 | r.add_vpp_config() |
| 82 | self.net_objs.append(r) |
| 83 | |
| 84 | self.logger.info(self.vapi.ppcli("show ipsec all")) |
| 85 | |
| 86 | def unconfig_network(self): |
| 87 | for o in reversed(self.net_objs): |
| 88 | o.remove_vpp_config() |
| 89 | self.net_objs = [] |
| 90 | |
| 91 | def config_esp_tun(self, params): |
| 92 | addr_type = params.addr_type |
| 93 | scapy_tun_sa_id = params.scapy_tun_sa_id |
| 94 | scapy_tun_spi = params.scapy_tun_spi |
| 95 | vpp_tun_sa_id = params.vpp_tun_sa_id |
| 96 | vpp_tun_spi = params.vpp_tun_spi |
| 97 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 98 | auth_key = params.auth_key |
| 99 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 100 | crypt_key = params.crypt_key |
| 101 | remote_tun_if_host = params.remote_tun_if_host |
| 102 | addr_any = params.addr_any |
| 103 | addr_bcast = params.addr_bcast |
| 104 | e = VppEnum.vl_api_ipsec_spd_action_t |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 105 | flags = params.flags |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 106 | salt = params.salt |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 107 | objs = [] |
| 108 | |
| 109 | params.tun_sa_in = VppIpsecSA(self, scapy_tun_sa_id, scapy_tun_spi, |
| 110 | auth_algo_vpp_id, auth_key, |
| 111 | crypt_algo_vpp_id, crypt_key, |
| 112 | self.vpp_esp_protocol, |
| 113 | self.tun_if.local_addr[addr_type], |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 114 | self.tun_if.remote_addr[addr_type], |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 115 | flags=flags, |
| 116 | salt=salt) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 117 | params.tun_sa_out = VppIpsecSA(self, vpp_tun_sa_id, vpp_tun_spi, |
| 118 | auth_algo_vpp_id, auth_key, |
| 119 | crypt_algo_vpp_id, crypt_key, |
| 120 | self.vpp_esp_protocol, |
| 121 | self.tun_if.remote_addr[addr_type], |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 122 | self.tun_if.local_addr[addr_type], |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 123 | flags=flags, |
| 124 | salt=salt) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 125 | objs.append(params.tun_sa_in) |
| 126 | objs.append(params.tun_sa_out) |
| 127 | |
| 128 | params.spd_policy_in_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 129 | scapy_tun_sa_id, |
| 130 | addr_any, addr_bcast, |
| 131 | addr_any, addr_bcast, |
| 132 | socket.IPPROTO_ESP) |
| 133 | params.spd_policy_out_any = VppIpsecSpdEntry(self, self.tun_spd, |
| 134 | scapy_tun_sa_id, |
| 135 | addr_any, addr_bcast, |
| 136 | addr_any, addr_bcast, |
| 137 | socket.IPPROTO_ESP, |
| 138 | is_outbound=0) |
| 139 | objs.append(params.spd_policy_out_any) |
| 140 | objs.append(params.spd_policy_in_any) |
| 141 | |
| 142 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 143 | remote_tun_if_host, remote_tun_if_host, |
| 144 | self.pg1.remote_addr[addr_type], |
| 145 | self.pg1.remote_addr[addr_type], |
| 146 | 0, |
| 147 | priority=10, |
| 148 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 149 | is_outbound=0)) |
| 150 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 151 | self.pg1.remote_addr[addr_type], |
| 152 | self.pg1.remote_addr[addr_type], |
| 153 | remote_tun_if_host, remote_tun_if_host, |
| 154 | 0, |
| 155 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 156 | priority=10)) |
| 157 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, vpp_tun_sa_id, |
| 158 | remote_tun_if_host, remote_tun_if_host, |
| 159 | self.pg0.local_addr[addr_type], |
| 160 | self.pg0.local_addr[addr_type], |
| 161 | 0, |
| 162 | priority=20, |
| 163 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 164 | is_outbound=0)) |
| 165 | objs.append(VppIpsecSpdEntry(self, self.tun_spd, scapy_tun_sa_id, |
| 166 | self.pg0.local_addr[addr_type], |
| 167 | self.pg0.local_addr[addr_type], |
| 168 | remote_tun_if_host, remote_tun_if_host, |
| 169 | 0, |
| 170 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 171 | priority=20)) |
| 172 | for o in objs: |
| 173 | o.add_vpp_config() |
| 174 | self.net_objs = self.net_objs + objs |
| 175 | |
| 176 | def config_esp_tra(self, params): |
| 177 | addr_type = params.addr_type |
| 178 | scapy_tra_sa_id = params.scapy_tra_sa_id |
| 179 | scapy_tra_spi = params.scapy_tra_spi |
| 180 | vpp_tra_sa_id = params.vpp_tra_sa_id |
| 181 | vpp_tra_spi = params.vpp_tra_spi |
| 182 | auth_algo_vpp_id = params.auth_algo_vpp_id |
| 183 | auth_key = params.auth_key |
| 184 | crypt_algo_vpp_id = params.crypt_algo_vpp_id |
| 185 | crypt_key = params.crypt_key |
| 186 | addr_any = params.addr_any |
| 187 | addr_bcast = params.addr_bcast |
| 188 | flags = (VppEnum.vl_api_ipsec_sad_flags_t. |
| 189 | IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY) |
| 190 | e = VppEnum.vl_api_ipsec_spd_action_t |
| 191 | flags = params.flags | flags |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 192 | salt = params.salt |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 193 | objs = [] |
| 194 | |
| 195 | params.tra_sa_in = VppIpsecSA(self, scapy_tra_sa_id, scapy_tra_spi, |
| 196 | auth_algo_vpp_id, auth_key, |
| 197 | crypt_algo_vpp_id, crypt_key, |
| 198 | self.vpp_esp_protocol, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 199 | flags=flags, |
| 200 | salt=salt) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 201 | params.tra_sa_out = VppIpsecSA(self, vpp_tra_sa_id, vpp_tra_spi, |
| 202 | auth_algo_vpp_id, auth_key, |
| 203 | crypt_algo_vpp_id, crypt_key, |
| 204 | self.vpp_esp_protocol, |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 205 | flags=flags, |
| 206 | salt=salt) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 207 | objs.append(params.tra_sa_in) |
| 208 | objs.append(params.tra_sa_out) |
| 209 | |
| 210 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 211 | addr_any, addr_bcast, |
| 212 | addr_any, addr_bcast, |
| 213 | socket.IPPROTO_ESP)) |
| 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 | is_outbound=0)) |
| 219 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, vpp_tra_sa_id, |
| 220 | self.tra_if.local_addr[addr_type], |
| 221 | self.tra_if.local_addr[addr_type], |
| 222 | self.tra_if.remote_addr[addr_type], |
| 223 | self.tra_if.remote_addr[addr_type], |
| 224 | 0, priority=10, |
| 225 | policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 226 | is_outbound=0)) |
| 227 | objs.append(VppIpsecSpdEntry(self, self.tra_spd, scapy_tra_sa_id, |
| 228 | self.tra_if.local_addr[addr_type], |
| 229 | self.tra_if.local_addr[addr_type], |
| 230 | self.tra_if.remote_addr[addr_type], |
| 231 | self.tra_if.remote_addr[addr_type], |
| 232 | 0, policy=e.IPSEC_API_SPD_ACTION_PROTECT, |
| 233 | priority=10)) |
| 234 | for o in objs: |
| 235 | o.add_vpp_config() |
| 236 | self.net_objs = self.net_objs + objs |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 237 | |
| 238 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 239 | class TemplateIpsecEsp(ConfigIpsecESP): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 240 | """ |
| 241 | Basic test for ipsec esp sanity - tunnel and transport modes. |
| 242 | |
| 243 | Below 4 cases are covered as part of this test |
| 244 | 1) ipsec esp v4 transport basic test - IPv4 Transport mode |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 245 | scenario using HMAC-SHA1-96 integrity algo |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 246 | 2) ipsec esp v4 transport burst test |
| 247 | Above test for 257 pkts |
| 248 | 3) ipsec esp 4o4 tunnel basic test - IPv4 Tunnel mode |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 249 | scenario using HMAC-SHA1-96 integrity algo |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 250 | 4) ipsec esp 4o4 tunnel burst test |
| 251 | Above test for 257 pkts |
| 252 | |
| 253 | TRANSPORT MODE: |
| 254 | |
| 255 | --- encrypt --- |
| 256 | |pg2| <-------> |VPP| |
| 257 | --- decrypt --- |
| 258 | |
| 259 | TUNNEL MODE: |
| 260 | |
| 261 | --- encrypt --- plain --- |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 262 | |pg0| <------- |VPP| <------ |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 263 | --- --- --- |
| 264 | |
| 265 | --- decrypt --- plain --- |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 266 | |pg0| -------> |VPP| ------> |pg1| |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 267 | --- --- --- |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 268 | """ |
| 269 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 270 | @classmethod |
| 271 | def setUpClass(cls): |
| 272 | super(TemplateIpsecEsp, cls).setUpClass() |
| 273 | |
| 274 | @classmethod |
| 275 | def tearDownClass(cls): |
| 276 | super(TemplateIpsecEsp, cls).tearDownClass() |
| 277 | |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 278 | def setUp(self): |
| 279 | super(TemplateIpsecEsp, self).setUp() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 280 | self.config_network(self.params.values()) |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 281 | |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 282 | def tearDown(self): |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 283 | self.unconfig_network() |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 284 | super(TemplateIpsecEsp, self).tearDown() |
Neale Ranns | 8e4a89b | 2019-01-23 08:16:17 -0800 | [diff] [blame] | 285 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 286 | |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 287 | class TestIpsecEsp1(TemplateIpsecEsp, IpsecTra46Tests, IpsecTun46Tests): |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 288 | """ Ipsec ESP - TUN & TRA tests """ |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 289 | pass |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 290 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 291 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 292 | class TestIpsecEsp2(TemplateIpsecEsp, IpsecTcpTests): |
| 293 | """ Ipsec ESP - TCP tests """ |
| 294 | pass |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 295 | |
| 296 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 297 | class TemplateIpsecEspUdp(ConfigIpsecESP): |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 298 | """ |
| 299 | UDP encapped ESP |
| 300 | """ |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 301 | |
| 302 | @classmethod |
| 303 | def setUpClass(cls): |
| 304 | super(TemplateIpsecEspUdp, cls).setUpClass() |
| 305 | |
| 306 | @classmethod |
| 307 | def tearDownClass(cls): |
| 308 | super(TemplateIpsecEspUdp, cls).tearDownClass() |
| 309 | |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 310 | def setUp(self): |
| 311 | super(TemplateIpsecEspUdp, self).setUp() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 312 | self.net_objs = [] |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 313 | self.tun_if = self.pg0 |
| 314 | self.tra_if = self.pg2 |
| 315 | self.logger.info(self.vapi.ppcli("show int addr")) |
| 316 | |
| 317 | p = self.ipv4_params |
| 318 | p.flags = (VppEnum.vl_api_ipsec_sad_flags_t. |
| 319 | IPSEC_API_SAD_FLAG_UDP_ENCAP) |
| 320 | p.nat_header = UDP(sport=5454, dport=4500) |
| 321 | |
| 322 | self.tra_spd = VppIpsecSpd(self, self.tra_spd_id) |
| 323 | self.tra_spd.add_vpp_config() |
| 324 | VppIpsecSpdItfBinding(self, self.tra_spd, |
| 325 | self.tra_if).add_vpp_config() |
| 326 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 327 | self.config_esp_tra(p) |
Neale Ranns | 2ac885c | 2019-03-20 18:24:43 +0000 | [diff] [blame] | 328 | config_tra_params(p, self.encryption_type) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 329 | |
| 330 | self.tun_spd = VppIpsecSpd(self, self.tun_spd_id) |
| 331 | self.tun_spd.add_vpp_config() |
| 332 | VppIpsecSpdItfBinding(self, self.tun_spd, |
| 333 | self.tun_if).add_vpp_config() |
| 334 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 335 | self.config_esp_tun(p) |
Neale Ranns | 92e9384 | 2019-04-08 07:36:50 +0000 | [diff] [blame] | 336 | self.logger.info(self.vapi.ppcli("show ipsec all")) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 337 | |
| 338 | d = DpoProto.DPO_PROTO_IP4 |
| 339 | VppIpRoute(self, p.remote_tun_if_host, p.addr_len, |
| 340 | [VppRoutePath(self.tun_if.remote_addr[p.addr_type], |
| 341 | 0xffffffff, |
| 342 | proto=d)]).add_vpp_config() |
| 343 | |
| 344 | def tearDown(self): |
| 345 | super(TemplateIpsecEspUdp, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 346 | |
| 347 | def show_commands_at_teardown(self): |
| 348 | self.logger.info(self.vapi.cli("show hardware")) |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 349 | |
| 350 | |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 351 | class TestIpsecEspUdp(TemplateIpsecEspUdp, IpsecTra4Tests): |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 352 | """ Ipsec NAT-T ESP UDP tests """ |
Neale Ranns | 53f526b | 2019-02-25 14:32:02 +0000 | [diff] [blame] | 353 | pass |
| 354 | |
| 355 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 356 | class TestIpsecEspAll(ConfigIpsecESP, |
| 357 | IpsecTra4, IpsecTra6, |
| 358 | IpsecTun4, IpsecTun6): |
| 359 | """ Ipsec ESP all Algos """ |
| 360 | |
| 361 | def setUp(self): |
| 362 | super(TestIpsecEspAll, self).setUp() |
| 363 | |
| 364 | def tearDown(self): |
| 365 | super(TestIpsecEspAll, self).tearDown() |
| 366 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 367 | @parameterized.expand(["ia32", "ipsecmb", "openssl"]) |
| 368 | def test_crypto_algs(self, engine): |
Dmitry Vakhrushev | 77cc14a | 2019-08-14 00:12:33 -0400 | [diff] [blame] | 369 | """AES-[CBC, GCM]-[128, 192, 256] 3DES-CBC SHA1 MD5 w/ & w/o ESN""" |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 370 | |
| 371 | # foreach crypto algorithm |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 372 | algos = [{'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 373 | IPSEC_API_CRYPTO_ALG_AES_GCM_128), |
| 374 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 375 | IPSEC_API_INTEG_ALG_NONE), |
| 376 | 'scapy-crypto': "AES-GCM", |
| 377 | 'scapy-integ': "NULL", |
| 378 | 'key': "JPjyOWBeVEQiMe7h", |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 379 | 'salt': 0}, |
| 380 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 381 | IPSEC_API_CRYPTO_ALG_AES_GCM_192), |
| 382 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 383 | IPSEC_API_INTEG_ALG_NONE), |
| 384 | 'scapy-crypto': "AES-GCM", |
| 385 | 'scapy-integ': "NULL", |
| 386 | 'key': "JPjyOWBeVEQiMe7h01234567", |
| 387 | 'salt': 1010}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 388 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 389 | IPSEC_API_CRYPTO_ALG_AES_GCM_256), |
| 390 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 391 | IPSEC_API_INTEG_ALG_NONE), |
| 392 | 'scapy-crypto': "AES-GCM", |
| 393 | 'scapy-integ': "NULL", |
| 394 | 'key': "JPjyOWBeVEQiMe7h0123456787654321", |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 395 | 'salt': 2020}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 396 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 397 | IPSEC_API_CRYPTO_ALG_AES_CBC_128), |
| 398 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
Dmitry Vakhrushev | 77cc14a | 2019-08-14 00:12:33 -0400 | [diff] [blame] | 399 | IPSEC_API_INTEG_ALG_MD5_96), |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 400 | 'scapy-crypto': "AES-CBC", |
Dmitry Vakhrushev | 77cc14a | 2019-08-14 00:12:33 -0400 | [diff] [blame] | 401 | 'scapy-integ': "HMAC-MD5-96", |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 402 | 'salt': 0, |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 403 | 'key': "JPjyOWBeVEQiMe7h"}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 404 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 405 | IPSEC_API_CRYPTO_ALG_AES_CBC_192), |
| 406 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 407 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 408 | 'scapy-crypto': "AES-CBC", |
| 409 | 'scapy-integ': "HMAC-SHA1-96", |
Neale Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 410 | 'salt': 0, |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 411 | 'key': "JPjyOWBeVEQiMe7hJPjyOWBe"}, |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 412 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 413 | IPSEC_API_CRYPTO_ALG_AES_CBC_256), |
| 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 Ranns | 80f6fd5 | 2019-04-16 02:41:34 +0000 | [diff] [blame] | 418 | 'salt': 0, |
Vladimir Ratnikov | f480507 | 2019-05-17 09:17:59 -0400 | [diff] [blame] | 419 | 'key': "JPjyOWBeVEQiMe7hJPjyOWBeVEQiMe7h"}, |
| 420 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 421 | IPSEC_API_CRYPTO_ALG_3DES_CBC), |
| 422 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 423 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 424 | 'scapy-crypto': "3DES", |
| 425 | 'scapy-integ': "HMAC-SHA1-96", |
| 426 | 'salt': 0, |
Neale Ranns | 2cdcd0c | 2019-08-27 12:26:14 +0000 | [diff] [blame] | 427 | 'key': "JPjyOWBeVEQiMe7h00112233"}, |
| 428 | {'vpp-crypto': (VppEnum.vl_api_ipsec_crypto_alg_t. |
| 429 | IPSEC_API_CRYPTO_ALG_NONE), |
| 430 | 'vpp-integ': (VppEnum.vl_api_ipsec_integ_alg_t. |
| 431 | IPSEC_API_INTEG_ALG_SHA1_96), |
| 432 | 'scapy-crypto': "NULL", |
| 433 | 'scapy-integ': "HMAC-SHA1-96", |
| 434 | 'salt': 0, |
Vladimir Ratnikov | f480507 | 2019-05-17 09:17:59 -0400 | [diff] [blame] | 435 | 'key': "JPjyOWBeVEQiMe7h00112233"}] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 436 | |
Neale Ranns | 49e7ef6 | 2019-04-10 17:24:29 +0000 | [diff] [blame] | 437 | # with and without ESN |
| 438 | flags = [0, |
| 439 | VppEnum.vl_api_ipsec_sad_flags_t.IPSEC_API_SAD_FLAG_USE_ESN] |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 440 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 441 | self.vapi.cli("set crypto handler all %s" % engine) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 442 | # |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 443 | # loop through each of the algorithms |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 444 | # |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 445 | for algo in algos: |
| 446 | # with self.subTest(algo=algo['scapy']): |
| 447 | for flag in flags: |
| 448 | # |
| 449 | # setup up the config paramters |
| 450 | # |
| 451 | self.ipv4_params = IPsecIPv4Params() |
| 452 | self.ipv6_params = IPsecIPv6Params() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 453 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 454 | self.params = {self.ipv4_params.addr_type: |
| 455 | self.ipv4_params, |
| 456 | self.ipv6_params.addr_type: |
| 457 | self.ipv6_params} |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 458 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 459 | for _, p in self.params.items(): |
| 460 | p.auth_algo_vpp_id = algo['vpp-integ'] |
| 461 | p.crypt_algo_vpp_id = algo['vpp-crypto'] |
| 462 | p.crypt_algo = algo['scapy-crypto'] |
| 463 | p.auth_algo = algo['scapy-integ'] |
| 464 | p.crypt_key = algo['key'] |
| 465 | p.salt = algo['salt'] |
| 466 | p.flags = p.flags | flag |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 467 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 468 | self.reporter.send_keep_alive(self) |
juraj.linkes | 1105766 | 2019-07-08 10:22:55 +0200 | [diff] [blame] | 469 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 470 | # |
| 471 | # configure the SPDs. SAs, etc |
| 472 | # |
| 473 | self.config_network(self.params.values()) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 474 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 475 | # |
| 476 | # run some traffic. |
| 477 | # An exhautsive 4o6, 6o4 is not necessary |
| 478 | # for each algo |
| 479 | # |
| 480 | self.verify_tra_basic6(count=NUM_PKTS) |
| 481 | self.verify_tra_basic4(count=NUM_PKTS) |
| 482 | self.verify_tun_66(self.params[socket.AF_INET6], |
| 483 | count=NUM_PKTS) |
| 484 | self.verify_tun_44(self.params[socket.AF_INET], |
| 485 | count=NUM_PKTS) |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 486 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 487 | # |
| 488 | # remove the SPDs, SAs, etc |
| 489 | # |
| 490 | self.unconfig_network() |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 491 | |
Neale Ranns | 00625a6 | 2019-07-31 00:13:18 -0700 | [diff] [blame] | 492 | # |
| 493 | # reconfigure the network and SA to run the |
| 494 | # anti replay tests |
| 495 | # |
| 496 | self.config_network(self.params.values()) |
| 497 | self.verify_tra_anti_replay() |
| 498 | self.unconfig_network() |
Neale Ranns | 6afaae1 | 2019-07-17 15:07:14 +0000 | [diff] [blame] | 499 | |
Neale Ranns | 4f33c80 | 2019-04-10 12:39:10 +0000 | [diff] [blame] | 500 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 501 | if __name__ == '__main__': |
| 502 | unittest.main(testRunner=VppTestRunner) |