idnits 2.17.1 draft-ietf-oauth-spop-01.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 date (October 26, 2014) is 3441 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) == Missing Reference: 'A-Z' is mentioned on line 159, but not defined == Missing Reference: '0-9' is mentioned on line 159, but not defined == Unused Reference: 'RFC4949' is defined on line 417, but no explicit reference was found in the text ** Obsolete normative reference: RFC 4634 (Obsoleted by RFC 6234) -- Possible downref: Non-RFC (?) normative reference: ref. 'USASCII' Summary: 1 error (**), 0 flaws (~~), 4 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 OAuth Working Group N. Sakimura, Ed. 3 Internet-Draft Nomura Research Institute 4 Intended status: Standards Track J. Bradley 5 Expires: April 29, 2015 Ping Identity 6 N. Agarwal 7 Google 8 October 26, 2014 10 Symmetric Proof of Possession for the OAuth Authorization Code Grant 11 draft-ietf-oauth-spop-01 13 Abstract 15 The OAuth 2.0 public client utilizing Authorization Code Grant (RFC 16 6749 - 4.1) is susceptible to the code interception attack. This 17 specification describes a mechanism that acts as a control against 18 this threat. 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 April 29, 2015. 37 Copyright Notice 39 Copyright (c) 2014 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. Notational Conventions . . . . . . . . . . . . . . . . . . . 3 56 3. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 3 57 4. Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . 4 58 4.1. Client creates a code verifier . . . . . . . . . . . . . 4 59 4.2. Client creates the code challenge . . . . . . . . . . . . 4 60 4.3. Client sends the code challenge with the authorization 61 request . . . . . . . . . . . . . . . . . . . . . . . . . 5 62 4.4. Server returns the code . . . . . . . . . . . . . . . . . 5 63 4.5. Client sends the code and the secret to the token 64 endpoint . . . . . . . . . . . . . . . . . . . . . . . . 5 65 4.6. Server verifies code_verifier before returning the tokens 5 66 5. Compatibility . . . . . . . . . . . . . . . . . . . . . . . . 6 67 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 6 68 6.1. OAuth Parameters Registry . . . . . . . . . . . . . . . . 6 69 7. Security Considerations . . . . . . . . . . . . . . . . . . . 7 70 7.1. Entropy of the code verifier . . . . . . . . . . . . . . 7 71 7.2. Protection against eavesdroppers . . . . . . . . . . . . 7 72 7.3. Chekcing the Server support . . . . . . . . . . . . . . . 7 73 7.4. OAuth security considerations . . . . . . . . . . . . . . 7 74 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 8 75 9. Revision History . . . . . . . . . . . . . . . . . . . . . . 8 76 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 9 77 10.1. Normative References . . . . . . . . . . . . . . . . . . 9 78 10.2. Informative References . . . . . . . . . . . . . . . . . 9 79 Appendix A. Notes on implementing base64url encoding without 80 padding . . . . . . . . . . . . . . . . . . . . . . 9 81 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 11 83 1. Introduction 85 Public clients in OAuth 2.0 [RFC6749] are susceptible to the 86 authorization "code" interception attack. A malicious client 87 intercepts the authorization code returned from the authorization 88 endpoint and uses it to obtain the access token. This is possible on 89 a public client as there is no client secret associated for it to be 90 sent to the token endpoint. This is especially true on Smartphone 91 applications where the authorization code can be returned through 92 custom URL Schemes where the same scheme can be registered by 93 multiple applications. Under this scenario, the mitigation strategy 94 stated in section 4.4.1 of [RFC6819] does not work as they rely on 95 per-client instance secret or per client instance redirect URI. 97 To mitigate this attack, this extension utilizes a dynamically 98 created cryptographically random key called 'code verifier'. The 99 code verifier is created for every authorization request and its 100 transformed value, called 'code challenge', is sent to the 101 authorization server to obtain the authorization code. The 102 authorization "code" obtained is then sent to the token endpoint with 103 the 'code verifier' and the server compares it with the previously 104 received request code so that it can perform the proof of possession 105 of the 'code verifier' by the client. This works as the mitigation 106 since the attacker would not know this one-time key. 108 2. Notational Conventions 110 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 111 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 112 "OPTIONAL" in this document are to be interpreted as described in Key 113 words for use in RFCs to Indicate Requirement Levels [RFC2119]. If 114 these words are used without being spelled in uppercase then they are 115 to be interpreted with their normal natural language meanings. 117 BASE64URL(OCTETS) denotes the base64url encoding of OCTETS, per 118 Section 3producing a [USASCII] STRING. 120 BASE64URL-DECODE(STRING) denotes the base64url decoding of STRING, 121 per Section 3, producing a UTF-8 sequence of octets. 123 SHA256(STRING) denotes a SHA2 256bit hash [RFC4634] of STRING. 125 UTF8(STRING) denotes the octets of the UTF-8 [RFC3629] representation 126 of STRING. 128 ASCII(STRING) denotes the octets of the ASCII [USASCII] 129 representation of STRING. 131 The concatenation of two values A and B is denoted as A || B. 133 3. Terminology 135 In addition to the terms defined in OAuth 2.0 [RFC6749], this 136 specification defines the following terms: 138 code verifier A cryptographically random string that is used to 139 correlate the authorization request to the token request. 141 code challenge A challenge derived from the code verifier that is 142 sent in the authorization request, to be verified against later. 144 Base64url Encoding Base64 encoding using the URL- and filename-safe 145 character set defined in Section 5 of RFC 4648 [RFC4648], with all 146 trailing '=' characters omitted (as permitted by Section 3.2) and 147 without the inclusion of any line breaks, white space, or other 148 additional characters. (See Appendix A for notes on implementing 149 base64url encoding without padding.) 151 4. Protocol 153 4.1. Client creates a code verifier 155 The client first creates a code verifier, "code_verifier", for each 156 OAuth 2.0 [RFC6749] Authorization Request, in the following manner: 158 code_verifier = high entropy cryptographic random [USASCII] sequence 159 using the url and filename safe Alphabet [A-Z] / [a-z] / [0-9] / "-" 160 / "_" from Sec 5 of RFC 4648 [RFC4648] , with length less than 128 161 characters. 163 ABNF for "code_verifier" is as follows. 165 code_verifier = 42*128unreserved 166 unreserved = [A-Z] / [a-z] / [0-9] / "-" / "_" 168 NOTE: code verifier SHOULD have enough entropy to make it impractical 169 to guess the value. It is RECOMMENDED that the output of a suitable 170 random number generator be used to create a 32-octet sequence. The 171 Octet sequence is then BASE64URL encoded to produce a 42-octet URL 172 safe string to use as the code verifier. 174 4.2. Client creates the code challenge 176 The client then creates a code challenge, "code_challenge", derived 177 from the "code_verifier". The code challenge can use one of two 178 transformations on the "code_verifier". 180 plain "code_challenge" = "code_verifier" 182 S256 "code_challenge" = BASE64URL(SHA256("code_verifier")) 184 It is RECOMMENDED to use the S256 [RFC4634] transformation when 185 possible. 187 ABNF for "code_challenge" is as follows. 189 code_challenge = 42*128unreserved 190 unreserved = [A-Z] / [a-z] / [0-9] / "-" / "_" 192 4.3. Client sends the code challenge with the authorization request 194 The client sends the code challenge as part of the OAuth 2.0 195 [RFC6749] Authorization Request (Section 4.1.1.) using the following 196 additional parameters: 198 code_challenge REQUIRED. Code challenge. 200 code_challenge_method OPTIONAL, defaults to "plain". Code verifier 201 transformation method, "S256" or "plain". 203 4.4. Server returns the code 205 When the server issues the "code" in the Authorization Response, it 206 MUST associate the "code_challenge" and "code_challenge_method" 207 values with the "code" so it can be verified later. 209 Typically, the "code_challenge" and "code_challenge_method" values 210 are stored in encrypted form in the "code" itself, but it could as 211 well be just stored at the server, associated with the code. The 212 server MUST NOT include the "code_challenge" value in the form that 213 other entities can extract. 215 The exact method that the server uses to associate the 216 "code_challenge" with the issued "code" is out of scope for this 217 specification. 219 4.5. Client sends the code and the secret to the token endpoint 221 Upon receipt of the "code", the client sends the Access Token Request 222 to the token endpoint. In addition to the parameters defined in 223 OAuth 2.0 [RFC6749] Access Token Request (Section 4.1.3.), it sends 224 the following parameter: 226 code_verifier REQUIRED. Code verifier 228 4.6. Server verifies code_verifier before returning the tokens 230 Upon receipt of the request at the Access Token endpoint, the server 231 verifies it by calculating the code challenge from received 232 "code_verifier" and comparing it with the previously associated 233 "code_challenge", after first transforming it according to the 234 "code_challenge_method" method specified by the client. 236 If the "code_challenge_method" from 3.2 was "S256", the received 237 "code_verifier" is first hashed with SHA-256 then compared to the 238 base64url decoded "code_challenge". i.e., 239 SHA256("code_verifier" ) == BASE64URL-DECODE("code_challenge"). 241 If the "code_challenge_method" from 3.2 was "none", they are compared 242 directly. i.e., 244 "code_challenge" == "code_verifier". 246 If the values are equal, the Access Token endpoint MUST continue 247 processing as normal (as defined by OAuth 2.0 [RFC6749]). If the 248 values are not equal, an error response indicating "invalid_grant" as 249 described in section 5.2 of OAuth 2.0 [RFC6749] MUST be returned. 251 5. Compatibility 253 Server implementations of this specification MAY accept OAuth2.0 254 Clients that do not implement this extension. If the "code_verifier" 255 is not received from the client in the Authorization Request, servers 256 supporting backwards compatibility SHOULD revert to a normal OAuth 257 2.0 [RFC6749] protocol. 259 As the OAuth 2.0 [RFC6749] server responses are unchanged by this 260 specification, client implementations of this specification do not 261 need to know if the server has implemented this specification or not, 262 and SHOULD send the additional parameters as defined in Section 3. to 263 all servers. 265 6. IANA Considerations 267 This specification makes a registration request as follows: 269 6.1. OAuth Parameters Registry 271 This specification registers the following parameters in the IANA 272 OAuth Parameters registry defined in OAuth 2.0 [RFC6749]. 274 o Parameter name: code_verifier 276 o Parameter usage location: Access Token Request 278 o Change controller: IESG 280 o Specification document(s): this document 282 o Parameter name: code_challenge 284 o Parameter usage location: Authorization Request 286 o Change controller: IESG 287 o Specification document(s): this document 289 o Parameter name: code_challenge_method 291 o Parameter usage location: Authorization Request 293 o Change controller: IESG 295 o Specification document(s): this document 297 7. Security Considerations 299 7.1. Entropy of the code verifier 301 The security model relies on the fact that the code verifier is not 302 learned or guessed by the attacker. It is vitally important to 303 adhere to this principle. As such, the code verifier has to be 304 created in such a manner that it is cryptographically random and has 305 high entropy that it is not practical for the attacker to guess. It 306 is RECOMMENDED that the output of a suitable random number generator 307 be used to create a 32-octet sequence. 309 7.2. Protection against eavesdroppers 311 Unless there is a compelling reason, implementations SHOULD use 312 "S256" method to protect against eavesdroppers intercepting the 313 "code_challenge". If the no transformation algorithm, which is the 314 default algorithm, is used, the client SHOULD make sure that the 315 authorization request is adequately protected from an eavesdropper. 316 If "code_challenge" is to be returned inside authorization "code", it 317 has to be encrypted in such a manner that only the server can decrypt 318 and extract it. 320 7.3. Chekcing the Server support 322 Before starting the authorization process, the client SHOULD make 323 sure that the server supports this specification. Confirmation of 324 the server support may be obtained out-of-band or through some other 325 mechanisms such as the discovery document in OpenID Connect Discovery 326 [OpenID.Discovery]. The exact mechanism on how the client obtains 327 this information is out of scope of this specification. 329 7.4. OAuth security considerations 331 All the OAuth security analysis presented in [RFC6819] applies so 332 readers SHOULD carefully follow it. 334 8. Acknowledgements 336 The initial draft of this specification was created by the OpenID AB/ 337 Connect Working Group of the OpenID Foundation, by most notably of 338 the following people: 340 o Naveen Agarwal, Google 342 o Dirk Balfanz, Google 344 o Sergey Beryozkin 346 o John Bradley, Ping Identity 348 o Brian Campbell, Ping Identity 350 o William Denniss, Google 352 o Eduardo Gueiros, Jive Communications 354 o Phil Hunt, Oracle 356 o Ryo Ito, mixi 358 o Michael B. Jones, Microsoft 360 o Torsten Lodderstedt, Deutsche Telekom 362 o Breno de Medeiros, Google 364 o Prateek Mishra, Oracle 366 o Anthony Nadalin, Microsoft 368 o Axel Nenker, Deutsche Telekom 370 o Nat Sakimura, Nomura Research Institute 372 9. Revision History 374 -01 376 o Specified exactly two supported transformations 378 o Moved discovery steps to security considerations. 380 o Incorporated readability comments by Eduardo Gueiros. 382 o Changed MUST in 3.1 to SHOULD. 384 -00 386 o Initial IETF version. 388 10. References 390 10.1. Normative References 392 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 393 Requirement Levels", BCP 14, RFC 2119, March 1997. 395 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 396 10646", STD 63, RFC 3629, November 2003. 398 [RFC4634] Eastlake, D. and T. Hansen, "US Secure Hash Algorithms 399 (SHA and HMAC-SHA)", RFC 4634, July 2006. 401 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 402 Encodings", RFC 4648, October 2006. 404 [RFC6749] Hardt, D., "The OAuth 2.0 Authorization Framework", RFC 405 6749, October 2012. 407 [USASCII] American National Standards Institute, "Coded Character 408 Set -- 7-bit American Standard Code for Information 409 Interchange", ANSI X3.4, 1986. 411 10.2. Informative References 413 [OpenID.Discovery] 414 Sakimura, N., Bradley, J., Jones, M., and E. Jay, "OpenID 415 Connect Discovery 1.0", February 2014. 417 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", RFC 418 4949, August 2007. 420 [RFC6819] Lodderstedt, T., McGloin, M., and P. Hunt, "OAuth 2.0 421 Threat Model and Security Considerations", RFC 6819, 422 January 2013. 424 Appendix A. Notes on implementing base64url encoding without padding 426 This appendix describes how to implement base64url encoding and 427 decoding functions without padding based upon standard base64 428 encoding and decoding functions that do use padding. 430 To be concrete, example C# code implementing these functions is shown 431 below. Similar code could be used in other languages. 433 static string base64urlencode(byte [] arg) 434 { 435 string s = Convert.ToBase64String(arg); // Regular base64 encoder 436 s = s.Split('=')[0]; // Remove any trailing '='s 437 s = s.Replace('+', '-'); // 62nd char of encoding 438 s = s.Replace('/', '_'); // 63rd char of encoding 439 return s; 440 } 442 static byte [] base64urldecode(string arg) 443 { 444 string s = arg; 445 s = s.Replace('-', '+'); // 62nd char of encoding 446 s = s.Replace('_', '/'); // 63rd char of encoding 447 switch (s.Length % 4) // Pad with trailing '='s 448 { 449 case 0: break; // No pad chars in this case 450 case 2: s += "=="; break; // Two pad chars 451 case 3: s += "="; break; // One pad char 452 default: throw new System.Exception( 453 "Illegal base64url string!"); 454 } 455 return Convert.FromBase64String(s); // Standard base64 decoder 456 } 458 As per the example code above, the number of '=' padding characters 459 that needs to be added to the end of a base64url encoded string 460 without padding to turn it into one with padding is a deterministic 461 function of the length of the encoded string. Specifically, if the 462 length mod 4 is 0, no padding is added; if the length mod 4 is 2, two 463 '=' padding characters are added; if the length mod 4 is 3, one '=' 464 padding character is added; if the length mod 4 is 1, the input is 465 malformed. 467 An example correspondence between unencoded and encoded values 468 follows. The octet sequence below encodes into the string below, 469 which when decoded, reproduces the octet sequence. 471 3 236 255 224 193 473 A-z_4ME 475 Authors' Addresses 477 Nat Sakimura (editor) 478 Nomura Research Institute 479 1-6-5 Marunouchi, Marunouchi Kitaguchi Bldg. 480 Chiyoda-ku, Tokyo 100-0005 481 Japan 483 Phone: +81-3-5533-2111 484 Email: n-sakimura@nri.co.jp 485 URI: http://nat.sakimura.org/ 487 John Bradley 488 Ping Identity 489 Casilla 177, Sucursal Talagante 490 Talagante, RM 491 Chile 493 Phone: +44 20 8133 3718 494 Email: ve7jtb@ve7jtb.com 495 URI: http://www.thread-safe.com/ 497 Naveen Agarwal 498 Google 500 Email: naa@google.com