idnits 2.17.1 draft-ietf-ipsecme-ddos-protection-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. 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 == The document seems to use 'NOT RECOMMENDED' as an RFC 2119 keyword, but does not include the phrase in its RFC 2119 key words list. -- The document date (July 1, 2016) is 2853 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Possible downref: Non-RFC (?) normative reference: ref. 'IKEV2-IANA' Summary: 0 errors (**), 0 flaws (~~), 2 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 IPSecME Working Group Y. Nir 3 Internet-Draft Check Point 4 Intended status: Standards Track V. Smyslov 5 Expires: January 2, 2017 ELVIS-PLUS 6 July 1, 2016 8 Protecting Internet Key Exchange Protocol version 2 (IKEv2) 9 Implementations from Distributed Denial of Service Attacks 10 draft-ietf-ipsecme-ddos-protection-07 12 Abstract 14 This document recommends implementation and configuration best 15 practices for Internet Key Exchange Protocol version 2 (IKEv2) 16 Responders, to allow them to resist Denial of Service and Distributed 17 Denial of Service attacks. Additionally, the document introduces a 18 new mechanism called "Client Puzzles" that help accomplish this task. 20 Status of This Memo 22 This Internet-Draft is submitted in full conformance with the 23 provisions of BCP 78 and BCP 79. 25 Internet-Drafts are working documents of the Internet Engineering 26 Task Force (IETF). Note that other groups may also distribute 27 working documents as Internet-Drafts. The list of current Internet- 28 Drafts is at http://datatracker.ietf.org/drafts/current/. 30 Internet-Drafts are draft documents valid for a maximum of six months 31 and may be updated, replaced, or obsoleted by other documents at any 32 time. It is inappropriate to use Internet-Drafts as reference 33 material or to cite them other than as "work in progress." 35 This Internet-Draft will expire on January 2, 2017. 37 Copyright Notice 39 Copyright (c) 2016 IETF Trust and the persons identified as the 40 document authors. All rights reserved. 42 This document is subject to BCP 78 and the IETF Trust's Legal 43 Provisions Relating to IETF Documents 44 (http://trustee.ietf.org/license-info) in effect on the date of 45 publication of this document. Please review these documents 46 carefully, as they describe your rights and restrictions with respect 47 to this document. Code Components extracted from this document must 48 include Simplified BSD License text as described in Section 4.e of 49 the Trust Legal Provisions and are provided without warranty as 50 described in the Simplified BSD License. 52 Table of Contents 54 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 55 2. Conventions Used in This Document . . . . . . . . . . . . . . 3 56 3. The Vulnerability . . . . . . . . . . . . . . . . . . . . . . 3 57 4. Defense Measures while the IKE SA is being created . . . . . 6 58 4.1. Retention Periods for Half-Open SAs . . . . . . . . . . . 6 59 4.2. Rate Limiting . . . . . . . . . . . . . . . . . . . . . . 6 60 4.3. The Stateless Cookie . . . . . . . . . . . . . . . . . . 7 61 4.4. Puzzles . . . . . . . . . . . . . . . . . . . . . . . . . 8 62 4.5. Session Resumption . . . . . . . . . . . . . . . . . . . 10 63 4.6. Keeping computed Shared Keys . . . . . . . . . . . . . . 11 64 4.7. Preventing "Hash and URL" Certificate Encoding Attacks . 11 65 4.8. IKE Fragmentation . . . . . . . . . . . . . . . . . . . . 12 66 5. Defense Measures after an IKE SA is created . . . . . . . . . 12 67 6. Plan for Defending a Responder . . . . . . . . . . . . . . . 13 68 7. Using Puzzles in the Protocol . . . . . . . . . . . . . . . . 15 69 7.1. Puzzles in IKE_SA_INIT Exchange . . . . . . . . . . . . . 15 70 7.1.1. Presenting a Puzzle . . . . . . . . . . . . . . . . . 16 71 7.1.2. Solving a Puzzle and Returning the Solution . . . . . 18 72 7.1.3. Computing a Puzzle . . . . . . . . . . . . . . . . . 19 73 7.1.4. Analyzing Repeated Request . . . . . . . . . . . . . 19 74 7.1.5. Deciding if to Serve the Request . . . . . . . . . . 21 75 7.2. Puzzles in an IKE_AUTH Exchange . . . . . . . . . . . . . 22 76 7.2.1. Presenting Puzzle . . . . . . . . . . . . . . . . . . 22 77 7.2.2. Solving Puzzle and Returning the Solution . . . . . . 23 78 7.2.3. Computing the Puzzle . . . . . . . . . . . . . . . . 24 79 7.2.4. Receiving the Puzzle Solution . . . . . . . . . . . . 24 80 8. Payload Formats . . . . . . . . . . . . . . . . . . . . . . . 25 81 8.1. PUZZLE Notification . . . . . . . . . . . . . . . . . . . 25 82 8.2. Puzzle Solution Payload . . . . . . . . . . . . . . . . . 25 83 9. Operational Considerations . . . . . . . . . . . . . . . . . 26 84 10. Security Considerations . . . . . . . . . . . . . . . . . . . 27 85 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 27 86 12. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 28 87 13. References . . . . . . . . . . . . . . . . . . . . . . . . . 28 88 13.1. Normative References . . . . . . . . . . . . . . . . . . 28 89 13.2. Informative References . . . . . . . . . . . . . . . . . 28 90 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 29 92 1. Introduction 94 Denial of Service (DoS) attacks have always been considered a serious 95 threat. These attacks are usually difficult to defend against since 96 the amount of resources the victim has is always bounded (regardless 97 of how high it is) and because some resources are required for 98 distinguishing a legitimate session from an attack. 100 The Internet Key Exchange protocol version 2 (IKEv2) described in 101 [RFC7296] includes defense against DoS attacks. In particular, there 102 is a cookie mechanism that allows the IKE Responder to defend itself 103 against DoS attacks from spoofed IP-addresses. However, bot-nets 104 have become widespread, allowing attackers to perform Distributed 105 Denial of Service (DDoS) attacks, which are more difficult to defend 106 against. This document presents recommendations to help the 107 Responder counter (D)DoS attacks. It also introduces a new mechanism 108 -- "puzzles" -- that can help accomplish this task. 110 2. Conventions Used in This Document 112 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 113 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 114 document are to be interpreted as described in [RFC2119]. 116 3. The Vulnerability 118 The IKE_SA_INIT Exchange described in Section 1.2 of [RFC7296] 119 involves the Initiator sending a single message. The Responder 120 replies with a single message and also allocates memory for a 121 structure called a half-open IKE Security Association (SA). This 122 half-open SA is later authenticated in the IKE_AUTH Exchange. If 123 that IKE_AUTH request never comes, the half-open SA is kept for an 124 unspecified amount of time. Depending on the algorithms used and 125 implementation, such a half-open SA will use from around 100 bytes to 126 several thousands bytes of memory. 128 This creates an easy attack vector against an IKE Responder. 129 Generating the IKE_SA_INIT request is cheap. Sending large amounts 130 of IKE_SA_INIT requests can cause a Responder to use up all its 131 resources. If the Responder tries to defend against this by 132 throttling new requests, this will also prevent legitimate Initiators 133 from setting up IKE SAs. 135 An obvious defense, which is described in Section 4.2, is limiting 136 the number of half-open SAs opened by a single peer. However, since 137 all that is required is a single packet, an attacker can use multiple 138 spoofed source IP addresses. 140 If we break down what a Responder has to do during an initial 141 exchange, there are three stages: 143 1. When the IKE_SA_INIT request arrives, the Responder: 145 * Generates or re-uses a Diffie-Hellman (D-H) private part. 147 * Generates a Responder Security Parameter Index (SPI). 149 * Stores the private part and peer public part in a half-open SA 150 database. 152 2. When the IKE_AUTH request arrives, the Responder: 154 * Derives the keys from the half-open SA. 156 * Decrypts the request. 158 3. If the IKE_AUTH request decrypts properly: 160 * Validates the certificate chain (if present) in the IKE_AUTH 161 request. 163 The fourth stage where the Responder creates the Child SA is not 164 reached by attackers who cannot pass the authentication step. 166 Stage #1 is pretty light on CPU power, but requires some storage, and 167 it's very light for the Initiator as well. Stage #2 includes 168 private-key operations, so it is much heavier CPU-wise. Stage #3 may 169 include public key operations if certificates are involved. These 170 operations are often more computationly expensive than those 171 performed at stage #2. 173 To attack such a Responder, an attacker can attempt either to exhaust 174 memory or to exhaust CPU. Without any protection, the most efficient 175 attack is to send multiple IKE_SA_INIT requests and exhaust memory. 176 This is easy because IKE_SA_INIT requests are cheap. 178 There are obvious ways for the Responder to protect itself without 179 changes to the protocol. It can reduce the time that an entry 180 remains in the half-open SA database, and it can limit the amount of 181 concurrent half-open SAs from a particular address or prefix. The 182 attacker can overcome this by using spoofed source addresses. 184 The stateless cookie mechanism from Section 2.6 of [RFC7296] prevents 185 an attack with spoofed source addresses. This doesn't completely 186 solve the issue, but it makes the limiting of half-open SAs by 187 address or prefix work. Puzzles, introduced in Section 4.4, 188 accomplish the same thing only more of it. They make it harder for 189 an attacker to reach the goal of getting a half-open SA. Puzzles do 190 not have to be so hard that an attacker cannot afford to solve a 191 single puzzle; it is enough that puzzles increase the cost of 192 creating a half-open SAs, so the attacker is limited in the amount 193 they can create. 195 Reducing the lifetime of an abandoned half-open SA also reduces the 196 impact of such attacks. For example, if a half-open SA is kept for 1 197 minute and the capacity is 60 thousand half-open SAs, an attacker 198 would need to create one thousand half-open SAs per second. If the 199 retention time is reduced to 3 seconds, the attacker would need to 200 create 20 thousand half-open SAs per second to get the same result. 201 By introducing a puzzle, each half-open SA becomes more expensive for 202 an attacker, making it more likely to prevent an exhaustion attack 203 against Responder memory. 205 At this point, filling up the half-open SA database is no longer the 206 most efficient DoS attack. The attacker has two alternative attacks 207 to do better: 209 1. Go back to spoofed addresses and try to overwhelm the CPU that 210 deals with generating cookies, or 212 2. Take the attack to the next level by also sending an IKE_AUTH 213 request. 215 If an attacker is so powerfull that it is able to overwhelm the 216 Responder's CPU that deals with generating cookies, then the attack 217 cannot be dealt with at the IKE level and must be handled by means of 218 the Intrusion Prevention System (IPS) technology. 220 On the other hand, the second alternative of sending an IKE_AUTH 221 request is very cheap. It requires generating a proper IKE header 222 with the correct IKE SPIs and a single Encrypted payload. The 223 content of the payload is irrelevant and might be junk. The 224 Responder has to perform the relatively expensive key derivation, 225 only to find that the MAC on the Encrypted payload on the IKE_AUTH 226 request fails the integrity check. If a Responder does not hold on 227 to the calculated SKEYSEED and SK_* keys (which it should in case a 228 valid IKE_AUTH comes in later) this attack might be repeated on the 229 same half-open SA. Puzzles make attacks of such sort more costly for 230 an attacker. See Section 7.2 for details. 232 Here too, the number of half-open SAs that the attacker can achieve 233 is crucial, because each one allows the attacker to waste some CPU 234 time. So making it hard to make many half-open SAs is important. 236 A strategy against DDoS has to rely on at least 4 components: 238 1. Hardening the half-open SA database by reducing retention time. 240 2. Hardening the half-open SA database by rate-limiting single IPs/ 241 prefixes. 243 3. Guidance on what to do when an IKE_AUTH request fails to decrypt. 245 4. Increasing the cost of half-open SAs up to what is tolerable for 246 legitimate clients. 248 Puzzles are used as a solution for strategy #4. 250 4. Defense Measures while the IKE SA is being created 252 4.1. Retention Periods for Half-Open SAs 254 As a UDP-based protocol, IKEv2 has to deal with packet loss through 255 retransmissions. Section 2.4 of [RFC7296] recommends "that messages 256 be retransmitted at least a dozen times over a period of at least 257 several minutes before giving up". Many retransmission policies in 258 practice wait one or two seconds before retransmitting for the first 259 time. 261 Because of this, setting the timeout on a half-open SA too low will 262 cause it to expire whenever even one IKE_AUTH request packet is lost. 263 When not under attack, the half-open SA timeout SHOULD be set high 264 enough that the Initiator will have enough time to send multiple 265 retransmissions, minimizing the chance of transient network 266 congestion causing an IKE failure. 268 When the system is under attack, as measured by the amount of half- 269 open SAs, it makes sense to reduce this lifetime. The Responder 270 should still allow enough time for the round-trip, enough time for 271 the Initiator to derive the D-H shared value, and enough time to 272 derive the IKE SA keys and the create the IKE_AUTH request. Two 273 seconds is probably as low a value as can realistically be used. 275 It could make sense to assign a shorter value to half-open SAs 276 originating from IP addresses or prefixes that are considered suspect 277 because of multiple concurrent half-open SAs. 279 4.2. Rate Limiting 281 Even with DDoS, the attacker has only a limited amount of nodes 282 participating in the attack. By limiting the amount of half-open SAs 283 that are allowed to exist concurrently with each such node, the total 284 amount of half-open SAs is capped, as is the total amount of key 285 derivations that the Responder is forced to complete. 287 In IPv4 it makes sense to limit the number of half-open SAs based on 288 IP address. Most IPv4 nodes are either directly attached to the 289 Internet using a routable address or are hidden behind a NAT device 290 with a single IPv4 external address. For IPv6, ISPs assign between a 291 /48 and a /64, so it does not make sense for rate-limiting to work on 292 single IPv6 IPs. Instead, ratelimits should be done based on either 293 the /48 or /64 of the misbehaving IPv6 address observed. 295 The number of half-open SAs is easy to measure, but it is also 296 worthwhile to measure the number of failed IKE_AUTH exchanges. If 297 possible, both factors should be taken into account when deciding 298 which IP address or prefix is considered suspicious. 300 There are two ways to rate-limit a peer address or prefix: 302 1. Hard Limit - where the number of half-open SAs is capped, and any 303 further IKE_SA_INIT requests are rejected. 305 2. Soft Limit - where if a set number of half-open SAs exist for a 306 particular address or prefix, any IKE_SA_INIT request will be 307 required to solve a puzzle. 309 The advantage of the hard limit method is that it provides a hard cap 310 on the amount of half-open SAs that the attacker is able to create. 311 The disadvantage is that it allows the attacker to block IKE 312 initiation from small parts of the Internet. For example, if an 313 network service provider or some establishment offers Internet 314 connectivity to its customers or employees through an IPv4 NAT 315 device, a single malicious customer can create enough half-open SAs 316 to fill the quota for the NAT device external IP address. Legitimate 317 Initiators on the same network will not be able to initiate IKE. 319 The advantage of a soft limit is that legitimate clients can always 320 connect. The disadvantage is that an adversary with sufficient CPU 321 resources can still effectively DoS the Responder. 323 Regardless of the type of rate-limiting used, legitimate initiators 324 that are not on the same network segments as the attackers will not 325 be affected. This is very important as it reduces the adverse impact 326 caused by the measures used to counteract the attack, and allows most 327 initiators to keep working even if they do not support puzzles. 329 4.3. The Stateless Cookie 331 Section 2.6 of [RFC7296] offers a mechanism to mitigate DoS attacks: 332 the stateless cookie. When the server is under load, the Responder 333 responds to the IKE_SA_INIT request with a calculated "stateless 334 cookie" - a value that can be re-calculated based on values in the 335 IKE_SA_INIT request without storing Responder-side state. The 336 Initiator is expected to repeat the IKE_SA_INIT request, this time 337 including the stateless cookie. This mechanism prevents DoS attacks 338 from spoofed IP addresses, since an attacker needs to have a routable 339 IP address to return the cookie. 341 Attackers that have multiple source IP addresses with return 342 routability, such as in the case of bot-nets, can fill up a half-open 343 SA table anyway. The cookie mechanism limits the amount of allocated 344 state to the number of attackers, multiplied by the number of half- 345 open SAs allowed per peer address, multiplied by the amount of state 346 allocated for each half-open SA. With typical values this can easily 347 reach hundreds of megabytes. 349 4.4. Puzzles 351 The puzzle introduced here extends the cookie mechanism of [RFC7296]. 352 It is loosely based on the proof-of-work technique used in Bitcoins 353 [bitcoins]. Puzzles set an upper bound, determined by the attacker's 354 CPU, to the number of negotiations the attacker can initiate in a 355 unit of time. 357 A puzzle is sent to the Initiator in two cases: 359 o The Responder is so overloaded that no half-open SAs may be 360 created without solving a puzzle, or 362 o The Responder is not too loaded, but the rate-limiting method 363 described in Section 4.2 prevents half-open SAs from being created 364 with this particular peer address or prefix without first solving 365 a puzzle. 367 When the Responder decides to send the challenge to solve a puzzle in 368 response to a IKE_SA_INIT request, the message includes at least 369 three components: 371 1. Cookie - this is calculated the same as in [RFC7296], i.e. the 372 process of generating the cookie is not specified. 374 2. Algorithm, this is the identifier of a Pseudo-Random Function 375 (PRF) algorithm, one of those proposed by the Initiator in the SA 376 payload. 378 3. Zero Bit Count (ZBC). This is a number between 8 and 255 (or a 379 special value - 0, see Section 7.1.1.1) that represents the 380 length of the zero-bit run at the end of the output of the PRF 381 function calculated over the cookie that the Initiator is to 382 send. The values 1-8 are explicitly excluded, because they 383 create a puzzle that is too easy to solve. Since the mechanism 384 is supposed to be stateless for the Responder, either the same 385 ZBC is used for all Initiators, or the ZBC is somehow encoded in 386 the cookie. If it is global then it means that this value is the 387 same for all the Initiators who are receiving puzzles at any 388 given point of time. The Responder, however, may change this 389 value over time depending on its load. 391 Upon receiving this challenge, the Initiator attempts to calculate 392 the PRF output using different keys. When enough keys are found such 393 that the resulting PRF output calculated using each of them has a 394 sufficient number of trailing zero bits, that result is sent to the 395 Responder. 397 The reason for using several keys in the results, rather than just 398 one key, is to reduce the variance in the time it takes the initiator 399 to solve the puzzle. We have chosen the number of keys to be four 400 (4) as a compromise between the conflicting goals of reducing 401 variance and reducing the work the Responder needs to perform to 402 verify the puzzle solution. 404 When receiving a request with a solved puzzle, the Responder verifies 405 two things: 407 o That the cookie is indeed valid. 409 o That the results of PRF of the transmitted cookie calculated with 410 the transmitted keys has a sufficient number of trailing zero 411 bits. 413 Example 1: Suppose the calculated cookie is 414 739ae7492d8a810cf5e8dc0f9626c9dda773c5a3 (20 octets), the algorithm 415 is PRF-HMAC-SHA256, and the required number of zero bits is 18. 416 After successively trying a bunch of keys, the Initiator finds the 417 following four 3-octet keys that work: 419 +--------+----------------------------------+----------+ 420 | Key | Last 32 Hex PRF Digits | # 0-bits | 421 +--------+----------------------------------+----------+ 422 | 061840 | e4f957b859d7fb1343b7b94a816c0000 | 18 | 423 | 073324 | 0d4233d6278c96e3369227a075800000 | 23 | 424 | 0c8a2a | 952a35d39d5ba06709da43af40700000 | 20 | 425 | 0d94c8 | 5a0452b21571e401a3d00803679c0000 | 18 | 426 +--------+----------------------------------+----------+ 428 Table 1: Three solutions for 18-bit puzzle 430 Example 2: Same cookie, but modify the required number of zero bits 431 to 22. The first 4-octet keys that work to satisfy that requirement 432 are 005d9e57, 010d8959, 0110778d, and 01187e37. Finding these 433 requires 18,382,392 invocations of the PRF. 435 +----------+-------------------------------+ 436 | # 0-bits | Time to Find 4 keys (seconds) | 437 +----------+-------------------------------+ 438 | 8 | 0.0025 | 439 | 10 | 0.0078 | 440 | 12 | 0.0530 | 441 | 14 | 0.2521 | 442 | 16 | 0.8504 | 443 | 17 | 1.5938 | 444 | 18 | 3.3842 | 445 | 19 | 3.8592 | 446 | 20 | 10.8876 | 447 +----------+-------------------------------+ 449 Table 2: The time needed to solve a puzzle of various difficulty for 450 the cookie = 739ae7492d8a810cf5e8dc0f9626c9dda773c5a3 452 The figures above were obtained on a 2.4 GHz single core i5. Run 453 times can be halved or quartered with multi-core code, but would be 454 longer on mobile phone processors, even if those are multi-core as 455 well. With these figures 18 bits is believed to be a reasonable 456 choice for puzzle level difficulty for all Initiators, and 20 bits is 457 acceptable for specific hosts/prefixes. 459 Using puzzles mechanism in the IKE_SA_INIT exchange is described in 460 Section 7.1. 462 4.5. Session Resumption 464 When the Responder is under attack, it SHOULD prefer previously 465 authenticated peers who present a Session Resumption ticket 466 [RFC5723]. However, the Responder SHOULD NOT serve resumed 467 Initiators exclusively because dropping all IKE_SA_INIT requests 468 would lock out legitimate Initiators that have no resumption ticket. 469 When under attack the Responder SHOULD require Initiators presenting 470 Session Resumption Tickets to pass a return routability check by 471 including the COOKIE notification in the IKE_SESSION_RESUME response 472 message, as described in Section 4.3.2. of [RFC5723]. Note that the 473 Responder SHOULD cache tickets for a short time to reject reused 474 tickets (Section 4.3.1), and therefore there should be no issue of 475 half-open SAs resulting from replayed IKE_SESSION_RESUME messages. 477 Several kinds of DoS attacks are possible on servers supported IKE 478 Session Resumption. See Section 9.3 of [RFC5723] for details. 480 4.6. Keeping computed Shared Keys 482 Once the IKE_SA_INIT exchange is finished, the Responder is waiting 483 for the first message of the IKE_AUTH exchange from the Initiator. 484 At this point the Initiator is not yet authenticated, and this fact 485 allows an attacker to perform an attack, described in Section 3. The 486 attacker can just send garbage in the IKE_AUTH message forcing the 487 Responder to perform costly CPU operations to compute SK_* keys. 489 If the received IKE_AUTH message failed to decrypt correctly (or 490 failed to pass ICV check), then the Responder SHOULD still keep the 491 computed SK_* keys, so that if it happened to be an attack, then an 492 attacker cannot get advantage of repeating the attack multiple times 493 on a single IKE SA. The responder can also use puzzles in the 494 IKE_AUTH exchange as decribed in Section 7.2. 496 4.7. Preventing "Hash and URL" Certificate Encoding Attacks 498 In IKEv2 each side may use the "Hash and URL" Certificate Encoding to 499 instruct the peer to retrieve certificates from the specified 500 location (see Section 3.6 of [RFC7296] for details). Malicious 501 initiators can use this feature to mount a DoS attack on the 502 responder by providing an URL pointing to a large file possibly 503 containing garbage. While downloading the file the responder 504 consumes CPU, memory and network bandwidth. 506 To prevent this kind of attack, the responder should not blindly 507 download the whole file. Instead, it SHOULD first read the initial 508 few bytes, decode the length of the ASN.1 structure from these bytes, 509 and then download no more than the decoded number of bytes. Note, 510 that it is always possible to determine the length of ASN.1 511 structures used in IKEv2, if they are DER-encoded, by analyzing the 512 first few bytes. However, since the content of the file being 513 downloaded can be under the attacker's control, implementations 514 should not blindly trust the decoded length and SHOULD check whether 515 it makes sense before continuing to download the file. 516 Implementations SHOULD also apply a configurable hard limit to the 517 number of pulled bytes and SHOULD provide an ability for an 518 administrator to either completely disable this feature or to limit 519 its use to a configurable list of trusted URLs. 521 4.8. IKE Fragmentation 523 IKE Fragmentation described in [RFC7383] allows IKE peers to avoid IP 524 fragmentation of large IKE messages. Attackers can mount several 525 kinds of DoS attacks using IKE Fragmentation. See Section 5 of 526 [RFC7383] for details on how to mitigate these attacks. 528 5. Defense Measures after an IKE SA is created 530 Once an IKE SA is created there usually are only a limited amount of 531 IKE messages exchanged. This IKE traffic consists of exchanges aimed 532 to create additional Child SAs, IKE rekeys, IKE deletions and IKE 533 liveness tests. Some of these exchanges require relatively little 534 resources (like liveness check), while others may be resource 535 consuming (like creating or rekeying Child SA with D-H exchange). 537 Since any endpoint can initiate a new exchange, there is a 538 possibility that a peer would initiate too many exchanges that could 539 exhaust host resources. For example, the peer can perform endless 540 continuous Child SA rekeying or create an overwhelming number of 541 Child SAs with the same Traffic Selectors etc. Such behavior can be 542 caused by broken implementations, misconfiguration, or as an 543 intentional attack. The latter becomes more of a real threat if the 544 peer uses NULL Authentication, as described in [RFC7619]. In this 545 case the peer remains anonymous, allowing it to escape any 546 responsibility for its behaviour. See Section 3 of [RFC7619] for 547 details on how to mitigate attacks when using NULL Authentication. 549 The following recommendations apply especially for NULL Authenticated 550 IKE sessions, but also apply to authenticated IKE sessions, with the 551 difference that in the latter case, the identified peer can be locked 552 out. 554 o If the IKEv2 window size is greater than one, peers are able to 555 initiate multiple simultaneous exchanges that increase host 556 resource consumption. Since there is no way in IKEv2 to decrease 557 window size once it has been increased (see Section 2.3 of 558 [RFC7296]), the window size cannot be dynamically adjusted 559 depending on the load. It is NOT RECOMMENDED to allow an IKEv2 560 window size greater than one when NULL Authentication has been 561 used. 563 o If a peer initiates an abusive amount of CREATE_CHILD_SA exchanges 564 to rekey IKE SAs or Child SAs, the Responder SHOULD reply with 565 TEMPORARY_FAILURE notifications indicating the peer must slow down 566 their requests. 568 o If a peer creates many Child SA with the same or overlapping 569 Traffic Selectors, implementations MAY respond with the 570 NO_ADDITIONAL_SAS notification. 572 o If a peer initiates many exchanges of any kind, the Responder MAY 573 introduce an artificial delay before responding to each request 574 message. This delay would decrease the rate the Responder needs 575 to process requests from any particular peer, and frees up 576 resources on the Responder that can be used for answering 577 legitimate clients. If the Responder receives retransmissions of 578 the request message during the delay period, the retransmitted 579 messages MUST be silently discarded. The delay must be short 580 enough to avoid legitimate peers deleting the IKE SA due to a 581 timeout. It is believed that a few seconds is enough. Note 582 however, that even a few seconds may be too long when settings 583 rely on an immediate response to the request message, e.g. for the 584 purposes of quick detection of a dead peer. 586 o If these counter-measures are inefficient, implementations MAY 587 delete the IKE SA with an offending peer by sending Delete 588 Payload. 590 In IKE, a client can request various configuration attributes from 591 server. Most often these attributes include internal IP addresses. 592 Malicious clients can try to exhaust a server's IP address pool by 593 continuously requesting a large number of internal addresses. Server 594 implementations SHOULD limit the number of IP addresses allocated to 595 any particular client. Note, this is not possible with clients using 596 NULL Authentication, since their identity cannot be verified. 598 6. Plan for Defending a Responder 600 This section outlines a plan for defending a Responder from a DDoS 601 attack based on the techniques described earlier. The numbers given 602 here are not normative, and their purpose is to illustrate the 603 configurable parameters needed for surviving DDoS attacks. 605 Implementations are deployed in different environments, so it is 606 RECOMMENDED that the parameters be settable. For example, most 607 commercial products are required to undergo benchmarking where the 608 IKE SA establishment rate is measured. Benchmarking is 609 indistinguishable from a DoS attack and the defenses described in 610 this document may defeat the benchmark by causing exchanges to fail 611 or take a long time to complete. Parameters SHOULD be tunable to 612 allow for benchmarking (if only by turning DDoS protection off). 614 Since all countermeasures may cause delays and additional work for 615 the Initiators, they SHOULD NOT be deployed unless an attack is 616 likely to be in progress. To minimize the burden imposed on 617 Initiators, the Responder should monitor incoming IKE requests, for 618 two scenarios: 620 1. A general DDoS attack. Such an attack is indicated by a high 621 number of concurrent half-open SAs, a high rate of failed 622 IKE_AUTH exchanges, or a combination of both. For example, 623 consider a Responder that has 10,000 distinct peers of which at 624 peak 7,500 concurrently have VPN tunnels. At the start of peak 625 time, 600 peers might establish tunnels within any given minute, 626 and tunnel establishment (both IKE_SA_INIT and IKE_AUTH) takes 627 anywhere from 0.5 to 2 seconds. For this Responder, we expect 628 there to be less than 20 concurrent half-open SAs, so having 100 629 concurrent half-open SAs can be interpreted as an indication of 630 an attack. Similarly, IKE_AUTH request decryption failures 631 should never happen. Supposing that the tunnels are established 632 using EAP (see Section 2.16 of [RFC7296]), users may be expected 633 to enter a wrong password about 20% of the time. So we'd expect 634 125 wrong password failures a minute. If we get IKE_AUTH 635 decryption failures from multiple sources more than once per 636 second, or EAP failures more than 300 times per minute, this can 637 also be an indication of a DDoS attack. 639 2. An attack from a particular IP address or prefix. Such an attack 640 is indicated by an inordinate amount of half-open SAs from a 641 specific IP address or prefix, or an inordinate amount of 642 IKE_AUTH failures. A DDoS attack may be viewed as multiple such 643 attacks. If these are mitigated successfully, there will not be 644 a need to enact countermeasures on all Initiators. For example, 645 measures might be 5 concurrent half-open SAs, 1 decrypt failure, 646 or 10 EAP failures within a minute. 648 Note that using counter-measures against an attack from a particular 649 IP address may be enough to avoid the overload on the half-open SA 650 database. In this case the number of failed IKE_AUTH exchanges will 651 never exceed the threshold of attack detection. 653 When there is no general DDoS attack, it is suggested that no cookie 654 or puzzles be used. At this point the only defensive measure is to 655 monitor the number of half-open SAs, and setting a soft limit per 656 peer IP or prefix. The soft limit can be set to 3-5. If the puzzles 657 are used, the puzzle difficulty should be set to such a level (number 658 of zero-bits) that all legitimate clients can handle it without 659 degraded user experience. 661 As soon as any kind of attack is detected, either a lot of 662 initiations from multiple sources or a lot of initiations from a few 663 sources, it is best to begin by requiring stateless cookies from all 664 Initiators. This will This will mitigate attacks based on IP address 665 spoofing, and help avoid the need to impose a greater burden in the 666 form of puzzles on the general population of Initiators. This makes 667 the per-node or per-prefix soft limit more effective. 669 When cookies are activated for all requests and the attacker is still 670 managing to consume too many resources, the Responder MAY start to 671 use puzzles for these requests or increase the difficulty of puzzles 672 imposed on IKE_SA_INIT requests coming from suspicious nodes/ 673 prefixes. This should still be doable by all legitimate peers, but 674 the use of puzzles at a higher difficulty may degrade the user 675 experience, for example by taking up to 10 seconds to solve the 676 puzzle. 678 If the load on the Responder is still too great, and there are many 679 nodes causing multiple half-open SAs or IKE_AUTH failures, the 680 Responder MAY impose hard limits on those nodes. 682 If it turns out that the attack is very widespread and the hard caps 683 are not solving the issue, a puzzle MAY be imposed on all Initiators. 684 Note that this is the last step, and the Responder should avoid this 685 if possible. 687 7. Using Puzzles in the Protocol 689 This section describes how the puzzle mechanism is used in IKEv2. It 690 is organized as follows. The Section 7.1 describes using puzzles in 691 the IKE_SA_INIT exchange and the Section 7.2 describes using puzzles 692 in the IKE_AUTH exchange. Both sections are divided into subsections 693 describing how puzzles should be presented, solved and processed by 694 the Initiator and the Responder. 696 7.1. Puzzles in IKE_SA_INIT Exchange 698 IKE Initiator indicates the desire to create a new IKE SA by sending 699 an IKE_SA_INIT request message. The message may optionally contain a 700 COOKIE notification if this is a repeated request performed after the 701 Responder's demand to return a cookie. 703 HDR, [N(COOKIE),] SA, KE, Ni, [V+][N+] --> 705 According to the plan, described in Section 6, the IKE Responder 706 should monitor incoming requests to detect whether it is under 707 attack. If the Responder learns that a (D)DoS attack is likely to be 708 in progress, then its actions depend on the volume of the attack. If 709 the volume is moderate, then the Responder requests the Initiator to 710 return a cookie. If the volume is so high, that puzzles need to be 711 used for defense, then the Responder requests the Initiator to solve 712 a puzzle. 714 The Responder MAY choose to process some fraction of IKE_SA_INIT 715 requests without presenting a puzzle while being under attack to 716 allow legacy clients, that don't support puzzles, to have a chance to 717 be served. The decision whether to process any particular request 718 must be probabilistic, with the probability depending on the 719 Responder's load (i.e. on the volume of attack). The requests that 720 don't contain the COOKIE notification MUST NOT participate in this 721 lottery. In other words, the Responder must first perform a return 722 routability check before allowing any legacy client to be served if 723 it is under attack. See Section 7.1.4 for details. 725 7.1.1. Presenting a Puzzle 727 If the Responder makes a decision to use puzzles, then it includes 728 two notifications in its response message - the COOKIE notification 729 and the PUZZLE notification. Note that the PUZZLE notification MUST 730 always be accompanied with the COOKIE notification, since the content 731 of the COOKIE notification is used as an input data when solving 732 puzzle. The format of the PUZZLE notification is described in 733 Section 8.1. 735 <-- HDR, N(COOKIE), N(PUZZLE), [V+][N+] 737 The presence of these notifications in an IKE_SA_INIT response 738 message indicates to the Initiator that it should solve the puzzle to 739 have a better chance to be served. 741 7.1.1.1. Selecting the Puzzle Difficulty Level 743 The PUZZLE notification contains the difficulty level of the puzzle - 744 the minimum number of trailing zero bits that the result of PRF must 745 contain. In diverse environments it is next to impossible for the 746 Responder to set any specific difficulty level that will result in 747 roughly the same amount of work for all Initiators, because 748 computation power of different Initiators may vary by an order of 749 magnitude, or even more. The Responder may set the difficulty level 750 to 0, meaning that the Initiator is requested to spend as much power 751 to solve a puzzle as it can afford. In this case no specific value 752 of ZBC is required from the Initiator, however the larger the ZBC 753 that Initiator is able to get, the better the chance is that it will 754 be served by the Responder. In diverse environments it is 755 RECOMMENDED that the Initiator set the difficulty level to 0, unless 756 the attack volume is very high. 758 If the Responder sets a non-zero difficulty level, then the level 759 should be determined by analyzing the volume of the attack. The 760 Responder MAY set different difficulty levels to different requests 761 depending on the IP address the request has come from. 763 7.1.1.2. Selecting the Puzzle Algorithm 765 The PUZZLE notification also contains identifier of the algorithm, 766 that must be used by Initiator to compute puzzle. 768 Cryptographic algorithm agility is considered an important feature 769 for modern protocols ([RFC7696]). Algorithm agility ensures that a 770 protocol doesn't rely on a single built-in set of cryptographic 771 algorithms, but has a means to replace one set with another, and 772 negotiate new algorithms with the peer. IKEv2 fully supports 773 cryptographic algorithm agility for its core operations. 775 To support crypto agility in case of puzzles, the algorithm that is 776 used to compute a puzzle needs to be negotiated during the 777 IKE_SA_INIT exchange. The negotiation is performed as follows. The 778 initial request message sent by the Initiator contains an SA payload 779 with the list of transforms the Initiator supports and is willing to 780 use in the IKE SA being established. The Responder parses the 781 received SA payload and finds a mutually supported PRFs. The 782 Responder selects the preferred PRF from the list of mutually 783 supported ones and includes it into the PUZZLE notification. There 784 is no requirement that the PRF selected for puzzles be the same as 785 the PRF that is negotiated later for use in core IKE SA crypto 786 operations. If there are no mutually supported PRFs, then IKE SA 787 negotiation will fail anyway and there is no reason to return a 788 puzzle. In this case the Responder returns a NO_PROPOSAL_CHOSEN 789 notification. Note that PRF is a mandatory transform type for IKE SA 790 (see Sections 3.3.2 and 3.3.3 of [RFC7296]) and at least one 791 transform of this type must always be present in the SA payload in an 792 IKE_SA_INIT request message. 794 7.1.1.3. Generating a Cookie 796 If the Responder supports puzzles then a cookie should be computed in 797 such a manner that the Responder is able to learn some important 798 information from the sole cookie, when it is later returned back by 799 Initiator. In particular - the Responder should be able to learn the 800 following information: 802 o Whether the puzzle was given to the Initiator or only the cookie 803 was requested. 805 o The difficulty level of the puzzle given to the Initiator. 807 o The number of consecutive puzzles given to the Initiator. 809 o The amount of time the Initiator spent to solve the puzzles. This 810 can be calculated if the cookie is timestamped. 812 This information helps the Responder to make a decision whether to 813 serve this request or demand more work from the Initiator. 815 One possible approach to get this information is to encode it in the 816 cookie. The format of such encoding is an implementation detail of 817 Responder, as the cookie would remain an opaque blob to the 818 Initiator. If this information is encoded in the cookie, then the 819 Responder MUST make it integrity protected, so that any intended or 820 accidental alteration of this information in the returned cookie is 821 detectable. So, the cookie would be generated as: 823 Cookie = | | 824 Hash(Ni | IPi | SPIi | | ) 826 Note, that according to the Section 2.6 of [RFC7296], the size of the 827 cookie cannot exceed 64 bytes. 829 Alternatively, the Responder may continue to generate a cookie as 830 suggested in Section 2.6 of [RFC7296], but associate the additional 831 information, using local storage identified with the particular 832 version of the secret. In this case the Responder should have 833 different secrets for every combination of difficulty level and 834 number of consecutive puzzles, and should change the secrets 835 periodically, keeping a few previous versions, to be able to 836 calculate how long ago a cookie was generated. 838 The Responder may also combine these approaches. This document 839 doesn't mandate how the Responder learns this information from a 840 cookie. 842 7.1.2. Solving a Puzzle and Returning the Solution 844 If the Initiator receives a puzzle but it doesn't support puzzles, 845 then it will ignore the PUZZLE notification as an unrecognized status 846 notification (in accordance to Section 3.10.1 of [RFC7296]). The 847 Initiator MAY ignore the PUZZLE notification if it is not willing to 848 spend resources to solve the puzzle of the requested difficulty, even 849 if it supports puzzles. In both cases the Initiator acts as 850 described in Section 2.6 of [RFC7296] - it restarts the request and 851 includes the received COOKIE notification into it. The Responder 852 should be able to distinguish the situation when it just requested a 853 cookie from the situation where the puzzle was given to the 854 Initiator, but the Initiator for some reason ignored it. 856 If the received message contains a PUZZLE notification and doesn't 857 contain a COOKIE notification, then this message is malformed because 858 it requests to solve the puzzle, but doesn't provide enough 859 information to allow the puzzle to be solved. In this case the 860 Initiator MUST ignore the received message and continue to wait until 861 either a valid PUZZLE notification is received or the retransmission 862 timer fires. If it fails to receive a valid message after several 863 retransmissions of IKE_SA_INIT requests, then it means that something 864 is wrong and the IKE SA cannot be established. 866 If the Initiator supports puzzles and is ready to solve them, then it 867 tries to solve the given puzzle. After the puzzle is solved the 868 Initiator restarts the request and returns back to the Responder the 869 puzzle solution in a new payload called a Puzzle Solution payload 870 (denoted as PS, see Section 8.2) along with the received COOKIE 871 notification. 873 HDR, N(COOKIE), [PS,] SA, KE, Ni, [V+][N+] --> 875 7.1.3. Computing a Puzzle 877 General principals of constructing puzzles in IKEv2 are described in 878 Section 4.4. They can be summarized as follows: given unpredictable 879 string S and pseudo-random function PRF find N different keys Ki 880 (where i=[1..N]) for that PRF so that the result of PRF(Ki,S) has at 881 least the specified number of trailing zero bits. This specification 882 requires that the solution to the puzzle contain 4 different keys 883 (i.e. N=4). 885 In the IKE_SA_INIT exchange it is the cookie that plays the role of 886 unpredictable string S. In other words, in the IKE_SA_INIT the task 887 for the IKE Initiator is to find the four different, equal-sized keys 888 Ki for the agreed upon PRF such that each result of PRF(Ki,cookie) 889 where i = [1..4] has a sufficient number of trailing zero bits. Only 890 the content of the COOKIE notification is used in puzzle calculation, 891 i.e. the header of the Notification payload is not included. 893 Note, that puzzles in the IKE_AUTH exchange are computed differently 894 than in the IKE_SA_INIT_EXCHANGE. See Section 7.2.3 for details. 896 7.1.4. Analyzing Repeated Request 898 The received request must at least contain a COOKIE notification. 899 Otherwise it is an initial request and it must be processed according 900 to Section 7.1. First, the cookie MUST be checked for validity. If 901 the cookie is invalid, then the request is treated as initial and is 902 processed according to Section 7.1. It is RECOMMENDED that a new 903 cookie is requested in this case. 905 If the cookie is valid, then some important information is learned 906 from it, or from local state based on identifier of the cookie's 907 secret (see Section 7.1.1.3 for details). This information helps the 908 Responder to sort out incoming requests, giving more priority to 909 those which were created by spending more of the Initiator's 910 resources. 912 First, the Responder determines if it requested only a cookie, or 913 presented a puzzle to the Initiator. If no puzzle was given, this 914 means that at the time the Responder requested a cookie it didn't 915 detect the (D)DoS attack or the attack volume was low. In this case 916 the received request message must not contain the PS payload, and 917 this payload MUST be ignored if the message contains a PS payload for 918 any reason. Since no puzzle was given, the Responder marks the 919 request with the lowest priority since the Initiator spent little 920 resources creating it. 922 If the Responder learns from the cookie that the puzzle was given to 923 the Initiator, then it looks for the PS payload to determine whether 924 its request to solve the puzzle was honored or not. If the incoming 925 message doesn't contain a PS payload, this means that the Initiator 926 either doesn't support puzzles or doesn't want to deal with them. In 927 either case the request is marked with the lowest priority since the 928 Initiator spent little resources creating it. 930 If a PS payload is found in the message, then the Responder MUST 931 verify the puzzle solution that it contains. The solution is 932 interpreted as four different keys. The result of using each of them 933 in the PRF (as described in Section 7.1.3) must contain at least the 934 requested number of trailing zero bits. The Responder MUST check all 935 of the four returned keys. 937 If any checked result contains fewer bits than were requested, this 938 means that the Initiator spent less resources than expected by the 939 Responder. This request is marked with the lowest priority. 941 If the Initiator provided the solution to the puzzle satisfying the 942 requested difficulty level, or if the Responder didn't indicate any 943 particular difficulty level (by setting ZBC to zero) and the 944 Initiator was free to select any difficulty level it can afford, then 945 the priority of the request is calculated based on the following 946 considerations: 948 o The Responder must take the smallest number of trailing zero bits 949 among the checked results and count it as the number of zero bits 950 the Initiator solved for. 952 o The higher number of zero bits the Initiator provides, the higher 953 priority its request should receive. 955 o The more consecutive puzzles the Initiator solved, the higher 956 priority it should receive. 958 o The more time the Initiator spent solving the puzzles, the higher 959 priority it should receive. 961 After the priority of the request is determined the final decision 962 whether to serve it or not is made. 964 7.1.5. Deciding if to Serve the Request 966 The Responder decides what to do with the request based on the 967 request's priority and the Responder's current load. There are three 968 possible actions: 970 o Accept request. 972 o Reject request. 974 o Demand more work from the Initiator by giving it a new puzzle. 976 The Responder SHOULD accept an incoming request if its priority is 977 high - this means that the Initiator spent quite a lot of resources. 978 The Responder MAY also accept some low-priority requests where the 979 Initiators don't support puzzles. The percentage of accepted legacy 980 requests depends on the Responder's current load. 982 If the Initiator solved the puzzle, but didn't spend much resources 983 for it (the selected puzzle difficulty level appeared to be low and 984 the Initiator solved it quickly), then the Responder SHOULD give it 985 another puzzle. The more puzzles the Initiator solves the higher its 986 chances are to be served. 988 The details of how the Responder makes a decision for any particular 989 request are implementation dependent. The Responder can collect all 990 of the incoming requests for some short period of time, sort them out 991 based on their priority, calculate the number of available memory 992 slots for half-open IKE SAs and then serve that number of requests 993 from the head of the sorted list. The remainder of requests can be 994 either discarded or responded to with new puzzle requests. 996 Alternatively, the Responder may decide whether to accept every 997 incoming request with some kind of lottery, taking into account its 998 priority and the available resources. 1000 7.2. Puzzles in an IKE_AUTH Exchange 1002 Once the IKE_SA_INIT exchange is completed, the Responder has created 1003 a state and is waiting for the first message of the IKE_AUTH exchange 1004 from the Initiator. At this point the Initiator has already passed 1005 the return routability check and has proved that it has performed 1006 some work to complete IKE_SA_INIT exchange. However, the Initiator 1007 is not yet authenticated and this allows a malicious Initiator to 1008 perform an attack, described in Section 3. Unlike a DoS attack in 1009 the IKE_SA_INIT exchange, which is targeted on the Responder's memory 1010 resources, the goal of this attack is to exhaust a Responder's CPU 1011 power. The attack is performed by sending the first IKE_AUTH message 1012 containing garbage. This costs nothing to the Initiator, but the 1013 Responder has to perform relatively costly operations when computing 1014 the D-H shared secret and deriving SK_* keys to be able to verify 1015 authenticity of the message. If the Responder doesn't keep the 1016 computed keys after an unsuccessful verification of the IKE_AUTH 1017 message, then the attack can be repeated several times on the same 1018 IKE SA. 1020 The Responder can use puzzles to make this attack more costly for the 1021 Initiator. The idea is that the Responder includes a puzzle in the 1022 IKE_SA_INIT response message and the Initiator includes a puzzle 1023 solution in the first IKE_AUTH request message outside the Encrypted 1024 payload, so that the Responder is able to verify puzzle solution 1025 before computing the D-H shared secret. The difficulty level of the 1026 puzzle should be selected so that the Initiator would spend 1027 substantially more time to solve the puzzle than the Responder to 1028 compute the shared secret. 1030 The Responder should constantly monitor the amount of the half-open 1031 IKE SA states that receive IKE_AUTH messages that cannot be decrypted 1032 due to integrity check failures. If the percentage of such states is 1033 high and it takes an essential fraction of Responder's computing 1034 power to calculate keys for them, then the Responder may assume that 1035 it is under attack and SHOULD use puzzles to make it harder for 1036 attackers. 1038 7.2.1. Presenting Puzzle 1040 The Responder requests the Initiator to solve a puzzle by including 1041 the PUZZLE notification in the IKE_SA_INIT response message. The 1042 Responder MUST NOT use puzzles in the IKE_AUTH exchange unless a 1043 puzzle has been previously presented and solved in the preceding 1044 IKE_SA_INIT exchange. 1046 <-- HDR, SA, KE, Nr, N(PUZZLE), [V+][N+] 1048 7.2.1.1. Selecting Puzzle Difficulty Level 1050 The difficulty level of the puzzle in the IKE_AUTH exchange should be 1051 chosen so that the Initiator would spend more time to solve the 1052 puzzle than the Responder to compute the D-H shared secret and the 1053 keys needed to decrypt and verify the IKE_AUTH request message. On 1054 the other hand, the difficulty level should not be too high, 1055 otherwise legitimate clients will experience an additional delay 1056 while establishing the IKE SA. 1058 Note, that since puzzles in the IKE_AUTH exchange are only allowed to 1059 be used if they were used in the preceding IKE_SA_INIT exchange, the 1060 Responder would be able to estimate the computational power of the 1061 Initiator and select the difficulty level accordingly. Unlike 1062 puzzles in the IKE_SA_INIT, the requested difficulty level for 1063 IKE_AUTH puzzles MUST NOT be zero. In other words, the Responder 1064 must always set a specific difficulty level and must not let the 1065 Initiator to choose it on its own. 1067 7.2.1.2. Selecting the Puzzle Algorithm 1069 The algorithm for the puzzle is selected as described in 1070 Section 7.1.1.2. There is no requirement that the algorithm for the 1071 puzzle in the IKE_SA INIT exchange be the same as the algorithm for 1072 the puzzle in IKE_AUTH exchange; however, it is expected that in most 1073 cases they will be the same. 1075 7.2.2. Solving Puzzle and Returning the Solution 1077 If the IKE_SA_INIT response message contains the PUZZLE notification 1078 and the Initiator supports puzzles, it MUST solve the puzzle. Note, 1079 that puzzle construction in the IKE_AUTH exchange differs from the 1080 puzzle construction in the IKE_SA_INIT exchange and is described in 1081 Section 7.2.3. Once the puzzle is solved the Initiator sends the 1082 IKE_AUTH request message, containing the Puzzle Solution payload. 1084 HDR, PS, SK {IDi, [CERT,] [CERTREQ,] 1085 [IDr,] AUTH, SA, TSi, TSr} --> 1087 The Puzzle Solution (PS) payload MUST be placed outside the Encrypted 1088 payload, so that the Responder is able to verify the puzzle before 1089 calculating the D-H shared secret and the SK_* keys. 1091 If IKE Fragmentation [RFC7383] is used in IKE_AUTH exchange, then the 1092 PS payload MUST be present only in the first IKE Fragment message, in 1093 accordance with the Section 2.5.3 of [RFC7383]. Note, that 1094 calculation of the puzzle in the IKE_AUTH exchange doesn't depend on 1095 the content of the IKE_AUTH message (see Section 7.2.3). Thus the 1096 Initiator has to solve the puzzle only once and the solution is valid 1097 for both unfragmented and fragmented IKE messages. 1099 7.2.3. Computing the Puzzle 1101 A puzzle in the IKE_AUTH exchange is computed differently than in the 1102 IKE_SA_INIT exchange (see Section 7.1.3). The general principle is 1103 the same; the difference is in the construction of the string S. 1104 Unlike the IKE_SA_INIT exchange, where S is the cookie, in the 1105 IKE_AUTH exchange S is a concatenation of Nr and SPIr. In other 1106 words, the task for IKE Initiator is to find the four different keys 1107 Ki for the agreed upon PRF such that each result of PRF(Ki,Nr | SPIr) 1108 where i=[1..4] has a sufficient number of trailing zero bits. Nr is 1109 a nonce used by the Responder in the IKE_SA_INIT exchange, stripped 1110 of any headers. SPIr is the IKE Responder's SPI from the IKE header 1111 of the SA being established. 1113 7.2.4. Receiving the Puzzle Solution 1115 If the Responder requested the Initiator to solve a puzzle in the 1116 IKE_AUTH exchange, then it MUST silently discard all the IKE_AUTH 1117 request messages without the Puzzle Solution payload. 1119 Once the message containing a solution to the puzzle is received, the 1120 Responder MUST verify the solution before performing computationlly 1121 intensive operations i.e. computing the D-H shared secret and the 1122 SK_* keys. The Responder MUST verify all four of the returned keys. 1124 The Responder MUST silently discard the received message if any 1125 checked verification result is not correct (contains insufficient 1126 number of trailing zero bits). If the Responder successfully 1127 verifies the puzzle and calculates the SK_* key, but the message 1128 authenticity check fails, then it SHOULD save the calculated keys in 1129 the IKE SA state while waiting for the retransmissions from the 1130 Initiator. In this case the Responder may skip verification of the 1131 puzzle solution and ignore the Puzzle Solution payload in the 1132 retransmitted messages. 1134 If the Initiator uses IKE Fragmentation, then it is possible, that 1135 due to packet loss and/or reordering the Responder could receive non- 1136 first IKE Fragment messages before receiving the first one containing 1137 the PS payload. In this case the Responder MAY choose to keep the 1138 received fragments until the first fragment containing the solution 1139 to the puzzle is received. In this case the Responder SHOULD NOT try 1140 to verify authenticity of the kept fragments until the first fragment 1141 with the PS payload is received and the solution to the puzzle is 1142 verified. After successful verification of the puzzle, the Responder 1143 can then calculate the SK_* key and verify authenticity of the 1144 collected fragments. 1146 8. Payload Formats 1148 8.1. PUZZLE Notification 1150 The PUZZLE notification is used by the IKE Responder to inform the 1151 Initiator about the need to solve the puzzle. It contains the 1152 difficulty level of the puzzle and the PRF the Initiator should use. 1154 1 2 3 1155 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 1156 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1157 | Next Payload |C| RESERVED | Payload Length | 1158 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1159 |Protocol ID(=0)| SPI Size (=0) | Notify Message Type | 1160 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1161 | PRF | Difficulty | 1162 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1164 o Protocol ID (1 octet) -- MUST be 0. 1166 o SPI Size (1 octet) - MUST be 0, meaning no Security Parameter 1167 Index (SPI) is present. 1169 o Notify Message Type (2 octets) -- MUST be , the value 1170 assigned for the PUZZLE notification. 1172 o PRF (2 octets) -- Transform ID of the PRF algorithm that must be 1173 used to solve the puzzle. Readers should refer to the section 1174 "Transform Type 2 - Pseudo-Random Function Transform IDs" in 1175 [IKEV2-IANA] for the list of possible values. 1177 o Difficulty (1 octet) -- Difficulty Level of the puzzle. Specifies 1178 the minimum number of trailing zero bits (ZBC), that each of the 1179 results of PRF must contain. Value 0 means that the Responder 1180 doesn't request any specific difficulty level and the Initiator is 1181 free to select an appropriate difficulty level on its own (see 1182 Section 7.1.1.1 for details). 1184 This notification contains no data. 1186 8.2. Puzzle Solution Payload 1188 The solution to the puzzle is returned back to the Responder in a 1189 dedicated payload, called the Puzzle Solution payload and denoted as 1190 PS in this document. 1192 1 2 3 1193 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 1194 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1195 | Next Payload |C| RESERVED | Payload Length | 1196 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1197 | | 1198 ~ Puzzle Solution Data ~ 1199 | | 1200 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1202 o Puzzle Solution Data (variable length) -- Contains the solution to 1203 the puzzle - four different keys for the selected PRF. This field 1204 MUST NOT be empty. All of the keys MUST have the same size, 1205 therefore the size of this field is always a mutiple of 4 bytes. 1206 If the selected PRF accepts only fixed-size keys, then the size of 1207 each key MUST be of that fixed size. If the agreed upon PRF 1208 accepts keys of any size, then then the size of each key MUST be 1209 between 1 octet and the preferred key length of the PRF 1210 (inclusive). It is expected that in most cases the keys will be 4 1211 (or even less) octets in length, however it depends on puzzle 1212 difficulty and on the Initiator's strategy to find solutions, and 1213 thus the size is not mandated by this specification. The 1214 Responder determines the size of each key by dividing the size of 1215 the Puzzle Solution Data by 4 (the number of keys). Note that the 1216 size of Puzzle Solution Data is the size of Payload (as indicated 1217 in Payload Length field) minus 4 - the size of Payload Header. 1219 The payload type for the Puzzle Solution payload is . 1221 9. Operational Considerations 1223 The puzzle difficulty level should be set by balancing the 1224 requirement to minimize the latency for legitimate Initiators with 1225 making things difficult for attackers. A good rule of thumb is for 1226 taking about 1 second to solve the puzzle. A typical Initiator or 1227 bot-net member in 2014 can perform slightly less than a million 1228 hashes per second per core, so setting the difficulty level to n=20 1229 is a good compromise. It should be noted that mobile Initiators, 1230 especially phones are considerably weaker than that. Implementations 1231 should allow administrators to set the difficulty level, and/or be 1232 able to set the difficulty level dynamically in response to load. 1234 Initiators should set a maximum difficulty level beyond which they 1235 won't try to solve the puzzle and log or display a failure message to 1236 the administrator or user. 1238 10. Security Considerations 1240 Care must be taken when selecting parameters for the puzzles, in 1241 particular the puzzle difficulty. If the puzzles are too easy for 1242 the majority of attacker, then the puzzle mechanism wouldn't be able 1243 to prevent (D)DoS attacks and would only impose an additional burden 1244 on legitimate Initiators. On the other hand, if the puzzles are too 1245 hard for the majority of Initiators, then many legitimate users would 1246 experience unacceptable delays in IKE SA setup (and unacceptable 1247 power consumption on mobile devices), that might cause them to cancel 1248 the connection attempt. In this case the resources of the Responder 1249 are preserved, however the DoS attack can be considered successful. 1250 Thus a sensible balance should be kept by the Responder while 1251 choosing the puzzle difficulty - to defend itself and to not over- 1252 defend itself. It is RECOMMENDED that the puzzle difficulty be 1253 chosen so, that the Responder's load remains close to the maximum it 1254 can tolerate. It is also RECOMMENDED to dynamically adjust the 1255 puzzle difficulty in accordance to the current Responder's load. 1257 Solving puzzles requires a lot of CPU power that increases power 1258 consumption. This additional power consumption can negatively affect 1259 battery-powered Initiators, e.g. mobile phones or some IoT devices. 1260 If puzzles are too hard, then the required additional power 1261 consumption may appear to be unacceptable for some Initiators. The 1262 Responder SHOULD take this possibility into consideration while 1263 choosing the puzzle difficulty, and while selecting which percentage 1264 of Initiators are allowed to reject solving puzzles. See 1265 Section 7.1.4 for details. 1267 If the Initiator uses NULL Authentication [RFC7619] then its identity 1268 is never verified. This condition may be used by attackers to 1269 perform a DoS attack after the IKE SA is established. Responders 1270 that allow unauthenticated Initiators to connect must be prepared to 1271 deal with various kinds of DoS attacks even after the IKE SA is 1272 created. See Section 5 for details. 1274 To prevent amplification attacks implementations must strictly follow 1275 the retransmission rules described in Section 2.1 of [RFC7296]. 1277 11. IANA Considerations 1279 This document defines a new payload in the "IKEv2 Payload Types" 1280 registry: 1282 Puzzle Solution PS 1284 This document also defines a new Notify Message Type in the "IKEv2 1285 Notify Message Types - Status Types" registry: 1287 PUZZLE 1289 12. Acknowledgements 1291 The authors thank Tero Kivinen, Yaron Sheffer, and Scott Fluhrer for 1292 their contributions to the design of the protocol. In particular, 1293 Tero Kivinen suggested the kind of puzzle where the task is to find a 1294 solution with a requested number of zero trailing bits. Yaron 1295 Sheffer and Scott Fluhrer suggested a way to make puzzle difficulty 1296 less erratic by solving several weaker puzles. The authors also 1297 thank David Waltermire and Paul Wouters for their careful reviews of 1298 the document, Graham Bartlett for pointing out to the possibility of 1299 the "Hash & URL" related attack, and all others who commented the 1300 document. 1302 13. References 1304 13.1. Normative References 1306 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1307 Requirement Levels", BCP 14, RFC 2119, 1308 DOI 10.17487/RFC2119, March 1997, 1309 . 1311 [RFC7296] Kaufman, C., Hoffman, P., Nir, Y., Eronen, P., and T. 1312 Kivinen, "Internet Key Exchange Protocol Version 2 1313 (IKEv2)", STD 79, RFC 7296, DOI 10.17487/RFC7296, October 1314 2014, . 1316 [RFC7383] Smyslov, V., "Internet Key Exchange Protocol Version 2 1317 (IKEv2) Message Fragmentation", RFC 7383, 1318 DOI 10.17487/RFC7383, November 2014, 1319 . 1321 [IKEV2-IANA] 1322 "Internet Key Exchange Version 2 (IKEv2) Parameters", 1323 . 1325 13.2. Informative References 1327 [bitcoins] 1328 Nakamoto, S., "Bitcoin: A Peer-to-Peer Electronic Cash 1329 System", October 2008, . 1331 [RFC5723] Sheffer, Y. and H. Tschofenig, "Internet Key Exchange 1332 Protocol Version 2 (IKEv2) Session Resumption", RFC 5723, 1333 DOI 10.17487/RFC5723, January 2010, 1334 . 1336 [RFC7619] Smyslov, V. and P. Wouters, "The NULL Authentication 1337 Method in the Internet Key Exchange Protocol Version 2 1338 (IKEv2)", RFC 7619, DOI 10.17487/RFC7619, August 2015, 1339 . 1341 [RFC7696] Housley, R., "Guidelines for Cryptographic Algorithm 1342 Agility and Selecting Mandatory-to-Implement Algorithms", 1343 BCP 201, RFC 7696, DOI 10.17487/RFC7696, November 2015, 1344 . 1346 Authors' Addresses 1348 Yoav Nir 1349 Check Point Software Technologies Ltd. 1350 5 Hasolelim st. 1351 Tel Aviv 6789735 1352 Israel 1354 EMail: ynir.ietf@gmail.com 1356 Valery Smyslov 1357 ELVIS-PLUS 1358 PO Box 81 1359 Moscow (Zelenograd) 124460 1360 Russian Federation 1362 Phone: +7 495 276 0211 1363 EMail: svan@elvis.ru