idnits 2.17.1 draft-ietf-ipsecme-esp-null-heuristics-05.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 1338 has weird spacing: '...lure if it is...' -- The document date (January 28, 2010) is 5199 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 1, 2010 January 28, 2010 8 Heuristics for Detecting ESP-NULL packets 9 draft-ietf-ipsecme-esp-null-heuristics-05.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 1, 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 . . . . . . . . . . . . . . . . . . . . . 19 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 as it can be there depending on the receiving implementation 192 it is safer to assume it is always part of the flow 193 identification. 195 2. Other Options 197 This document will discuss the heuristic approach of detecting ESP- 198 NULL packets. There are some other options which can be used, and 199 this section will briefly discuss them. 201 2.1. AH 203 The most logical approach would use the already defined protocol 204 which offers authentication and integrity protection, but not 205 confidentiality, namely AH. AH traffic is clearly marked as not 206 encrypted, and can always be inspected by intermediate devices. 208 Using AH has two problems. First is that, as it also protects the IP 209 headers, it will also protect against NATs on the path, thus it will 210 not work if there is NAT on the path between end nodes. In some 211 environments this might not be a problem, but some environments 212 include heavy use of NATs even inside the internal network of the 213 enterprise or organization. NAT-Traversal (NAT-T, [RFC3948]) could 214 be extended to support AH also, and the early versions of the NAT-T 215 proposals did include that, but it was left out as it was not seen as 216 necessary. 218 The another problem is that in the new IPsec Architecture [RFC4301] 219 the support for AH is now optional, meaning not all implementations 220 support it. ESP-NULL has been defined to be mandatory to implement 221 by the Cryptographic Algorithm Implementation Requirements for 222 Encapsulating Security Payload (ESP) document [RFC4835]. 224 AH has also quite complex processing rules compared to ESP when 225 calculating the ICV, including things like zeroing out mutable 226 fields, also as AH is not as widely used than ESP, the AH support is 227 not as well tested in the interoperability events. 229 2.2. Mandating by Policy 231 Another easy way to solve this problem is to mandate the use of ESP- 232 NULL with common parameters within an entire organization. This 233 either removes the need for heuristics (if no ESP encrypted traffic 234 is allowed at all) or simplifies them considerably (only one set of 235 parameters needs to be inspected, e.g. everybody in the organization 236 who is using ESP-NULL must use HMAC-SHA-1-96 as their integrity 237 algorithm). This does not work unless one of a pair of communicating 238 machines is not under the same administrative domain as the deep 239 inspection engine. (IPsec Security Associations must be satisfactory 240 to all communicating parties, so only one communicating peer needs to 241 have a sufficiently narrow policy.) Also, such a solution might 242 require some kind of centralized policy management to make sure 243 everybody in an administrative domain uses the same policy. 245 2.3. Modifying ESP 247 Several internet drafts discuss ways of modifying ESP to offer 248 intermediate devices information about an ESP packet's use of NULL 249 encryption. The following methods have been discussed: adding an IP- 250 option, adding a new IP-protocol number plus an extra header 251 [I-D.ietf-ipsecme-traffic-visibility], adding new IP-protocol numbers 252 which tell the ESP-NULL parameters [I-D.hoffman-esp-null-protocol], 253 reserving an SPI range for ESP-NULL [I-D.bhatia-ipsecme-esp-null], 254 and using UDP encapsulation with a different format and ports. 256 All of the aforementioned drafts require modification to ESP, which 257 requires that all end nodes need to be modified before intermediate 258 devices can assume that this new ESP format is in use. Updating end 259 nodes will require lots of time. An example of slow end-node 260 deployment is IKEv2. Considering an implementation that requires 261 both IKEv2 and a new ESP format, it would take several years, 262 possibly as long as a decade, before widespread deployment. 264 3. Description of Heuristics 266 The heuristics to detect ESP-NULL packets will only require changes 267 to those intermediate devices which do deep inspection or other 268 operations which require detecting ESP-NULL. As those nodes require 269 changes regardless of any ESP-NULL method, updating intermediate 270 nodes is unavoidable. Heuristics do not require updating or 271 modifying any other devices on the rest of the network, including 272 (especially) end-nodes. 274 In this document it is assumed that an affected intermediate node 275 will act as a stateful interception device, meaning it will keep 276 state of the IPsec flows - where flows are defined by the ESP SPI and 277 IP addresses forming an IPsec SA - going through it. The heuristics 278 can also be used without storing any state, but performance will be 279 worse in that case, as heuristic checks will need to be done for each 280 packet, not only once per flow. This will also affect the 281 reliability of the heuristics. 283 Generally, an intermediate node runs heuristics only for the first 284 few packets of the new flow (i.e. the new IPsec SA). After those few 285 packets, the node detects parameters of the IPsec flow, it skips 286 detection heuristics, and it can perform direct packet-inspecting 287 action based on its own policy. Once detected, ESP-NULL packets will 288 never be detected as encrypted ESP packets, meaning that valid ESP- 289 NULL packets will never bypass the deep inspection. The only failure 290 mode of these heuristics is to assume encrypted ESP packets are ESP- 291 NULL packets, thus causing completely random packet data to be deeply 292 inspected. An attacker can easily send random-looking ESP-NULL 293 packets which will cause heuristics to detect packets as encrypted 294 ESP, but that is no worse than sending non-ESP fuzz through an 295 intermediate node. 297 For hardware implementations all the flow lookup based on the ESP 298 next header number (50), source address, destination address, and SPI 299 can be done by the hardware (there is usually already similar 300 functionality there, for TCP/UDP flows). The heuristics can be 301 implemented by the hardware, but using software will allow faster 302 updates when new protocol modifications come out or new protocols 303 need support. 305 As described in section 7, UDP encapsulated ESP traffic may also have 306 have NAPT applied to it, and so there is already a 5-tuple state in 307 the stateful inspection gateway 309 4. IPsec flows 311 ESP is a stateful protocol, meaning there is state stored in the both 312 end nodes of the ESP IPsec SA, and the state is identified by the 313 pair of destination IP and SPI. End nodes also often fix the source 314 IP address in an SA unless the destination is a multicast group. 315 Typically most (if not all) flows of interest to an intermediate 316 device are unicast, so it is safer to assume the receiving node also 317 uses a source address, and the intermediate device should therefore 318 do the same. In some cases this might cause extraneous cached ESP 319 IPsec SA flows, but by using the source address two distinct flows 320 will never be mixed. For sites which heavily use multicast, such 321 traffic is deterministically identifiable (224.0.0.0/4 for IPv4 and 322 ff00::0/8 for IPv6), and an implementation can save the space of 323 multiple cache entries for a multicast flow by checking the 324 destination address first. 326 When the intermediate device sees a new ESP IPsec flow, i.e. a new 327 flow of ESP packets where the source address, destination address, 328 and SPI number forms a triplet which has not been cached, it will 329 start the heuristics to detect whether this flow is ESP-NULL or not. 330 These heuristics appear in Section 8. 332 When the heuristics finish, they will label the flow as either 333 encrypted (which tells that packets in this flow are encrypted, and 334 cannot be ESP-NULL packets) or as ESP-NULL. This information, along 335 with the ESP-NULL parameters detected by the heuristics, is stored to 336 a flow cache, which will be used in the future when processing 337 packets of the same flow. 339 Both encrypted ESP and ESP-NULL flows are processed based on the 340 local policy. In normal operation encrypted ESP flows are passed 341 through or dropped per local policy, and ESP-NULL flows are passed to 342 the deep inspection engine. Local policy will also be used to 343 determine other packet-processing parameters. Local policy issues 344 will be clearly marked in this document to ease implementation. 346 In some cases the heuristics cannot determine the type of flow from a 347 single packet, and in that case it might need multiple packets before 348 it can finish the process. In those cases the heuristics return 349 "unsure" status. In that case the packet processed based on the 350 local policy and flow cache is updated with "unsure" status. Local 351 policy for "unsure" packets could range from dropping (which 352 encourages end-node retransmission) to queuing (which may preserve 353 delivery, at the cost of artificially inflating round-trip times if 354 they are measured). When the next packet to the flow arrives, it is 355 heuristically processed again, and the cached flow may continue to be 356 "unsure", marked as ESP, or marked as an ESP-NULL flow. 358 There are several reasons why a single packet might not be enough to 359 detect type of flow. One of them is that the next header number was 360 unknown, i.e. if heuristics do not know about the protocol for the 361 packet, it cannot verify it has properly detected ESP-NULL 362 parameters, even when the packet otherwise looks like ESP-NULL. If 363 the packet does not look like ESP-NULL at all, then encrypted ESP 364 status can be returned quickly. As ESP-NULL heuristics should know 365 the same protocols as a deep inspection device, an unknown protocol 366 should not be handled any differently than a cleartext instance of an 367 unknown protocol if possible. 369 5. Deep Inspection Engine 371 A deep inspection engine running on an intermediate node usually 372 checks deeply into the packet and performs policy decisions based on 373 the contents of the packet. The deep inspection engine should be 374 able to tell the difference between success, failure, and garbage. 375 Success means that a packet was successfully checked with the deep 376 inspection engine, and it passed the checks and is allowed to be 377 forwarded. Failure means that a packet was successfully checked but 378 the actual checks done indicated that packets should be dropped, i.e. 379 the packet contained a virus, was a known attack, or something 380 similar. 382 Garbage means that the packet's protocol headers or other portions 383 were unparseable. For the heuristics, it would be useful if the deep 384 inspection engine can differentiate the garbage and failure cases, as 385 garbage cases can be used to detect certain error cases (e.g. where 386 the ESP-NULL parameters are incorrect, or the flow is really an 387 encrypted ESP flow, not an ESP-NULL flow). 389 If the deep inspection engine will only return failure for all 390 garbage packets in addition to real failure cases, then a system 391 implementing the ESP-NULL heuristics cannot recover from error 392 situations quickly. 394 6. Special and Error Cases 396 There is a small probability that an encrypted ESP packet (which 397 looks like it contains completely random bytes) will have plausible 398 bytes in expected locations, such that heuristics will detect the 399 packet as an ESP-NULL packet instead of detecting that it is 400 encrypted ESP packet. The actual probabilities will be computed 401 later in this document. Such a packet will not cause problems, as 402 the deep inspection engine will most likely reject the packet and 403 return that it is garbage. If the deep inspection engine is 404 rejecting a high number of packets as garbage, it might indicate an 405 original ESP-NULL detection for the flow was wrong (i.e. an encrypted 406 ESP flow was improperly detected as ESP-NULL). In that case, the 407 cached flow should be invalidated and discovery should happen again. 409 Each ESP-NULL flow should also keep statistics about how many packets 410 have been detected as garbage by deep inspection, how many have 411 passed checks, or how many have failed checks with policy violations 412 (i.e. failed because actual inspection policy failures, not because 413 the packet looked like garbage). If the number of garbage packets 414 suddenly increases (e.g. most of the packets start to be look like 415 garbage according to the deep inspection engine), it is possible the 416 old ESP-NULL SA was replaced by an identical-SPI encrypting ESP SA. 417 If both ends use random SPI generation, this is a very unlikely 418 situation (1 in 2^32), but it is possible that some nodes reuse SPI 419 numbers (e.g. a 32-bit memory address of the SA descriptor), thus 420 this situation needs to be handled. 422 Actual limits for cache invalidation are local policy decisions. 423 Sample invalidation policies include: 50% of packets marked as 424 garbage within a second; or if a deep inspection engine cannot 425 differentiate between garbage and failure, failing more than 95% of 426 packets in last 10 seconds. For implementations that do not 427 distinguish between garbage and failure, failures should not be 428 treated too quickly as indication of SA reuse. Often, single packets 429 cause state-related errors that block otherwise normal packets from 430 passing. 432 7. UDP encapsulation 434 The flow lookup code needs to detect UDP packets to or from port 4500 435 in addition to the ESP packets, and perform similar processing to 436 them after skipping the UDP header. Port-translation by NAT often 437 rewrites what was originally 4500 into a different value, which means 438 each unique port pair constitutes a separate IPsec flow. I.e. UDP 439 encapsulated IPsec flows are identified by the source and destination 440 IP, source and destination port number and SPI number. As devices 441 might be using MOBIKE ([RFC4555]), that also means that the flow 442 cache should be shared between the UDP encapsulated IPsec flows and 443 non encapsulated IPsec flows. As previously mentioned, 444 differentiating between garbage and actual policy failures will help 445 in proper detection immensely. 447 Because the checks are run for packets having just source port 4500 448 or packets having just destination port 4500, this might cause checks 449 to be run for non-ESP traffic too. Some traffic may randomly use 450 port 4500 for other reasons, especially if a port-translating NAT is 451 involved. The UDP encapsulation processing should also be aware of 452 that possibility. 454 8. Heuristic Checks 456 Normally, HMAC-SHA1-96 or HMAC-MD5-96 gives 1 out of 2^96 probability 457 that a random packet will pass the HMAC test. This yields a 458 99.999999999999999999999999998% probability that an end node will 459 correctly detect a random packet as being invalid. This means that 460 it should be enough for an intermediate device to check around 96 461 bits from the input packet. By comparing them against known values 462 for the packet, a deep inspection engine gains more or less the same 463 probability as an end node is using. This gives an upper limit of 464 how many bits heuristics need to check - there is no point of 465 checking much more than that many bits (since that same probability 466 is acceptable for the end node). In most of the cases the 467 intermediate device does not need that high probability, perhaps 468 something around 32-64 bits is enough. 470 IPsec's ESP has a well-understood packet layout, but its variable- 471 length fields reduce the ability of pure algorithmic matching to one 472 requiring heuristics and assigning probabilities. 474 8.1. ESP-NULL format 476 The ESP-NULL format is as follows: 478 0 1 2 3 479 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 480 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 481 | Security Parameters Index (SPI) | 482 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 483 | Sequence Number | 484 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 485 | IV (optional) | 486 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 487 | Payload Data (variable) | 488 ~ ~ 489 | | 490 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 491 | | Padding (0-255 bytes) | 492 +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 493 | | Pad Length | Next Header | 494 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 495 | Integrity Check Value-ICV (variable) | 496 ~ ~ 497 | | 498 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 500 Figure 1 502 The output of the heuristics should provide information about whether 503 the packet is encrypted ESP or ESP-NULL. In case it is ESP-NULL the 504 heuristics should also provide the Integrity Check Value (ICV) field 505 length and the Initialization Vector (IV) length. 507 The currently defined ESP authentication algorithms have 4 different 508 lengths for the ICV field. Most commonly used is 96 bits, and after 509 that comes 128 bit ICV lengths. 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 packets remain, so the next header 609 number is inspected. If the next header number is known (and 610 supported) then the packet can be inspected based on the next header 611 number. If the next header number is unknown (i.e. not any of those 612 with protocol checking support) the packet is marked "unsure", 613 because there is no way to detect the IV length without inspecting 614 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 bring 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, thus the IP 693 numbers used in the checksum are wrong, thus the checksum is wrong. 694 If the checksum is correct that can again be used to increase the 695 valid bit count, but verifying checksums is a costly operation, thus 696 skipping that check might be best unless there is hardware to help 697 the calculation. Window size, urgent pointer, sequence number, and 698 acknowledgement numbers can be used, but there is not one specific 699 known value for them. 701 One good method of detection is if a packet is dropped then the next 702 packet will most likely be a retransmission of the previous packet. 703 Thus if two packets are received with the same source, and 704 destination port numbers, and where sequence numbers are either same 705 or right after each other, then it's likely a TCP packet has been 706 correctly detected. 708 Existing deep inspection engines usually do very good TCP flow 709 checking already, including flow tracking, verification of sequence 710 numbers, and reconstruction of the whole TCP flow. Similar methods 711 can be used here, but they are implementation-dependent and not 712 described here. 714 8.3.2. UDP checks 716 UDP header has even more problems than the TCP header, as UDP has 717 even less known data. The checksum has the same problem as the TCP 718 checksum, due to NATs. The UDP length field might not match the 719 overall packet length, as the sender is allowed to include TFC 720 (traffic flow confidentiality, see section 2.7 of IP Encapsulating 721 Security Payload document [RFC4303]) padding. 723 With UDP packets similar multiple packet methods can be used as with 724 TCP, as UDP protocols usually include several packets using same port 725 numbers going from one end node to another, thus receiving multiple 726 packets having a known pair of UDP port numbers is good indication 727 that the heuristics have passed. 729 Some UDP protocols also use identical source and destination port 730 numbers, thus that is also a good check. 732 8.3.3. ICMP checks 734 As ICMP messages are usually sent as return packets for other 735 packets, they are not very common packets to get as first packets for 736 the SA, the ICMP ECHO_REQUEST message being a noteworthy exception. 737 ICMP ECHO_REQUEST has a known type and code, identifier, and sequence 738 number. The checksum, however, might be incorrect again because of 739 NATs. 741 For ICMP error messages, the ICMP message contains part of the 742 original IP packet inside. Then the same rules which are used to 743 detect IPv4/IPv6 tunnel checks can be used. 745 8.3.4. SCTP checks 747 SCTP [RFC4960] has a self-contained checksum, which is computed over 748 the SCTP payload and is not affected by NATs unless the NAT is SCTP- 749 aware. Even more than the TCP and UDP checksums, the SCTP checksum 750 is expensive, and may be prohibitive even for deep-packet 751 inspections. 753 SCTP chunks can be inspected to see if their lengths are consistent 754 across the total length of the IP datagram, so long as TFC padding is 755 not present. 757 8.3.5. IPv4 and IPv6 Tunnel checks 759 In cases of tunneled traffic the packet inside contains a full IPv4 760 or IPv6 packet. Many fields are usable. For IPv4 those fields 761 include version, header length, total length (again TFC padding might 762 confuse things there), protocol number, and 16-bit header checksum. 763 In those cases the intermediate device should give the decapsulated 764 IP packet to the deep inspection engine. IPv6 has fewer usable 765 fields, but the version number, packet length (modulo TFC confusion) 766 and next-header all can be used by deep-packet inspection. 768 In both IPv4 and IPv6 the heuristics can also check the IP addresses 769 either to be in the known range (for example check that both IPv6 770 source and destination have same prefix etc), or checking addresses 771 across more than one packet. 773 9. Security Considerations 775 Attackers can always bypass ESP-NULL deep packet inspection by using 776 encrypted ESP (or some other encryption or tunneling method) instead, 777 unless the intermediate node's policy requires dropping of packets 778 that it cannot inspect. Ultimately the responsibility for performing 779 deep inspection, or allowing intermediate nodes to perform deep 780 inspection, must rest on the end nodes. I.e. if a server allows 781 encrypted connections also, then an attacker who wants to attack the 782 server and wants to bypass a deep inspection device in the middle, 783 will use encrypted traffic. This means that the protection of the 784 whole network is only as good as the policy enforcement and 785 protection of the end node. One way to enforce deep inspection for 786 all traffic, is to forbid encrypted ESP completely, in which case 787 ESP-NULL detection is easier, as all packets must be ESP-NULL based 788 on the policy, and further restrictions can eliminate ambiguities in 789 ICV and IV sizes. 791 Using ESP-NULL or especially forcing using of it everywhere inside 792 the enterprise can have increased risk of sending confidential 793 information where eavesdroppers can see it. 795 10. IANA Considerations 797 No IANA assignments are needed. 799 11. References 801 11.1. Normative References 803 [RFC2410] Glenn, R. and S. Kent, "The NULL Encryption Algorithm and 804 Its Use With IPsec", RFC 2410, November 1998. 806 [RFC4301] Kent, S. and K. Seo, "Security Architecture for the 807 Internet Protocol", RFC 4301, December 2005. 809 [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, 810 December 2005. 812 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 813 RFC 4303, December 2005. 815 11.2. Informative References 817 [I-D.bhatia-ipsecme-esp-null] 818 Bhatia, M., "Identifying ESP-NULL Packets", 819 draft-bhatia-ipsecme-esp-null-00 (work in progress), 820 December 2008. 822 [I-D.hoffman-esp-null-protocol] 823 Hoffman, P. and D. McGrew, "An Authentication-only Profile 824 for ESP with an IP Protocol Identifier", 825 draft-hoffman-esp-null-protocol-00 (work in progress), 826 August 2007. 828 [I-D.ietf-ipsecme-traffic-visibility] 829 Grewal, K., Montenegro, G., and M. Bhatia, "Wrapped ESP 830 for Traffic Visibility", 831 draft-ietf-ipsecme-traffic-visibility-12 (work in 832 progress), January 2010. 834 [RFC3948] Huttunen, A., Swander, B., Volpe, V., DiBurro, L., and M. 835 Stenberg, "UDP Encapsulation of IPsec ESP Packets", 836 RFC 3948, January 2005. 838 [RFC4359] Weis, B., "The Use of RSA/SHA-1 Signatures within 839 Encapsulating Security Payload (ESP) and Authentication 840 Header (AH)", RFC 4359, January 2006. 842 [RFC4555] Eronen, P., "IKEv2 Mobility and Multihoming Protocol 843 (MOBIKE)", RFC 4555, June 2006. 845 [RFC4835] Manral, V., "Cryptographic Algorithm Implementation 846 Requirements for Encapsulating Security Payload (ESP) and 847 Authentication Header (AH)", RFC 4835, April 2007. 849 [RFC4960] Stewart, R., "Stream Control Transmission Protocol", 850 RFC 4960, September 2007. 852 Appendix A. Example Pseudocode 854 This appendix is meant for the implementors. It does not include all 855 the required checks, and this is just example pseudocode, so final 856 implementation can be very different. It mostly lists things that 857 need to be done, but implementations can optimize steps depending on 858 their other parts. For example, implementation might combine 859 heuristics and deep inspection tightly together. 861 A.1. Fastpath 863 The following example pseudocode show the fastpath part of the packet 864 processing engine. This part is usually implemented in hardware. 866 //////////////////////////////////////////////////////////// 867 // This pseudocode uses following variables: 868 // 869 // SPI_offset: Number of bytes between start of protocol 870 // data and SPI. This is 0 for ESP, and 871 // 8 for UDP encapsulated ESP (i.e skipping 872 // UDP header). 873 // 874 // IV_len: Length of the IV of the ESP-NULL packet. 875 // 876 // ICV_len: Length of the ICV of the ESP-NULL packet. 877 // 878 // State: State of the packet, i.e. ESP-NULL, ESP, or 879 // unsure. 880 // 881 // Also following data is taken from the packet: 882 // 883 // IP_total_len: Total IP packet length 884 // IP_hdr_len: Header length of IP packet in bytes 885 // IP_Src_IP: Source address of IP packet 886 // IP_Dst_IP: Destination address of IP packet 887 // 888 // UDP_len: Length of the UDP packet taken from UDP header. 889 // UDP_src_port: Source port of UDP packet. 890 // UDP_dst_port: Destination port of UDP packet. 891 // 892 // SPI: SPI number from ESP packet. 893 // 894 // Protocol: Actual protocol number of the protocol inside 895 // ESP-NULL packet. 896 // Protocol_off: Calculated offset to the protocol payload data 897 // inside ESP-NULL packet. 899 //////////////////////////////////////////////////////////// 900 // This is the main processing code for the packet 901 // This will check if the packet requires ESP processing, 902 // 903 Process packet: 904 * If IP protocol is ESP 905 * Set SPI_offset to 0 bytes 906 * Goto Process ESP 907 * If IP protocol is UDP 908 * Goto Process UDP 909 * If IP protocol is WESP 910 // For information about WESP processing see WESP 911 // specification. 912 * Continue WESP processing 913 * Continue Non-ESP processing 915 //////////////////////////////////////////////////////////// 916 // This code is run for UDP packets, and it checks if the 917 // packet is UDP encapsulated UDP packet, or UDP 918 // encapsulated IKE packet, or keepalive packet. 919 // 920 Process UDP: 921 // Reassembly is not mandatory here, we could 922 // do reassembly also only after detecting the 923 // packet being UDP encapsulated ESP packet, but 924 // that would complicated the pseudocode here 925 // a lot, as then we would need to add code 926 // for checking if the UDP header is in this 927 // packet or not. 928 // Reassembly is to simplify things 929 * If packet is fragment 930 * Do full reassembly before processing 931 * If UDP_src_port != 4500 and UDP_dst_port != 4500 932 * Continue Non-ESP processing 933 * Set SPI_offset to 8 bytes 934 * If UDP_len > 4 and first 4 bytes of UDP packet are 0x000000 935 * Continue Non-ESP processing (pass IKE-packet) 936 * If UDP_len > 4 and first 4 bytes of UDP packet are 0x000002 937 * Continue WESP processing 938 * If UDP_len == 1 and first byte is 0xff 939 * Continue Non-ESP processing (pass NAT-Keepalive Packet) 940 * Goto Process ESP 942 //////////////////////////////////////////////////////////// 943 // This code is run for ESP packets (or UDP encapsulated ESP 944 // packets). This checks if IPsec flow is known, and 945 // if not calls heuristics. If IPsec flow is known 946 // then it continues processing based on the policy. 948 // 949 Process ESP: 950 * If packet is fragment 951 * Do full reassembly before processing 952 * If IP_total_len < IP_hdr_len + SPI_offset + 4 953 // If this packet was UDP encapsulated ESP packet then 954 // this might be valid UDP packet which might 955 // be passed or dropped depending on policy 956 * Continue normal packet processing 957 * Load SPI from IP_hdr_len + SPI_offset 958 * Initialize State to ESP 959 // In case this was UDP encapsulated ESP then use UDP_src_port and 960 // UDP_dst_port also when finding data from SPI cache. 961 * Find IP_Src_IP + IP_Dst_IP + SPI from SPI cache 962 * If SPI found 963 * Load State, IV_len, ICV_len from cache 964 * If SPI not found or State is unsure 965 * Call Autodetect ESP parameters (drop to slowpath) 966 * If State is ESP 967 * Continue Non-ESP-NULL processing 968 * Goto Check ESP-NULL packet 970 //////////////////////////////////////////////////////////// 971 // This code is run for ESP-NULL packets, and this 972 // finds out the data required for deep inspection 973 // engine (protocol number, and offset to data) 974 // and calls the deep inspection engine. 975 // 976 Check ESP-NULL packet: 977 * If IP_total_len < IP_hdr_len + SPI_offset + IV_len + ICV_len 978 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 979 // This packet was detected earlier as being part of 980 // ESP-NULL flow, so this means that either ESP-NULL 981 // was replaced with other flow or this is invalid packet. 982 // Either drop or pass the packet, or restart 983 // heuristics based on the policy 984 * Continue packet processing 985 * Load Protocol from IP_total_len - ICV_len - 1 986 * Set Protocol_off to 987 IP_hdr_len + SPI_offset + IV_len + 4 (spi) + 4 (seq no) 988 * Do normal deep inspection on packet. 990 Figure 3 992 A.2. Slowpath 994 The following example pseudocode show the actual heuristics part of 995 the packet processing engine. This part is usually implemented in 996 software. 998 //////////////////////////////////////////////////////////// 999 // This pseudocode uses following variables: 1000 // 1001 // SPI_offset, IV_len, ICV_len, State, SPI, 1002 // IP_total_len, IP_hdr_len, IP_Src_IP, IP_Dst_IP 1003 // as defined in fastpath pseudocode. 1004 // 1005 // Stored_Check_Bits:Number of bits we have successfully 1006 // checked to contain acceptable values 1007 // in the actual payload data. This value 1008 // is stored / retrieved from SPI cache. 1009 // 1010 // Check_Bits: Number of bits we have successfully 1011 // checked to contain acceptable values 1012 // in the actual payload data. This value 1013 // is updated during the packet 1014 // verification. 1015 // 1016 // Last_Packet_Data: Contains selected pieces from the 1017 // last packet. This is used to compare 1018 // certain fields of this packet to 1019 // same fields in previous packet. 1020 // 1021 // Packet_Data: Selected pieces of this packet, same 1022 // fields as Last_Packet_Data, and this 1023 // is stored as new Last_Packet_Data to 1024 // SPI cache after this packet is processed. 1025 // 1026 // Test_ICV_len: Temporary ICV length used during tests. 1027 // This is stored to ICV_len when 1028 // padding checks for the packet succeed 1029 // and the packet didn't yet have unsure 1030 // status. 1031 // 1032 // Test_IV_len: Temporary IV length used during tests. 1033 // 1034 // Pad_len: Padding length from the ESP packet. 1035 // 1036 // Protocol: Protocol number of the packet inside ESP 1037 // packet. 1038 // 1039 // TCP.*: Fields from TCP header (from inside ESP) 1040 // UDP.*: Fields from UDP header (from inside ESP) 1041 //////////////////////////////////////////////////////////// 1042 // This code starts the actual heuristics. 1043 // During this the fastpath has already loaded 1044 // State, ICV_len and IV_len in case they were 1045 // found from the SPI cache (i.e. in case the flow 1046 // had unsure status). 1047 // 1048 Autodetect ESP parameters: 1049 // First we check if this is unsure flow, and 1050 // if so, we check next packet against the 1051 // already set IV/ICV_len combination. 1052 * If State is unsure 1053 * Call Verify next packet 1054 * If State is ESP-NULL 1055 * Goto Store ESP-NULL SPI cache info 1056 * If State is unsure 1057 * Goto Verify unsure 1058 // If we failed the test, i.e. State 1059 // was changed to ESP, we check other 1060 // ICV/IV_len values, i.e. fall through 1061 // ICV lengths are tested in order of ICV lengths, 1062 // from shortest to longest. 1063 * Call Try standard algorithms 1064 * If State is ESP-NULL 1065 * Goto Store ESP-NULL SPI cache info 1066 * Call Try 128bit algorithms 1067 * If State is ESP-NULL 1068 * Goto Store ESP-NULL SPI cache info 1069 * Call Try 192bit algorithms 1070 * If State is ESP-NULL 1071 * Goto Store ESP-NULL SPI cache info 1072 * Call Try 256bit algorithms 1073 * If State is ESP-NULL 1074 * Goto Store ESP-NULL SPI cache info 1075 // AUTH_DES_MAC and AUTH_KPDK_MD5 are left out from 1076 // this document. 1077 // If any of those test above set state to unsure 1078 // we mark IPsec flow as unsure. 1079 * If State is unsure 1080 * Goto Store unsure SPI cache info 1081 // All of the test failed, meaning the packet cannot 1082 // be ESP-NULL packet, thus we mark IPsec flow as ESP 1083 * Goto Store ESP SPI cache info 1085 //////////////////////////////////////////////////////////// 1086 // Store ESP-NULL status to the IPsec flow cache. 1087 // 1088 Store ESP-NULL SPI cache info: 1090 * Store State, IV_len, ICV_len to SPI cache 1091 using IP_Src_IP + IP_Dst_IP + SPI as key 1092 * Continue Check ESP-NULL packet 1094 //////////////////////////////////////////////////////////// 1095 // Store encrypted ESP status to the IPsec flow cache. 1096 // 1097 Store ESP SPI cache info: 1098 * Store State, IV_len, ICV_len to SPI cache 1099 using IP_Src_IP + IP_Dst_IP + SPI as key 1100 * Continue Check non-ESP-NULL packet 1102 //////////////////////////////////////////////////////////// 1103 // Store unsure flow status to IPsec flow cache. 1104 // Here we also store the Check_Bits. 1105 // 1106 Store unsure SPI cache info: 1107 * Store State, IV_len, ICV_len, 1108 Stored_Check_Bits to SPI cache 1109 using IP_Src_IP + IP_Dst_IP + SPI as key 1110 * Continue Check unknown packet 1112 //////////////////////////////////////////////////////////// 1113 // Verify this packet against the previously selected 1114 // ICV_len and IV_len values. This will either 1115 // fail (and set state to ESP to mark we do not yet 1116 // know what type of flow this is), or it will 1117 // increment Check_Bits. 1118 // 1119 Verify next packet: 1120 // We already have IV_len, ICV_len and State loaded 1121 * Load Stored_Check_Bits, Last_Packet_Data from SPI Cache 1122 * Set Test_ICV_len to ICV_len, Test_IV_len to IV_len 1123 * Initialize Check_Bits to 0 1124 * Call Verify padding 1125 * If verify padding returned Failure 1126 // Initial guess was wrong, restart 1127 * Set State to ESP 1128 * Clear IV_len, ICV_len, State, 1129 Stored_Check_Bits, Last_Packet_Data 1130 from SPI Cache 1131 * Return 1132 // Ok, padding check succeeded again 1133 * Call Verify packet 1134 * If verify packet returned Failure 1135 // Guess was wrong, restart 1136 * Set State to ESP 1137 * Clear IV_len, ICV_len, State, 1138 Stored_Check_Bits, Last_Packet_Data 1139 from SPI Cache 1140 * Return 1141 // It succeeded and updated Check_Bits and Last_Packet_Data store 1142 // them to SPI cache 1143 * Increment Stored_Check_Bits by Check_Bits 1144 * Store Stored_Check_Bits to SPI Cache 1145 * Store Packet_Data as Last_Packet_Data to SPI cache 1146 * Return 1148 //////////////////////////////////////////////////////////// 1149 // This will check if we have already seen enough bits 1150 // acceptable from the payload data, so we can decide 1151 // that this IPsec flow is ESP-NULL flow. 1152 // 1153 Verify unsure: 1154 // Check if we have enough check bits 1155 * If Stored_Check_Bits > configured limit 1156 // We have checked enough bits, return ESP-NULL 1157 * Set State ESP-NULL 1158 * Goto Store ESP-NULL SPI cache info 1159 // Not yet enough bits, continue 1160 * Continue Check unknown packet 1162 //////////////////////////////////////////////////////////// 1163 // Check for standard 96-bit algorithms. 1164 // 1165 Try standard algorithms: 1166 // AUTH_HMAC_MD5_96, AUTH_HMAC_SHA1_96, AUTH_AES_XCBC_96, 1167 // AUTH_AES_CMAC_96 1168 * Set Test_ICV_len to 12, Test_IV_len to 0 1169 * Goto Check packet 1171 //////////////////////////////////////////////////////////// 1172 // Check for 128-bit algorithms, this is only one that 1173 // can have IV, so we need to check different IV_len values 1174 // here too. 1175 // 1176 Try 128bit algorithms: 1177 // AUTH_HMAC_SHA2_256_128, ENCR_NULL_AUTH_AES_GMAC 1178 * Set Test_ICV_len to 16, Test_IV_len to 0 1179 * If IP_total_len < IP_hdr_len + SPI_offset 1180 + Test_IV_len + Test_ICV_len 1181 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1182 * Return 1183 * Call Verify padding 1184 * If verify padding returned Failure 1185 * Return 1187 * Initialize Check_Bits to 0 1188 * Call Verify packet 1189 * If verify packet returned Failure 1190 * Goto Try GMAC 1191 // Ok, packet seemed ok, but go now and check if we have enough 1192 // data bits so we can assume it is ESP-NULL 1193 * Goto Check if done for unsure 1195 //////////////////////////////////////////////////////////// 1196 // Check for GMAC macs, i.e. macs having 8 byte IV. 1197 // 1198 Try GMAC: 1199 // ENCR_NULL_AUTH_AES_GMAC 1200 * Set Test_IV_len to 8 1201 * If IP_total_len < IP_hdr_len + SPI_offset 1202 + Test_IV_len + Test_ICV_len 1203 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1204 * Return 1205 * Initialize Check_Bits to 0 1206 * Call Verify packet 1207 * If verify packet returned Failure 1208 // Guess was wrong, continue 1209 * Return 1210 // Ok, packet seemed ok, but go now and check if we have enough 1211 // data bits so we can assume it is ESP-NULL 1212 * Goto Check if done for unsure 1214 //////////////////////////////////////////////////////////// 1215 // Check for 192-bit algorithms. 1216 // 1217 Try 192bit algorithms: 1218 // AUTH_HMAC_SHA2_384_192 1219 * Set Test_ICV_len to 24, Test_IV_len to 0 1220 * Goto Check packet 1222 //////////////////////////////////////////////////////////// 1223 // Check for 256-bit algorithms. 1224 // 1225 Try 256bit algorithms: 1226 // AUTH_HMAC_SHA2_512_256 1227 * Set Test_ICV_len to 32, Test_IV_len to 0 1228 * Goto Check packet 1230 //////////////////////////////////////////////////////////// 1231 // This actually does the checking for the packet, by 1232 // first verifying the length, and then self describing 1233 // padding, and if that succeeds, then checks the actual 1234 // payload content. 1236 // 1237 Check packet: 1238 * If IP_total_len < IP_hdr_len + SPI_offset 1239 + Test_IV_len + Test_ICV_len 1240 + 4 (spi) + 4 (seq no) + 4 (protocol + padding) 1241 * Return 1242 * Call Verify padding 1243 * If verify padding returned Failure 1244 * Return 1245 * Initialize Check_Bits to 0 1246 * Call Verify packet 1247 * If verify packet returned Failure 1248 // Guess was wrong, continue 1249 * Return 1250 // Ok, packet seemed ok, but go now and check if we have enough 1251 // data bits so we can assume it is ESP-NULL 1252 * Goto Check if done for unsure 1254 //////////////////////////////////////////////////////////// 1255 // This code checks if we have seen enough acceptable 1256 // values in the payload data, so we can decide that this 1257 // IPsec flow is ESP-NULL flow. 1258 // 1259 Check if done for unsure: 1260 * If Stored_Check_Bits > configured limit 1261 // We have checked enough bits, return ESP-NULL 1262 * Set State ESP-NULL 1263 * Set IV_len to Test_IV_len, ICV_len to Test_ICV_len 1264 * Clear Stored_Check_Bits, Last_Packet_Data from SPI Cache 1265 * Return 1266 // Not yet enough bits, check this is first unsure, if so 1267 // store information. In case there is multiple 1268 // tests succeeding, we always assume the first one 1269 // (the wone using shortest MAC) is the one we want to 1270 // check in the future. 1271 * If State is not unsure 1272 * Set State unsure 1273 // These values will be stored to SPI cache if 1274 // the final state will be unsure 1275 * Set IV_len to Test_IV_len, ICV_len to Test_ICV_len 1276 * Set Stored_Check_Bits as Check_Bits 1277 * Return 1279 //////////////////////////////////////////////////////////// 1280 // Verify self describing padding 1281 // 1282 Verify padding: 1283 * Load Pad_len from IP_total_len - Test_ICV_len - 2 1284 * Verify padding bytes at 1285 IP_total_len - Test_ICV_len - 1 - Pad_len .. 1286 IP_total_len - Test_ICV_len - 2 are 1287 1, 2, ..., Pad_len 1288 * If Verify of padding bytes succeeded 1289 * Return Success 1290 * Return Failure 1292 //////////////////////////////////////////////////////////// 1293 // This will verify the actual protocol content inside ESP 1294 // packet. 1295 // 1296 Verify packet: 1297 // We need to first check things that cannot be set, i.e if any of 1298 // those are incorrect, then we return Failure. For any 1299 / fields which might be correct, we increment the Check_Bits 1300 // for a suitable amount of bits. If all checks pass, then 1301 // we just return Success, and the upper layer will then 1302 // later check if we have enough bits checked already. 1303 * Load Protocol From IP_total_len - Test_ICV_len - 1 1304 * If Protocol TCP 1305 * Goto Verify TCP 1306 * If Protocol UDP 1307 * Goto Verify UDP 1308 // Other protocols can be added here as needed, most likely same 1309 // protocols as deep inspection does 1310 // Tunnel mode checks (protocol 4 for IPv4 and protocol 41 for 1311 // IPv6) is also left out from here to make the document shorter. 1312 * Return Failure 1314 //////////////////////////////////////////////////////////// 1315 // Verify TCP protocol headers 1316 // 1317 Verify TCP: 1318 // First we check things that must be set correctly. 1319 * If TCP.Data_Offset field < 5 1320 // TCP head length too small 1321 * Return Failure 1322 // After that we start to check things that does not 1323 // have one definitive value, but can have multiple possible 1324 // valid values 1325 * If TCP.ACK bit is not set, then check 1326 that TCP.Acknowledgment_number field contains 0 1327 // If ACK bit is not set then the acknowledgment 1328 // field usually contains 0, but I do not think 1329 // RFCs mandate it being zero, so we cannot make 1330 // this a failure if it is not so. 1331 * Increment Check_Bits by 32 1333 * If TCP.URG bit is not set, then check 1334 that TCP.Urgent_Pointer field contains 0 1335 // If URG bit is not set then urgent pointer 1336 // field usually contains 0, but I do not think 1337 // RFCs mandate it being zero, so we cannot make 1338 // this failure if it is not so. 1339 * Increment Check_Bits by 16 1340 * If TCP.Data_Offset field == 5 1341 * Increment Check_Bits by 4 1342 * If TCP.Data_Offset field > 5 1343 * If TCP options format is valid and it is padded correctly 1344 * Increment Check_Bits accordingly 1345 * If TCP options format was garbage 1346 * Return Failure 1347 * If TCP.checksum is correct 1348 // This might be wrong because packet passed NAT, so 1349 // we cannot make this failure case 1350 * Increment Check_Bits by 16 1351 // We can also do normal deeper TCP inspection here, i.e. 1352 // check that SYN/ACK/FIN/RST bits are correct and state 1353 // matches the state of existing flow if this is packet 1354 // to existing flow etc. 1355 // If there is anything clearly wrong in the packet (i.e. 1356 // some data is set to something that it cannot be), then 1357 // this can return Failure, otherwise it should just 1358 // increment Check_Bits matching the number of bits checked. 1359 // 1360 // We can also check things here compared to the last packet 1361 * If Last_Packet_Data.TCP.source port = 1362 Packet_Data.TCP.source_port and 1363 Last_Packet_Data.TCP.destination port = 1364 Packet_Data.TCP.destination port 1365 * Increment Check_Bits by 32 1366 * If Last_Packet_Data.TCP.acknowledgement_number = 1367 Packet_Data.TCP.acknowledgement_number 1368 * Increment Check_Bits by 32 1369 * If Last_Packet_Data.TCP.sequence_number = 1370 Packet_Data.TCP.sequence_number 1371 * Increment Check_Bits by 32 1372 // We can do other similar checks here 1373 * Return Success 1375 //////////////////////////////////////////////////////////// 1376 // Verify UDP protocol headers 1377 // 1378 Verify UDP: 1379 // First we check things that must be set correctly. 1380 * If UDP.UDP_length > IP_total_len - IP_hdr_len - SPI_offset 1381 - Test_IV_len - Test_ICV_len - 4 (spi) 1382 - 4 (seq no) - 1 (protocol) 1383 - Pad_len - 1 (Pad_len) 1384 * Return Failure 1385 * If UDP.UDP_length < 8 1386 * Return Failure 1387 // After that we start to check things that does not 1388 // have one definitive value, but can have multiple possible 1389 // valid values 1390 * If UDP.UDP_checksum is correct 1391 // This might be wrong because packet passed NAT, so 1392 // we cannot make this failure case 1393 * Increment Check_Bits by 16 1394 * If UDP.UDP_length = IP_total_len - IP_hdr_len - SPI_offset 1395 - Test_IV_len - Test_ICV_len - 4 (spi) 1396 - 4 (seq no) - 1 (protocol) 1397 - Pad_len - 1 (Pad_len) 1398 // If there is no TFC padding then UDP_length 1399 // will be matching the full packet length 1400 * Increment Check_Bits by 16 1401 // We can also do normal deeper UDP inspection here. 1402 // If there is anything clearly wrong in the packet (i.e. 1403 // some data is set to something that it cannot be), then 1404 // this can return Failure, otherwise it should just 1405 // increment Check_Bits matching the number of bits checked. 1406 // 1407 // We can also check things here compared to the last packet 1408 * If Last_Packet_Data.UDP.source_port = 1409 Packet_Data.UDP.source_port and 1410 Last_Packet_Data.destination_port = 1411 Packet_Data.UDP.destination_port 1412 * Increment Check_Bits by 32 1413 * Return Success 1415 Figure 4 1417 Authors' Addresses 1419 Tero Kivinen 1420 Safenet, Inc. 1421 Fredrikinkatu 47 1422 HELSINKI FIN-00100 1423 FI 1425 Email: kivinen@iki.fi 1427 Daniel L. McDonald 1428 Sun Microsystems, Inc. 1429 35 Network Drive 1430 MS UBUR02-212 1431 Burlington, MA 01803 1432 USA 1434 Email: danmcd@sun.com