idnits 2.17.1 draft-ietf-ipsecme-esp-null-heuristics-06.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** You're using the IETF Trust Provisions' Section 6.b License Notice from 12 Sep 2009 rather than the newer Notice from 28 Dec 2009. (See https://trustee.ietf.org/license-info/) Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 1344 has weird spacing: '...lure if it is...' -- The document date (February 26, 2010) is 5174 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- -- Obsolete informational reference (is this intentional?): RFC 4835 (Obsoleted by RFC 7321) -- Obsolete informational reference (is this intentional?): RFC 4960 (Obsoleted by RFC 9260) Summary: 1 error (**), 0 flaws (~~), 2 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 IP Security Maintenance and T. Kivinen 3 Extensions (ipsecme) Safenet, Inc. 4 Internet-Draft D. McDonald 5 Intended status: Informational Sun Microsystems, Inc. 6 Expires: August 30, 2010 February 26, 2010 8 Heuristics for Detecting ESP-NULL packets 9 draft-ietf-ipsecme-esp-null-heuristics-06.txt 11 Abstract 13 This document describes a set of heuristics for distinguishing IPsec 14 ESP-NULL (Encapsulating Security Payload without encryption) packets 15 from encrypted ESP packets. These heuristics can be used on 16 intermediate devices, like traffic analyzers, and deep inspection 17 engines, to quickly decide whether given packet flow is interesting 18 or not. Use of these heuristics does not require any changes made on 19 existing RFC4303 compliant IPsec hosts. 21 Status of this Memo 23 This Internet-Draft is submitted to IETF in full conformance with the 24 provisions of BCP 78 and BCP 79. 26 Internet-Drafts are working documents of the Internet Engineering 27 Task Force (IETF), its areas, and its working groups. Note that 28 other groups may also distribute working documents as Internet- 29 Drafts. 31 Internet-Drafts are draft documents valid for a maximum of six months 32 and may be updated, replaced, or obsoleted by other documents at any 33 time. It is inappropriate to use Internet-Drafts as reference 34 material or to cite them other than as "work in progress." 36 The list of current Internet-Drafts can be accessed at 37 http://www.ietf.org/ietf/1id-abstracts.txt. 39 The list of Internet-Draft Shadow Directories can be accessed at 40 http://www.ietf.org/shadow.html. 42 This Internet-Draft will expire on August 30, 2010. 44 Copyright Notice 46 Copyright (c) 2010 IETF Trust and the persons identified as the 47 document authors. All rights reserved. 49 This document is subject to BCP 78 and the IETF Trust's Legal 50 Provisions Relating to IETF Documents 51 (http://trustee.ietf.org/license-info) in effect on the date of 52 publication of this document. Please review these documents 53 carefully, as they describe your rights and restrictions with respect 54 to this document. Code Components extracted from this document must 55 include Simplified BSD License text as described in Section 4.e of 56 the Trust Legal Provisions and are provided without warranty as 57 described in the BSD License. 59 Table of Contents 61 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3 62 1.1. Applicability: Heuristic Traffic Inspection and 63 Wrapped ESP . . . . . . . . . . . . . . . . . . . . . . . 4 64 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 4 65 2. Other Options . . . . . . . . . . . . . . . . . . . . . . . . 6 66 2.1. AH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 67 2.2. Mandating by Policy . . . . . . . . . . . . . . . . . . . 6 68 2.3. Modifying ESP . . . . . . . . . . . . . . . . . . . . . . 7 69 3. Description of Heuristics . . . . . . . . . . . . . . . . . . 8 70 4. IPsec flows . . . . . . . . . . . . . . . . . . . . . . . . . 9 71 5. Deep Inspection Engine . . . . . . . . . . . . . . . . . . . . 11 72 6. Special and Error Cases . . . . . . . . . . . . . . . . . . . 12 73 7. UDP encapsulation . . . . . . . . . . . . . . . . . . . . . . 13 74 8. Heuristic Checks . . . . . . . . . . . . . . . . . . . . . . . 14 75 8.1. ESP-NULL format . . . . . . . . . . . . . . . . . . . . . 14 76 8.2. Self Describing Padding Check . . . . . . . . . . . . . . 16 77 8.3. Protocol Checks . . . . . . . . . . . . . . . . . . . . . 18 78 8.3.1. TCP checks . . . . . . . . . . . . . . . . . . . . . . 18 79 8.3.2. UDP checks . . . . . . . . . . . . . . . . . . . . . . 19 80 8.3.3. ICMP checks . . . . . . . . . . . . . . . . . . . . . 20 81 8.3.4. SCTP checks . . . . . . . . . . . . . . . . . . . . . 20 82 8.3.5. IPv4 and IPv6 Tunnel checks . . . . . . . . . . . . . 20 83 9. Security Considerations . . . . . . . . . . . . . . . . . . . 21 84 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 22 85 11. References . . . . . . . . . . . . . . . . . . . . . . . . . . 23 86 11.1. Normative References . . . . . . . . . . . . . . . . . . . 23 87 11.2. Informative References . . . . . . . . . . . . . . . . . . 23 88 Appendix A. Example Pseudocode . . . . . . . . . . . . . . . . . 25 89 A.1. Fastpath . . . . . . . . . . . . . . . . . . . . . . . . . 25 90 A.2. Slowpath . . . . . . . . . . . . . . . . . . . . . . . . . 27 91 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 37 93 1. Introduction 95 The ESP (Encapsulating Security Payload [RFC4303]) protocol can be 96 used with NULL encryption [RFC2410] to provide authentication, 97 integrity protection, and optionally replay detection; but not 98 confidentiality. NULL encryption with ESP (referred to as ESP-NULL) 99 offers similar properties to IPsec's AH (Authentication Header 100 [RFC4302]). One reason to use ESP-NULL instead of AH is that AH 101 cannot be used if there are NATs (Network Address Translation 102 devices) on the path. With AH it would be easy to detect packets 103 which have only authentication and integrity protection, as AH has 104 its own protocol number and deterministic packet length. With ESP- 105 NULL such detection is nondeterministic, in spite of the base ESP 106 packet format being fixed. 108 In some cases intermediate devices would like to detect ESP-NULL 109 packets so they could perform deep inspection or enforce access 110 control. This kind of deep inspection includes virus detection, spam 111 filtering, and intrusion detection. As end nodes might be able to 112 bypass those checks by using encrypted ESP instead of ESP-NULL, these 113 kinds of scenarios also require very specific policies to forbid such 114 circumvention. 116 These sorts of policy requirements usually mean that the whole 117 network needs to be controlled, i.e. under the same administrative 118 domain. Such setups are usually limited to inside the network of one 119 enterprise or organization, and encryption is not used as the network 120 is considered safe enough from eavesdroppers. 122 Because the traffic inspected is usually host to host traffic inside 123 one organization, that usually means transport mode IPsec is used. 124 Note, that most of the current uses of the IPsec are not host to host 125 traffic inside one organization, but for the intended use cases for 126 the heuristics this will most likely be the case. Also tunnel mode 127 case is much easier to solve than transport mode as it is much easier 128 to detect the IP header inside the ESP-NULL packet. 130 It should also be noted that even if new protocol modifications for 131 ESP support easier detection of ESP-NULL in the future, this document 132 will aid in transition of older end-systems. That way, a solution 133 can be implemented immediately, and not after a 5-10 year upgrade- 134 and-deployment time frame. Even with protocol modification for end 135 nodes, the intermediate devices will need heuristics until they can 136 assume that those protocol modifications can be found from all the 137 end devices. To make sure that any solution does not break in the 138 future it would be best if such heuristics are documented - i.e. 139 publishing an RFC for what to do now, even when there might be a new 140 protocol coming in the future that will solve the same problem 141 better. 143 1.1. Applicability: Heuristic Traffic Inspection and Wrapped ESP 145 There are two ways to enable intermediate security devices to 146 distinguish between encrypted and unencrypted ESP traffic: 148 o The heuristics approach has the intermediate node inspect the 149 unchanged ESP traffic, to determine with extremely high 150 probability whether or not the traffic stream is encrypted. 152 o The Wrapped ESP approach [I-D.ietf-ipsecme-traffic-visibility], in 153 contrast, requires the ESP endpoints to be modified to support the 154 new protocol. WESP allows the intermediate node to distinguish 155 encrypted and unencrypted traffic deterministically, using a 156 simpler implementation for the intermediate node. 158 Both approaches are being documented simultaneously by the IPsecME 159 Working Group, with WESP being put on Standards Track while the 160 heuristics approach is being published as an Informational RFC. 161 While endpoints are being modified to adopt WESP, both approaches 162 will likely coexist for years, because the heuristic approach is 163 needed to inspect traffic where at least one of the endpoints has not 164 been modified. In other words, intermediate nodes are expected to 165 support both approaches in order to achieve good security and 166 performance during the transition period. 168 1.2. Terminology 170 This document uses following terminology: 172 Flow 174 A TCP/UDP or IPsec flow is a stream of packets part of the same 175 TCP/UDP or IPsec stream, i.e. TCP or UDP flow is a stream of 176 packets having same 5 tuple (source and destination IP and port, 177 and TCP/UDP protocol). Note, that this kind of flow is also 178 called microflow in some documents. 180 Flow Cache 182 Deep inspection engines and similar devices use a cache of flows 183 going through the device, and that cache keeps state of all flows 184 going through the device. 186 IPsec Flow 188 An IPsec flow is a stream of packets sharing the same source IP, 189 destination IP, protocol (ESP/AH) and SPI. Strictly speaking, the 190 source IP does not need to be as part of the flow identification, 191 but it can be. For this reason, it is safer to assume that the 192 source IP is always part of the flow identification. 194 2. Other Options 196 This document will discuss the heuristic approach of detecting ESP- 197 NULL packets. There are some other options which can be used, and 198 this section will briefly discuss them. 200 2.1. AH 202 The most logical approach would use the already defined protocol 203 which offers authentication and integrity protection, but not 204 confidentiality, namely AH. AH traffic is clearly marked as not 205 encrypted, and can always be inspected by intermediate devices. 207 Using AH has two problems. First is that, as it also protects the IP 208 headers, it will also protect against NATs on the path, thus it will 209 not work if there is NAT on the path between end nodes. In some 210 environments this might not be a problem, but some environments 211 include heavy use of NATs even inside the internal network of the 212 enterprise or organization. NAT-Traversal (NAT-T, [RFC3948]) could 213 be extended to support AH also, and the early versions of the NAT-T 214 proposals did include that, but it was left out as it was not seen as 215 necessary. 217 Another problem is that in the new IPsec Architecture [RFC4301] the 218 support for AH is now optional, meaning not all implementations 219 support it. ESP-NULL has been defined to be mandatory to implement 220 by the Cryptographic Algorithm Implementation Requirements for 221 Encapsulating Security Payload (ESP) document [RFC4835]. 223 AH has also quite complex processing rules compared to ESP when 224 calculating the ICV, including things like zeroing out mutable 225 fields. Also as AH is not as widely used than ESP, the AH support is 226 not as well tested in the interoperability events. 228 2.2. Mandating by Policy 230 Another easy way to solve this problem is to mandate the use of ESP- 231 NULL with common parameters within an entire organization. This 232 either removes the need for heuristics (if no ESP encrypted traffic 233 is allowed at all) or simplifies them considerably (only one set of 234 parameters needs to be inspected, e.g. everybody in the organization 235 who is using ESP-NULL must use HMAC-SHA-1-96 as their integrity 236 algorithm). This does work unless one of a pair of communicating 237 machines is not under the same administrative domain as the deep 238 inspection engine. (IPsec Security Associations must be satisfactory 239 to all communicating parties, so only one communicating peer needs to 240 have a sufficiently narrow policy.) Also, such a solution might 241 require some kind of centralized policy management to make sure 242 everybody in an administrative domain uses the same policy, and that 243 changes to that single policy can be coordinated throughout the 244 administrative domain. 246 2.3. Modifying ESP 248 Several internet drafts discuss ways of modifying ESP to offer 249 intermediate devices information about an ESP packet's use of NULL 250 encryption. The following methods have been discussed: adding an IP- 251 option, adding a new IP-protocol number plus an extra header 252 [I-D.ietf-ipsecme-traffic-visibility], adding new IP-protocol numbers 253 which tell the ESP-NULL parameters [I-D.hoffman-esp-null-protocol], 254 reserving an SPI range for ESP-NULL [I-D.bhatia-ipsecme-esp-null], 255 and using UDP encapsulation with a different format and ports. 257 All of the aforementioned drafts require modification to ESP, which 258 requires that all end nodes need to be modified before intermediate 259 devices can assume that this new ESP format is in use. Updating end 260 nodes will require lots of time. An example of slow end-node 261 deployment is IKEv2. Considering an implementation that requires 262 both IKEv2 and a new ESP format, it would take several years, 263 possibly as long as a decade, before widespread deployment. 265 3. Description of Heuristics 267 The heuristics to detect ESP-NULL packets will only require changes 268 to those intermediate devices which do deep inspection or other 269 operations which require detecting ESP-NULL. As those nodes require 270 changes regardless of any ESP-NULL method, updating intermediate 271 nodes is unavoidable. Heuristics do not require updating or 272 modifying any other devices on the rest of the network, including 273 (especially) end-nodes. 275 In this document it is assumed that an affected intermediate node 276 will act as a stateful interception device, meaning it will keep 277 state of the IPsec flows - where flows are defined by the ESP SPI and 278 IP addresses forming an IPsec SA - going through it. The heuristics 279 can also be used without storing any state, but performance will be 280 worse in that case, as heuristic checks will need to be done for each 281 packet, not only once per flow. This will also affect the 282 reliability of the heuristics. 284 Generally, an intermediate node runs heuristics only for the first 285 few packets of the new flow (i.e. the new IPsec SA). After those few 286 packets, the node detects parameters of the IPsec flow, it skips 287 detection heuristics, and it can perform direct packet-inspecting 288 action based on its own policy. Once detected, ESP-NULL packets will 289 never be detected as encrypted ESP packets, meaning that valid ESP- 290 NULL packets will never bypass the deep inspection. The only failure 291 mode of these heuristics is to assume encrypted ESP packets are ESP- 292 NULL packets, thus causing completely random packet data to be deeply 293 inspected. An attacker can easily send random-looking ESP-NULL 294 packets which will cause heuristics to detect packets as encrypted 295 ESP, but that is no worse than sending non-ESP fuzz through an 296 intermediate node. 298 For hardware implementations all the flow lookup based on the ESP 299 next header number (50), source address, destination address, and SPI 300 can be done by the hardware (there is usually already similar 301 functionality there, for TCP/UDP flows). The heuristics can be 302 implemented by the hardware, but using software will allow faster 303 updates when new protocol modifications come out or new protocols 304 need support. 306 As described in Section 7, UDP encapsulated ESP traffic may also have 307 have NAPT applied to it, and so there is already a 5-tuple state in 308 the stateful inspection gateway. 310 4. IPsec flows 312 ESP is a stateful protocol, meaning there is state stored in both end 313 nodes of the ESP IPsec SA, and the state is identified by the pair of 314 destination IP and SPI. End nodes also often fix the source IP 315 address in an SA unless the destination is a multicast group. 316 Typically most (if not all) flows of interest to an intermediate 317 device are unicast, so it is safer to assume the receiving node also 318 uses a source address, and the intermediate device should therefore 319 do the same. In some cases this might cause extraneous cached ESP 320 IPsec SA flows, but by using the source address two distinct flows 321 will never be mixed. For sites which heavily use multicast, such 322 traffic is deterministically identifiable (224.0.0.0/4 for IPv4 and 323 ff00::0/8 for IPv6), and an implementation can save the space of 324 multiple cache entries for a multicast flow by checking the 325 destination address first. 327 When the intermediate device sees a new ESP IPsec flow, i.e. a new 328 flow of ESP packets where the source address, destination address, 329 and SPI number forms a triplet which has not been cached, it will 330 start the heuristics to detect whether this flow is ESP-NULL or not. 331 These heuristics appear in Section 8. 333 When the heuristics finish, they will label the flow as either 334 encrypted (which tells that packets in this flow are encrypted, and 335 cannot be ESP-NULL packets) or as ESP-NULL. This information, along 336 with the ESP-NULL parameters detected by the heuristics, is stored to 337 a flow cache, which will be used in the future when processing 338 packets of the same flow. 340 Both encrypted ESP and ESP-NULL flows are processed based on the 341 local policy. In normal operation encrypted ESP flows are passed 342 through or dropped per local policy, and ESP-NULL flows are passed to 343 the deep inspection engine. Local policy will also be used to 344 determine other packet-processing parameters. Local policy issues 345 will be clearly marked in this document to ease implementation. 347 In some cases the heuristics cannot determine the type of flow from a 348 single packet, and in that case it might need multiple packets before 349 it can finish the process. In those cases the heuristics return 350 "unsure" status. In that case the packet processed based on the 351 local policy and flow cache is updated with "unsure" status. Local 352 policy for "unsure" packets could range from dropping (which 353 encourages end-node retransmission) to queuing (which may preserve 354 delivery, at the cost of artificially inflating round-trip times if 355 they are measured). When the next packet to the flow arrives, it is 356 heuristically processed again, and the cached flow may continue to be 357 "unsure", marked as ESP, or marked as an ESP-NULL flow. 359 There are several reasons why a single packet might not be enough to 360 detect type of flow. One of them is that the next header number was 361 unknown, i.e. if heuristics do not know about the protocol for the 362 packet, it cannot verify it has properly detected ESP-NULL 363 parameters, even when the packet otherwise looks like ESP-NULL. If 364 the packet does not look like ESP-NULL at all, then encrypted ESP 365 status can be returned quickly. As ESP-NULL heuristics need to know 366 the same protocols as a deep inspection device, an ESP-NULL instance 367 of an unknown protocol can be handled the same way as a cleartext 368 instance of the same unknown protocol. 370 5. Deep Inspection Engine 372 A deep inspection engine running on an intermediate node usually 373 checks deeply into the packet and performs policy decisions based on 374 the contents of the packet. The deep inspection engine should be 375 able to tell the difference between success, failure, and garbage. 376 Success means that a packet was successfully checked with the deep 377 inspection engine, and it passed the checks and is allowed to be 378 forwarded. Failure means that a packet was successfully checked but 379 the actual checks done indicated that packets should be dropped, i.e. 380 the packet contained a virus, was a known attack, or something 381 similar. 383 Garbage means that the packet's protocol headers or other portions 384 were unparseable. For the heuristics, it would be useful if the deep 385 inspection engine can differentiate the garbage and failure cases, as 386 garbage cases can be used to detect certain error cases (e.g. where 387 the ESP-NULL parameters are incorrect, or the flow is really an 388 encrypted ESP flow, not an ESP-NULL flow). 390 If the deep inspection engine will only return failure for all 391 garbage packets in addition to real failure cases, then a system 392 implementing the ESP-NULL heuristics cannot recover from error 393 situations quickly. 395 6. Special and Error Cases 397 There is a small probability that an encrypted ESP packet (which 398 looks like it contains completely random bytes) will have plausible 399 bytes in expected locations, such that heuristics will detect the 400 packet as an ESP-NULL packet instead of detecting that it is 401 encrypted ESP packet. The actual probabilities will be computed 402 later in this document. Such a packet will not cause problems, as 403 the deep inspection engine will most likely reject the packet and 404 return that it is garbage. If the deep inspection engine is 405 rejecting a high number of packets as garbage, it might indicate an 406 original ESP-NULL detection for the flow was wrong (i.e. an encrypted 407 ESP flow was improperly detected as ESP-NULL). In that case, the 408 cached flow should be invalidated and discovery should happen again. 410 Each ESP-NULL flow should also keep statistics about how many packets 411 have been detected as garbage by deep inspection, how many have 412 passed checks, or how many have failed checks with policy violations 413 (i.e. failed because of actual inspection policy failures, not 414 because the packet looked like garbage). If the number of garbage 415 packets suddenly increases (e.g. most of the packets start to be look 416 like garbage according to the deep inspection engine), it is possible 417 the old ESP-NULL SA was replaced by an identical-SPI encrypting ESP 418 SA. If both ends use random SPI generation, this is a very unlikely 419 situation (1 in 2^32), but it is possible that some nodes reuse SPI 420 numbers (e.g. a 32-bit memory address of the SA descriptor), thus 421 this situation needs to be handled. 423 Actual limits for cache invalidation are local policy decisions. 424 Sample invalidation policies include: 50% of packets marked as 425 garbage within a second; or if a deep inspection engine cannot 426 differentiate between garbage and failure, failing more than 95% of 427 packets in last 10 seconds. For implementations that do not 428 distinguish between garbage and failure, failures should not be 429 treated too quickly as indication of SA reuse. Often, single packets 430 cause state-related errors that block otherwise normal packets from 431 passing. 433 7. UDP encapsulation 435 The flow lookup code needs to detect UDP packets to or from port 4500 436 in addition to the ESP packets, and perform similar processing to 437 them after skipping the UDP header. Port-translation by NAT often 438 rewrites what was originally 4500 into a different value, which means 439 each unique port pair constitutes a separate IPsec flow. I.e. UDP 440 encapsulated IPsec flows are identified by the source and destination 441 IP, source and destination port number and SPI number. As devices 442 might be using MOBIKE ([RFC4555]), that also means that the flow 443 cache should be shared between the UDP encapsulated IPsec flows and 444 non encapsulated IPsec flows. As previously mentioned, 445 differentiating between garbage and actual policy failures will help 446 in proper detection immensely. 448 Because the checks are run for packets having just source port 4500 449 or packets having just destination port 4500, this might cause checks 450 to be run for non-ESP traffic too. Some traffic may randomly use 451 port 4500 for other reasons, especially if a port-translating NAT is 452 involved. The UDP encapsulation processing should also be aware of 453 that possibility. 455 8. Heuristic Checks 457 Normally, HMAC-SHA1-96 or HMAC-MD5-96 gives 1 out of 2^96 probability 458 that a random packet will pass the HMAC test. This yields a 459 99.999999999999999999999999998% probability that an end node will 460 correctly detect a random packet as being invalid. This means that 461 it should be enough for an intermediate device to check around 96 462 bits from the input packet. By comparing them against known values 463 for the packet, a deep inspection engine gains more or less the same 464 probability as an end node is using. This gives an upper limit of 465 how many bits heuristics need to check - there is no point of 466 checking much more than that many bits (since that same probability 467 is acceptable for the end node). In most of the cases the 468 intermediate device does not need that high probability, perhaps 469 something around 32-64 bits is enough. 471 IPsec's ESP has a well-understood packet layout, but its variable- 472 length fields reduce the ability of pure algorithmic matching to one 473 requiring heuristics and assigning probabilities. 475 8.1. ESP-NULL format 477 The ESP-NULL format is as follows: 479 0 1 2 3 480 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 481 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 482 | Security Parameters Index (SPI) | 483 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 484 | Sequence Number | 485 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 486 | IV (optional) | 487 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 488 | Payload Data (variable) | 489 ~ ~ 490 | | 491 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 492 | | Padding (0-255 bytes) | 493 +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 494 | | Pad Length | Next Header | 495 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 496 | Integrity Check Value-ICV (variable) | 497 ~ ~ 498 | | 499 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 501 Figure 1 503 The output of the heuristics should provide information about whether 504 the packet is encrypted ESP or ESP-NULL. In case it is ESP-NULL the 505 heuristics should also provide the Integrity Check Value (ICV) field 506 length and the Initialization Vector (IV) length. 508 The currently defined ESP authentication algorithms have 4 different 509 lengths for the ICV field. 511 Different ICV lengths for different algorithm: 513 Algorithm ICV Length 514 ------------------------------- ---------- 515 AUTH_HMAC_MD5_96 96 516 AUTH_HMAC_SHA1_96 96 517 AUTH_AES_XCBC_96 96 518 AUTH_AES_CMAC_96 96 519 AUTH_HMAC_SHA2_256_128 128 520 AUTH_HMAC_SHA2_384_192 192 521 AUTH_HMAC_SHA2_512_256 256 523 Figure 2 525 In addition to the ESP authentication algorithms listed above, there 526 is also encryption algorithm ENCR_NULL_AUTH_AES_GMAC which does not 527 provide confidentiality but provides authentication, just like ESP- 528 NULL does. This algorithm has ICV Length of 128 bits, and it also 529 requires eight bytes of IV. 531 In addition to the ICV length, there are also two possible values for 532 IV lengths: zero bytes (default) and eight bytes (for 533 ENCR_NULL_AUTH_AES_GMAC). Detecting the IV length requires 534 understanding the payload, i.e. the actual protocol data (meaning 535 TCP, UDP, etc). This is required to distinguish the optional IV from 536 the actual protocol data. How well IV can be distinguished from the 537 actual protocol data depends how the IV is generated. If IV is 538 generated using a method that generates random looking data (i.e. 539 encrypted counter etc) then distinguishing protocol data from IV is 540 quite easy. If an IV is a counter or similar non-random value, then 541 there are more possibilities for error. If the protocol (also known 542 as the, "next header") of the packet is one that is not supported by 543 the heuristics, then detecting the IV length is impossible, thus the 544 heuristics cannot finish. In that case, the heuristics return 545 "unsure" and requires further packets. 547 This document does not cover RSA authentication in ESP ([RFC4359]), 548 as it is considered being beyond the scope of this document. 550 8.2. Self Describing Padding Check 552 Before obtaining the next header field, the ICV length must be 553 measured. Four different ICV lengths lead to four possible places 554 for the pad length and padding. Implementations must be careful when 555 trying larger sizes of ICV such that the inspected bytes do not 556 belong to data that is not payload data. For example, a ten-byte 557 ICMP echo request will have zero-length padding, but any checks for 558 256-bit ICVs will inspect sequence number or SPI data if the packet 559 actually contains a 96-bit or 128-bit ICV. 561 ICV lengths should always be checked from shortest to longest. It is 562 much more likely to obtain valid-looking padding bytes in the 563 cleartext part of the payload than from the ICV field of a longer ICV 564 than what is currently inspected. For example, if a packet has a 96- 565 bit ICV and the implementation starts first checking for a 256-bit 566 ICV, it is possible that the cleartext part of the payload contains 567 valid-looking bytes. If done in the other order, i.e. a packet 568 having a 256-bit ICV and the implementation checks for a 96-bit ICV 569 first, the inspected bytes are part of the longer ICV field, and 570 should be indistinguishable from random noise. 572 Each ESP packet always has between 0-255 bytes of padding, and 573 payload, pad length, and next header are always right aligned within 574 a 4-byte boundary. Normally implementations use minimal amount of 575 padding, but the heuristics method would be even more reliable if 576 some extra padding is added. The actual padding data has bytes 577 starting from 01 and ending to the pad length, i.e. exact padding and 578 pad length bytes for 4 bytes of padding would be 01 02 03 04 04. 580 Two cases of ESP-NULL padding are matched bytes (like the 04 04 shown 581 above), or the zero-byte padding case. In cases where there is one 582 or more bytes of padding, a node can perform a very simple and fast 583 test -- a sequence of N N in any of those four locations. Given four 584 two-byte locations (assuming the packet size allows all four possible 585 ICV lengths), the upper-bound probability of finding a random 586 encrypted packet that exhibits non-zero length ESP-NULL properties 587 is: 589 1 - (1 - 255 / 65536) ^ 4 == 0.015 == 1.5% 591 In the cases where there is 0 bytes of padding, a random encrypted 592 ESP packet has: 594 1 - (1 - 1 / 256) ^ 4 == 0.016 == 1.6%. 596 Together, both cases yields a 3.1% upper-bound chance of 597 misclassifying an encrypted packet as an ESP-NULL packet. 599 In the matched bytes case, further inspection (counting the pad bytes 600 backward and downward from the pad-length match) can reduce the 601 number of misclassified packets further. A padding length of 255 602 means a specific 256^254 sequence of bytes must occur. This 603 virtually eliminates pairs of 'FF FF' as viable ESP-NULL padding. 604 Every one of the 255 pairs for padding length N has only a 1 / 256^N 605 probability of being correct ESP-NULL padding. This shrinks the 606 aforementioned 1.5% of matched-pairs to virtually nothing. 608 At this point a maximum of 1.6% of possible byte values remain, so 609 the next header number is inspected. If the next header number is 610 known (and supported) then the packet can be inspected based on the 611 next header number. If the next header number is unknown (i.e. not 612 any of those with protocol checking support) the packet is marked 613 "unsure", because there is no way to detect the IV length without 614 inspecting the inner protocol payload. 616 There are six different next header fields which are in common use 617 (TCP (6), UDP (17), ICMP (1), SCTP (132), IPv4 (4) and IPv6 (41)), 618 and if IPv6 is in heavy use, that number increases to nine (Fragment 619 (44), ICMPv6 (58), and IPv6 options (60)). To ensure that no packet 620 is misinterpreted as an encrypted ESP packet even when it is an ESP- 621 NULL packet, a packet cannot be marked as a failure even when the 622 next header number is one of those which is not known and supported. 623 In those cases the packets are marked as "unsure". 625 An intermediate node's policy, however, can aid in detecting an ESP- 626 NULL flow even when the protocol is not a common-case one. By 627 counting how many "unsure" returns obtained via heuristics, and after 628 the receipt of a consistent, but unknown, next-header number in same 629 location (i.e. likely with the same ICV length), the node can 630 conclude that the flow has high probability of being ESP-NULL (since 631 it is unlikely that so many packets would pass the integrity check at 632 the destination unless they are legitimate). The flow can be 633 classified as ESP-NULL with a known ICV length, but an unknown IV 634 length. 636 Fortunately, in unknown protocol cases the IV length does not matter. 637 If the protocol is unknown to the heuristics, it will most likely be 638 unknown by the deep inspection engine also. It is therefore 639 important that heuristics should support at least those same 640 protocols as the deep inspection engine does. Upon receipt of any 641 inner next header number that is known by the heuristics (and deep 642 inspection engine), the heuristics can detect the IV length properly. 644 8.3. Protocol Checks 646 Generic protocol checking is much easier with pre-existing state. 647 For example, when many TCP / UDP flows are established over one IPsec 648 SA, a rekey produces a new SA which needs heuristics to detect its 649 parameters, and those heuristics benefit from the existing TCP / UDP 650 flows which were present in the previous IPsec SA. In that case it 651 is just enough to check that if a new IPsec SA has packets belonging 652 to the flows of some other IPsec SA (previous IPsec SA before rekey), 653 and if those flows are already known by the deep inspection engine, 654 it will give a strong indication that the new SA is really ESP-NULL. 656 The worst case scenario is when an end node starts up communication, 657 i.e. it does not have any previous flows through the device. 658 Heuristics will run on the first few packets received from the end 659 node. The later subsections mainly cover these start-up cases, as 660 they are the most difficult. 662 In the protocol checks there are two different types of checks. The 663 first check is for packet validity, i.e. certain locations must 664 contain specific values. For example, an inner IPv4 header of an 665 IPv4 tunnel packet must have its 4-bit version number set to 4. If 666 it does not, the packet is not valid, and can be marked as a failure. 667 Other positions depending on ICV and IV lengths must also be checked, 668 and if all of them are failures, then the packet is a failure. If 669 any of the checks are "unsure" the packet is marked as such. 671 The second type of check is for variable, but easy-to-parse values. 672 For example, the 4-bit header length field of an inner IPv4 packet. 673 It has a fixed value (5) as long as there are no inner IPv4 options. 674 If the header-length has that specific value, the number of known 675 "good" bits increases. If it has some other value, the known "good" 676 bit count stays the same. A local policy might include reaching a 677 bit count that is over a threshold (for example 96 bits), causing a 678 packet to be marked as valid. 680 8.3.1. TCP checks 682 When the first TCP packet is fed to the heuristics, it is most likely 683 going to be the SYN packet of the new connection, thus it will have 684 less useful information than other later packets might have. The 685 best valid packet checks include: checking that header length and 686 flags have valid values; checking source and destination port 687 numbers, which in some cases can be used for heuristics (but in 688 general they cannot be reliably distinguished from random numbers 689 apart from some well-known ports like 25/80/110/143). 691 The most obvious field, TCP checksum, might not be usable, as it is 692 possible that the packet has already transited a NAT box which 693 changed the IP addresses but assumed any ESP payload was encrypted 694 and did not fix the transport checksums with the new IP addresses. 695 Thus the IP numbers used in the checksum are wrong, thus the checksum 696 is wrong. If the checksum is correct that can again be used to 697 increase the valid bit count, but verifying checksums is a costly 698 operation, thus skipping that check might be best unless there is 699 hardware to help the calculation. Window size, urgent pointer, 700 sequence number, and acknowledgement numbers can be used, but there 701 is not one specific known value for them. 703 One good method of detection is if a packet is dropped then the next 704 packet will most likely be a retransmission of the previous packet. 705 Thus if two packets are received with the same source, and 706 destination port numbers, and where sequence numbers are either same 707 or right after each other, then it's likely a TCP packet has been 708 correctly detected. This heuristics is most helpful when only one 709 packet is outstanding. For example, if a TCP SYN packet is lost (or 710 dropped because of policy), the next packet would always be a 711 retransmission of the same TCP SYN packet. 713 Existing deep inspection engines usually do very good TCP flow 714 checking already, including flow tracking, verification of sequence 715 numbers, and reconstruction of the whole TCP flow. Similar methods 716 can be used here, but they are implementation-dependent and not 717 described here. 719 8.3.2. UDP checks 721 UDP header has even more problems than the TCP header, as UDP has 722 even less known data. The checksum has the same problem as the TCP 723 checksum, due to NATs. The UDP length field might not match the 724 overall packet length, as the sender is allowed to include TFC 725 (traffic flow confidentiality, see section 2.7 of IP Encapsulating 726 Security Payload document [RFC4303]) padding. 728 With UDP packets similar multiple packet methods can be used as with 729 TCP, as UDP protocols usually include several packets using same port 730 numbers going from one end node to another, thus receiving multiple 731 packets having a known pair of UDP port numbers is good indication 732 that the heuristics have passed. 734 Some UDP protocols also use identical source and destination port 735 numbers, thus that is also a good check. 737 8.3.3. ICMP checks 739 As ICMP messages are usually sent as return packets for other 740 packets, they are not very common packets to get as first packets for 741 the SA, the ICMP ECHO_REQUEST message being a noteworthy exception. 742 ICMP ECHO_REQUEST has a known type and code, identifier, and sequence 743 number. The checksum, however, might be incorrect again because of 744 NATs. 746 For ICMP error messages, the ICMP message contains part of the 747 original IP packet inside. Then the same rules which are used to 748 detect IPv4/IPv6 tunnel checks can be used. 750 8.3.4. SCTP checks 752 SCTP [RFC4960] has a self-contained checksum, which is computed over 753 the SCTP payload and is not affected by NATs unless the NAT is SCTP- 754 aware. Even more than the TCP and UDP checksums, the SCTP checksum 755 is expensive, and may be prohibitive even for deep-packet 756 inspections. 758 SCTP chunks can be inspected to see if their lengths are consistent 759 across the total length of the IP datagram, so long as TFC padding is 760 not present. 762 8.3.5. IPv4 and IPv6 Tunnel checks 764 In cases of tunneled traffic the packet inside contains a full IPv4 765 or IPv6 packet. Many fields are usable. For IPv4 those fields 766 include version, header length, total length (again TFC padding might 767 confuse things there), protocol number, and 16-bit header checksum. 768 In those cases the intermediate device should give the decapsulated 769 IP packet to the deep inspection engine. IPv6 has fewer usable 770 fields, but the version number, packet length (modulo TFC confusion) 771 and next-header all can be used by deep-packet inspection. 773 In both IPv4 and IPv6 the heuristics can also check the IP addresses 774 either to be in the known range (for example check that both IPv6 775 source and destination have same prefix etc), or checking addresses 776 across more than one packet. 778 9. Security Considerations 780 Attackers can always bypass ESP-NULL deep packet inspection by using 781 encrypted ESP (or some other encryption or tunneling method) instead, 782 unless the intermediate node's policy requires dropping of packets 783 that it cannot inspect. Ultimately the responsibility for performing 784 deep inspection, or allowing intermediate nodes to perform deep 785 inspection, must rest on the end nodes. I.e. if a server allows 786 encrypted connections also, then an attacker who wants to attack the 787 server and wants to bypass a deep inspection device in the middle, 788 will use encrypted traffic. This means that the protection of the 789 whole network is only as good as the policy enforcement and 790 protection of the end node. One way to enforce deep inspection for 791 all traffic, is to forbid encrypted ESP completely, in which case 792 ESP-NULL detection is easier, as all packets must be ESP-NULL based 793 on the policy, and further restrictions can eliminate ambiguities in 794 ICV and IV sizes. 796 Forcing use of ESP-NULL everywhere inside the enterprise, so that 797 accounting, logging, network monitoring, and intrusion detection all 798 work, increases the risk of sending confidential information where 799 eavesdroppers can see it. 801 10. IANA Considerations 803 No IANA assignments are needed. 805 11. References 807 11.1. Normative References 809 [RFC2410] Glenn, R. and S. Kent, "The NULL Encryption Algorithm and 810 Its Use With IPsec", RFC 2410, November 1998. 812 [RFC4301] Kent, S. and K. Seo, "Security Architecture for the 813 Internet Protocol", RFC 4301, December 2005. 815 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, 816 December 2005. 818 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 819 RFC 4303, December 2005. 821 11.2. Informative References 823 [I-D.bhatia-ipsecme-esp-null] 824 Bhatia, M., "Identifying ESP-NULL Packets", 825 draft-bhatia-ipsecme-esp-null-00 (work in progress), 826 December 2008. 828 [I-D.hoffman-esp-null-protocol] 829 Hoffman, P. and D. McGrew, "An Authentication-only Profile 830 for ESP with an IP Protocol Identifier", 831 draft-hoffman-esp-null-protocol-00 (work in progress), 832 August 2007. 834 [I-D.ietf-ipsecme-traffic-visibility] 835 Grewal, K., Montenegro, G., and M. Bhatia, "Wrapped ESP 836 for Traffic Visibility", 837 draft-ietf-ipsecme-traffic-visibility-12 (work in 838 progress), January 2010. 840 [RFC3948] Huttunen, A., Swander, B., Volpe, V., DiBurro, L., and M. 841 Stenberg, "UDP Encapsulation of IPsec ESP Packets", 842 RFC 3948, January 2005. 844 [RFC4359] Weis, B., "The Use of RSA/SHA-1 Signatures within 845 Encapsulating Security Payload (ESP) and Authentication 846 Header (AH)", RFC 4359, January 2006. 848 [RFC4555] Eronen, P., "IKEv2 Mobility and Multihoming Protocol 849 (MOBIKE)", RFC 4555, June 2006. 851 [RFC4835] Manral, V., "Cryptographic Algorithm Implementation 852 Requirements for Encapsulating Security Payload (ESP) and 853 Authentication Header (AH)", RFC 4835, April 2007. 855 [RFC4960] Stewart, R., "Stream Control Transmission Protocol", 856 RFC 4960, September 2007. 858 Appendix A. Example Pseudocode 860 This appendix is meant for the implementors. It does not include all 861 the required checks, and this is just example pseudocode, so final 862 implementation can be very different. It mostly lists things that 863 need to be done, but implementations can optimize steps depending on 864 their other parts. For example, implementation might combine 865 heuristics and deep inspection tightly together. 867 A.1. Fastpath 869 The following example pseudocode show the fastpath part of the packet 870 processing engine. This part is usually implemented in hardware. 872 //////////////////////////////////////////////////////////// 873 // This pseudocode uses following variables: 874 // 875 // SPI_offset: Number of bytes between start of protocol 876 // data and SPI. This is 0 for ESP, and 877 // 8 for UDP encapsulated ESP (i.e skipping 878 // UDP header). 879 // 880 // IV_len: Length of the IV of the ESP-NULL packet. 881 // 882 // ICV_len: Length of the ICV of the ESP-NULL packet. 883 // 884 // State: State of the packet, i.e. ESP-NULL, ESP, or 885 // unsure. 886 // 887 // Also following data is taken from the packet: 888 // 889 // IP_total_len: Total IP packet length 890 // IP_hdr_len: Header length of IP packet in bytes 891 // IP_Src_IP: Source address of IP packet 892 // IP_Dst_IP: Destination address of IP packet 893 // 894 // UDP_len: Length of the UDP packet taken from UDP header. 895 // UDP_src_port: Source port of UDP packet. 896 // UDP_dst_port: Destination port of UDP packet. 897 // 898 // SPI: SPI number from ESP packet. 899 // 900 // Protocol: Actual protocol number of the protocol inside 901 // ESP-NULL packet. 902 // Protocol_off: Calculated offset to the protocol payload data 903 // inside ESP-NULL packet. 905 //////////////////////////////////////////////////////////// 906 // This is the main processing code for the packet 907 // This will check if the packet requires ESP processing, 908 // 909 Process packet: 910 * If IP protocol is ESP 911 * Set SPI_offset to 0 bytes 912 * Goto Process ESP 913 * If IP protocol is UDP 914 * Goto Process UDP 915 * If IP protocol is WESP 916 // For information about WESP processing see WESP 917 // specification. 918 * Continue WESP processing 919 * Continue Non-ESP processing 921 //////////////////////////////////////////////////////////// 922 // This code is run for UDP packets, and it checks if the 923 // packet is UDP encapsulated UDP packet, or UDP 924 // encapsulated IKE packet, or keepalive packet. 925 // 926 Process UDP: 927 // Reassembly is not mandatory here, we could 928 // do reassembly also only after detecting the 929 // packet being UDP encapsulated ESP packet, but 930 // that would complicated the pseudocode here 931 // a lot, as then we would need to add code 932 // for checking if the UDP header is in this 933 // packet or not. 934 // Reassembly is to simplify things 935 * If packet is fragment 936 * Do full reassembly before processing 937 * If UDP_src_port != 4500 and UDP_dst_port != 4500 938 * Continue Non-ESP processing 939 * Set SPI_offset to 8 bytes 940 * If UDP_len > 4 and first 4 bytes of UDP packet are 0x000000 941 * Continue Non-ESP processing (pass IKE-packet) 942 * If UDP_len > 4 and first 4 bytes of UDP packet are 0x000002 943 * Continue WESP processing 944 * If UDP_len == 1 and first byte is 0xff 945 * Continue Non-ESP processing (pass NAT-Keepalive Packet) 946 * Goto Process ESP 948 //////////////////////////////////////////////////////////// 949 // This code is run for ESP packets (or UDP encapsulated ESP 950 // packets). This checks if IPsec flow is known, and 951 // if not calls heuristics. If IPsec flow is known 952 // then it continues processing based on the policy. 954 // 955 Process ESP: 956 * If packet is fragment 957 * Do full reassembly before processing 958 * If IP_total_len < IP_hdr_len + SPI_offset + 4 959 // If this packet was UDP encapsulated ESP packet then 960 // this might be valid UDP packet which might 961 // be passed or dropped depending on policy 962 * Continue normal packet processing 963 * Load SPI from IP_hdr_len + SPI_offset 964 * Initialize State to ESP 965 // In case this was UDP encapsulated ESP then use UDP_src_port and 966 // UDP_dst_port also when finding data from SPI cache. 967 * Find IP_Src_IP + IP_Dst_IP + SPI from SPI cache 968 * If SPI found 969 * Load State, IV_len, ICV_len from cache 970 * If SPI not found or State is unsure 971 * Call Autodetect ESP parameters (drop to slowpath) 972 * If State is ESP 973 * Continue Non-ESP-NULL processing 974 * Goto Check ESP-NULL packet 976 //////////////////////////////////////////////////////////// 977 // This code is run for ESP-NULL packets, and this 978 // finds out the data required for deep inspection 979 // engine (protocol number, and offset to data) 980 // and calls the deep inspection engine. 981 // 982 Check ESP-NULL packet: 983 * If IP_total_len < IP_hdr_len + SPI_offset + IV_len + ICV_len 984 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 985 // This packet was detected earlier as being part of 986 // ESP-NULL flow, so this means that either ESP-NULL 987 // was replaced with other flow or this is invalid packet. 988 // Either drop or pass the packet, or restart 989 // heuristics based on the policy 990 * Continue packet processing 991 * Load Protocol from IP_total_len - ICV_len - 1 992 * Set Protocol_off to 993 IP_hdr_len + SPI_offset + IV_len + 4 (spi) + 4 (seq no) 994 * Do normal deep inspection on packet. 996 Figure 3 998 A.2. Slowpath 1000 The following example pseudocode show the actual heuristics part of 1001 the packet processing engine. This part is usually implemented in 1002 software. 1004 //////////////////////////////////////////////////////////// 1005 // This pseudocode uses following variables: 1006 // 1007 // SPI_offset, IV_len, ICV_len, State, SPI, 1008 // IP_total_len, IP_hdr_len, IP_Src_IP, IP_Dst_IP 1009 // as defined in fastpath pseudocode. 1010 // 1011 // Stored_Check_Bits:Number of bits we have successfully 1012 // checked to contain acceptable values 1013 // in the actual payload data. This value 1014 // is stored / retrieved from SPI cache. 1015 // 1016 // Check_Bits: Number of bits we have successfully 1017 // checked to contain acceptable values 1018 // in the actual payload data. This value 1019 // is updated during the packet 1020 // verification. 1021 // 1022 // Last_Packet_Data: Contains selected pieces from the 1023 // last packet. This is used to compare 1024 // certain fields of this packet to 1025 // same fields in previous packet. 1026 // 1027 // Packet_Data: Selected pieces of this packet, same 1028 // fields as Last_Packet_Data, and this 1029 // is stored as new Last_Packet_Data to 1030 // SPI cache after this packet is processed. 1031 // 1032 // Test_ICV_len: Temporary ICV length used during tests. 1033 // This is stored to ICV_len when 1034 // padding checks for the packet succeed 1035 // and the packet didn't yet have unsure 1036 // status. 1037 // 1038 // Test_IV_len: Temporary IV length used during tests. 1039 // 1040 // Pad_len: Padding length from the ESP packet. 1041 // 1042 // Protocol: Protocol number of the packet inside ESP 1043 // packet. 1044 // 1045 // TCP.*: Fields from TCP header (from inside ESP) 1046 // UDP.*: Fields from UDP header (from inside ESP) 1047 //////////////////////////////////////////////////////////// 1048 // This code starts the actual heuristics. 1049 // During this the fastpath has already loaded 1050 // State, ICV_len and IV_len in case they were 1051 // found from the SPI cache (i.e. in case the flow 1052 // had unsure status). 1053 // 1054 Autodetect ESP parameters: 1055 // First we check if this is unsure flow, and 1056 // if so, we check next packet against the 1057 // already set IV/ICV_len combination. 1058 * If State is unsure 1059 * Call Verify next packet 1060 * If State is ESP-NULL 1061 * Goto Store ESP-NULL SPI cache info 1062 * If State is unsure 1063 * Goto Verify unsure 1064 // If we failed the test, i.e. State 1065 // was changed to ESP, we check other 1066 // ICV/IV_len values, i.e. fall through 1067 // ICV lengths are tested in order of ICV lengths, 1068 // from shortest to longest. 1069 * Call Try standard algorithms 1070 * If State is ESP-NULL 1071 * Goto Store ESP-NULL SPI cache info 1072 * Call Try 128bit algorithms 1073 * If State is ESP-NULL 1074 * Goto Store ESP-NULL SPI cache info 1075 * Call Try 192bit algorithms 1076 * If State is ESP-NULL 1077 * Goto Store ESP-NULL SPI cache info 1078 * Call Try 256bit algorithms 1079 * If State is ESP-NULL 1080 * Goto Store ESP-NULL SPI cache info 1081 // AUTH_DES_MAC and AUTH_KPDK_MD5 are left out from 1082 // this document. 1083 // If any of those test above set state to unsure 1084 // we mark IPsec flow as unsure. 1085 * If State is unsure 1086 * Goto Store unsure SPI cache info 1087 // All of the test failed, meaning the packet cannot 1088 // be ESP-NULL packet, thus we mark IPsec flow as ESP 1089 * Goto Store ESP SPI cache info 1091 //////////////////////////////////////////////////////////// 1092 // Store ESP-NULL status to the IPsec flow cache. 1093 // 1094 Store ESP-NULL SPI cache info: 1096 * Store State, IV_len, ICV_len to SPI cache 1097 using IP_Src_IP + IP_Dst_IP + SPI as key 1098 * Continue Check ESP-NULL packet 1100 //////////////////////////////////////////////////////////// 1101 // Store encrypted ESP status to the IPsec flow cache. 1102 // 1103 Store ESP SPI cache info: 1104 * Store State, IV_len, ICV_len to SPI cache 1105 using IP_Src_IP + IP_Dst_IP + SPI as key 1106 * Continue Check non-ESP-NULL packet 1108 //////////////////////////////////////////////////////////// 1109 // Store unsure flow status to IPsec flow cache. 1110 // Here we also store the Check_Bits. 1111 // 1112 Store unsure SPI cache info: 1113 * Store State, IV_len, ICV_len, 1114 Stored_Check_Bits to SPI cache 1115 using IP_Src_IP + IP_Dst_IP + SPI as key 1116 * Continue Check unknown packet 1118 //////////////////////////////////////////////////////////// 1119 // Verify this packet against the previously selected 1120 // ICV_len and IV_len values. This will either 1121 // fail (and set state to ESP to mark we do not yet 1122 // know what type of flow this is), or it will 1123 // increment Check_Bits. 1124 // 1125 Verify next packet: 1126 // We already have IV_len, ICV_len and State loaded 1127 * Load Stored_Check_Bits, Last_Packet_Data from SPI Cache 1128 * Set Test_ICV_len to ICV_len, Test_IV_len to IV_len 1129 * Initialize Check_Bits to 0 1130 * Call Verify padding 1131 * If verify padding returned Failure 1132 // Initial guess was wrong, restart 1133 * Set State to ESP 1134 * Clear IV_len, ICV_len, State, 1135 Stored_Check_Bits, Last_Packet_Data 1136 from SPI Cache 1137 * Return 1138 // Ok, padding check succeeded again 1139 * Call Verify packet 1140 * If verify packet returned Failure 1141 // Guess was wrong, restart 1142 * Set State to ESP 1143 * Clear IV_len, ICV_len, State, 1144 Stored_Check_Bits, Last_Packet_Data 1145 from SPI Cache 1146 * Return 1147 // It succeeded and updated Check_Bits and Last_Packet_Data store 1148 // them to SPI cache 1149 * Increment Stored_Check_Bits by Check_Bits 1150 * Store Stored_Check_Bits to SPI Cache 1151 * Store Packet_Data as Last_Packet_Data to SPI cache 1152 * Return 1154 //////////////////////////////////////////////////////////// 1155 // This will check if we have already seen enough bits 1156 // acceptable from the payload data, so we can decide 1157 // that this IPsec flow is ESP-NULL flow. 1158 // 1159 Verify unsure: 1160 // Check if we have enough check bits 1161 * If Stored_Check_Bits > configured limit 1162 // We have checked enough bits, return ESP-NULL 1163 * Set State ESP-NULL 1164 * Goto Store ESP-NULL SPI cache info 1165 // Not yet enough bits, continue 1166 * Continue Check unknown packet 1168 //////////////////////////////////////////////////////////// 1169 // Check for standard 96-bit algorithms. 1170 // 1171 Try standard algorithms: 1172 // AUTH_HMAC_MD5_96, AUTH_HMAC_SHA1_96, AUTH_AES_XCBC_96, 1173 // AUTH_AES_CMAC_96 1174 * Set Test_ICV_len to 12, Test_IV_len to 0 1175 * Goto Check packet 1177 //////////////////////////////////////////////////////////// 1178 // Check for 128-bit algorithms, this is only one that 1179 // can have IV, so we need to check different IV_len values 1180 // here too. 1181 // 1182 Try 128bit algorithms: 1183 // AUTH_HMAC_SHA2_256_128, ENCR_NULL_AUTH_AES_GMAC 1184 * Set Test_ICV_len to 16, Test_IV_len to 0 1185 * If IP_total_len < IP_hdr_len + SPI_offset 1186 + Test_IV_len + Test_ICV_len 1187 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1188 * Return 1189 * Call Verify padding 1190 * If verify padding returned Failure 1191 * Return 1193 * Initialize Check_Bits to 0 1194 * Call Verify packet 1195 * If verify packet returned Failure 1196 * Goto Try GMAC 1197 // Ok, packet seemed ok, but go now and check if we have enough 1198 // data bits so we can assume it is ESP-NULL 1199 * Goto Check if done for unsure 1201 //////////////////////////////////////////////////////////// 1202 // Check for GMAC macs, i.e. macs having 8 byte IV. 1203 // 1204 Try GMAC: 1205 // ENCR_NULL_AUTH_AES_GMAC 1206 * Set Test_IV_len to 8 1207 * If IP_total_len < IP_hdr_len + SPI_offset 1208 + Test_IV_len + Test_ICV_len 1209 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1210 * Return 1211 * Initialize Check_Bits to 0 1212 * Call Verify packet 1213 * If verify packet returned Failure 1214 // Guess was wrong, continue 1215 * Return 1216 // Ok, packet seemed ok, but go now and check if we have enough 1217 // data bits so we can assume it is ESP-NULL 1218 * Goto Check if done for unsure 1220 //////////////////////////////////////////////////////////// 1221 // Check for 192-bit algorithms. 1222 // 1223 Try 192bit algorithms: 1224 // AUTH_HMAC_SHA2_384_192 1225 * Set Test_ICV_len to 24, Test_IV_len to 0 1226 * Goto Check packet 1228 //////////////////////////////////////////////////////////// 1229 // Check for 256-bit algorithms. 1230 // 1231 Try 256bit algorithms: 1232 // AUTH_HMAC_SHA2_512_256 1233 * Set Test_ICV_len to 32, Test_IV_len to 0 1234 * Goto Check packet 1236 //////////////////////////////////////////////////////////// 1237 // This actually does the checking for the packet, by 1238 // first verifying the length, and then self describing 1239 // padding, and if that succeeds, then checks the actual 1240 // payload content. 1242 // 1243 Check packet: 1244 * If IP_total_len < IP_hdr_len + SPI_offset 1245 + Test_IV_len + Test_ICV_len 1246 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1247 * Return 1248 * Call Verify padding 1249 * If verify padding returned Failure 1250 * Return 1251 * Initialize Check_Bits to 0 1252 * Call Verify packet 1253 * If verify packet returned Failure 1254 // Guess was wrong, continue 1255 * Return 1256 // Ok, packet seemed ok, but go now and check if we have enough 1257 // data bits so we can assume it is ESP-NULL 1258 * Goto Check if done for unsure 1260 //////////////////////////////////////////////////////////// 1261 // This code checks if we have seen enough acceptable 1262 // values in the payload data, so we can decide that this 1263 // IPsec flow is ESP-NULL flow. 1264 // 1265 Check if done for unsure: 1266 * If Stored_Check_Bits > configured limit 1267 // We have checked enough bits, return ESP-NULL 1268 * Set State ESP-NULL 1269 * Set IV_len to Test_IV_len, ICV_len to Test_ICV_len 1270 * Clear Stored_Check_Bits, Last_Packet_Data from SPI Cache 1271 * Return 1272 // Not yet enough bits, check this is first unsure, if so 1273 // store information. In case there is multiple 1274 // tests succeeding, we always assume the first one 1275 // (the wone using shortest MAC) is the one we want to 1276 // check in the future. 1277 * If State is not unsure 1278 * Set State unsure 1279 // These values will be stored to SPI cache if 1280 // the final state will be unsure 1281 * Set IV_len to Test_IV_len, ICV_len to Test_ICV_len 1282 * Set Stored_Check_Bits as Check_Bits 1283 * Return 1285 //////////////////////////////////////////////////////////// 1286 // Verify self describing padding 1287 // 1288 Verify padding: 1289 * Load Pad_len from IP_total_len - Test_ICV_len - 2 1290 * Verify padding bytes at 1291 IP_total_len - Test_ICV_len - 1 - Pad_len .. 1292 IP_total_len - Test_ICV_len - 2 are 1293 1, 2, ..., Pad_len 1294 * If Verify of padding bytes succeeded 1295 * Return Success 1296 * Return Failure 1298 //////////////////////////////////////////////////////////// 1299 // This will verify the actual protocol content inside ESP 1300 // packet. 1301 // 1302 Verify packet: 1303 // We need to first check things that cannot be set, i.e if any of 1304 // those are incorrect, then we return Failure. For any 1305 / fields which might be correct, we increment the Check_Bits 1306 // for a suitable amount of bits. If all checks pass, then 1307 // we just return Success, and the upper layer will then 1308 // later check if we have enough bits checked already. 1309 * Load Protocol From IP_total_len - Test_ICV_len - 1 1310 * If Protocol TCP 1311 * Goto Verify TCP 1312 * If Protocol UDP 1313 * Goto Verify UDP 1314 // Other protocols can be added here as needed, most likely same 1315 // protocols as deep inspection does 1316 // Tunnel mode checks (protocol 4 for IPv4 and protocol 41 for 1317 // IPv6) is also left out from here to make the document shorter. 1318 * Return Failure 1320 //////////////////////////////////////////////////////////// 1321 // Verify TCP protocol headers 1322 // 1323 Verify TCP: 1324 // First we check things that must be set correctly. 1325 * If TCP.Data_Offset field < 5 1326 // TCP head length too small 1327 * Return Failure 1328 // After that we start to check things that does not 1329 // have one definitive value, but can have multiple possible 1330 // valid values 1331 * If TCP.ACK bit is not set, then check 1332 that TCP.Acknowledgment_number field contains 0 1333 // If ACK bit is not set then the acknowledgment 1334 // field usually contains 0, but I do not think 1335 // RFCs mandate it being zero, so we cannot make 1336 // this a failure if it is not so. 1337 * Increment Check_Bits by 32 1339 * If TCP.URG bit is not set, then check 1340 that TCP.Urgent_Pointer field contains 0 1341 // If URG bit is not set then urgent pointer 1342 // field usually contains 0, but I do not think 1343 // RFCs mandate it being zero, so we cannot make 1344 // this failure if it is not so. 1345 * Increment Check_Bits by 16 1346 * If TCP.Data_Offset field == 5 1347 * Increment Check_Bits by 4 1348 * If TCP.Data_Offset field > 5 1349 * If TCP options format is valid and it is padded correctly 1350 * Increment Check_Bits accordingly 1351 * If TCP options format was garbage 1352 * Return Failure 1353 * If TCP.checksum is correct 1354 // This might be wrong because packet passed NAT, so 1355 // we cannot make this failure case 1356 * Increment Check_Bits by 16 1357 // We can also do normal deeper TCP inspection here, i.e. 1358 // check that SYN/ACK/FIN/RST bits are correct and state 1359 // matches the state of existing flow if this is packet 1360 // to existing flow etc. 1361 // If there is anything clearly wrong in the packet (i.e. 1362 // some data is set to something that it cannot be), then 1363 // this can return Failure, otherwise it should just 1364 // increment Check_Bits matching the number of bits checked. 1365 // 1366 // We can also check things here compared to the last packet 1367 * If Last_Packet_Data.TCP.source port = 1368 Packet_Data.TCP.source_port and 1369 Last_Packet_Data.TCP.destination port = 1370 Packet_Data.TCP.destination port 1371 * Increment Check_Bits by 32 1372 * If Last_Packet_Data.TCP.acknowledgement_number = 1373 Packet_Data.TCP.acknowledgement_number 1374 * Increment Check_Bits by 32 1375 * If Last_Packet_Data.TCP.sequence_number = 1376 Packet_Data.TCP.sequence_number 1377 * Increment Check_Bits by 32 1378 // We can do other similar checks here 1379 * Return Success 1381 //////////////////////////////////////////////////////////// 1382 // Verify UDP protocol headers 1383 // 1384 Verify UDP: 1385 // First we check things that must be set correctly. 1386 * If UDP.UDP_length > IP_total_len - IP_hdr_len - SPI_offset 1387 - Test_IV_len - Test_ICV_len - 4 (spi) 1388 - 4 (seq no) - 1 (protocol) 1389 - Pad_len - 1 (Pad_len) 1390 * Return Failure 1391 * If UDP.UDP_length < 8 1392 * Return Failure 1393 // After that we start to check things that does not 1394 // have one definitive value, but can have multiple possible 1395 // valid values 1396 * If UDP.UDP_checksum is correct 1397 // This might be wrong because packet passed NAT, so 1398 // we cannot make this failure case 1399 * Increment Check_Bits by 16 1400 * If UDP.UDP_length = IP_total_len - IP_hdr_len - SPI_offset 1401 - Test_IV_len - Test_ICV_len - 4 (spi) 1402 - 4 (seq no) - 1 (protocol) 1403 - Pad_len - 1 (Pad_len) 1404 // If there is no TFC padding then UDP_length 1405 // will be matching the full packet length 1406 * Increment Check_Bits by 16 1407 // We can also do normal deeper UDP inspection here. 1408 // If there is anything clearly wrong in the packet (i.e. 1409 // some data is set to something that it cannot be), then 1410 // this can return Failure, otherwise it should just 1411 // increment Check_Bits matching the number of bits checked. 1412 // 1413 // We can also check things here compared to the last packet 1414 * If Last_Packet_Data.UDP.source_port = 1415 Packet_Data.UDP.source_port and 1416 Last_Packet_Data.destination_port = 1417 Packet_Data.UDP.destination_port 1418 * Increment Check_Bits by 32 1419 * Return Success 1421 Figure 4 1423 Authors' Addresses 1425 Tero Kivinen 1426 Safenet, Inc. 1427 Fredrikinkatu 47 1428 HELSINKI FIN-00100 1429 FI 1431 Email: kivinen@iki.fi 1433 Daniel L. McDonald 1434 Sun Microsystems, Inc. 1435 35 Network Drive 1436 MS UBUR02-212 1437 Burlington, MA 01803 1438 USA 1440 Email: danmcd@sun.com