idnits 2.17.1 draft-jones-json-web-signature-00.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 : ---------------------------------------------------------------------------- ** There are 7 instances of too long lines in the document, the longest one being 270 characters in excess of 72. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 28, 2011) is 4777 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) -- Looks like a reference, but probably isn't: '123' on line 1145 -- Looks like a reference, but probably isn't: '34' on line 1145 -- Looks like a reference, but probably isn't: '97' on line 1145 -- Looks like a reference, but probably isn't: '108' on line 1145 -- Looks like a reference, but probably isn't: '103' on line 1145 -- Looks like a reference, but probably isn't: '58' on line 1145 -- Looks like a reference, but probably isn't: '82' on line 986 -- Looks like a reference, but probably isn't: '83' on line 1145 -- Looks like a reference, but probably isn't: '50' on line 1145 -- Looks like a reference, but probably isn't: '53' on line 1145 -- Looks like a reference, but probably isn't: '54' on line 1145 -- Looks like a reference, but probably isn't: '125' on line 1145 -- Looks like a reference, but probably isn't: '1' on line 1049 -- Looks like a reference, but probably isn't: '0' on line 1259 -- Looks like a reference, but probably isn't: '69' on line 1145 -- Possible downref: Non-RFC (?) normative reference: ref. 'JWT' ** Obsolete normative reference: RFC 1738 (Obsoleted by RFC 4248, RFC 4266) ** Downref: Normative reference to an Informational RFC: RFC 2104 ** Obsolete normative reference: RFC 3447 (Obsoleted by RFC 8017) ** Obsolete normative reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) -- Possible downref: Non-RFC (?) normative reference: ref. 'USA15' Summary: 6 errors (**), 0 flaws (~~), 1 warning (==), 18 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group M. Jones 3 Internet-Draft Microsoft 4 Intended status: Standards Track D. Balfanz 5 Expires: September 29, 2011 Google 6 J. Bradley 7 independent 8 Y. Goland 9 Microsoft 10 J. Panzer 11 Google 12 N. Sakimura 13 Nomura Research Institute 14 P. Tarjan 15 Facebook 16 March 28, 2011 18 JSON Web Signature (JWS) 19 draft-jones-json-web-signature-00 21 Abstract 23 JSON Web Signature (JWS) is a means of representing signed content 24 using JSON data structures. Related encryption capabilities are 25 described in the separate JSON Web Encryption (JWE) specification. 27 Requirements Language 29 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 30 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 31 document are to be interpreted as described in RFC 2119 [RFC2119]. 33 Status of this Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at http://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on September 29, 2011. 50 Copyright Notice 52 Copyright (c) 2011 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 68 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 4 69 3. JSON Web Signature (JWS) Overview . . . . . . . . . . . . . . 5 70 3.1. Example JWS . . . . . . . . . . . . . . . . . . . . . . . 5 71 4. JWS Header . . . . . . . . . . . . . . . . . . . . . . . . . . 6 72 4.1. Reserved Header Parameter Names . . . . . . . . . . . . . 6 73 4.2. Public Header Parameter Names . . . . . . . . . . . . . . 9 74 4.3. Private Header Parameter Names . . . . . . . . . . . . . . 9 75 5. Rules for Creating and Validating a JWS . . . . . . . . . . . 9 76 6. Base64url encoding as used by JWSs . . . . . . . . . . . . . . 11 77 7. Signing JWSs with Cryptographic Algorithms . . . . . . . . . . 11 78 7.1. Creating a JWS with HMAC SHA-256 . . . . . . . . . . . . . 12 79 7.2. Creating a JWS with RSA SHA-256 . . . . . . . . . . . . . 13 80 7.3. Creating a JWS with ECDSA P-256 SHA-256 . . . . . . . . . 14 81 7.4. Additional Algorithms . . . . . . . . . . . . . . . . . . 15 82 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 16 83 9. Security Considerations . . . . . . . . . . . . . . . . . . . 16 84 9.1. Unicode Comparison Security Issues . . . . . . . . . . . . 16 85 10. Open Issues and Things To Be Done (TBD) . . . . . . . . . . . 17 86 11. References . . . . . . . . . . . . . . . . . . . . . . . . . . 19 87 11.1. Normative References . . . . . . . . . . . . . . . . . . . 19 88 11.2. Informative References . . . . . . . . . . . . . . . . . . 20 89 Appendix A. JWS Examples . . . . . . . . . . . . . . . . . . . . 20 90 A.1. JWS using HMAC SHA-256 . . . . . . . . . . . . . . . . . . 20 91 A.1.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 20 92 A.1.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 22 93 A.1.3. Validating . . . . . . . . . . . . . . . . . . . . . . 22 94 A.2. JWS using RSA SHA-256 . . . . . . . . . . . . . . . . . . 23 95 A.2.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 23 96 A.2.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 26 97 A.2.3. Validating . . . . . . . . . . . . . . . . . . . . . . 26 98 A.3. JWS using ECDSA P-256 SHA-256 . . . . . . . . . . . . . . 27 99 A.3.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 27 100 A.3.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 28 101 A.3.3. Validating . . . . . . . . . . . . . . . . . . . . . . 29 102 Appendix B. Notes on implementing base64url encoding without 103 padding . . . . . . . . . . . . . . . . . . . . . . . 29 104 Appendix C. Acknowledgements . . . . . . . . . . . . . . . . . . 30 105 Appendix D. Document History . . . . . . . . . . . . . . . . . . 31 106 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 31 108 1. Introduction 110 JSON Web Signature (JWS) is a compact signature format intended for 111 space constrained environments such as HTTP Authorization headers and 112 URI query parameters. The JWS signature mechanisms are independent 113 of the type of content being signed, allowing arbitrary content to be 114 signed. A related encryption capability is described in a separate 115 JSON Web Encryption (JWE) [JWE] specification. 117 2. Terminology 119 JSON Web Signature (JWS) A data structure cryptographically securing 120 a JWS Header Input and a JWS Payload Input with a JWS Crypto 121 Output. 123 JWS Header Input A string containing a base64url encoded JSON object 124 that describes the cryptographic operations applied to the JWS 125 Header Input and the JWS Payload Input. 127 JWS Payload Input A string containing base64url encoded content. 129 JWS Crypto Output A string containing base64url encoded 130 cryptographic material that secures the contents of the JWS Header 131 Input and the JWS Payload Input. 133 Decoded JWS Header Input JWS Header Input that has been base64url 134 decoded back into a JSON object. 136 Decoded JWS Payload Input JWS Payload Input that has been base64url 137 decoded. 139 Decoded JWS Crypto Output JWS Crypto Output that has been base64url 140 decoded back into cryptographic material. 142 JWS Signing Input The concatenation of the JWS Header Input, a 143 period ('.') character, and the JWS Payload Input. 145 Header Parameter Names The names of the members within the JSON 146 object represented in a JWS Header Input. 148 Header Parameter Values The values of the members within the JSON 149 object represented in a JWS Header Input. 151 Digital Signature For the purposes of this specification, we use 152 this term to encompass both Hash-based Message Authentication 153 Codes (HMACs), which can provide authenticity but not non- 154 repudiation, and digital signatures using public key algorithms, 155 which can provide both. Readers should be aware of this 156 distinction, despite the decision to use a single term for both 157 concepts to improve readability of the specification. 159 Base64url Encoding For the purposes of this specification, this term 160 always refers to the he URL- and filename-safe Base64 encoding 161 described in RFC 4648 [RFC4648], Section 5, with the '=' padding 162 characters omitted, as permitted by Section 3.2. 164 3. JSON Web Signature (JWS) Overview 166 JWSs represent content that is base64url encoded and digitally 167 signed, and optionally encrypted, using JSON data structures. A 168 portion of the base64url encoded content that is signed is the JWS 169 Payload Input. 171 An accompanying base64url encoded JSON object - the JWS Header Input 172 - describes the signature method used. 174 The names within the header JSON object MUST be unique. These names 175 are referred to as Header Parameter Names. The corresponding values 176 are referred to as Header Parameter Values. 178 JWSs contain a signature that ensures the integrity of the contents 179 of the JWS Header Input and the JWS Payload Input. This signature 180 value is the JWS Crypto Output. The JSON Header object MUST contain 181 an "alg" parameter, the value of which is a string that unambiguously 182 identifies the algorithm used to sign the JWS Header Input and the 183 JWS Payload Input to produce the JWS Crypto Output. 185 3.1. Example JWS 187 The following example JSON header object declares that the encoded 188 object is a JSON Web Token (JWT) [JWT] and the JWS Header Input and 189 the JWS Payload Input are signed using the HMAC SHA-256 algorithm: 190 {"typ":"JWT", 191 "alg":"HS256"} 193 Base64url encoding the UTF-8 representation of the JSON header object 194 yields this JWS Header Input value: 195 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 197 The following is an example of a JSON object that can be encoded to 198 produce a JWS Payload Input. (Note that the payload can be any 199 base64url encoded content, and need not be a base64url encoded JSON 200 object.) 201 {"iss":"joe", 202 "exp":1300819380, 203 "http://example.com/is_root":true} 205 Base64url encoding the UTF-8 representation of the JSON object yields 206 the following JWS Payload Input. 207 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ 209 Signing the UTF-8 representation of the JWS Signing Input (the 210 concatenation of the JWS Header Input, a period ('.') character, and 211 the JWS Payload Input) with the HMAC SHA-256 algorithm and base64url 212 encoding the result, as per Section 7.1, yields this JWS Crypto 213 Output value: 214 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 216 This computation is illustrated in more detail in Appendix A.1. 218 4. JWS Header 220 The members of the JSON object represented by the Decoded JWS Header 221 Input describe the signature applied to the JWS Header Input and the 222 JWS Payload Input and optionally additional properties of the JWS. 223 Implementations MUST understand the entire contents of the header; 224 otherwise, the JWS MUST be rejected for processing. 226 4.1. Reserved Header Parameter Names 228 The following header parameter names are reserved. All the names are 229 short because a core goal of JWSs is for the representations to be 230 compact. 232 +-----------+--------+--------------+-------------------------------+ 233 | Header | JSON | Header | Header Parameter Semantics | 234 | Parameter | Value | Parameter | | 235 | Name | Type | Syntax | | 236 +-----------+--------+--------------+-------------------------------+ 237 | alg | string | StringAndURI | The "alg" (algorithm) header | 238 | | | | parameter identifies the | 239 | | | | cryptographic algorithm used | 240 | | | | to secure the JWS. A list of | 241 | | | | reserved alg values is in | 242 | | | | Table 3. The processing of | 243 | | | | the "alg" (algorithm) header | 244 | | | | parameter, if present, | 245 | | | | requires that the value of | 246 | | | | the "alg" header parameter | 247 | | | | MUST be one that is both | 248 | | | | supported and for which there | 249 | | | | exists a key for use with | 250 | | | | that algorithm associated | 251 | | | | with the signer of the | 252 | | | | content. This header | 253 | | | | parameter is REQUIRED. | 254 | typ | string | String | The "typ" (type) header | 255 | | | | parameter is used to declare | 256 | | | | the type of the signed | 257 | | | | content. This header | 258 | | | | parameter is OPTIONAL. | 259 | jku | string | URL | The "jku" (JSON Key URL) | 260 | | | | header parameter is a URL | 261 | | | | that points to JSON-encoded | 262 | | | | public key certificates that | 263 | | | | can be used to validate the | 264 | | | | signature. The specification | 265 | | | | for this encoding is TBD. | 266 | | | | This header parameter is | 267 | | | | OPTIONAL. | 268 | kid | string | String | The "kid" (key ID) header | 269 | | | | parameter is a hint | 270 | | | | indicating which specific key | 271 | | | | owned by the signer should be | 272 | | | | used to validate the | 273 | | | | signature. This allows | 274 | | | | signers to explicitly signal | 275 | | | | a change of key to | 276 | | | | recipients. Omitting this | 277 | | | | parameter is equivalent to | 278 | | | | setting it to an empty | 279 | | | | string. The interpretation | 280 | | | | of the contents of the "kid" | 281 | | | | parameter is unspecified. | 282 | | | | This header parameter is | 283 | | | | OPTIONAL. | 284 | x5u | string | URL | The "x5u" (X.509 URL) header | 285 | | | | parameter is a URL that | 286 | | | | points to an X.509 public key | 287 | | | | certificate that can be used | 288 | | | | to validate the signature. | 289 | | | | This certificate MUST conform | 290 | | | | to RFC 5280 [RFC5280]. This | 291 | | | | header parameter is OPTIONAL. | 292 | x5t | string | String | The "x5t" (x.509 certificate | 293 | | | | thumbprint) header parameter | 294 | | | | provides a base64url encoded | 295 | | | | SHA-256 thumbprint (a.k.a. | 296 | | | | digest) of the DER encoding | 297 | | | | of an X.509 certificate that | 298 | | | | can be used to match a | 299 | | | | certificate. This header | 300 | | | | parameter is OPTIONAL. | 301 +-----------+--------+--------------+-------------------------------+ 303 Table 1: Reserved Header Parameter Definitions 305 Additional reserved header parameter names MAY be defined via the 306 IANA JSON Web Signature Header Parameters registry, as per Section 8. 307 The syntax values used above are defined as follows: 309 +--------------+----------------------------------------------------+ 310 | Syntax Name | Syntax Definition | 311 +--------------+----------------------------------------------------+ 312 | IntDate | The number of seconds from 1970-01-01T0:0:0Z as | 313 | | measured in UTC until the desired date/time. See | 314 | | RFC 3339 [RFC3339] for details regarding | 315 | | date/times in general and UTC in particular. | 316 | String | Any string value MAY be used. | 317 | StringAndURI | Any string value MAY be used but a value | 318 | | containing a ":" character MUST be a URI as | 319 | | defined in RFC 3986 [RFC3986]. | 320 | URL | A URL as defined in RFC 1738 [RFC1738]. | 321 +--------------+----------------------------------------------------+ 323 Table 2: Header Parameter Syntax Definitions 325 4.2. Public Header Parameter Names 327 Additional header parameter names can be defined by those using JWSs. 328 However, in order to prevent collisions, any new header parameter 329 name or algorithm value SHOULD either be defined in the IANA JSON Web 330 Signature Header Parameters registry or be defined as a URI that 331 contains a collision resistant namespace. In each case, the definer 332 of the name or value MUST take reasonable precautions to make sure 333 they are in control of the part of the namespace they use to define 334 the header parameter name. 336 New header parameters should be introduced sparingly, as they can 337 result in non-interoperable JWSs. 339 4.3. Private Header Parameter Names 341 A producer and consumer of a JWS may agree to any header parameter 342 name that is not a Reserved Name Section 4.1 or a Public Name 343 Section 4.2. Unlike Public Names, these private names are subject to 344 collision and should be used with caution. 346 New header parameters should be introduced sparingly, as they can 347 result in non-interoperable JWSs. 349 5. Rules for Creating and Validating a JWS 351 To create a JWS, one MUST follow these steps: 353 1. Create the payload content to be encoded as the Decoded JWS 354 Payload Input. 356 2. Base64url encode the Decoded JWS Payload Input. This encoding 357 becomes the JWS Payload Input. 359 3. Create a JSON object containing a set of desired header 360 parameters. Note that white space is explicitly allowed in the 361 representation and no canonicalization is performed before 362 encoding. 364 4. Translate this JSON object's Unicode code points into UTF-8, as 365 defined in RFC 3629 [RFC3629]. 367 5. Base64url encode the UTF-8 representation of this JSON object as 368 defined in this specification (without padding). This encoding 369 becomes the JWS Header Input. 371 6. Compute the JWS Crypto Output in the manner defined for the 372 particular algorithm being used. The JWS Signing Input is always 373 the concatenation of the JWS Header Input, a period ('.') 374 character, and the JWS Payload Input. The "alg" header parameter 375 MUST be present in the JSON Header Input, with the algorithm 376 value accurately representing the algorithm used to construct the 377 JWS Crypto Input. 379 When validating a JWS, the following steps MUST be taken. If any of 380 the listed steps fails, then the signed content MUST be rejected. 382 1. The JWS Payload Input MUST be successfully base64url decoded 383 following the restriction given in this specification that no 384 padding characters have been used. 386 2. The JWS Header Input MUST be successfully base64url decoded 387 following the restriction given in this specification that no 388 padding characters have been used. 390 3. The Decoded JWS Header Input MUST be completely valid JSON syntax 391 conforming to RFC 4627 [RFC4627]. 393 4. The JWS Crypto Output MUST be successfully base64url decoded 394 following the restriction given in this specification that no 395 padding characters have been used. 397 5. The JWS Header Input MUST be validated to only include parameters 398 and values whose syntax and semantics are both understood and 399 supported. 401 6. The JWS Crypto Output MUST be successfully validated against the 402 JWS Header Input and JWS Payload Input in the manner defined for 403 the algorithm being used, which MUST be accurately represented by 404 the value of the "alg" header parameter, which MUST be present. 406 Processing a JWS inevitably requires comparing known strings to 407 values in the header. For example, in checking what the algorithm 408 is, the Unicode string encoding "alg" will be checked against the 409 member names in the Decoded JWS Header Input to see if there is a 410 matching header parameter name. A similar process occurs when 411 determining if the value of the "alg" header parameter represents a 412 supported algorithm. Comparing Unicode strings, however, has 413 significant security implications, as per Section 9. 415 Comparisons between JSON strings and other Unicode strings MUST be 416 performed as specified below: 418 1. Remove any JSON applied escaping to produce an array of Unicode 419 code points. 421 2. Unicode Normalization [USA15] MUST NOT be applied at any point to 422 either the JSON string or to the string it is to be compared 423 against. 425 3. Comparisons between the two strings MUST be performed as a 426 Unicode code point to code point equality comparison. 428 6. Base64url encoding as used by JWSs 430 JWSs make use of the base64url encoding as defined in RFC 4648 431 [RFC4648]. As allowed by Section 3.2 of the RFC, this specification 432 mandates that base64url encoding when used with JWSs MUST NOT use 433 padding. The reason for this restriction is that the padding 434 character ('=') is not URL safe. 436 For notes on implementing base64url encoding without padding, see 437 Appendix B. 439 7. Signing JWSs with Cryptographic Algorithms 441 JWSs use specific cryptographic algorithms to sign the contents of 442 the JWS Header Input and the JWS Payload Input. The use of the 443 following algorithms for producing JWSs is defined in this section. 444 The table below is the list of "alg" header parameter values reserved 445 by this specification, each of which is explained in more detail in 446 the following sections: 448 +--------------------+----------------------------------------------+ 449 | Alg Parameter | Algorithm | 450 | Value | | 451 +--------------------+----------------------------------------------+ 452 | HS256 | HMAC using SHA-256 hash algorithm | 453 | HS384 | HMAC using SHA-384 hash algorithm | 454 | HS512 | HMAC using SHA-512 hash algorithm | 455 | RS256 | RSA using SHA-256 hash algorithm | 456 | RS384 | RSA using SHA-384 hash algorithm | 457 | RS512 | RSA using SHA-512 hash algorithm | 458 | ES256 | ECDSA using P-256 curve and SHA-256 hash | 459 | | algorithm | 460 | ES384 | ECDSA using P-384 curve and SHA-384 hash | 461 | | algorithm | 462 | ES512 | ECDSA using P-521 curve and SHA-512 hash | 463 | | algorithm | 464 +--------------------+----------------------------------------------+ 466 Table 3: JSON Web Signature Reserved Algorithm Values 468 Of these algorithms, only HMAC SHA-256 and RSA SHA-256 MUST be 469 implemented by conforming implementations. It is RECOMMENDED that 470 implementations also support the ECDSA P-256 SHA-256 algorithm. 471 Support for other algorithms is OPTIONAL. 473 The signed content for a JWS is the same for all algorithms: the 474 concatenation of the JWS Header Input, a period ('.') character, and 475 the JWS Payload Input. This character sequence is referred to as the 476 JWS Signing Input. Note that if the JWS represents a JWT, this 477 corresponds to the portion of the JWT representation preceding the 478 second period character. The UTF-8 representation of the JWS Signing 479 Input is passed to the respective signing algorithms. 481 7.1. Creating a JWS with HMAC SHA-256 483 Hash based Message Authentication Codes (HMACs) enable one to use a 484 secret plus a cryptographic hash function to generate a Message 485 Authentication Code (MAC). This can be used to demonstrate that the 486 MAC matches the hashed content, in this case the JWS Signing Input, 487 which therefore demonstrates that whoever generated the MAC was in 488 possession of the secret. 490 The algorithm for implementing and validating HMACs is provided in 491 RFC 2104 [RFC2104]. Although any HMAC can be used with JWSs, this 492 section defines the use of the SHA-256 cryptographic hash function as 493 defined in FIPS 180-3 [FIPS.180-3]. The reserved "alg" header 494 parameter value "HS256" is used in the JWS Header Input to indicate 495 that the JWS Crypto Output contains a base64url encoded HMAC SHA-256 496 HMAC value. 498 The HMAC SHA-256 MAC is generated as follows: 500 1. Apply the HMAC SHA-256 algorithm to the UTF-8 representation of 501 the JWS Signing Input using the shared key to produce an HMAC. 503 2. Base64url encode the HMAC as defined in this document. 505 The output is the JWS Crypto Output for that JWS. 507 The HMAC SHA-256 MAC for a JWS is validated as follows: 509 1. Apply the HMAC SHA-256 algorithm to the UTF-8 representation of 510 the JWS Signing Input of the JWS using the shared key. 512 2. Base64url encode the previously generated HMAC as defined in this 513 document. 515 3. If the JWS Crypto Output and the previously calculated value 516 exactly match, then one has confirmation that the key was used to 517 generate the HMAC on the JWS and that the contents of the JWS 518 have not be tampered with. 520 4. If the validation fails, the signed content MUST be rejected. 522 Signing with the HMAC SHA-384 and HMAC SHA-512 algorithms is 523 performed identically to the procedure for HMAC SHA-256 - just with 524 correspondingly longer key and result values. 526 7.2. Creating a JWS with RSA SHA-256 528 This section defines the use of the RSASSA-PKCS1-v1_5 signature 529 algorithm as defined in RFC 3447 [RFC3447], Section 8.2 (commonly 530 known as PKCS#1), using SHA-256 as the hash function. Note that the 531 use of the RSASSA-PKCS1-v1_5 algorithm is described in FIPS 186-3 532 [FIPS.186-3], Section 5.5, as is the SHA-256 cryptographic hash 533 function, which is defined in FIPS 180-3 [FIPS.180-3]. The reserved 534 "alg" header parameter value "RS256" is used in the JWS Header Input 535 to indicate that the JWS Crypto Output contains an RSA SHA-256 536 signature. 538 A 2048-bit or longer key length MUST be used with this algorithm. 540 The RSA SHA-256 signature is generated as follows: 542 1. Let K be the signer's RSA private key and let M be the UTF-8 543 representation of the JWS Signing Input. 545 2. Compute the octet string S = RSASSA-PKCS1-V1_5-SIGN (K, M) using 546 SHA-256 as the hash function. 548 3. Base64url encode the octet string S, as defined in this document. 550 The output is the JWS Crypto Output for that JWS. 552 The RSA SHA-256 signature for a JWS is validated as follows: 554 1. Take the JWS Crypto Output and base64url decode it into an octet 555 string S. If decoding fails, then the signed content MUST be 556 rejected. 558 2. Let M be the UTF-8 representation of the JWS Signing Input and 559 let (n, e) be the public key corresponding to the private key 560 used by the signer. 562 3. Validate the signature with RSASSA-PKCS1-V1_5-VERIFY ((n, e), M, 563 S) using SHA-256 as the hash function. 565 4. If the validation fails, the signed content MUST be rejected. 567 Signing with the RSA SHA-384 and RSA SHA-512 algorithms is performed 568 identically to the procedure for RSA SHA-256 - just with 569 correspondingly longer key and result values. 571 7.3. Creating a JWS with ECDSA P-256 SHA-256 573 The Elliptic Curve Digital Signature Algorithm (ECDSA) is defined by 574 FIPS 186-3 [FIPS.186-3]. ECDSA provides for the use of Elliptic 575 Curve cryptography, which is able to provide equivalent security to 576 RSA cryptography but using shorter key lengths and with greater 577 processing speed. This means that ECDSA signatures will be 578 substantially smaller in terms of length than equivalently strong RSA 579 Digital Signatures. 581 This specification defines the use of ECDSA with the P-256 curve and 582 the SHA-256 cryptographic hash function. The P-256 curve is also 583 defined in FIPS 186-3. The reserved "alg" header parameter value 584 "ES256" is used in the JWS Header Input to indicate that the JWS 585 Crypto Output contains an ECDSA P-256 SHA-256 signature. 587 A JWS is signed with an ECDSA P-256 SHA-256 signature as follows: 589 1. Generate a digital signature of the UTF-8 representation of the 590 JWS Signing Input using ECDSA P-256 SHA-256 with the desired 591 private key. The output will be the EC point (R, S), where R and 592 S are unsigned integers. 594 2. Turn R and S into byte arrays in big endian order. Each array 595 will be 32 bytes long. 597 3. Concatenate the two byte arrays in the order R and then S. 599 4. Base64url encode the 64 byte array as defined in this 600 specification. 602 The output is the JWS Crypto Output for the JWS. 604 The ECDSA P-256 SHA-256 signature for a JWS is validated as follows: 606 1. Take the JWS Crypto Output and base64url decode it into a byte 607 array. If decoding fails, the signed content MUST be rejected. 609 2. The output of the base64url decoding MUST be a 64 byte array. 611 3. Split the 64 byte array into two 32 byte arrays. The first array 612 will be R and the second S. Remember that the byte arrays are in 613 big endian byte order; please check the ECDSA validator in use to 614 see what byte order it requires. 616 4. Submit the UTF-8 representation of the JWS Signing Input, R, S 617 and the public key (x, y) to the ECDSA P-256 SHA-256 validator. 619 5. If the validation fails, the signed content MUST be rejected. 621 The ECDSA validator will then determine if the digital signature is 622 valid, given the inputs. Note that ECDSA digital signature contains 623 a value referred to as K, which is a random number generated for each 624 digital signature instance. This means that two ECDSA digital 625 signatures using exactly the same input parameters will output 626 different signatures because their K values will be different. The 627 consequence of this is that one must validate an ECDSA signature by 628 submitting the previously specified inputs to an ECDSA validator. 630 Signing with the ECDSA P-384 SHA-384 and ECDSA P-521 SHA-512 631 algorithms is performed identically to the procedure for ECDSA P-256 632 SHA-256 - just with correspondingly longer key and result values. 634 7.4. Additional Algorithms 636 Additional algorithms MAY be used to protect JWSs with corresponding 637 "alg" header parameter values being defined to refer to them. New 638 "alg" header parameter values SHOULD either be defined in the IANA 639 JSON Web Signature Algorithms registry or be a URI that contains a 640 collision resistant namespace. In particular, the use of algorithm 641 identifiers defined in XML DSIG [RFC3275] and related specifications 642 is permitted. 644 8. IANA Considerations 646 This specification calls for: 648 o A new IANA registry entitled "JSON Web Signature Header 649 Parameters" for reserved header parameter names is defined in 650 Section 4.1. Inclusion in the registry is RFC Required in the RFC 651 5226 [RFC5226] sense for reserved JWS header parameter names that 652 are intended to be interoperable between implementations. The 653 registry will just record the reserved header parameter name and a 654 pointer to the RFC that defines it. This specification defines 655 inclusion of the header parameter names defined in Table 1. 657 o A new IANA registry entitled "JSON Web Signature Algorithms" for 658 reserved values used with the "alg" header parameter values is 659 defined in Section 7.4. Inclusion in the registry is RFC Required 660 in the RFC 5226 [RFC5226] sense. The registry will just record 661 the "alg" value and a pointer to the RFC that defines it. This 662 specification defines inclusion of the algorithm values defined in 663 Table 3. 665 9. Security Considerations 667 TBD: Lots of work to do here. We need to remember to look into any 668 issues relating to security and JSON parsing. One wonders just how 669 secure most JSON parsing libraries are. Were they ever hardened for 670 security scenarios? If not, what kind of holes does that open up? 671 Also, we need to walk through the JSON standard and see what kind of 672 issues we have especially around comparison of names. For instance, 673 comparisons of header parameter names and other parameters must occur 674 after they are unescaped. Need to also put in text about: Importance 675 of keeping secrets secret. Rotating keys. Strengths and weaknesses 676 of the different algorithms. 678 TBD: Need to put in text about why strict JSON validation is 679 necessary. Basically, that if malformed JSON is received then the 680 intent of the sender is impossible to reliably discern. 682 9.1. Unicode Comparison Security Issues 684 Header parameter names in JWSs are Unicode strings. For security 685 reasons, the representations of these names must be compared verbatim 686 after performing any escape processing (as per RFC 4627 [RFC4627], 687 Section 2.5). 689 This means, for instance, that these JSON strings must compare as 690 being equal ("sig", "\u0073ig"), whereas these must all compare as 691 being not equal to the first set or to each other ("SIG", "Sig", 692 "si\u0047"). 694 JSON strings MAY contain characters outside the Unicode Basic 695 Multilingual Plane. For instance, the G clef character (U+1D11E) may 696 be represented in a JSON string as "\uD834\uDD1E". Ideally, JWS 697 implementations SHOULD ensure that characters outside the Basic 698 Multilingual Plane are preserved and compared correctly; 699 alternatively, if this is not possible due to these characters 700 exercising limitations present in the underlying JSON implementation, 701 then input containing them MUST be rejected. 703 10. Open Issues and Things To Be Done (TBD) 705 The following items remain to be done in this draft (and related 706 drafts): 708 o Consider whether there is a better term than "Digital Signature" 709 for the concept that includes both HMACs and digital signatures 710 using public keys. 712 o Consider whether we really want to allow private header parameter 713 names that are not registered with IANA and are not in collision- 714 resistant namespaces. Eventually this could result in interop 715 nightmares where you need to have different code to talk to 716 different endpoints that "knows" about each endpoints' private 717 parameters. 719 o Clarify the optional ability to provide type information in the 720 JWS header. Specifically, clarify the intended use of the "typ" 721 Header Parameter, whether it conveys syntax or semantics, and 722 indeed, whether this is the right approach. Also clarify the 723 relationship between these type values and MIME [RFC2045] types. 725 o Clarify the semantics of the "kid" (key ID) header parameter. 726 Open issues include: What happens if a kid header is received with 727 an unrecognized value? Is that an error? Should it be treated as 728 if it's empty? What happens if the header has a recognized value 729 but the value doesn't match the key associated with that value, 730 but it does match another key that is associated with the issuer? 731 Is that an error? 733 o The "x5t" parameter is currently specified as "a base64url encoded 734 SHA-256 thumbprint of the DER encoding of an X.509 certificate". 735 SHA-1 was traditionally used for certificate digests but 736 collisions are possible to create and can be used for denial of 737 service attacks within multi-tenant services. We need to 738 understand the compatibility issues of using SHA-256 thumbprints 739 instead. We also likely want to specify the digest algorithm 740 explicitly. 742 o Several people have objected to the requirement for implementing 743 RSA SHA-256, some because they will only be using HMACs and 744 symmetric keys, and others because they only want to use ECDSA 745 when using asymmetric keys, either for security or key length 746 reasons, or both. I believe therefore, that we should consider 747 changing the MUST for RSA SHA-256 to RECOMMENDED. 749 o Since RFC 3447 Section 8 explicitly calls for people NOT to adopt 750 RSASSA-PKCS1 for new applications and instead requests that people 751 transition to RSASSA-PSS, we probably need some Security 752 Considerations text explaining why RSASSA-PKCS1 is being used 753 (it's what's commonly implemented) and what the potential 754 consequences are. 756 o Generalize the normative text on signing algorithms so that the 757 descriptions apply equally to the use of various key lengths - not 758 just HMAC SHA-256, RSA SHA-256, and ECDSA P-256 SHA-256. 760 o Add a table cross-referencing the algorithm name strings used in 761 standard software packages and specifications. 763 o Add Security Considerations text on timing attacks. 765 o Finish the Security Considerations section. 767 o Sort out what to do with the IANA registries if this is first 768 standardized as an OpenID specification. 770 o Write the related specification for encoding public keys using 771 JSON, as per the agreement documented at 772 http://self-issued.info/?p=390. This will be used by the "jku" 773 (JSON Key URL) header parameter. 775 o Write the companion encryption specification, per the agreements 776 documented at http://self-issued.info/?p=378. 778 11. References 779 11.1. Normative References 781 [FIPS.180-3] 782 National Institute of Standards and Technology, "Secure 783 Hash Standard (SHS)", FIPS PUB 180-3, October 2008. 785 [FIPS.186-3] 786 National Institute of Standards and Technology, "Digital 787 Signature Standard (DSS)", FIPS PUB 186-3, June 2009. 789 [JWT] Jones, M., Balfanz, D., Bradley, J., Goland, Y., Panzer, 790 J., Sakimura, N., and P. Tarjan, "JSON Web Token (JWT)", 791 March 2011. 793 [RFC1738] Berners-Lee, T., Masinter, L., and M. McCahill, "Uniform 794 Resource Locators (URL)", RFC 1738, December 1994. 796 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 797 Extensions (MIME) Part One: Format of Internet Message 798 Bodies", RFC 2045, November 1996. 800 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 801 Hashing for Message Authentication", RFC 2104, 802 February 1997. 804 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 805 Requirement Levels", BCP 14, RFC 2119, March 1997. 807 [RFC3339] Klyne, G., Ed. and C. Newman, "Date and Time on the 808 Internet: Timestamps", RFC 3339, July 2002. 810 [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography 811 Standards (PKCS) #1: RSA Cryptography Specifications 812 Version 2.1", RFC 3447, February 2003. 814 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 815 10646", STD 63, RFC 3629, November 2003. 817 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 818 Resource Identifier (URI): Generic Syntax", STD 66, 819 RFC 3986, January 2005. 821 [RFC4627] Crockford, D., "The application/json Media Type for 822 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 824 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 825 Encodings", RFC 4648, October 2006. 827 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 828 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 829 May 2008. 831 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 832 Housley, R., and W. Polk, "Internet X.509 Public Key 833 Infrastructure Certificate and Certificate Revocation List 834 (CRL) Profile", RFC 5280, May 2008. 836 [USA15] Davis, M., Whistler, K., and M. Duerst, "Unicode 837 Normalization Forms", Unicode Standard Annex 15, 09 2009. 839 11.2. Informative References 841 [CanvasApp] 842 Facebook, "Canvas Applications", 2010. 844 [JSS] Bradley, J. and N. Sakimura (editor), "JSON Simple Sign", 845 September 2010. 847 [JWE] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 848 Encryption (JWE)", March 2011. 850 [MagicSignatures] 851 Panzer (editor), J., Laurie, B., and D. Balfanz, "Magic 852 Signatures", August 2010. 854 [RFC3275] Eastlake, D., Reagle, J., and D. Solo, "(Extensible Markup 855 Language) XML-Signature Syntax and Processing", RFC 3275, 856 March 2002. 858 Appendix A. JWS Examples 860 This section provides several examples of JWSs. While these examples 861 all represent JSON Web Tokens (JWTs) [JWT], note that the payload can 862 be any base64url encoded content. 864 A.1. JWS using HMAC SHA-256 866 A.1.1. Encoding 868 The following example JSON header object declares that the data 869 structure is a JSON Web Token (JWT) [JWT] and the JWS Signing Input 870 is signed using the HMAC SHA-256 algorithm. Note that white space is 871 explicitly allowed in Decoded JWS Header Input strings and no 872 canonicalization is performed before encoding. 874 {"typ":"JWT", 875 "alg":"HS256"} 877 The following byte array contains the UTF-8 characters for the 878 Decoded JWS Header Input: 880 [123, 34, 116, 121, 112, 34, 58, 34, 74, 87, 84, 34, 44, 13, 10, 32, 881 34, 97, 108, 103, 34, 58, 34, 72, 83, 50, 53, 54, 34, 125] 883 Base64url encoding this UTF-8 representation yields this JWS Header 884 Input value: 885 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 887 The Decoded JWS Payload Input used in this example follows. (Note 888 that the payload can be any base64url encoded content, and need not 889 be a base64url encoded JSON object.) 890 {"iss":"joe", 891 "exp":1300819380, 892 "http://example.com/is_root":true} 894 The following byte array contains the UTF-8 characters for the 895 Decoded JWS Payload Input: 897 [123, 34, 105, 115, 115, 34, 58, 34, 106, 111, 101, 34, 44, 13, 10, 898 32, 34, 101, 120, 112, 34, 58, 49, 51, 48, 48, 56, 49, 57, 51, 56, 899 48, 44, 13, 10, 32, 34, 104, 116, 116, 112, 58, 47, 47, 101, 120, 97, 900 109, 112, 108, 101, 46, 99, 111, 109, 47, 105, 115, 95, 114, 111, 901 111, 116, 34, 58, 116, 114, 117, 101, 125] 903 Base64url encoding the above yields the JWS Payload Input value: 904 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ 906 Concatenating the JWS Header Input, a period character, and the JWS 907 Payload Input yields this JWS Signing Input value (with line breaks 908 for display purposes only): 909 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 910 . 911 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ 913 The UTF-8 representation of the JWS Signing Input is the following 914 byte array: 916 [101, 121, 74, 48, 101, 88, 65, 105, 79, 105, 74, 75, 86, 49, 81, 917 105, 76, 65, 48, 75, 73, 67, 74, 104, 98, 71, 99, 105, 79, 105, 74, 918 73, 85, 122, 73, 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 919 77, 105, 79, 105, 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 920 74, 108, 101, 72, 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 921 107, 122, 79, 68, 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 922 72, 65, 54, 76, 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 923 109, 78, 118, 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 924 106, 112, 48, 99, 110, 86, 108, 102, 81] 926 HMACs are generated using keys. This example uses the key 927 represented by the following byte array: 929 [3, 35, 53, 75, 43, 15, 165, 188, 131, 126, 6, 101, 119, 123, 166, 930 143, 90, 179, 40, 230, 240, 84, 201, 40, 169, 15, 132, 178, 210, 80, 931 46, 191, 211, 251, 90, 146, 210, 6, 71, 239, 150, 138, 180, 195, 119, 932 98, 61, 34, 61, 46, 33, 114, 5, 46, 79, 8, 192, 205, 154, 245, 103, 933 208, 128, 163] 935 Running the HMAC SHA-256 algorithm on the UTF-8 representation of the 936 JWS Signing Input with this key yields the following byte array: 938 [116, 24, 223, 180, 151, 153, 224, 37, 79, 250, 96, 125, 216, 173, 939 187, 186, 22, 212, 37, 77, 105, 214, 191, 240, 91, 88, 5, 88, 83, 940 132, 141, 121] 942 Base64url encoding the above HMAC output yields the JWS Crypto Output 943 value: 944 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 946 A.1.2. Decoding 948 Decoding the JWS first requires removing the base64url encoding from 949 the JWS Header Input, the JWS Payload Input, and the JWS Crypto 950 Output. We base64url decode the inputs per Section 6 and turn them 951 into the corresponding byte arrays. We translate the header input 952 byte array containing UTF-8 encoded characters into the Decoded JWS 953 Header Input string. 955 A.1.3. Validating 957 Next we validate the decoded results. Since the "alg" parameter in 958 the header is "HS256", we validate the HMAC SHA-256 signature 959 contained in the JWS Crypto Output. If any of the validation steps 960 fail, the signed content MUST be rejected. 962 First, we validate that the decoded JWS Header Input string is legal 963 JSON. 965 To validate the signature, we repeat the previous process of using 966 the correct key and the UTF-8 representation of the JWS Signing Input 967 as input to a SHA-256 HMAC function and then taking the output and 968 determining if it matches the Decoded JWS Crypto Output. If it 969 matches exactly, the signature has been validated. 971 A.2. JWS using RSA SHA-256 973 A.2.1. Encoding 975 The Decoded JWS Header Input in this example is different from the 976 previous example in two ways: First, because a different algorithm is 977 being used, the "alg" value is different. Second, for illustration 978 purposes only, the optional "typ" parameter is not used. (This 979 difference is not related to the signature algorithm employed.) The 980 Decoded JWS Header Input used is: 981 {"alg":"RS256"} 983 The following byte array contains the UTF-8 characters for the 984 Decoded JWS Header Input: 986 [123, 34, 97, 108, 103, 34, 58, 34, 82, 83, 50, 53, 54, 34, 125] 988 Base64url encoding this UTF-8 representation yields this JWS Header 989 Input value: 990 eyJhbGciOiJSUzI1NiJ9 992 The Decoded JWS Payload Input used in this example, which follows, is 993 the same as in the previous example. Since the JWS Payload Input 994 will therefore be the same, its computation is not repeated here. 995 {"iss":"joe", 996 "exp":1300819380, 997 "http://example.com/is_root":true} 999 Concatenating the JWS Header Input, a period character, and the JWS 1000 Payload Input yields this JWS Signing Input value (with line breaks 1001 for display purposes only): 1002 eyJhbGciOiJSUzI1NiJ9 1003 . 1004 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1006 The UTF-8 representation of the JWS Signing Input is the following 1007 byte array: 1009 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 1010 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1011 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1012 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1013 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1014 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1015 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1016 99, 110, 86, 108, 102, 81] 1018 The RSA key consists of a public part (n, e), and a private exponent 1019 d. The values of the RSA key used in this example, presented as the 1020 byte arrays representing big endian integers are: 1022 +-----------+-------------------------------------------------------+ 1023 | Parameter | Value | 1024 | Name | | 1025 +-----------+-------------------------------------------------------+ 1026 | n | [161, 248, 22, 10, 226, 227, 201, 180, 101, 206, 141, | 1027 | | 45, 101, 98, 99, 54, 43, 146, 125, 190, 41, 225, 240, | 1028 | | 36, 119, 252, 22, 37, 204, 144, 161, 54, 227, 139, | 1029 | | 217, 52, 151, 197, 182, 234, 99, 221, 119, 17, 230, | 1030 | | 124, 116, 41, 249, 86, 176, 251, 138, 143, 8, 154, | 1031 | | 220, 75, 105, 137, 60, 193, 51, 63, 83, 237, 208, 25, | 1032 | | 184, 119, 132, 37, 47, 236, 145, 79, 228, 133, 119, | 1033 | | 105, 89, 75, 234, 66, 128, 211, 44, 15, 85, 191, 98, | 1034 | | 148, 79, 19, 3, 150, 188, 110, 155, 223, 110, 189, | 1035 | | 210, 189, 163, 103, 142, 236, 160, 198, 104, 247, 1, | 1036 | | 179, 141, 191, 251, 56, 200, 52, 44, 226, 254, 109, | 1037 | | 39, 250, 222, 74, 90, 72, 116, 151, 157, 212, 185, | 1038 | | 207, 154, 222, 196, 199, 91, 5, 133, 44, 44, 15, 94, | 1039 | | 248, 165, 193, 117, 3, 146, 249, 68, 232, 237, 100, | 1040 | | 193, 16, 198, 182, 71, 96, 154, 164, 120, 58, 235, | 1041 | | 156, 108, 154, 215, 85, 49, 48, 80, 99, 139, 131, | 1042 | | 102, 92, 111, 111, 122, 130, 163, 150, 112, 42, 31, | 1043 | | 100, 27, 130, 211, 235, 242, 57, 34, 25, 73, 31, 182, | 1044 | | 134, 135, 44, 87, 22, 245, 10, 248, 53, 141, 154, | 1045 | | 139, 157, 23, 195, 64, 114, 143, 127, 135, 216, 154, | 1046 | | 24, 216, 252, 171, 103, 173, 132, 89, 12, 46, 207, | 1047 | | 117, 147, 57, 54, 60, 7, 3, 77, 111, 96, 111, 158, | 1048 | | 33, 224, 84, 86, 202, 229, 233, 161] | 1049 | e | [1, 0, 1] | 1050 | d | [18, 174, 113, 164, 105, 205, 10, 43, 195, 126, 82, | 1051 | | 108, 69, 0, 87, 31, 29, 97, 117, 29, 100, 233, 73, | 1052 | | 112, 123, 98, 89, 15, 157, 11, 165, 124, 150, 60, 64, | 1053 | | 30, 63, 207, 47, 44, 211, 189, 236, 136, 229, 3, 191, | 1054 | | 198, 67, 155, 11, 40, 200, 47, 125, 55, 151, 103, 31, | 1055 | | 82, 19, 238, 216, 193, 90, 37, 216, 213, 206, 160, 2, | 1056 | | 94, 227, 171, 46, 139, 127, 121, 33, 111, 198, 59, | 1057 | | 234, 86, 39, 83, 180, 6, 68, 198, 161, 81, 39, 217, | 1058 | | 178, 149, 69, 64, 160, 187, 225, 163, 5, 86, 152, 45, | 1059 | | 78, 159, 222, 95, 100, 37, 241, 77, 75, 113, 52, 65, | 1060 | | 181, 93, 199, 59, 155, 74, 237, 204, 146, 172, 227, | 1061 | | 146, 126, 55, 245, 125, 12, 253, 94, 117, 129, 250, | 1062 | | 81, 44, 143, 73, 97, 169, 235, 11, 128, 248, 168, 7, | 1063 | | 70, 114, 138, 85, 255, 70, 71, 31, 52, 37, 6, 59, | 1064 | | 157, 83, 100, 47, 94, 222, 30, 132, 214, 19, 8, 26, | 1065 | | 250, 92, 34, 208, 81, 40, 91, 214, 59, 148, 59, 86, | 1066 | | 93, 137, 138, 5, 104, 84, 19, 229, 60, 60, 108, 101, | 1067 | | 37, 255, 31, 227, 78, 61, 220, 112, 240, 213, 100, | 1068 | | 80, 253, 164, 139, 161, 46, 16, 78, 157, 235, 159, | 1069 | | 184, 24, 129, 225, 196, 189, 242, 93, 146, 71, 244, | 1070 | | 80, 200, 101, 146, 121, 104, 231, 115, 52, 244, 65, | 1071 | | 79, 117, 167, 80, 225, 57, 84, 110, 58, 138, 115, | 1072 | | 157] | 1073 +-----------+-------------------------------------------------------+ 1075 The RSA private key (n, d) is then passed to the RSA signing 1076 function, which also takes the hash type, SHA-256, and the UTF-8 1077 representation of the JWS Signing Input as inputs. The result of the 1078 signature is a byte array S, which represents a big endian integer. 1079 In this example, S is: 1081 +--------+----------------------------------------------------------+ 1082 | Result | Value | 1083 | Name | | 1084 +--------+----------------------------------------------------------+ 1085 | S | [112, 46, 33, 137, 67, 232, 143, 209, 30, 181, 216, 45, | 1086 | | 191, 120, 69, 243, 65, 6, 174, 27, 129, 255, 247, 115, | 1087 | | 17, 22, 173, 209, 113, 125, 131, 101, 109, 66, 10, 253, | 1088 | | 60, 150, 238, 221, 115, 162, 102, 62, 81, 102, 104, 123, | 1089 | | 0, 11, 135, 34, 110, 1, 135, 237, 16, 115, 249, 69, 229, | 1090 | | 130, 173, 252, 239, 22, 216, 90, 121, 142, 232, 198, | 1091 | | 109, 219, 61, 184, 151, 91, 23, 208, 148, 2, 190, 237, | 1092 | | 213, 217, 217, 112, 7, 16, 141, 178, 129, 96, 213, 248, | 1093 | | 4, 12, 167, 68, 87, 98, 184, 31, 190, 127, 249, 217, 46, | 1094 | | 10, 231, 111, 36, 242, 91, 51, 187, 230, 244, 74, 230, | 1095 | | 30, 177, 4, 10, 203, 32, 4, 77, 62, 249, 18, 142, 212, | 1096 | | 1, 48, 121, 91, 212, 189, 59, 65, 238, 202, 208, 102, | 1097 | | 171, 101, 25, 129, 253, 228, 141, 247, 127, 55, 45, 195, | 1098 | | 139, 159, 175, 221, 59, 239, 177, 139, 93, 163, 204, 60, | 1099 | | 46, 176, 47, 158, 58, 65, 214, 18, 202, 173, 21, 145, | 1100 | | 18, 115, 160, 95, 35, 185, 232, 56, 250, 175, 132, 157, | 1101 | | 105, 132, 41, 239, 90, 30, 136, 121, 130, 54, 195, 212, | 1102 | | 14, 96, 69, 34, 165, 68, 200, 242, 122, 122, 45, 184, 6, | 1103 | | 99, 209, 108, 247, 202, 234, 86, 222, 64, 92, 178, 33, | 1104 | | 90, 69, 178, 194, 85, 102, 181, 90, 193, 167, 72, 160, | 1105 | | 112, 223, 200, 163, 42, 70, 149, 67, 208, 25, 238, 251, | 1106 | | 71] | 1107 +--------+----------------------------------------------------------+ 1109 Base64url encoding the signature produces this value for the JWS 1110 Crypto Output: 1111 cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw 1113 A.2.2. Decoding 1115 Decoding the JWS from this example requires processing the JWS Header 1116 Input and JWS Payload Input exactly as done in the first example. 1118 A.2.3. Validating 1120 Since the "alg" parameter in the header is "RS256", we validate the 1121 RSA SHA-256 signature contained in the JWS Crypto Output. If any of 1122 the validation steps fail, the signed content MUST be rejected. 1124 First, we validate that the decoded JWS Header Input string is legal 1125 JSON. 1127 Validating the JWS Crypto Output is a little different from the 1128 previous example. First, we base64url decode the JWS Crypto Output 1129 to produce a signature S to check. We then pass (n, e), S and the 1130 UTF-8 representation of the JWS Signing Input to an RSA signature 1131 verifier that has been configured to use the SHA-256 hash function. 1133 A.3. JWS using ECDSA P-256 SHA-256 1135 A.3.1. Encoding 1137 The Decoded JWS Header Input for this example differs from the 1138 previous example because a different algorithm is being used. The 1139 Decoded JWS Header Input used is: 1140 {"alg":"ES256"} 1142 The following byte array contains the UTF-8 characters for the 1143 Decoded JWS Header Input: 1145 [123, 34, 97, 108, 103, 34, 58, 34, 69, 83, 50, 53, 54, 34, 125] 1147 Base64url encoding this UTF-8 representation yields this JWS Header 1148 Input value: 1149 eyJhbGciOiJFUzI1NiJ9 1151 The Decoded JWS Payload Input used in this example, which follows, is 1152 the same as in the previous examples. Since the JWS Payload Input 1153 will therefore be the same, its computation is not repeated here. 1154 {"iss":"joe", 1155 "exp":1300819380, 1156 "http://example.com/is_root":true} 1158 Concatenating the JWS Header Input, a period character, and the JWS 1159 Payload Input yields this JWS Signing Input value (with line breaks 1160 for display purposes only): 1161 eyJhbGciOiJFUzI1NiJ9 1162 . 1163 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1165 The UTF-8 representation of the JWS Signing Input is the following 1166 byte array: 1168 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 70, 85, 122, 73, 1169 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1170 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1171 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1172 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1173 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1174 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1175 99, 110, 86, 108, 102, 81] 1176 The ECDSA key consists of a public part, the EC point (x, y), and a 1177 private part d. The values of the ECDSA key used in this example, 1178 presented as the byte arrays representing big endian integers are: 1180 +-----------+-------------------------------------------------------+ 1181 | Parameter | Value | 1182 | Name | | 1183 +-----------+-------------------------------------------------------+ 1184 | x | [127, 205, 206, 39, 112, 246, 196, 93, 65, 131, 203, | 1185 | | 238, 111, 219, 75, 123, 88, 7, 51, 53, 123, 233, 239, | 1186 | | 19, 186, 207, 110, 60, 123, 209, 84, 69] | 1187 | y | [199, 241, 68, 205, 27, 189, 155, 126, 135, 44, 223, | 1188 | | 237, 185, 238, 185, 244, 179, 105, 93, 110, 169, 11, | 1189 | | 36, 173, 138, 70, 35, 40, 133, 136, 229, 173] | 1190 | d | [142, 155, 16, 158, 113, 144, 152, 191, 152, 4, 135, | 1191 | | 223, 31, 93, 119, 233, 203, 41, 96, 110, 190, 210, | 1192 | | 38, 59, 95, 87, 194, 19, 223, 132, 244, 178] | 1193 +-----------+-------------------------------------------------------+ 1195 The ECDSA private part d is then passed to an ECDSA signing function, 1196 which also takes the curve type, P-256, the hash type, SHA-256, and 1197 the UTF-8 representation of the JWS Signing Input as inputs. The 1198 result of the signature is the EC point (R, S), where R and S are 1199 unsigned integers. In this example, the R and S values, given as 1200 byte arrays representing big endian integers are: 1202 +--------+----------------------------------------------------------+ 1203 | Result | Value | 1204 | Name | | 1205 +--------+----------------------------------------------------------+ 1206 | R | [14, 209, 33, 83, 121, 99, 108, 72, 60, 47, 127, 21, 88, | 1207 | | 7, 212, 2, 163, 178, 40, 3, 58, 249, 124, 126, 23, 129, | 1208 | | 154, 195, 22, 158, 166, 101] | 1209 | S | [197, 10, 7, 211, 140, 60, 112, 229, 216, 241, 45, 175, | 1210 | | 8, 74, 84, 128, 166, 101, 144, 197, 242, 147, 80, 154, | 1211 | | 143, 63, 127, 138, 131, 163, 84, 213] | 1212 +--------+----------------------------------------------------------+ 1214 Concatenating the S array to the end of the R array and base64url 1215 encoding the result produces this value for the JWS Crypto Output: 1216 DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q 1218 A.3.2. Decoding 1220 Decoding the JWS from this example requires processing the JWS Header 1221 Input and JWS Payload Input exactly as done in the first example. 1223 A.3.3. Validating 1225 Since the "alg" parameter in the header is "ES256", we validate the 1226 ECDSA P-256 SHA-256 signature contained in the JWS Crypto Output. If 1227 any of the validation steps fail, the signed content MUST be 1228 rejected. 1230 First, we validate that the decoded JWS Header Input string is legal 1231 JSON. 1233 Validating the JWS Crypto Output is a little different from the first 1234 example. First, we base64url decode the JWS Crypto Output as in the 1235 previous examples but we then need to split the 64 member byte array 1236 that must result into two 32 byte arrays, the first R and the second 1237 S. We then pass (x, y), (R, S) and the UTF-8 representation of the 1238 JWS Signing Input to an ECDSA signature verifier that has been 1239 configured to use the P-256 curve with the SHA-256 hash function. 1241 As explained in Section 7.3, the use of the k value in ECDSA means 1242 that we cannot validate the correctness of the signature in the same 1243 way we validated the correctness of the HMAC. Instead, 1244 implementations MUST use an ECDSA validator to validate the 1245 signature. 1247 Appendix B. Notes on implementing base64url encoding without padding 1249 This appendix describes how to implement base64url encoding and 1250 decoding functions without padding based upon standard base64 1251 encoding and decoding functions that do use padding. 1253 To be concrete, example C# code implementing these functions is shown 1254 below. Similar code could be used in other languages. 1256 static string base64urlencode(byte [] arg) 1257 { 1258 string s = Convert.ToBase64String(arg); // Standard base64 encoder 1259 s = s.Split('=')[0]; // Remove any trailing '='s 1260 s = s.Replace('+', '-'); // 62nd char of encoding 1261 s = s.Replace('/', '_'); // 63rd char of encoding 1262 return s; 1263 } 1265 static byte [] base64urldecode(string arg) 1266 { 1267 string s = arg; 1268 s = s.Replace('-', '+'); // 62nd char of encoding 1269 s = s.Replace('_', '/'); // 63rd char of encoding 1270 switch (s.Length % 4) // Pad with trailing '='s 1271 { 1272 case 0: break; // No pad chars in this case 1273 case 2: s += "=="; break; // Two pad chars 1274 case 3: s += "="; break; // One pad char 1275 default: throw new System.Exception( 1276 "Illegal base64url string!"); 1277 } 1278 return Convert.FromBase64String(s); // Standard base64 decoder 1279 } 1281 As per the example code above, the number of '=' padding characters 1282 that needs to be added to the end of a base64url encoded string 1283 without padding to turn it into one with padding is a deterministic 1284 function of the length of the encoded string. Specifically, if the 1285 length mod 4 is 0, no padding is added; if the length mod 4 is 2, two 1286 '=' padding characters are added; if the length mod 4 is 3, one '=' 1287 padding character is added; if the length mod 4 is 1, the input is 1288 malformed. 1290 An example correspondence between unencoded and encoded values 1291 follows. The byte sequence below encodes into the string below, 1292 which when decoded, reproduces the byte sequence. 1293 3 236 255 224 193 1294 A-z_4ME 1296 Appendix C. Acknowledgements 1298 Solutions for signing JSON content were previously explored by Magic 1299 Signatures [MagicSignatures], JSON Simple Sign [JSS], and Canvas 1300 Applications [CanvasApp], all of which influenced this draft. 1302 Appendix D. Document History 1304 -00 1306 o Created first signature draft using content split from 1307 draft-jones-json-web-token-01. This split introduced no semantic 1308 changes. 1310 Authors' Addresses 1312 Michael B. Jones 1313 Microsoft 1315 Email: mbj@microsoft.com 1316 URI: http://self-issued.info/ 1318 Dirk Balfanz 1319 Google 1321 Email: balfanz@google.com 1323 John Bradley 1324 independent 1326 Email: ve7jtb@ve7jtb.com 1328 Yaron Y. Goland 1329 Microsoft 1331 Email: yarong@microsoft.com 1333 John Panzer 1334 Google 1336 Email: jpanzer@google.com 1338 Nat Sakimura 1339 Nomura Research Institute 1341 Email: n-sakimura@nri.co.jp 1342 Paul Tarjan 1343 Facebook 1345 Email: pt@fb.com