idnits 2.17.1 draft-ietf-jose-json-web-signature-37.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 (November 19, 2014) is 3444 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. 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 2025 -- Looks like a reference, but probably isn't: '34' on line 2025 -- Looks like a reference, but probably isn't: '97' on line 2035 -- Looks like a reference, but probably isn't: '108' on line 2035 -- Looks like a reference, but probably isn't: '103' on line 2025 -- Looks like a reference, but probably isn't: '58' on line 2025 -- Looks like a reference, but probably isn't: '82' on line 1763 -- Looks like a reference, but probably isn't: '83' on line 2025 -- Looks like a reference, but probably isn't: '50' on line 2025 -- Looks like a reference, but probably isn't: '53' on line 2025 -- Looks like a reference, but probably isn't: '54' on line 1911 -- Looks like a reference, but probably isn't: '125' on line 2025 -- Looks like a reference, but probably isn't: '69' on line 2025 -- Looks like a reference, but probably isn't: '49' on line 2025 -- Looks like a reference, but probably isn't: '80' on line 2035 -- Looks like a reference, but probably isn't: '121' on line 2035 -- Looks like a reference, but probably isn't: '111' on line 2035 -- Looks like a reference, but probably isn't: '100' on line 2035 -- Looks like a reference, but probably isn't: '0' on line 2371 -- Possible downref: Non-RFC (?) normative reference: ref. 'ECMAScript' -- Possible downref: Non-RFC (?) normative reference: ref. 'ITU.X690.1994' ** Obsolete normative reference: RFC 2818 (Obsoleted by RFC 9110) ** Downref: Normative reference to an Informational RFC: RFC 4949 ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 6125 (Obsoleted by RFC 9525) ** Obsolete normative reference: RFC 7159 (Obsoleted by RFC 8259) == Outdated reference: A later version (-11) exists of draft-ietf-uta-tls-bcp-07 -- Obsolete informational reference (is this intentional?): RFC 3447 (Obsoleted by RFC 8017) -- Obsolete informational reference (is this intentional?): RFC 5226 (Obsoleted by RFC 8126) Summary: 5 errors (**), 0 flaws (~~), 2 warnings (==), 25 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 JOSE Working Group M. Jones 3 Internet-Draft Microsoft 4 Intended status: Standards Track J. Bradley 5 Expires: May 23, 2015 Ping Identity 6 N. Sakimura 7 NRI 8 November 19, 2014 10 JSON Web Signature (JWS) 11 draft-ietf-jose-json-web-signature-37 13 Abstract 15 JSON Web Signature (JWS) represents content secured with digital 16 signatures or Message Authentication Codes (MACs) using JavaScript 17 Object Notation (JSON) based data structures. Cryptographic 18 algorithms and identifiers for use with this specification are 19 described in the separate JSON Web Algorithms (JWA) specification and 20 an IANA registry defined by that specification. Related encryption 21 capabilities are described in the separate JSON Web Encryption (JWE) 22 specification. 24 Status of this Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at http://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on May 23, 2015. 41 Copyright Notice 43 Copyright (c) 2014 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (http://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 59 1.1. Notational Conventions . . . . . . . . . . . . . . . . . 5 60 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 6 61 3. JSON Web Signature (JWS) Overview . . . . . . . . . . . . . . 7 62 3.1. JWS Compact Serialization Overview . . . . . . . . . . . 8 63 3.2. JWS JSON Serialization Overview . . . . . . . . . . . . . 8 64 3.3. Example JWS . . . . . . . . . . . . . . . . . . . . . . . 9 65 4. JOSE Header . . . . . . . . . . . . . . . . . . . . . . . . . 10 66 4.1. Registered Header Parameter Names . . . . . . . . . . . . 11 67 4.1.1. "alg" (Algorithm) Header Parameter . . . . . . . . . . 11 68 4.1.2. "jku" (JWK Set URL) Header Parameter . . . . . . . . . 11 69 4.1.3. "jwk" (JSON Web Key) Header Parameter . . . . . . . . 11 70 4.1.4. "kid" (Key ID) Header Parameter . . . . . . . . . . . 12 71 4.1.5. "x5u" (X.509 URL) Header Parameter . . . . . . . . . . 12 72 4.1.6. "x5c" (X.509 Certificate Chain) Header Parameter . . . 12 73 4.1.7. "x5t" (X.509 Certificate SHA-1 Thumbprint) Header 74 Parameter . . . . . . . . . . . . . . . . . . . . . . 13 75 4.1.8. "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) 76 Header Parameter . . . . . . . . . . . . . . . . . . . 13 77 4.1.9. "typ" (Type) Header Parameter . . . . . . . . . . . . 13 78 4.1.10. "cty" (Content Type) Header Parameter . . . . . . . . 14 79 4.1.11. "crit" (Critical) Header Parameter . . . . . . . . . . 14 80 4.2. Public Header Parameter Names . . . . . . . . . . . . . . 15 81 4.3. Private Header Parameter Names . . . . . . . . . . . . . 15 82 5. Producing and Consuming JWSs . . . . . . . . . . . . . . . . . 15 83 5.1. Message Signature or MAC Computation . . . . . . . . . . 15 84 5.2. Message Signature or MAC Validation . . . . . . . . . . . 16 85 5.3. String Comparison Rules . . . . . . . . . . . . . . . . . 18 86 6. Key Identification . . . . . . . . . . . . . . . . . . . . . . 19 87 7. Serializations . . . . . . . . . . . . . . . . . . . . . . . . 19 88 7.1. JWS Compact Serialization . . . . . . . . . . . . . . . . 20 89 7.2. JWS JSON Serialization . . . . . . . . . . . . . . . . . 20 90 7.2.1. General JWS JSON Serialization Syntax . . . . . . . . 20 91 7.2.2. Flattened JWS JSON Serialization Syntax . . . . . . . 22 92 8. TLS Requirements . . . . . . . . . . . . . . . . . . . . . . . 23 93 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 23 94 9.1. JSON Web Signature and Encryption Header Parameters 95 Registry . . . . . . . . . . . . . . . . . . . . . . . . 24 97 9.1.1. Registration Template . . . . . . . . . . . . . . . . 25 98 9.1.2. Initial Registry Contents . . . . . . . . . . . . . . 25 99 9.2. Media Type Registration . . . . . . . . . . . . . . . . . 27 100 9.2.1. Registry Contents . . . . . . . . . . . . . . . . . . 27 101 10. Security Considerations . . . . . . . . . . . . . . . . . . . 28 102 10.1. Key Entropy and Random Values . . . . . . . . . . . . . . 28 103 10.2. Key Protection . . . . . . . . . . . . . . . . . . . . . 29 104 10.3. Key Origin Authentication . . . . . . . . . . . . . . . . 29 105 10.4. Cryptographic Agility . . . . . . . . . . . . . . . . . . 29 106 10.5. Differences between Digital Signatures and MACs . . . . . 29 107 10.6. Algorithm Validation . . . . . . . . . . . . . . . . . . 30 108 10.7. Algorithm Protection . . . . . . . . . . . . . . . . . . 30 109 10.8. Chosen Plaintext Attacks . . . . . . . . . . . . . . . . 31 110 10.9. Timing Attacks . . . . . . . . . . . . . . . . . . . . . 31 111 10.10. Replay Protection . . . . . . . . . . . . . . . . . . . . 31 112 10.11. SHA-1 Certificate Thumbprints . . . . . . . . . . . . . . 31 113 10.12. JSON Security Considerations . . . . . . . . . . . . . . 32 114 10.13. Unicode Comparison Security Considerations . . . . . . . 32 115 11. References . . . . . . . . . . . . . . . . . . . . . . . . . . 33 116 11.1. Normative References . . . . . . . . . . . . . . . . . . 33 117 11.2. Informative References . . . . . . . . . . . . . . . . . 34 118 Appendix A. JWS Examples . . . . . . . . . . . . . . . . . . . . 36 119 A.1. Example JWS using HMAC SHA-256 . . . . . . . . . . . . . 36 120 A.1.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 36 121 A.1.2. Validating . . . . . . . . . . . . . . . . . . . . . . 38 122 A.2. Example JWS using RSASSA-PKCS-v1_5 SHA-256 . . . . . . . 38 123 A.2.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 39 124 A.2.2. Validating . . . . . . . . . . . . . . . . . . . . . . 41 125 A.3. Example JWS using ECDSA P-256 SHA-256 . . . . . . . . . . 42 126 A.3.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 42 127 A.3.2. Validating . . . . . . . . . . . . . . . . . . . . . . 44 128 A.4. Example JWS using ECDSA P-521 SHA-512 . . . . . . . . . . 44 129 A.4.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 44 130 A.4.2. Validating . . . . . . . . . . . . . . . . . . . . . . 46 131 A.5. Example Unsecured JWS . . . . . . . . . . . . . . . . . . 46 132 A.6. Example JWS using General JWS JSON Serialization . . . . 47 133 A.6.1. JWS Per-Signature Protected Headers . . . . . . . . . 48 134 A.6.2. JWS Per-Signature Unprotected Headers . . . . . . . . 48 135 A.6.3. Complete JOSE Header Values . . . . . . . . . . . . . 48 136 A.6.4. Complete JWS JSON Serialization Representation . . . . 49 137 A.7. Example JWS using Flattened JWS JSON Serialization . . . 49 138 Appendix B. "x5c" (X.509 Certificate Chain) Example . . . . . . . 50 139 Appendix C. Notes on implementing base64url encoding without 140 padding . . . . . . . . . . . . . . . . . . . . . . . 52 141 Appendix D. Notes on Key Selection . . . . . . . . . . . . . . . 53 142 Appendix E. Negative Test Case for "crit" Header Parameter . . . 54 143 Appendix F. Detached Content . . . . . . . . . . . . . . . . . . 55 144 Appendix G. Acknowledgements . . . . . . . . . . . . . . . . . . 55 145 Appendix H. Document History . . . . . . . . . . . . . . . . . . 56 146 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 66 148 1. Introduction 150 JSON Web Signature (JWS) represents content secured with digital 151 signatures or Message Authentication Codes (MACs) using JavaScript 152 Object Notation (JSON) [RFC7159] based data structures. The JWS 153 cryptographic mechanisms provide integrity protection for an 154 arbitrary sequence of octets. See Section 10.5 for a discussion on 155 the differences between Digital Signatures and MACs. 157 Two closely related serializations for JWS objects are defined. The 158 JWS Compact Serialization is a compact, URL-safe representation 159 intended for space constrained environments such as HTTP 160 Authorization headers and URI query parameters. The JWS JSON 161 Serialization represents JWS objects as JSON objects and enables 162 multiple signatures and/or MACs to be applied to the same content. 163 Both share the same cryptographic underpinnings. 165 Cryptographic algorithms and identifiers for use with this 166 specification are described in the separate JSON Web Algorithms (JWA) 167 [JWA] specification and an IANA registry defined by that 168 specification. Related encryption capabilities are described in the 169 separate JSON Web Encryption (JWE) [JWE] specification. 171 Names defined by this specification are short because a core goal is 172 for the resulting representations to be compact. 174 1.1. Notational Conventions 176 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 177 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 178 "OPTIONAL" in this document are to be interpreted as described in Key 179 words for use in RFCs to Indicate Requirement Levels [RFC2119]. If 180 these words are used without being spelled in uppercase then they are 181 to be interpreted with their normal natural language meanings. 183 BASE64URL(OCTETS) denotes the base64url encoding of OCTETS, per 184 Section 2. 186 UTF8(STRING) denotes the octets of the UTF-8 [RFC3629] representation 187 of STRING. 189 ASCII(STRING) denotes the octets of the ASCII [RFC20] representation 190 of STRING. 192 The concatenation of two values A and B is denoted as A || B. 194 2. Terminology 196 These terms are defined by this specification: 198 JSON Web Signature (JWS) 199 A data structure representing a digitally signed or MACed message. 201 JOSE Header 202 JSON object containing the parameters describing the cryptographic 203 operations and parameters employed. The JOSE Header is comprised 204 of a set of Header Parameters. 206 JWS Payload 207 The sequence of octets to be secured -- a.k.a., the message. The 208 payload can contain an arbitrary sequence of octets. 210 JWS Signature 211 Digital signature or MAC over the JWS Protected Header and the JWS 212 Payload. 214 Header Parameter 215 A name/value pair that is member of the JOSE Header. 217 JWS Protected Header 218 JSON object that contains the Header Parameters that are integrity 219 protected by the JWS Signature digital signature or MAC operation. 220 For the JWS Compact Serialization, this comprises the entire JOSE 221 Header. For the JWS JSON Serialization, this is one component of 222 the JOSE Header. 224 JWS Unprotected Header 225 JSON object that contains the Header Parameters that are not 226 integrity protected. This can only be present when using the JWS 227 JSON Serialization. 229 Base64url Encoding 230 Base64 encoding using the URL- and filename-safe character set 231 defined in Section 5 of RFC 4648 [RFC4648], with all trailing '=' 232 characters omitted (as permitted by Section 3.2) and without the 233 inclusion of any line breaks, white space, or other additional 234 characters. Note that the base64url encoding of the empty octet 235 sequence is the empty string. (See Appendix C for notes on 236 implementing base64url encoding without padding.) 238 JWS Signing Input 239 The input to the digital signature or MAC computation. Its value 240 is ASCII(BASE64URL(UTF8(JWS Protected Header)) || '.' || 241 BASE64URL(JWS Payload)). 243 JWS Compact Serialization 244 A representation of the JWS as a compact, URL-safe string. 246 JWS JSON Serialization 247 A representation of the JWS as a JSON object. Unlike the JWS 248 Compact Serialization, the JWS JSON Serialization enables multiple 249 digital signatures and/or MACs to be applied to the same content. 250 This representation is neither optimized for compactness nor URL- 251 safe. 253 Unsecured JWS 254 A JWS object that provides no integrity protection. Unsecured 255 JWSs use the "alg" value "none". 257 Collision-Resistant Name 258 A name in a namespace that enables names to be allocated in a 259 manner such that they are highly unlikely to collide with other 260 names. Examples of collision-resistant namespaces include: Domain 261 Names, Object Identifiers (OIDs) as defined in the ITU-T X.660 and 262 X.670 Recommendation series, and Universally Unique IDentifiers 263 (UUIDs) [RFC4122]. When using an administratively delegated 264 namespace, the definer of a name needs to take reasonable 265 precautions to ensure they are in control of the portion of the 266 namespace they use to define the name. 268 StringOrURI 269 A JSON string value, with the additional requirement that while 270 arbitrary string values MAY be used, any value containing a ":" 271 character MUST be a URI [RFC3986]. StringOrURI values are 272 compared as case-sensitive strings with no transformations or 273 canonicalizations applied. 275 These terms defined by the JSON Web Encryption (JWE) [JWE] 276 specification are incorporated into this specification: "JSON Web 277 Encryption (JWE)", "JWE Compact Serialization", and "JWE JSON 278 Serialization". 280 These terms defined by the Internet Security Glossary, Version 2 281 [RFC4949] are incorporated into this specification: "Digital 282 Signature" and "Message Authentication Code (MAC)". 284 3. JSON Web Signature (JWS) Overview 286 JWS represents digitally signed or MACed content using JSON data 287 structures and base64url encoding. These JSON data structures MAY 288 contain white space and/or line breaks before or after any JSON 289 values or structural characters, in accordance with Section 2 of RFC 290 7159 [RFC7159]. A JWS represents these logical values (each of which 291 is defined in Section 2): 293 o JOSE Header 294 o JWS Payload 295 o JWS Signature 297 For a JWS object, the JOSE Header members are the union of the 298 members of these values (each of which is defined in Section 2): 300 o JWS Protected Header 301 o JWS Unprotected Header 303 This document defines two serializations for JWS objects: a compact, 304 URL-safe serialization called the JWS Compact Serialization and a 305 JSON serialization called the JWS JSON Serialization. In both 306 serializations, the JWS Protected Header, JWS Payload, and JWS 307 Signature are base64url encoded, since JSON lacks a way to directly 308 represent arbitrary octet sequences. 310 3.1. JWS Compact Serialization Overview 312 In the JWS Compact Serialization, no JWS Unprotected Header is used. 313 In this case, the JOSE Header and the JWS Protected Header are the 314 same. 316 In the JWS Compact Serialization, a JWS object is represented as the 317 concatenation: 319 BASE64URL(UTF8(JWS Protected Header)) || '.' || 320 BASE64URL(JWS Payload) || '.' || 321 BASE64URL(JWS Signature) 323 See Section 7.1 for more information about the JWS Compact 324 Serialization. 326 3.2. JWS JSON Serialization Overview 328 In the JWS JSON Serialization, one or both of the JWS Protected 329 Header and JWS Unprotected Header MUST be present. In this case, the 330 members of the JOSE Header are the union of the members of the JWS 331 Protected Header and the JWS Unprotected Header values that are 332 present. 334 In the JWS JSON Serialization, a JWS object is represented as the 335 combination of these four values: 337 BASE64URL(UTF8(JWS Protected Header)) 338 JWS Unprotected Header 339 BASE64URL(JWS Payload) 340 BASE64URL(JWS Signature) 342 The three base64url encoded result strings and the JWS Unprotected 343 Header value are represented as members within a JSON object. The 344 inclusion of some of these values is OPTIONAL. The JWS JSON 345 Serialization can also represent multiple signature and/or MAC 346 values, rather than just one. See Section 7.2 for more information 347 about the JWS JSON Serialization. 349 3.3. Example JWS 351 This section provides an example of a JWS. Its computation is 352 described in more detail in Appendix A.1, including specifying the 353 exact octet sequences representing the JSON values used and the key 354 value used. 356 The following example JWS Protected Header declares that the encoded 357 object is a JSON Web Token (JWT) [JWT] and the JWS Protected Header 358 and the JWS Payload are secured using the HMAC SHA-256 [RFC2104, SHS] 359 algorithm: 361 {"typ":"JWT", 362 "alg":"HS256"} 364 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 365 Header)) gives this value: 367 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 369 The UTF-8 representation of following JSON object is used as the JWS 370 Payload. (Note that the payload can be any content, and need not be 371 a representation of a JSON object.) 373 {"iss":"joe", 374 "exp":1300819380, 375 "http://example.com/is_root":true} 377 Encoding this JWS Payload as BASE64URL(JWS Payload) gives this value 378 (with line breaks for display purposes only): 380 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 381 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 383 Computing the HMAC of the JWS Signing Input ASCII(BASE64URL(UTF8(JWS 384 Protected Header)) || '.' || BASE64URL(JWS Payload)) with the HMAC 385 SHA-256 algorithm using the key specified in Appendix A.1 and 386 base64url encoding the result yields this BASE64URL(JWS Signature) 387 value: 389 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 391 Concatenating these values in the order Header.Payload.Signature with 392 period ('.') characters between the parts yields this complete JWS 393 representation using the JWS Compact Serialization (with line breaks 394 for display purposes only): 396 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 397 . 398 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 399 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 400 . 401 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 403 See Appendix A for additional examples, including examples using the 404 JWS JSON Serialization in Sections A.6 and A.7. 406 4. JOSE Header 408 For a JWS object, the members of the JSON object(s) representing the 409 JOSE Header describe the digital signature or MAC applied to the JWS 410 Protected Header and the JWS Payload and optionally additional 411 properties of the JWS. The Header Parameter names within the JOSE 412 Header MUST be unique; JWS parsers MUST either reject JWSs with 413 duplicate Header Parameter names or use a JSON parser that returns 414 only the lexically last duplicate member name, as specified in 415 Section 15.12 (The JSON Object) of ECMAScript 5.1 [ECMAScript]. 417 Implementations are required to understand the specific Header 418 Parameters defined by this specification that are designated as "MUST 419 be understood" and process them in the manner defined in this 420 specification. All other Header Parameters defined by this 421 specification that are not so designated MUST be ignored when not 422 understood. Unless listed as a critical Header Parameter, per 423 Section 4.1.11, all Header Parameters not defined by this 424 specification MUST be ignored when not understood. 426 There are three classes of Header Parameter names: Registered Header 427 Parameter names, Public Header Parameter names, and Private Header 428 Parameter names. 430 4.1. Registered Header Parameter Names 432 The following Header Parameter names for use in JWS objects are 433 registered in the IANA JSON Web Signature and Encryption Header 434 Parameters registry defined in Section 9.1, with meanings as defined 435 below. 437 As indicated by the common registry, JWSs and JWEs share a common 438 Header Parameter space; when a parameter is used by both 439 specifications, its usage must be compatible between the 440 specifications. 442 4.1.1. "alg" (Algorithm) Header Parameter 444 The "alg" (algorithm) Header Parameter identifies the cryptographic 445 algorithm used to secure the JWS. The JWS Signature value is not 446 valid if the "alg" value does not represent a supported algorithm, or 447 if there is not a key for use with that algorithm associated with the 448 party that digitally signed or MACed the content. "alg" values should 449 either be registered in the IANA JSON Web Signature and Encryption 450 Algorithms registry defined in [JWA] or be a value that contains a 451 Collision-Resistant Name. The "alg" value is a case-sensitive ASCII 452 string containing a StringOrURI value. This Header Parameter MUST be 453 present and MUST be understood and processed by implementations. 455 A list of defined "alg" values for this use can be found in the IANA 456 JSON Web Signature and Encryption Algorithms registry defined in 457 [JWA]; the initial contents of this registry are the values defined 458 in Section 3.1 of the JSON Web Algorithms (JWA) [JWA] specification. 460 4.1.2. "jku" (JWK Set URL) Header Parameter 462 The "jku" (JWK Set URL) Header Parameter is a URI [RFC3986] that 463 refers to a resource for a set of JSON-encoded public keys, one of 464 which corresponds to the key used to digitally sign the JWS. The 465 keys MUST be encoded as a JSON Web Key Set (JWK Set) [JWK]. The 466 protocol used to acquire the resource MUST provide integrity 467 protection; an HTTP GET request to retrieve the JWK Set MUST use TLS 468 [RFC2818, RFC5246]; the identity of the server MUST be validated, as 469 per Section 6 of RFC 6125 [RFC6125]. Also, see Section 8 on TLS 470 requirements. Use of this Header Parameter is OPTIONAL. 472 4.1.3. "jwk" (JSON Web Key) Header Parameter 474 The "jwk" (JSON Web Key) Header Parameter is the public key that 475 corresponds to the key used to digitally sign the JWS. This key is 476 represented as a JSON Web Key [JWK]. Use of this Header Parameter is 477 OPTIONAL. 479 4.1.4. "kid" (Key ID) Header Parameter 481 The "kid" (key ID) Header Parameter is a hint indicating which key 482 was used to secure the JWS. This parameter allows originators to 483 explicitly signal a change of key to recipients. The structure of 484 the "kid" value is unspecified. Its value MUST be a case-sensitive 485 string. Use of this Header Parameter is OPTIONAL. 487 When used with a JWK, the "kid" value is used to match a JWK "kid" 488 parameter value. 490 4.1.5. "x5u" (X.509 URL) Header Parameter 492 The "x5u" (X.509 URL) Header Parameter is a URI [RFC3986] that refers 493 to a resource for the X.509 public key certificate or certificate 494 chain [RFC5280] corresponding to the key used to digitally sign the 495 JWS. The identified resource MUST provide a representation of the 496 certificate or certificate chain that conforms to RFC 5280 [RFC5280] 497 in PEM encoded form, with each certificate delimited as specified in 498 Section 6.1 of RFC 4945 [RFC4945]. The certificate containing the 499 public key corresponding to the key used to digitally sign the JWS 500 MUST be the first certificate. This MAY be followed by additional 501 certificates, with each subsequent certificate being the one used to 502 certify the previous one. The protocol used to acquire the resource 503 MUST provide integrity protection; an HTTP GET request to retrieve 504 the certificate MUST use TLS [RFC2818, RFC5246]; the identity of the 505 server MUST be validated, as per Section 6 of RFC 6125 [RFC6125]. 506 Also, see Section 8 on TLS requirements. Use of this Header 507 Parameter is OPTIONAL. 509 4.1.6. "x5c" (X.509 Certificate Chain) Header Parameter 511 The "x5c" (X.509 Certificate Chain) Header Parameter contains the 512 X.509 public key certificate or certificate chain [RFC5280] 513 corresponding to the key used to digitally sign the JWS. The 514 certificate or certificate chain is represented as a JSON array of 515 certificate value strings. Each string in the array is a base64 516 encoded ([RFC4648] Section 4 -- not base64url encoded) DER 517 [ITU.X690.1994] PKIX certificate value. The certificate containing 518 the public key corresponding to the key used to digitally sign the 519 JWS MUST be the first certificate. This MAY be followed by 520 additional certificates, with each subsequent certificate being the 521 one used to certify the previous one. The recipient MUST validate 522 the certificate chain according to RFC 5280 [RFC5280] and reject the 523 signature if any validation failure occurs. Use of this Header 524 Parameter is OPTIONAL. 526 See Appendix B for an example "x5c" value. 528 4.1.7. "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter 530 The "x5t" (X.509 Certificate SHA-1 Thumbprint) Header Parameter is a 531 base64url encoded SHA-1 thumbprint (a.k.a. digest) of the DER 532 encoding of the X.509 certificate [RFC5280] corresponding to the key 533 used to digitally sign the JWS. Note that certificate thumbprints 534 are also sometimes known as certificate fingerprints. Use of this 535 Header Parameter is OPTIONAL. 537 4.1.8. "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Header 538 Parameter 540 The "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Header 541 Parameter is a base64url encoded SHA-256 thumbprint (a.k.a. digest) 542 of the DER encoding of the X.509 certificate [RFC5280] corresponding 543 to the key used to digitally sign the JWS. Note that certificate 544 thumbprints are also sometimes known as certificate fingerprints. 545 Use of this Header Parameter is OPTIONAL. 547 4.1.9. "typ" (Type) Header Parameter 549 The "typ" (type) Header Parameter is used by JWS applications to 550 declare the MIME Media Type [IANA.MediaTypes] of this complete JWS 551 object. This is intended for use by the application when more than 552 one kind of object could be present in an application data structure 553 that can contain a JWS object; the application can use this value to 554 disambiguate among the different kinds of objects that might be 555 present. It will typically not be used by applications when the kind 556 of object is already known. This parameter is ignored by JWS 557 implementations; any processing of this parameter is performed by the 558 JWS application. Use of this Header Parameter is OPTIONAL. 560 Per RFC 2045 [RFC2045], all media type values, subtype values, and 561 parameter names are case-insensitive. However, parameter values are 562 case-sensitive unless otherwise specified for the specific parameter. 564 To keep messages compact in common situations, it is RECOMMENDED that 565 producers omit an "application/" prefix of a media type value in a 566 "typ" Header Parameter when no other '/' appears in the media type 567 value. A recipient using the media type value MUST treat it as if 568 "application/" were prepended to any "typ" value not containing a 569 '/'. For instance, a "typ" value of "example" SHOULD be used to 570 represent the "application/example" media type; whereas, the media 571 type "application/example;part="1/2"" cannot be shortened to 572 "example;part="1/2"". 574 The "typ" value "JOSE" can be used by applications to indicate that 575 this object is a JWS or JWE using the JWS Compact Serialization or 576 the JWE Compact Serialization. The "typ" value "JOSE+JSON" can be 577 used by applications to indicate that this object is a JWS or JWE 578 using the JWS JSON Serialization or the JWE JSON Serialization. 579 Other type values can also be used by applications. 581 4.1.10. "cty" (Content Type) Header Parameter 583 The "cty" (content type) Header Parameter is used by JWS applications 584 to declare the MIME Media Type [IANA.MediaTypes] of the secured 585 content (the payload). This is intended for use by the application 586 when more than one kind of object could be present in the JWS 587 payload; the application can use this value to disambiguate among the 588 different kinds of objects that might be present. It will typically 589 not be used by applications when the kind of object is already known. 590 This parameter is ignored by JWS implementations; any processing of 591 this parameter is performed by the JWS application. Use of this 592 Header Parameter is OPTIONAL. 594 Per RFC 2045 [RFC2045], all media type values, subtype values, and 595 parameter names are case-insensitive. However, parameter values are 596 case-sensitive unless otherwise specified for the specific parameter. 598 To keep messages compact in common situations, it is RECOMMENDED that 599 producers omit an "application/" prefix of a media type value in a 600 "cty" Header Parameter when no other '/' appears in the media type 601 value. A recipient using the media type value MUST treat it as if 602 "application/" were prepended to any "cty" value not containing a 603 '/'. For instance, a "cty" value of "example" SHOULD be used to 604 represent the "application/example" media type; whereas, the media 605 type "application/example;part="1/2"" cannot be shortened to 606 "example;part="1/2"". 608 4.1.11. "crit" (Critical) Header Parameter 610 The "crit" (critical) Header Parameter indicates that extensions to 611 the initial RFC versions of [[ this specification ]] and [JWA] are 612 being used that MUST be understood and processed. Its value is an 613 array listing the Header Parameter names present in the JOSE Header 614 that use those extensions. If any of the listed extension Header 615 Parameters are not understood and supported by the recipient, it MUST 616 reject the JWS. Producers MUST NOT include Header Parameter names 617 defined by the initial RFC versions of [[ this specification ]] or 618 [JWA] for use with JWS, duplicate names, or names that do not occur 619 as Header Parameter names within the JOSE Header in the "crit" list. 620 Producers MUST NOT use the empty list "[]" as the "crit" value. 621 Recipients MAY reject the JWS if the critical list contains any 622 Header Parameter names defined by the initial RFC versions of [[ this 623 specification ]] or [JWA] for use with JWS, or any other constraints 624 on its use are violated. When used, this Header Parameter MUST be 625 integrity protected; therefore, it MUST occur only within the JWS 626 Protected Header. Use of this Header Parameter is OPTIONAL. This 627 Header Parameter MUST be understood and processed by implementations. 629 An example use, along with a hypothetical "exp" (expiration-time) 630 field is: 632 {"alg":"ES256", 633 "crit":["exp"], 634 "exp":1363284000 635 } 637 4.2. Public Header Parameter Names 639 Additional Header Parameter names can be defined by those using JWSs. 640 However, in order to prevent collisions, any new Header Parameter 641 name should either be registered in the IANA JSON Web Signature and 642 Encryption Header Parameters registry defined in Section 9.1 or be a 643 Public Name: a value that contains a Collision-Resistant Name. In 644 each case, the definer of the name or value needs to take reasonable 645 precautions to make sure they are in control of the part of the 646 namespace they use to define the Header Parameter name. 648 New Header Parameters should be introduced sparingly, as they can 649 result in non-interoperable JWSs. 651 4.3. Private Header Parameter Names 653 A producer and consumer of a JWS may agree to use Header Parameter 654 names that are Private Names: names that are not Registered Header 655 Parameter names Section 4.1 or Public Header Parameter names 656 Section 4.2. Unlike Public Header Parameter names, Private Header 657 Parameter names are subject to collision and should be used with 658 caution. 660 5. Producing and Consuming JWSs 662 5.1. Message Signature or MAC Computation 664 To create a JWS, one MUST perform these steps. The order of the 665 steps is not significant in cases where there are no dependencies 666 between the inputs and outputs of the steps. 668 1. Create the content to be used as the JWS Payload. 670 2. Compute the encoded payload value BASE64URL(JWS Payload). 672 3. Create the JSON object(s) containing the desired set of Header 673 Parameters, which together comprise the JOSE Header: if the JWS 674 Compact Serialization is being used, the JWS Protected Header, or 675 if the JWS JSON Serialization is being used, the JWS Protected 676 Header and/or the JWS Unprotected Header. 678 4. Compute the encoded header value BASE64URL(UTF8(JWS Protected 679 Header)). If the JWS Protected Header is not present (which can 680 only happen when using the JWS JSON Serialization and no 681 "protected" member is present), let this value be the empty 682 string. 684 5. Compute the JWS Signature in the manner defined for the 685 particular algorithm being used over the JWS Signing Input 686 ASCII(BASE64URL(UTF8(JWS Protected Header)) || '.' || 687 BASE64URL(JWS Payload)). The "alg" (algorithm) Header Parameter 688 MUST be present in the JOSE Header, with the algorithm value 689 accurately representing the algorithm used to construct the JWS 690 Signature. 692 6. Compute the encoded signature value BASE64URL(JWS Signature). 694 7. If the JWS JSON Serialization is being used, repeat this process 695 (steps 3-6) for each digital signature or MAC operation being 696 performed. 698 8. Create the desired serialized output. The JWS Compact 699 Serialization of this result is BASE64URL(UTF8(JWS Protected 700 Header)) || '.' || BASE64URL(JWS Payload) || '.' || BASE64URL(JWS 701 Signature). The JWS JSON Serialization is described in 702 Section 7.2. 704 5.2. Message Signature or MAC Validation 706 When validating a JWS, the following steps MUST be taken. The order 707 of the steps is not significant in cases where there are no 708 dependencies between the inputs and outputs of the steps. If any of 709 the listed steps fails, then the signature or MAC cannot be 710 validated. 712 When there are multiple JWS Signature values, it is an application 713 decision which of the JWS Signature values must successfully validate 714 for the JWS to be accepted. In some cases, all must successfully 715 validate or the JWS will be considered invalid. In other cases, only 716 a specific JWS Signature value needs to be successfully validated. 717 However, in all cases, at least one JWS Signature value MUST 718 successfully validate or the JWS MUST be considered invalid. 720 1. Parse the JWS representation to extract the serialized values 721 for the components of the JWS. When using the JWS Compact 722 Serialization, these components are the base64url encoded 723 representations of the JWS Protected Header, the JWS Payload, 724 and the JWS Signature, and when using the JWS JSON 725 Serialization, these components also include the unencoded JWS 726 Unprotected Header value. When using the JWS Compact 727 Serialization, the JWS Protected Header, the JWS Payload, and 728 the JWS Signature are represented as base64url encoded values in 729 that order, with each value being separated from the next by a 730 single period ('.') character, resulting in exactly two 731 delimiting period characters being used. The JWS JSON 732 Serialization is described in Section 7.2. 734 2. Base64url decode the encoded representation of the JWS Protected 735 Header, following the restriction that no line breaks, white 736 space, or other additional characters have been used. 738 3. Verify that the resulting octet sequence is a UTF-8 encoded 739 representation of a completely valid JSON object conforming to 740 RFC 7159 [RFC7159]; let the JWS Protected Header be this JSON 741 object. 743 4. If using the JWS Compact Serialization, let the JOSE Header be 744 the JWS Protected Header. Otherwise, when using the JWS JSON 745 Serialization, let the JOSE Header be the union of the members 746 of the corresponding JWS Protected Header and JWS Unprotected 747 Header, all of which must be completely valid JSON objects. 748 During this step, verify that the resulting JOSE Header does not 749 contain duplicate Header Parameter names. When using the JWS 750 JSON Serialization, this restriction includes that the same 751 Header Parameter name also MUST NOT occur in distinct JSON 752 object values that together comprise the JOSE Header. 754 5. Verify that the implementation understands and can process all 755 fields that it is required to support, whether required by this 756 specification, by the algorithm being used, or by the "crit" 757 Header Parameter value, and that the values of those parameters 758 are also understood and supported. 760 6. Base64url decode the encoded representation of the JWS Payload, 761 following the restriction that no line breaks, white space, or 762 other additional characters have been used. 764 7. Base64url decode the encoded representation of the JWS 765 Signature, following the restriction that no line breaks, white 766 space, or other additional characters have been used. 768 8. Validate the JWS Signature against the JWS Signing Input 769 ASCII(BASE64URL(UTF8(JWS Protected Header)) || '.' || 770 BASE64URL(JWS Payload)) in the manner defined for the algorithm 771 being used, which MUST be accurately represented by the value of 772 the "alg" (algorithm) Header Parameter, which MUST be present. 773 See Section 10.6 for security considerations on algorithm 774 validation. Record whether the validation succeeded or not. 776 9. If the JWS JSON Serialization is being used, repeat this process 777 (steps 4-8) for each digital signature or MAC value contained in 778 the representation. 780 10. If none of the validations in step 9 succeeded, then the JWS 781 MUST be considered invalid. Otherwise, in the JWS JSON 782 Serialization case, return a result to the application 783 indicating which of the validations succeeded and failed. In 784 the JWS Compact Serialization case, the result can simply 785 indicate whether or not the JWS was successfully validated. 787 Finally, note that it is an application decision which algorithms may 788 be used in a given context. Even if a JWS can be successfully 789 validated, unless the algorithm(s) used in the JWS are acceptable to 790 the application, it SHOULD consider the JWS to be invalid. 792 5.3. String Comparison Rules 794 Processing a JWS inevitably requires comparing known strings to 795 members and values in JSON objects. For example, in checking what 796 the algorithm is, the Unicode string "alg" will be checked against 797 the member names in the JOSE Header to see if there is a matching 798 Header Parameter name. The same process is then used to determine if 799 the value of the "alg" Header Parameter represents a supported 800 algorithm. 802 The JSON rules for doing member name comparison are described in 803 Section 8.3 of RFC 7159 [RFC7159]. Since the only string comparison 804 operations that are performed are equality and inequality, the same 805 rules can be used for comparing both member names and member values 806 against known strings. 808 These comparison rules MUST be used for all JSON string comparisons 809 except in cases where the definition of the member explicitly calls 810 out that a different comparison rule is to be used for that member 811 value. Only the "typ" and "cty" member values defined in this 812 specification do not use these comparison rules. 814 Some applications may include case-insensitive information in a case- 815 sensitive value, such as including a DNS name as part of a "kid" (key 816 ID) value. In those cases, the application may need to define a 817 convention for the canonical case to use for representing the case- 818 insensitive portions, such as lowercasing them, if more than one 819 party might need to produce the same value so that they can be 820 compared. (However if all other parties consume whatever value the 821 producing party emitted verbatim without attempting to compare it to 822 an independently produced value, then the case used by the producer 823 will not matter.) 825 Also, see the JSON security considerations in Section 10.12 and the 826 Unicode security considerations in Section 10.13. 828 6. Key Identification 830 It is necessary for the recipient of a JWS to be able to determine 831 the key that was employed for the digital signature or MAC operation. 832 The key employed can be identified using the Header Parameter methods 833 described in Section 4.1 or can be identified using methods that are 834 outside the scope of this specification. Specifically, the Header 835 Parameters "jku", "jwk", "kid", "x5u", "x5c", "x5t", and "x5t#S256" 836 can be used to identify the key used. These Header Parameters MUST 837 be integrity protected if the information that they convey is to be 838 utilized in a trust decision; however, if the only information used 839 in the trust decision is a key, these parameters need not be 840 integrity protected, since changing them in a way that causes a 841 different key to be used will cause the validation to fail. 843 The producer SHOULD include sufficient information in the Header 844 Parameters to identify the key used, unless the application uses 845 another means or convention to determine the key used. Validation of 846 the signature or MAC fails when the algorithm used requires a key 847 (which is true of all algorithms except for "none") and the key used 848 cannot be determined. 850 The means of exchanging any shared symmetric keys used is outside the 851 scope of this specification. 853 Also, see Appendix D for notes on possible key selection algorithms. 855 7. Serializations 857 JWS objects use one of two serializations, the JWS Compact 858 Serialization or the JWS JSON Serialization. Applications using this 859 specification need to specify what serialization and serialization 860 features are used for that application. For instance, applications 861 might specify that only the JWS JSON Serialization is used, that only 862 JWS JSON Serialization support for a single signature or MAC value is 863 used, or that support for multiple signatures and/or MAC values is 864 used. JWS implementations only need to implement the features needed 865 for the applications they are designed to support. 867 7.1. JWS Compact Serialization 869 The JWS Compact Serialization represents digitally signed or MACed 870 content as a compact, URL-safe string. This string is: 872 BASE64URL(UTF8(JWS Protected Header)) || '.' || 873 BASE64URL(JWS Payload) || '.' || 874 BASE64URL(JWS Signature) 876 Only one signature/MAC is supported by the JWS Compact Serialization 877 and it provides no syntax to represent a JWS Unprotected Header 878 value. 880 7.2. JWS JSON Serialization 882 The JWS JSON Serialization represents digitally signed or MACed 883 content as a JSON object. This representation is neither optimized 884 for compactness nor URL-safe. 886 Two closely related syntaxes are defined for the JWS JSON 887 Serialization: a fully general syntax, with which content can be 888 secured with more than one digital signature and/or MAC operation, 889 and a flattened syntax, which is optimized for the single digital 890 signature or MAC case. 892 7.2.1. General JWS JSON Serialization Syntax 894 The following members are defined for use in top-level JSON objects 895 used for the fully general JWS JSON Serialization syntax: 897 payload 898 The "payload" member MUST be present and contain the value 899 BASE64URL(JWS Payload). 901 signatures 902 The "signatures" member value MUST be an array of JSON objects. 903 Each object represents a signature or MAC over the JWS Payload and 904 the JWS Protected Header. 906 The following members are defined for use in the JSON objects that 907 are elements of the "signatures" array: 909 protected 910 The "protected" member MUST be present and contain the value 911 BASE64URL(UTF8(JWS Protected Header)) when the JWS Protected 912 Header value is non-empty; otherwise, it MUST be absent. These 913 Header Parameter values are integrity protected. 915 header 916 The "header" member MUST be present and contain the value JWS 917 Unprotected Header when the JWS Unprotected Header value is non- 918 empty; otherwise, it MUST be absent. This value is represented as 919 an unencoded JSON object, rather than as a string. These Header 920 Parameter values are not integrity protected. 922 signature 923 The "signature" member MUST be present and contain the value 924 BASE64URL(JWS Signature). 926 At least one of the "protected" and "header" members MUST be present 927 for each signature/MAC computation so that an "alg" Header Parameter 928 value is conveyed. 930 Additional members can be present in both the JSON objects defined 931 above; if not understood by implementations encountering them, they 932 MUST be ignored. 934 The Header Parameter values used when creating or validating 935 individual signature or MAC values are the union of the two sets of 936 Header Parameter values that may be present: (1) the JWS Protected 937 Header represented in the "protected" member of the signature/MAC's 938 array element, and (2) the JWS Unprotected Header in the "header" 939 member of the signature/MAC's array element. The union of these sets 940 of Header Parameters comprises the JOSE Header. The Header Parameter 941 names in the two locations MUST be disjoint. 943 Each JWS Signature value is computed using the parameters of the 944 corresponding JOSE Header value in the same manner as for the JWS 945 Compact Serialization. This has the desirable property that each JWS 946 Signature value represented in the "signatures" array is identical to 947 the value that would have been computed for the same parameter in the 948 JWS Compact Serialization, provided that the JWS Protected Header 949 value for that signature/MAC computation (which represents the 950 integrity protected Header Parameter values) matches that used in the 951 JWS Compact Serialization. 953 In summary, the syntax of a JWS using the general JWS JSON 954 Serialization is as follows: 956 { 957 "payload":"", 958 "signatures":[ 959 {"protected":"", 960 "header":, 961 "signature":""}, 962 ... 963 {"protected":"", 964 "header":, 965 "signature":""}] 966 } 968 See Appendix A.6 for an example JWS using the general JWS JSON 969 Serialization syntax. 971 7.2.2. Flattened JWS JSON Serialization Syntax 973 The flattened JWS JSON Serialization syntax is based upon the general 974 syntax, but flattens it, optimizing it for the single digital 975 signature/MAC case. It flattens it by removing the "signatures" 976 member and instead placing those members defined for use in the 977 "signatures" array (the "protected", "header", and "signature" 978 members) in the top-level JSON object (at the same level as the 979 "payload" member). 981 The "signatures" member MUST NOT be present when using this syntax. 982 Other than this syntax difference, JWS JSON Serialization objects 983 using the flattened syntax are processed identically to those using 984 the general syntax. 986 In summary, the syntax of a JWS using the flattened JWS JSON 987 Serialization is as follows: 989 { 990 "payload":"", 991 "protected":"", 992 "header":, 993 "signature":"" 994 } 996 See Appendix A.7 for an example JWS using the flattened JWS JSON 997 Serialization syntax. 999 8. TLS Requirements 1001 Implementations supporting the "jku" and/or "x5u" Header Parameters 1002 MUST support TLS. Which TLS version(s) ought to be implemented will 1003 vary over time, and depend on the widespread deployment and known 1004 security vulnerabilities at the time of implementation. At the time 1005 of this writing, TLS version 1.2 [RFC5246] is the most recent 1006 version. 1008 To protect against information disclosure and tampering, 1009 confidentiality protection MUST be applied using TLS with a 1010 ciphersuite that provides confidentiality and integrity protection. 1011 See current publications by the IETF TLS working group, including RFC 1012 6176 [RFC6176], for guidance on the ciphersuites currently considered 1013 to be appropriate for use. Also, see Recommendations for Secure Use 1014 of TLS and DTLS [I-D.ietf-uta-tls-bcp] for recommendations on 1015 improving the security of software and services using TLS. 1017 Whenever TLS is used, the identity of the service provider encoded in 1018 the TLS server certificate MUST be verified using the procedures 1019 described in Section 6 of RFC 6125 [RFC6125]. 1021 9. IANA Considerations 1023 The following registration procedure is used for all the registries 1024 established by this specification. 1026 Values are registered on a Specification Required [RFC5226] basis 1027 after a three-week review period on the jose-reg-review@ietf.org 1028 mailing list, on the advice of one or more Designated Experts. 1029 However, to allow for the allocation of values prior to publication, 1030 the Designated Expert(s) may approve registration once they are 1031 satisfied that such a specification will be published. 1033 Registration requests must be sent to the jose-reg-review@ietf.org 1034 mailing list for review and comment, with an appropriate subject 1035 (e.g., "Request to register header parameter: example"). 1037 Within the review period, the Designated Expert(s) will either 1038 approve or deny the registration request, communicating this decision 1039 to the review list and IANA. Denials should include an explanation 1040 and, if applicable, suggestions as to how to make the request 1041 successful. Registration requests that are undetermined for a period 1042 longer than 21 days can be brought to the IESG's attention (using the 1043 iesg@ietf.org mailing list) for resolution. 1045 Criteria that should be applied by the Designated Expert(s) includes 1046 determining whether the proposed registration duplicates existing 1047 functionality, determining whether it is likely to be of general 1048 applicability or whether it is useful only for a single application, 1049 and whether the registration description is clear. 1051 IANA must only accept registry updates from the Designated Expert(s) 1052 and should direct all requests for registration to the review mailing 1053 list. 1055 It is suggested that multiple Designated Experts be appointed who are 1056 able to represent the perspectives of different applications using 1057 this specification, in order to enable broadly-informed review of 1058 registration decisions. In cases where a registration decision could 1059 be perceived as creating a conflict of interest for a particular 1060 Expert, that Expert should defer to the judgment of the other 1061 Expert(s). 1063 [[ Note to the RFC Editor and IANA: Pearl Liang of ICANN had 1064 requested that the draft supply the following proposed registry 1065 description information. It is to be used for all registries 1066 established by this specification. 1068 o Protocol Category: JSON Object Signing and Encryption (JOSE) 1070 o Registry Location: http://www.iana.org/assignments/jose 1072 o Webpage Title: (same as the protocol category) 1074 o Registry Name: (same as the section title, but excluding the word 1075 "Registry", for example "JSON Web Signature and Encryption Header 1076 Parameters") 1078 ]] 1080 9.1. JSON Web Signature and Encryption Header Parameters Registry 1082 This specification establishes the IANA JSON Web Signature and 1083 Encryption Header Parameters registry for Header Parameter names. 1084 The registry records the Header Parameter name and a reference to the 1085 specification that defines it. The same Header Parameter name can be 1086 registered multiple times, provided that the parameter usage is 1087 compatible between the specifications. Different registrations of 1088 the same Header Parameter name will typically use different Header 1089 Parameter Usage Location(s) values. 1091 9.1.1. Registration Template 1093 Header Parameter Name: 1094 The name requested (e.g., "kid"). Because a core goal of this 1095 specification is for the resulting representations to be compact, 1096 it is RECOMMENDED that the name be short -- not to exceed 8 1097 characters without a compelling reason to do so. This name is 1098 case-sensitive. Names may not match other registered names in a 1099 case-insensitive manner unless the Designated Expert(s) state that 1100 there is a compelling reason to allow an exception in this 1101 particular case. 1103 Header Parameter Description: 1104 Brief description of the Header Parameter (e.g., "Key ID"). 1106 Header Parameter Usage Location(s): 1107 The Header Parameter usage locations, which should be one or more 1108 of the values "JWS" or "JWE". 1110 Change Controller: 1111 For Standards Track RFCs, state "IESG". For others, give the name 1112 of the responsible party. Other details (e.g., postal address, 1113 email address, home page URI) may also be included. 1115 Specification Document(s): 1116 Reference to the document(s) that specify the parameter, 1117 preferably including URI(s) that can be used to retrieve copies of 1118 the document(s). An indication of the relevant sections may also 1119 be included but is not required. 1121 9.1.2. Initial Registry Contents 1123 This specification registers the Header Parameter names defined in 1124 Section 4.1 in this registry. 1126 o Header Parameter Name: "alg" 1127 o Header Parameter Description: Algorithm 1128 o Header Parameter Usage Location(s): JWS 1129 o Change Controller: IESG 1130 o Specification Document(s): Section 4.1.1 of [[ this document ]] 1132 o Header Parameter Name: "jku" 1133 o Header Parameter Description: JWK Set URL 1134 o Header Parameter Usage Location(s): JWS 1135 o Change Controller: IESG 1136 o Specification Document(s): Section 4.1.2 of [[ this document ]] 1137 o Header Parameter Name: "jwk" 1138 o Header Parameter Description: JSON Web Key 1139 o Header Parameter Usage Location(s): JWS 1140 o Change Controller: IESG 1141 o Specification document(s): Section 4.1.3 of [[ this document ]] 1143 o Header Parameter Name: "kid" 1144 o Header Parameter Description: Key ID 1145 o Header Parameter Usage Location(s): JWS 1146 o Change Controller: IESG 1147 o Specification Document(s): Section 4.1.4 of [[ this document ]] 1149 o Header Parameter Name: "x5u" 1150 o Header Parameter Description: X.509 URL 1151 o Header Parameter Usage Location(s): JWS 1152 o Change Controller: IESG 1153 o Specification Document(s): Section 4.1.5 of [[ this document ]] 1155 o Header Parameter Name: "x5c" 1156 o Header Parameter Description: X.509 Certificate Chain 1157 o Header Parameter Usage Location(s): JWS 1158 o Change Controller: IESG 1159 o Specification Document(s): Section 4.1.6 of [[ this document ]] 1161 o Header Parameter Name: "x5t" 1162 o Header Parameter Description: X.509 Certificate SHA-1 Thumbprint 1163 o Header Parameter Usage Location(s): JWS 1164 o Change Controller: IESG 1165 o Specification Document(s): Section 4.1.7 of [[ this document ]] 1167 o Header Parameter Name: "x5t#S256" 1168 o Header Parameter Description: X.509 Certificate SHA-256 Thumbprint 1169 o Header Parameter Usage Location(s): JWS 1170 o Change Controller: IESG 1171 o Specification Document(s): Section 4.1.8 of [[ this document ]] 1173 o Header Parameter Name: "typ" 1174 o Header Parameter Description: Type 1175 o Header Parameter Usage Location(s): JWS 1176 o Change Controller: IESG 1177 o Specification Document(s): Section 4.1.9 of [[ this document ]] 1179 o Header Parameter Name: "cty" 1180 o Header Parameter Description: Content Type 1181 o Header Parameter Usage Location(s): JWS 1182 o Change Controller: IESG 1183 o Specification Document(s): Section 4.1.10 of [[ this document ]] 1185 o Header Parameter Name: "crit" 1186 o Header Parameter Description: Critical 1187 o Header Parameter Usage Location(s): JWS 1188 o Change Controller: IESG 1189 o Specification Document(s): Section 4.1.11 of [[ this document ]] 1191 9.2. Media Type Registration 1193 9.2.1. Registry Contents 1195 This specification registers the "application/jose" Media Type 1196 [RFC2046] in the MIME Media Types registry [IANA.MediaTypes] in the 1197 manner described in RFC 6838 [RFC6838], which can be used to indicate 1198 that the content is a JWS or JWE object using the JWS Compact 1199 Serialization or the JWE Compact Serialization and the 1200 "application/jose+json" Media Type in the MIME Media Types registry, 1201 which can be used to indicate that the content is a JWS or JWE object 1202 using the JWS JSON Serialization or the JWE JSON Serialization. 1204 o Type name: application 1205 o Subtype name: jose 1206 o Required parameters: n/a 1207 o Optional parameters: n/a 1208 o Encoding considerations: 8bit; application/jose values are encoded 1209 as a series of base64url encoded values (some of which may be the 1210 empty string) each separated from the next by a single period 1211 ('.') character. 1212 o Security considerations: See the Security Considerations section 1213 of [[ this document ]] 1214 o Interoperability considerations: n/a 1215 o Published specification: [[ this document ]] 1216 o Applications that use this media type: OpenID Connect, Mozilla 1217 Persona, Salesforce, Google, Android, Windows Azure, Xbox One, 1218 Amazon Web Services, and numerous others that use JWTs 1219 o Fragment identifier considerations: n/a 1220 o Additional information: Magic number(s): n/a, File extension(s): 1221 n/a, Macintosh file type code(s): n/a 1222 o Person & email address to contact for further information: Michael 1223 B. Jones, mbj@microsoft.com 1224 o Intended usage: COMMON 1225 o Restrictions on usage: none 1226 o Author: Michael B. Jones, mbj@microsoft.com 1227 o Change Controller: IESG 1228 o Provisional registration? No 1229 o Type name: application 1230 o Subtype name: jose+json 1231 o Required parameters: n/a 1232 o Optional parameters: n/a 1233 o Encoding considerations: 8bit; application/jose+json values are 1234 represented as a JSON Object; UTF-8 encoding SHOULD be employed 1235 for the JSON object. 1236 o Security considerations: See the Security Considerations section 1237 of [[ this document ]] 1238 o Interoperability considerations: n/a 1239 o Published specification: [[ this document ]] 1240 o Applications that use this media type: TBD 1241 o Fragment identifier considerations: n/a 1242 o Additional information: Magic number(s): n/a, File extension(s): 1243 n/a, Macintosh file type code(s): n/a 1244 o Person & email address to contact for further information: Michael 1245 B. Jones, mbj@microsoft.com 1246 o Intended usage: COMMON 1247 o Restrictions on usage: none 1248 o Author: Michael B. Jones, mbj@microsoft.com 1249 o Change Controller: IESG 1250 o Provisional registration? No 1252 10. Security Considerations 1254 All of the security issues that are pertinent to any cryptographic 1255 application must be addressed by JWS/JWE/JWK agents. Among these 1256 issues are protecting the user's asymmetric private and symmetric 1257 secret keys and employing countermeasures to various attacks. 1259 All the security considerations in XML DSIG 2.0 1260 [W3C.NOTE-xmldsig-core2-20130411], also apply to this specification, 1261 other than those that are XML specific. Likewise, many of the best 1262 practices documented in XML Signature Best Practices 1263 [W3C.NOTE-xmldsig-bestpractices-20130411] also apply to this 1264 specification, other than those that are XML specific. 1266 10.1. Key Entropy and Random Values 1268 Keys are only as strong as the amount of entropy used to generate 1269 them. A minimum of 128 bits of entropy should be used for all keys, 1270 and depending upon the application context, more may be required. 1272 Implementations must randomly generate public/private key pairs, 1273 message authentication (MAC) keys, and padding values. The use of 1274 inadequate pseudo-random number generators (PRNGs) to generate 1275 cryptographic keys can result in little or no security. An attacker 1276 may find it much easier to reproduce the PRNG environment that 1277 produced the keys, searching the resulting small set of 1278 possibilities, rather than brute force searching the whole key space. 1279 The generation of quality random numbers is difficult. RFC 4086 1280 [RFC4086] offers important guidance in this area. 1282 10.2. Key Protection 1284 Implementations must protect the signer's private key. Compromise of 1285 the signer's private key permits an attacker to masquerade as the 1286 signer. 1288 Implementations must protect the message authentication (MAC) key. 1289 Compromise of the MAC key may result in undetectable modification of 1290 the authenticated content. 1292 10.3. Key Origin Authentication 1294 The key management technique employed to obtain public keys must 1295 authenticate the origin of the key; otherwise, it is unknown what 1296 party signed the message. 1298 Likewise, the key management technique employed to distribute MAC 1299 keys must provide data origin authentication; otherwise, the contents 1300 are delivered with integrity from an unknown source. 1302 10.4. Cryptographic Agility 1304 See Section 8.1 of [JWA] for security considerations on cryptographic 1305 agility. 1307 10.5. Differences between Digital Signatures and MACs 1309 While MACs and digital signatures can both be used for integrity 1310 checking, there are some significant differences between the security 1311 properties that each of them provides. These need to be taken into 1312 consideration when designing protocols and selecting the algorithms 1313 to be used in protocols. 1315 Both signatures and MACs provide for integrity checking -- verifying 1316 that the message has not been modified since the integrity value was 1317 computed. However, MACs provide for origination identification only 1318 under specific circumstances. It can normally be assumed that a 1319 private key used for a signature is only in the hands of a single 1320 entity (although perhaps a distributed entity, in the case of 1321 replicated servers); however, a MAC key needs to be in the hands of 1322 all the entities that use it for integrity computation and checking. 1323 Validation of a MAC only provides corroboration that the message was 1324 generated by one of the parties that knows the symmetric MAC key. 1325 This means that origination can only be determined if a MAC key is 1326 known only to two entities and the recipient knows that it did not 1327 create the message. MAC validation cannot be used to prove 1328 origination to a third party. 1330 10.6. Algorithm Validation 1332 The digital signature representations for some algorithms include 1333 information about the algorithm used inside the signature value. For 1334 instance, signatures produced with RSASSA-PKCS-v1_5 [RFC3447] encode 1335 the hash function used and many libraries actually use the hash 1336 algorithm specified inside the signature when validating the 1337 signature. When using such libraries, as part of the algorithm 1338 validation performed, implementations MUST ensure that the algorithm 1339 information encoded in the signature corresponds to that specified 1340 with the "alg" Header Parameter. If this is not done, an attacker 1341 could claim to have used a strong hash algorithm while actually using 1342 a weak one represented in the signature value. 1344 10.7. Algorithm Protection 1346 In some usages of JWS, there is a risk of algorithm substitution 1347 attacks, in which an attacker can use an existing digital signature 1348 value with a different signature algorithm to make it appear that a 1349 signer has signed something that it has not. These attacks have been 1350 discussed in detail in the context of CMS [RFC6211]. This risk 1351 arises when all of the following are true: 1353 o Verifiers of a signature support multiple algorithms. 1355 o Given an existing signature, an attacker can find another payload 1356 that produces the same signature value with a different algorithm. 1358 o The payload crafted by the attacker is valid in the application 1359 context. 1361 There are several ways for an application to mitigate algorithm 1362 substitution attacks: 1364 o Use only digital signature algorithms that are not vulnerable to 1365 substitution attacks. Substitution attacks are only feasible if 1366 an attacker can compute pre-images for a hash function accepted by 1367 the recipient. All JWA-defined signature algorithms use SHA-2 1368 hashes, for which there are no known pre-image attacks, as of the 1369 time of this writing. 1371 o Require that the "alg" Header Parameter be carried in the 1372 protected header. (This is always the case when using the JWS 1373 Compact Serialization and is the approach taken by CMS [RFC6211].) 1375 o Include a field containing the algorithm in the application 1376 payload, and require that it be matched with the "alg" Header 1377 Parameter during verification. (This is the approach taken by 1378 PKIX [RFC5280].) 1380 10.8. Chosen Plaintext Attacks 1382 Creators of JWSs should not allow third parties to insert arbitrary 1383 content into the message without adding entropy not controlled by the 1384 third party. 1386 10.9. Timing Attacks 1388 When cryptographic algorithms are implemented in such a way that 1389 successful operations take a different amount of time than 1390 unsuccessful operations, attackers may be able to use the time 1391 difference to obtain information about the keys employed. Therefore, 1392 such timing differences must be avoided. 1394 10.10. Replay Protection 1396 While not directly in scope for this specification, note that 1397 applications using JWS (or JWE) objects can thwart replay attacks by 1398 including a unique message identifier as integrity protected content 1399 in the JWS (or JWE) message and having the recipient verify that the 1400 message has not been previously received or acted upon. 1402 10.11. SHA-1 Certificate Thumbprints 1404 A SHA-1 hash is used when computing "x5t" (X.509 Certificate SHA-1 1405 Thumbprint) values, for compatibility reasons. Should an effective 1406 means of producing SHA-1 hash collisions be developed, and should an 1407 attacker wish to interfere with the use of a known certificate on a 1408 given system, this could be accomplished by creating another 1409 certificate whose SHA-1 hash value is the same and adding it to the 1410 certificate store used by the intended victim. A prerequisite to 1411 this attack succeeding is the attacker having write access to the 1412 intended victim's certificate store. 1414 Alternatively, the "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) 1415 Header Parameter could be used instead of "x5t". However, at the 1416 time of this writing, no development platform is known to support 1417 SHA-256 certificate thumbprints. 1419 10.12. JSON Security Considerations 1421 Strict JSON [RFC7159] validation is a security requirement. If 1422 malformed JSON is received, then the intent of the producer is 1423 impossible to reliably discern. Ambiguous and potentially 1424 exploitable situations could arise if the JSON parser used does not 1425 reject malformed JSON syntax. In particular, any JSON inputs not 1426 conforming to the JSON-text syntax defined in RFC 7159 input MUST be 1427 rejected in their entirety. 1429 Section 4 of the JSON Data Interchange Format specification [RFC7159] 1430 states "The names within an object SHOULD be unique", whereas this 1431 specification states that "Header Parameter names within this object 1432 MUST be unique; JWS parsers MUST either reject JWSs with duplicate 1433 Header Parameter names or use a JSON parser that returns only the 1434 lexically last duplicate member name, as specified in Section 15.12 1435 (The JSON Object) of ECMAScript 5.1 [ECMAScript]". Thus, this 1436 specification requires that the Section 4 "SHOULD" be treated as a 1437 "MUST" by producers and that it be either treated as a "MUST" or in 1438 the manner specified in ECMAScript 5.1 by consumers. Ambiguous and 1439 potentially exploitable situations could arise if the JSON parser 1440 used does not enforce the uniqueness of member names or returns an 1441 unpredictable value for duplicate member names. 1443 Some JSON parsers might not reject input that contains extra 1444 significant characters after a valid input. For instance, the input 1445 "{"tag":"value"}ABCD" contains a valid JSON-text object followed by 1446 the extra characters "ABCD". Such input MUST be rejected in its 1447 entirety. 1449 10.13. Unicode Comparison Security Considerations 1451 Header Parameter names and algorithm names are Unicode strings. For 1452 security reasons, the representations of these names must be compared 1453 verbatim after performing any escape processing (as per Section 8.3 1454 of RFC 7159 [RFC7159]). This means, for instance, that these JSON 1455 strings must compare as being equal ("sig", "\u0073ig"), whereas 1456 these must all compare as being not equal to the first set or to each 1457 other ("SIG", "Sig", "si\u0047"). 1459 JSON strings can contain characters outside the Unicode Basic 1460 Multilingual Plane. For instance, the G clef character (U+1D11E) may 1461 be represented in a JSON string as "\uD834\uDD1E". Ideally, JWS 1462 implementations SHOULD ensure that characters outside the Basic 1463 Multilingual Plane are preserved and compared correctly; 1464 alternatively, if this is not possible due to these characters 1465 exercising limitations present in the underlying JSON implementation, 1466 then input containing them MUST be rejected. 1468 11. References 1470 11.1. Normative References 1472 [ECMAScript] 1473 Ecma International, "ECMAScript Language Specification, 1474 5.1 Edition", ECMA 262, June 2011. 1476 [IANA.MediaTypes] 1477 Internet Assigned Numbers Authority (IANA), "MIME Media 1478 Types", 2005. 1480 [ITU.X690.1994] 1481 International Telecommunications Union, "Information 1482 Technology - ASN.1 encoding rules: Specification of Basic 1483 Encoding Rules (BER), Canonical Encoding Rules (CER) and 1484 Distinguished Encoding Rules (DER)", ITU-T Recommendation 1485 X.690, 1994. 1487 [JWA] Jones, M., "JSON Web Algorithms (JWA)", 1488 draft-ietf-jose-json-web-algorithms (work in progress), 1489 November 2014. 1491 [JWK] Jones, M., "JSON Web Key (JWK)", 1492 draft-ietf-jose-json-web-key (work in progress), 1493 November 2014. 1495 [RFC20] Cerf, V., "ASCII format for Network Interchange", RFC 20, 1496 October 1969. 1498 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 1499 Extensions (MIME) Part One: Format of Internet Message 1500 Bodies", RFC 2045, November 1996. 1502 [RFC2046] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 1503 Extensions (MIME) Part Two: Media Types", RFC 2046, 1504 November 1996. 1506 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1507 Requirement Levels", BCP 14, RFC 2119, March 1997. 1509 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 1511 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 1512 10646", STD 63, RFC 3629, November 2003. 1514 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1515 Resource Identifier (URI): Generic Syntax", STD 66, 1516 RFC 3986, January 2005. 1518 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 1519 Encodings", RFC 4648, October 2006. 1521 [RFC4945] Korver, B., "The Internet IP Security PKI Profile of 1522 IKEv1/ISAKMP, IKEv2, and PKIX", RFC 4945, August 2007. 1524 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 1525 RFC 4949, August 2007. 1527 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 1528 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 1530 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 1531 Housley, R., and W. Polk, "Internet X.509 Public Key 1532 Infrastructure Certificate and Certificate Revocation List 1533 (CRL) Profile", RFC 5280, May 2008. 1535 [RFC6125] Saint-Andre, P. and J. Hodges, "Representation and 1536 Verification of Domain-Based Application Service Identity 1537 within Internet Public Key Infrastructure Using X.509 1538 (PKIX) Certificates in the Context of Transport Layer 1539 Security (TLS)", RFC 6125, March 2011. 1541 [RFC6176] Turner, S. and T. Polk, "Prohibiting Secure Sockets Layer 1542 (SSL) Version 2.0", RFC 6176, March 2011. 1544 [RFC7159] Bray, T., "The JavaScript Object Notation (JSON) Data 1545 Interchange Format", RFC 7159, March 2014. 1547 11.2. Informative References 1549 [CanvasApp] 1550 Facebook, "Canvas Applications", 2010. 1552 [I-D.ietf-uta-tls-bcp] 1553 Sheffer, Y., Holz, R., and P. Saint-Andre, 1554 "Recommendations for Secure Use of TLS and DTLS", 1555 draft-ietf-uta-tls-bcp-07 (work in progress), 1556 November 2014. 1558 [JSS] Bradley, J. and N. Sakimura (editor), "JSON Simple Sign", 1559 September 2010. 1561 [JWE] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 1562 draft-ietf-jose-json-web-encryption (work in progress), 1563 November 2014. 1565 [JWT] Jones, M., Bradley, J., and N. Sakimura, "JSON Web Token 1566 (JWT)", draft-ietf-oauth-json-web-token (work in 1567 progress), November 2014. 1569 [MagicSignatures] 1570 Panzer (editor), J., Laurie, B., and D. Balfanz, "Magic 1571 Signatures", January 2011. 1573 [RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed- 1574 Hashing for Message Authentication", RFC 2104, 1575 February 1997. 1577 [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography 1578 Standards (PKCS) #1: RSA Cryptography Specifications 1579 Version 2.1", RFC 3447, February 2003. 1581 [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness 1582 Requirements for Security", BCP 106, RFC 4086, June 2005. 1584 [RFC4122] Leach, P., Mealling, M., and R. Salz, "A Universally 1585 Unique IDentifier (UUID) URN Namespace", RFC 4122, 1586 July 2005. 1588 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 1589 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 1590 May 2008. 1592 [RFC6211] Schaad, J., "Cryptographic Message Syntax (CMS) Algorithm 1593 Identifier Protection Attribute", RFC 6211, April 2011. 1595 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 1596 Specifications and Registration Procedures", BCP 13, 1597 RFC 6838, January 2013. 1599 [SHS] National Institute of Standards and Technology, "Secure 1600 Hash Standard (SHS)", FIPS PUB 180-4, March 2012. 1602 [W3C.NOTE-xmldsig-bestpractices-20130411] 1603 Hirsch, F. and P. Datta, "XML Signature Best Practices", 1604 World Wide Web Consortium Note NOTE-xmldsig-bestpractices- 1605 20130411, April 2013, . 1608 [W3C.NOTE-xmldsig-core2-20130411] 1609 Eastlake, D., Reagle, J., Solo, D., Hirsch, F., Roessler, 1610 T., Yiu, K., Datta, P., and S. Cantor, "XML Signature 1611 Syntax and Processing Version 2.0", World Wide Web 1612 Consortium Note NOTE-xmldsig-core2-20130411, April 2013, 1613 . 1615 Appendix A. JWS Examples 1617 This section provides several examples of JWSs. While the first 1618 three examples all represent JSON Web Tokens (JWTs) [JWT], the 1619 payload can be any octet sequence, as shown in Appendix A.4. 1621 A.1. Example JWS using HMAC SHA-256 1623 A.1.1. Encoding 1625 The following example JWS Protected Header declares that the data 1626 structure is a JSON Web Token (JWT) [JWT] and the JWS Signing Input 1627 is secured using the HMAC SHA-256 algorithm. 1629 {"typ":"JWT", 1630 "alg":"HS256"} 1632 To remove potential ambiguities in the representation of the JSON 1633 object above, the actual octet sequence representing UTF8(JWS 1634 Protected Header) used in this example is also included below. (Note 1635 that ambiguities can arise due to differing platform representations 1636 of line breaks (CRLF versus LF), differing spacing at the beginning 1637 and ends of lines, whether the last line has a terminating line break 1638 or not, and other causes. In the representation used in this 1639 example, the first line has no leading or trailing spaces, a CRLF 1640 line break (13, 10) occurs between the first and second lines, the 1641 second line has one leading space (32) and no trailing spaces, and 1642 the last line does not have a terminating line break.) The octets 1643 representing UTF8(JWS Protected Header) in this example (using JSON 1644 array notation) are: 1646 [123, 34, 116, 121, 112, 34, 58, 34, 74, 87, 84, 34, 44, 13, 10, 32, 1647 34, 97, 108, 103, 34, 58, 34, 72, 83, 50, 53, 54, 34, 125] 1649 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 1650 Header)) gives this value: 1652 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 1654 The JWS Payload used in this example is the octets of the UTF-8 1655 representation of the JSON object below. (Note that the payload can 1656 be any base64url encoded octet sequence, and need not be a base64url 1657 encoded JSON object.) 1658 {"iss":"joe", 1659 "exp":1300819380, 1660 "http://example.com/is_root":true} 1662 The following octet sequence, which is the UTF-8 representation used 1663 in this example for the JSON object above, is the JWS Payload: 1665 [123, 34, 105, 115, 115, 34, 58, 34, 106, 111, 101, 34, 44, 13, 10, 1666 32, 34, 101, 120, 112, 34, 58, 49, 51, 48, 48, 56, 49, 57, 51, 56, 1667 48, 44, 13, 10, 32, 34, 104, 116, 116, 112, 58, 47, 47, 101, 120, 97, 1668 109, 112, 108, 101, 46, 99, 111, 109, 47, 105, 115, 95, 114, 111, 1669 111, 116, 34, 58, 116, 114, 117, 101, 125] 1671 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 1672 Header)) gives this value (with line breaks for display purposes 1673 only): 1675 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1676 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1678 Combining these as BASE64URL(UTF8(JWS Protected Header)) || '.' || 1679 BASE64URL(JWS Payload) gives this string (with line breaks for 1680 display purposes only): 1682 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 1683 . 1684 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1685 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1687 The resulting JWS Signing Input value, which is the ASCII 1688 representation of above string, is the following octet sequence 1689 (using JSON array notation): 1691 [101, 121, 74, 48, 101, 88, 65, 105, 79, 105, 74, 75, 86, 49, 81, 1692 105, 76, 65, 48, 75, 73, 67, 74, 104, 98, 71, 99, 105, 79, 105, 74, 1693 73, 85, 122, 73, 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 1694 77, 105, 79, 105, 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 1695 74, 108, 101, 72, 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 1696 107, 122, 79, 68, 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 1697 72, 65, 54, 76, 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 1698 109, 78, 118, 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 1699 106, 112, 48, 99, 110, 86, 108, 102, 81] 1701 HMACs are generated using keys. This example uses the symmetric key 1702 represented in JSON Web Key [JWK] format below (with line breaks 1703 within values for display purposes only): 1705 {"kty":"oct", 1706 "k":"AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75 1707 aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow" 1708 } 1710 Running the HMAC SHA-256 algorithm on the JWS Signing Input with this 1711 key yields this JWS Signature octet sequence: 1713 [116, 24, 223, 180, 151, 153, 224, 37, 79, 250, 96, 125, 216, 173, 1714 187, 186, 22, 212, 37, 77, 105, 214, 191, 240, 91, 88, 5, 88, 83, 1715 132, 141, 121] 1717 Encoding this JWS Signature as BASE64URL(JWS Signature) gives this 1718 value: 1720 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 1722 Concatenating these values in the order Header.Payload.Signature with 1723 period ('.') characters between the parts yields this complete JWS 1724 representation using the JWS Compact Serialization (with line breaks 1725 for display purposes only): 1727 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 1728 . 1729 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1730 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1731 . 1732 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 1734 A.1.2. Validating 1736 Since the "alg" Header Parameter is "HS256", we validate the HMAC 1737 SHA-256 value contained in the JWS Signature. 1739 To validate the HMAC value, we repeat the previous process of using 1740 the correct key and the JWS Signing Input (which is the initial 1741 substring of the JWS Compact Serialization representation up until 1742 but not including the second period character) as input to the HMAC 1743 SHA-256 function and then taking the output and determining if it 1744 matches the JWS Signature (which is base64url decoded from the value 1745 encoded in the JWS representation). If it matches exactly, the HMAC 1746 has been validated. 1748 A.2. Example JWS using RSASSA-PKCS-v1_5 SHA-256 1749 A.2.1. Encoding 1751 The JWS Protected Header in this example is different from the 1752 previous example in two ways: First, because a different algorithm is 1753 being used, the "alg" value is different. Second, for illustration 1754 purposes only, the optional "typ" parameter is not used. (This 1755 difference is not related to the algorithm employed.) The JWS 1756 Protected Header used is: 1758 {"alg":"RS256"} 1760 The octets representing UTF8(JWS Protected Header) in this example 1761 (using JSON array notation) are: 1763 [123, 34, 97, 108, 103, 34, 58, 34, 82, 83, 50, 53, 54, 34, 125] 1765 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 1766 Header)) gives this value: 1768 eyJhbGciOiJSUzI1NiJ9 1770 The JWS Payload used in this example, which follows, is the same as 1771 in the previous example. Since the BASE64URL(JWS Payload) value will 1772 therefore be the same, its computation is not repeated here. 1774 {"iss":"joe", 1775 "exp":1300819380, 1776 "http://example.com/is_root":true} 1778 Combining these as BASE64URL(UTF8(JWS Protected Header)) || '.' || 1779 BASE64URL(JWS Payload) gives this string (with line breaks for 1780 display purposes only): 1782 eyJhbGciOiJSUzI1NiJ9 1783 . 1784 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1785 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1787 The resulting JWS Signing Input value, which is the ASCII 1788 representation of above string, is the following octet sequence: 1790 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 1791 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1792 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1793 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1794 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1795 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1796 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1797 99, 110, 86, 108, 102, 81] 1799 This example uses the RSA key represented in JSON Web Key [JWK] 1800 format below (with line breaks within values for display purposes 1801 only): 1803 {"kty":"RSA", 1804 "n":"ofgWCuLjybRlzo0tZWJjNiuSfb4p4fAkd_wWJcyQoTbji9k0l8W26mPddx 1805 HmfHQp-Vaw-4qPCJrcS2mJPMEzP1Pt0Bm4d4QlL-yRT-SFd2lZS-pCgNMs 1806 D1W_YpRPEwOWvG6b32690r2jZ47soMZo9wGzjb_7OMg0LOL-bSf63kpaSH 1807 SXndS5z5rexMdbBYUsLA9e-KXBdQOS-UTo7WTBEMa2R2CapHg665xsmtdV 1808 MTBQY4uDZlxvb3qCo5ZwKh9kG4LT6_I5IhlJH7aGhyxXFvUK-DWNmoudF8 1809 NAco9_h9iaGNj8q2ethFkMLs91kzk2PAcDTW9gb54h4FRWyuXpoQ", 1810 "e":"AQAB", 1811 "d":"Eq5xpGnNCivDflJsRQBXHx1hdR1k6Ulwe2JZD50LpXyWPEAeP88vLNO97I 1812 jlA7_GQ5sLKMgvfTeXZx9SE-7YwVol2NXOoAJe46sui395IW_GO-pWJ1O0 1813 BkTGoVEn2bKVRUCgu-GjBVaYLU6f3l9kJfFNS3E0QbVdxzubSu3Mkqzjkn 1814 439X0M_V51gfpRLI9JYanrC4D4qAdGcopV_0ZHHzQlBjudU2QvXt4ehNYT 1815 CBr6XCLQUShb1juUO1ZdiYoFaFQT5Tw8bGUl_x_jTj3ccPDVZFD9pIuhLh 1816 BOneufuBiB4cS98l2SR_RQyGWSeWjnczT0QU91p1DhOVRuOopznQ", 1817 "p":"4BzEEOtIpmVdVEZNCqS7baC4crd0pqnRH_5IB3jw3bcxGn6QLvnEtfdUdi 1818 YrqBdss1l58BQ3KhooKeQTa9AB0Hw_Py5PJdTJNPY8cQn7ouZ2KKDcmnPG 1819 BY5t7yLc1QlQ5xHdwW1VhvKn-nXqhJTBgIPgtldC-KDV5z-y2XDwGUc", 1820 "q":"uQPEfgmVtjL0Uyyx88GZFF1fOunH3-7cepKmtH4pxhtCoHqpWmT8YAmZxa 1821 ewHgHAjLYsp1ZSe7zFYHj7C6ul7TjeLQeZD_YwD66t62wDmpe_HlB-TnBA 1822 -njbglfIsRLtXlnDzQkv5dTltRJ11BKBBypeeF6689rjcJIDEz9RWdc", 1823 "dp":"BwKfV3Akq5_MFZDFZCnW-wzl-CCo83WoZvnLQwCTeDv8uzluRSnm71I3Q 1824 CLdhrqE2e9YkxvuxdBfpT_PI7Yz-FOKnu1R6HsJeDCjn12Sk3vmAktV2zb 1825 34MCdy7cpdTh_YVr7tss2u6vneTwrA86rZtu5Mbr1C1XsmvkxHQAdYo0", 1826 "dq":"h_96-mK1R_7glhsum81dZxjTnYynPbZpHziZjeeHcXYsXaaMwkOlODsWa 1827 7I9xXDoRwbKgB719rrmI2oKr6N3Do9U0ajaHF-NKJnwgjMd2w9cjz3_-ky 1828 NlxAr2v4IKhGNpmM5iIgOS1VZnOZ68m6_pbLBSp3nssTdlqvd0tIiTHU", 1829 "qi":"IYd7DHOhrWvxkwPQsRM2tOgrjbcrfvtQJipd-DlcxyVuuM9sQLdgjVk2o 1830 y26F0EmpScGLq2MowX7fhd_QJQ3ydy5cY7YIBi87w93IKLEdfnbJtoOPLU 1831 W0ITrJReOgo1cq9SbsxYawBgfp_gh6A5603k2-ZQwVK0JKSHuLFkuQ3U" 1832 } 1834 The RSA private key is then passed to the RSA signing function, which 1835 also takes the hash type, SHA-256, and the JWS Signing Input as 1836 inputs. The result of the digital signature is an octet sequence, 1837 which represents a big endian integer. In this example, it is: 1839 [112, 46, 33, 137, 67, 232, 143, 209, 30, 181, 216, 45, 191, 120, 69, 1840 243, 65, 6, 174, 27, 129, 255, 247, 115, 17, 22, 173, 209, 113, 125, 1841 131, 101, 109, 66, 10, 253, 60, 150, 238, 221, 115, 162, 102, 62, 81, 1842 102, 104, 123, 0, 11, 135, 34, 110, 1, 135, 237, 16, 115, 249, 69, 1843 229, 130, 173, 252, 239, 22, 216, 90, 121, 142, 232, 198, 109, 219, 1844 61, 184, 151, 91, 23, 208, 148, 2, 190, 237, 213, 217, 217, 112, 7, 1845 16, 141, 178, 129, 96, 213, 248, 4, 12, 167, 68, 87, 98, 184, 31, 1846 190, 127, 249, 217, 46, 10, 231, 111, 36, 242, 91, 51, 187, 230, 244, 1847 74, 230, 30, 177, 4, 10, 203, 32, 4, 77, 62, 249, 18, 142, 212, 1, 1848 48, 121, 91, 212, 189, 59, 65, 238, 202, 208, 102, 171, 101, 25, 129, 1849 253, 228, 141, 247, 127, 55, 45, 195, 139, 159, 175, 221, 59, 239, 1850 177, 139, 93, 163, 204, 60, 46, 176, 47, 158, 58, 65, 214, 18, 202, 1851 173, 21, 145, 18, 115, 160, 95, 35, 185, 232, 56, 250, 175, 132, 157, 1852 105, 132, 41, 239, 90, 30, 136, 121, 130, 54, 195, 212, 14, 96, 69, 1853 34, 165, 68, 200, 242, 122, 122, 45, 184, 6, 99, 209, 108, 247, 202, 1854 234, 86, 222, 64, 92, 178, 33, 90, 69, 178, 194, 85, 102, 181, 90, 1855 193, 167, 72, 160, 112, 223, 200, 163, 42, 70, 149, 67, 208, 25, 238, 1856 251, 71] 1858 Encoding the signature as BASE64URL(JWS Signature) produces this 1859 value (with line breaks for display purposes only): 1861 cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7 1862 AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4 1863 BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K 1864 0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv 1865 hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB 1866 p0igcN_IoypGlUPQGe77Rw 1868 Concatenating these values in the order Header.Payload.Signature with 1869 period ('.') characters between the parts yields this complete JWS 1870 representation using the JWS Compact Serialization (with line breaks 1871 for display purposes only): 1873 eyJhbGciOiJSUzI1NiJ9 1874 . 1875 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1876 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1877 . 1878 cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7 1879 AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4 1880 BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K 1881 0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv 1882 hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB 1883 p0igcN_IoypGlUPQGe77Rw 1885 A.2.2. Validating 1887 Since the "alg" Header Parameter is "RS256", we validate the RSASSA- 1888 PKCS-v1_5 SHA-256 digital signature contained in the JWS Signature. 1890 Validating the JWS Signature is a bit different from the previous 1891 example. We pass the public key (n, e), the JWS Signature (which is 1892 base64url decoded from the value encoded in the JWS representation), 1893 and the JWS Signing Input (which is the initial substring of the JWS 1894 Compact Serialization representation up until but not including the 1895 second period character) to an RSASSA-PKCS-v1_5 signature verifier 1896 that has been configured to use the SHA-256 hash function. 1898 A.3. Example JWS using ECDSA P-256 SHA-256 1900 A.3.1. Encoding 1902 The JWS Protected Header for this example differs from the previous 1903 example because a different algorithm is being used. The JWS 1904 Protected Header used is: 1906 {"alg":"ES256"} 1908 The octets representing UTF8(JWS Protected Header) in this example 1909 (using JSON array notation) are: 1911 [123, 34, 97, 108, 103, 34, 58, 34, 69, 83, 50, 53, 54, 34, 125] 1913 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 1914 Header)) gives this value: 1916 eyJhbGciOiJFUzI1NiJ9 1918 The JWS Payload used in this example, which follows, is the same as 1919 in the previous examples. Since the BASE64URL(JWS Payload) value 1920 will therefore be the same, its computation is not repeated here. 1922 {"iss":"joe", 1923 "exp":1300819380, 1924 "http://example.com/is_root":true} 1926 Combining these as BASE64URL(UTF8(JWS Protected Header)) || '.' || 1927 BASE64URL(JWS Payload) gives this string (with line breaks for 1928 display purposes only): 1930 eyJhbGciOiJFUzI1NiJ9 1931 . 1932 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1933 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1935 The resulting JWS Signing Input value, which is the ASCII 1936 representation of above string, is the following octet sequence: 1938 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 70, 85, 122, 73, 1939 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1940 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1941 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1942 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1943 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1944 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1945 99, 110, 86, 108, 102, 81] 1947 This example uses the elliptic curve key represented in JSON Web Key 1948 [JWK] format below: 1950 {"kty":"EC", 1951 "crv":"P-256", 1952 "x":"f83OJ3D2xF1Bg8vub9tLe1gHMzV76e8Tus9uPHvRVEU", 1953 "y":"x_FEzRu9m36HLN_tue659LNpXW6pCyStikYjKIWI5a0", 1954 "d":"jpsQnnGQmL-YBIffH1136cspYG6-0iY7X1fCE9-E9LI" 1955 } 1957 The ECDSA private part d is then passed to an ECDSA signing function, 1958 which also takes the curve type, P-256, the hash type, SHA-256, and 1959 the JWS Signing Input as inputs. The result of the digital signature 1960 is the EC point (R, S), where R and S are unsigned integers. In this 1961 example, the R and S values, given as octet sequences representing 1962 big endian integers are: 1964 +--------+----------------------------------------------------------+ 1965 | Result | Value | 1966 | Name | | 1967 +--------+----------------------------------------------------------+ 1968 | R | [14, 209, 33, 83, 121, 99, 108, 72, 60, 47, 127, 21, 88, | 1969 | | 7, 212, 2, 163, 178, 40, 3, 58, 249, 124, 126, 23, 129, | 1970 | | 154, 195, 22, 158, 166, 101] | 1971 | S | [197, 10, 7, 211, 140, 60, 112, 229, 216, 241, 45, 175, | 1972 | | 8, 74, 84, 128, 166, 101, 144, 197, 242, 147, 80, 154, | 1973 | | 143, 63, 127, 138, 131, 163, 84, 213] | 1974 +--------+----------------------------------------------------------+ 1976 The JWS Signature is the value R || S. Encoding the signature as 1977 BASE64URL(JWS Signature) produces this value (with line breaks for 1978 display purposes only): 1980 DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSA 1981 pmWQxfKTUJqPP3-Kg6NU1Q 1983 Concatenating these values in the order Header.Payload.Signature with 1984 period ('.') characters between the parts yields this complete JWS 1985 representation using the JWS Compact Serialization (with line breaks 1986 for display purposes only): 1988 eyJhbGciOiJFUzI1NiJ9 1989 . 1990 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1991 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1992 . 1993 DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSA 1994 pmWQxfKTUJqPP3-Kg6NU1Q 1996 A.3.2. Validating 1998 Since the "alg" Header Parameter is "ES256", we validate the ECDSA 1999 P-256 SHA-256 digital signature contained in the JWS Signature. 2001 Validating the JWS Signature is a bit different from the previous 2002 examples. We need to split the 64 member octet sequence of the JWS 2003 Signature (which is base64url decoded from the value encoded in the 2004 JWS representation) into two 32 octet sequences, the first 2005 representing R and the second S. We then pass the public key (x, y), 2006 the signature (R, S), and the JWS Signing Input (which is the initial 2007 substring of the JWS Compact Serialization representation up until 2008 but not including the second period character) to an ECDSA signature 2009 verifier that has been configured to use the P-256 curve with the 2010 SHA-256 hash function. 2012 A.4. Example JWS using ECDSA P-521 SHA-512 2014 A.4.1. Encoding 2016 The JWS Protected Header for this example differs from the previous 2017 example because different ECDSA curves and hash functions are used. 2018 The JWS Protected Header used is: 2020 {"alg":"ES512"} 2022 The octets representing UTF8(JWS Protected Header) in this example 2023 (using JSON array notation) are: 2025 [123, 34, 97, 108, 103, 34, 58, 34, 69, 83, 53, 49, 50, 34, 125] 2027 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 2028 Header)) gives this value: 2030 eyJhbGciOiJFUzUxMiJ9 2032 The JWS Payload used in this example, is the ASCII string "Payload". 2033 The representation of this string is the octet sequence: 2035 [80, 97, 121, 108, 111, 97, 100] 2036 Encoding this JWS Payload as BASE64URL(JWS Payload) gives this value: 2038 UGF5bG9hZA 2040 Combining these as BASE64URL(UTF8(JWS Protected Header)) || '.' || 2041 BASE64URL(JWS Payload) gives this string: 2043 eyJhbGciOiJFUzUxMiJ9.UGF5bG9hZA 2045 The resulting JWS Signing Input value, which is the ASCII 2046 representation of above string, is the following octet sequence: 2048 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 70, 85, 122, 85, 2049 120, 77, 105, 74, 57, 46, 85, 71, 70, 53, 98, 71, 57, 104, 90, 65] 2051 This example uses the elliptic curve key represented in JSON Web Key 2052 [JWK] format below (with line breaks within values for display 2053 purposes only): 2055 {"kty":"EC", 2056 "crv":"P-521", 2057 "x":"AekpBQ8ST8a8VcfVOTNl353vSrDCLLJXmPk06wTjxrrjcBpXp5EOnYG_ 2058 NjFZ6OvLFV1jSfS9tsz4qUxcWceqwQGk", 2059 "y":"ADSmRA43Z1DSNx_RvcLI87cdL07l6jQyyBXMoxVg_l2Th-x3S1WDhjDl 2060 y79ajL4Kkd0AZMaZmh9ubmf63e3kyMj2", 2061 "d":"AY5pb7A0UFiB3RELSD64fTLOSV_jazdF7fLYyuTw8lOfRhWg6Y6rUrPA 2062 xerEzgdRhajnu0ferB0d53vM9mE15j2C" 2063 } 2065 The ECDSA private part d is then passed to an ECDSA signing function, 2066 which also takes the curve type, P-521, the hash type, SHA-512, and 2067 the JWS Signing Input as inputs. The result of the digital signature 2068 is the EC point (R, S), where R and S are unsigned integers. In this 2069 example, the R and S values, given as octet sequences representing 2070 big endian integers are: 2072 +--------+----------------------------------------------------------+ 2073 | Result | Value | 2074 | Name | | 2075 +--------+----------------------------------------------------------+ 2076 | R | [1, 220, 12, 129, 231, 171, 194, 209, 232, 135, 233, | 2077 | | 117, 247, 105, 122, 210, 26, 125, 192, 1, 217, 21, 82, | 2078 | | 91, 45, 240, 255, 83, 19, 34, 239, 71, 48, 157, 147, | 2079 | | 152, 105, 18, 53, 108, 163, 214, 68, 231, 62, 153, 150, | 2080 | | 106, 194, 164, 246, 72, 143, 138, 24, 50, 129, 223, 133, | 2081 | | 206, 209, 172, 63, 237, 119, 109] | 2082 | S | [0, 111, 6, 105, 44, 5, 41, 208, 128, 61, 152, 40, 92, | 2083 | | 61, 152, 4, 150, 66, 60, 69, 247, 196, 170, 81, 193, | 2084 | | 199, 78, 59, 194, 169, 16, 124, 9, 143, 42, 142, 131, | 2085 | | 48, 206, 238, 34, 175, 83, 203, 220, 159, 3, 107, 155, | 2086 | | 22, 27, 73, 111, 68, 68, 21, 238, 144, 229, 232, 148, | 2087 | | 188, 222, 59, 242, 103] | 2088 +--------+----------------------------------------------------------+ 2090 The JWS Signature is the value R || S. Encoding the signature as 2091 BASE64URL(JWS Signature) produces this value (with line breaks for 2092 display purposes only): 2094 AdwMgeerwtHoh-l192l60hp9wAHZFVJbLfD_UxMi70cwnZOYaRI1bKPWROc-mZZq 2095 wqT2SI-KGDKB34XO0aw_7XdtAG8GaSwFKdCAPZgoXD2YBJZCPEX3xKpRwcdOO8Kp 2096 EHwJjyqOgzDO7iKvU8vcnwNrmxYbSW9ERBXukOXolLzeO_Jn 2098 Concatenating these values in the order Header.Payload.Signature with 2099 period ('.') characters between the parts yields this complete JWS 2100 representation using the JWS Compact Serialization (with line breaks 2101 for display purposes only): 2103 eyJhbGciOiJFUzUxMiJ9 2104 . 2105 UGF5bG9hZA 2106 . 2107 AdwMgeerwtHoh-l192l60hp9wAHZFVJbLfD_UxMi70cwnZOYaRI1bKPWROc-mZZq 2108 wqT2SI-KGDKB34XO0aw_7XdtAG8GaSwFKdCAPZgoXD2YBJZCPEX3xKpRwcdOO8Kp 2109 EHwJjyqOgzDO7iKvU8vcnwNrmxYbSW9ERBXukOXolLzeO_Jn 2111 A.4.2. Validating 2113 Since the "alg" Header Parameter is "ES512", we validate the ECDSA 2114 P-521 SHA-512 digital signature contained in the JWS Signature. 2116 Validating this JWS Signature is very similar to the previous 2117 example. We need to split the 132 member octet sequence of the JWS 2118 Signature into two 66 octet sequences, the first representing R and 2119 the second S. We then pass the public key (x, y), the signature (R, 2120 S), and the JWS Signing Input to an ECDSA signature verifier that has 2121 been configured to use the P-521 curve with the SHA-512 hash 2122 function. 2124 A.5. Example Unsecured JWS 2126 The following example JWS Protected Header declares that the encoded 2127 object is an Unsecured JWS: 2129 {"alg":"none"} 2131 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 2132 Header)) gives this value: 2134 eyJhbGciOiJub25lIn0 2136 The JWS Payload used in this example, which follows, is the same as 2137 in the previous examples. Since the BASE64URL(JWS Payload) value 2138 will therefore be the same, its computation is not repeated here. 2140 {"iss":"joe", 2141 "exp":1300819380, 2142 "http://example.com/is_root":true} 2144 The JWS Signature is the empty octet string and BASE64URL(JWS 2145 Signature) is the empty string. 2147 Concatenating these parts in the order Header.Payload.Signature with 2148 period ('.') characters between the parts yields this complete JWS 2149 (with line breaks for display purposes only): 2151 eyJhbGciOiJub25lIn0 2152 . 2153 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 2154 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 2155 . 2157 A.6. Example JWS using General JWS JSON Serialization 2159 This section contains an example using the general JWS JSON 2160 Serialization syntax. This example demonstrates the capability for 2161 conveying multiple digital signatures and/or MACs for the same 2162 payload. 2164 The JWS Payload used in this example is the same as that used in the 2165 examples in Appendix A.2 and Appendix A.3 (with line breaks for 2166 display purposes only): 2168 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 2169 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 2171 Two digital signatures are used in this example: the first using 2172 RSASSA-PKCS-v1_5 SHA-256 and the second using ECDSA P-256 SHA-256. 2173 For the first, the JWS Protected Header and key are the same as in 2174 Appendix A.2, resulting in the same JWS Signature value; therefore, 2175 its computation is not repeated here. For the second, the JWS 2176 Protected Header and key are the same as in Appendix A.3, resulting 2177 in the same JWS Signature value; therefore, its computation is not 2178 repeated here. 2180 A.6.1. JWS Per-Signature Protected Headers 2182 The JWS Protected Header value used for the first signature is: 2184 {"alg":"RS256"} 2186 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 2187 Header)) gives this value: 2189 eyJhbGciOiJSUzI1NiJ9 2191 The JWS Protected Header value used for the second signature is: 2193 {"alg":"ES256"} 2195 Encoding this JWS Protected Header as BASE64URL(UTF8(JWS Protected 2196 Header)) gives this value: 2198 eyJhbGciOiJFUzI1NiJ9 2200 A.6.2. JWS Per-Signature Unprotected Headers 2202 Key ID values are supplied for both keys using per-signature Header 2203 Parameters. The two values used to represent these Key IDs are: 2205 {"kid":"2010-12-29"} 2207 and 2209 {"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"} 2211 A.6.3. Complete JOSE Header Values 2213 Combining the protected and unprotected header values supplied, the 2214 JOSE Header values used for the first and second signatures 2215 respectively are: 2217 {"alg":"RS256", 2218 "kid":"2010-12-29"} 2220 and 2222 {"alg":"ES256", 2223 "kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"} 2225 A.6.4. Complete JWS JSON Serialization Representation 2227 The complete JWS JSON Serialization for these values is as follows 2228 (with line breaks within values for display purposes only): 2230 { 2231 "payload": 2232 "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGF 2233 tcGxlLmNvbS9pc19yb290Ijp0cnVlfQ", 2234 "signatures":[ 2235 {"protected":"eyJhbGciOiJSUzI1NiJ9", 2236 "header": 2237 {"kid":"2010-12-29"}, 2238 "signature": 2239 "cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZ 2240 mh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjb 2241 KBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHl 2242 b1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZES 2243 c6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AX 2244 LIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw"}, 2245 {"protected":"eyJhbGciOiJFUzI1NiJ9", 2246 "header": 2247 {"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"}, 2248 "signature": 2249 "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8IS 2250 lSApmWQxfKTUJqPP3-Kg6NU1Q"}] 2251 } 2253 A.7. Example JWS using Flattened JWS JSON Serialization 2255 This section contains an example using the flattened JWS JSON 2256 Serialization syntax. This example demonstrates the capability for 2257 conveying a single digital signature or MAC in a flattened JSON 2258 structure. 2260 The values in this example are the same as those in the second 2261 signature of the previous example in Appendix A.6. 2263 The complete JWS JSON Serialization for these values is as follows 2264 (with line breaks within values for display purposes only): 2266 { 2267 "payload": 2268 "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGF 2269 tcGxlLmNvbS9pc19yb290Ijp0cnVlfQ", 2270 "protected":"eyJhbGciOiJFUzI1NiJ9", 2271 "header": 2272 {"kid":"e9bc097a-ce51-4036-9562-d2ade882db0d"}, 2273 "signature": 2274 "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8IS 2275 lSApmWQxfKTUJqPP3-Kg6NU1Q" 2276 } 2278 Appendix B. "x5c" (X.509 Certificate Chain) Example 2280 The JSON array below is an example of a certificate chain that could 2281 be used as the value of an "x5c" (X.509 Certificate Chain) Header 2282 Parameter, per Section 4.1.6. Note that since these strings contain 2283 base64 encoded (not base64url encoded) values, they are allowed to 2284 contain white space and line breaks. 2286 ["MIIE3jCCA8agAwIBAgICAwEwDQYJKoZIhvcNAQEFBQAwYzELMAkGA1UEBhMCVVM 2287 xITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR2 2288 8gRGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExM 2289 TYwMTU0MzdaFw0yNjExMTYwMTU0MzdaMIHKMQswCQYDVQQGEwJVUzEQMA4GA1UE 2290 CBMHQXJpem9uYTETMBEGA1UEBxMKU2NvdHRzZGFsZTEaMBgGA1UEChMRR29EYWR 2291 keS5jb20sIEluYy4xMzAxBgNVBAsTKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYW 2292 RkeS5jb20vcmVwb3NpdG9yeTEwMC4GA1UEAxMnR28gRGFkZHkgU2VjdXJlIENlc 2293 nRpZmljYXRpb24gQXV0aG9yaXR5MREwDwYDVQQFEwgwNzk2OTI4NzCCASIwDQYJ 2294 KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMQt1RWMnCZM7DI161+4WQFapmGBWTt 2295 wY6vj3D3HKrjJM9N55DrtPDAjhI6zMBS2sofDPZVUBJ7fmd0LJR4h3mUpfjWoqV 2296 Tr9vcyOdQmVZWt7/v+WIbXnvQAjYwqDL1CBM6nPwT27oDyqu9SoWlm2r4arV3aL 2297 GbqGmu75RpRSgAvSMeYddi5Kcju+GZtCpyz8/x4fKL4o/K1w/O5epHBp+YlLpyo 2298 7RJlbmr2EkRTcDCVw5wrWCs9CHRK8r5RsL+H0EwnWGu1NcWdrxcx+AuP7q2BNgW 2299 JCJjPOq8lh8BJ6qf9Z/dFjpfMFDniNoW1fho3/Rb2cRGadDAW/hOUoz+EDU8CAw 2300 EAAaOCATIwggEuMB0GA1UdDgQWBBT9rGEyk2xF1uLuhV+auud2mWjM5zAfBgNVH 2301 SMEGDAWgBTSxLDSkdRMEXGzYcs9of7dqGrU4zASBgNVHRMBAf8ECDAGAQH/AgEA 2302 MDMGCCsGAQUFBwEBBCcwJTAjBggrBgEFBQcwAYYXaHR0cDovL29jc3AuZ29kYWR 2303 keS5jb20wRgYDVR0fBD8wPTA7oDmgN4Y1aHR0cDovL2NlcnRpZmljYXRlcy5nb2 2304 RhZGR5LmNvbS9yZXBvc2l0b3J5L2dkcm9vdC5jcmwwSwYDVR0gBEQwQjBABgRVH 2305 SAAMDgwNgYIKwYBBQUHAgEWKmh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5j 2306 b20vcmVwb3NpdG9yeTAOBgNVHQ8BAf8EBAMCAQYwDQYJKoZIhvcNAQEFBQADggE 2307 BANKGwOy9+aG2Z+5mC6IGOgRQjhVyrEp0lVPLN8tESe8HkGsz2ZbwlFalEzAFPI 2308 UyIXvJxwqoJKSQ3kbTJSMUA2fCENZvD117esyfxVgqwcSeIaha86ykRvOe5GPLL 2309 5CkKSkB2XIsKd83ASe8T+5o0yGPwLPk9Qnt0hCqU7S+8MxZC9Y7lhyVJEnfzuz9 2310 p0iRFEUOOjZv2kWzRaJBydTXRE4+uXR21aITVSzGh6O1mawGhId/dQb8vxRMDsx 2311 uxN89txJx9OjxUUAiKEngHUuHqDTMBqLdElrRhjZkAzVvb3du6/KFUJheqwNTrZ 2312 EjYx8WnM25sgVjOuH0aBsXBTWVU+4=", 2314 "MIIE+zCCBGSgAwIBAgICAQ0wDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1Z 2315 hbGlDZXJ0IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIE 2316 luYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb 2317 24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8x 2318 IDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTA0MDYyOTE3MDY 2319 yMFoXDTI0MDYyOTE3MDYyMFowYzELMAkGA1UEBhMCVVMxITAfBgNVBAoTGFRoZS 2320 BHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR28gRGFkZHkgQ2xhc3MgM 2321 iBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASAwDQYJKoZIhvcNAQEBBQADggEN 2322 ADCCAQgCggEBAN6d1+pXGEmhW+vXX0iG6r7d/+TvZxz0ZWizV3GgXne77ZtJ6XC 2323 APVYYYwhv2vLM0D9/AlQiVBDYsoHUwHU9S3/Hd8M+eKsaA7Ugay9qK7HFiH7Eux 2324 6wwdhFJ2+qN1j3hybX2C32qRe3H3I2TqYXP2WYktsqbl2i/ojgC95/5Y0V4evLO 2325 tXiEqITLdiOr18SPaAIBQi2XKVlOARFmR6jYGB0xUGlcmIbYsUfb18aQr4CUWWo 2326 riMYavx4A6lNf4DD+qta/KFApMoZFv6yyO9ecw3ud72a9nmYvLEHZ6IVDd2gWMZ 2327 Eewo+YihfukEHU1jPEX44dMX4/7VpkI+EdOqXG68CAQOjggHhMIIB3TAdBgNVHQ 2328 4EFgQU0sSw0pHUTBFxs2HLPaH+3ahq1OMwgdIGA1UdIwSByjCBx6GBwaSBvjCBu 2329 zEkMCIGA1UEBxMbVmFsaUNlcnQgVmFsaWRhdGlvbiBOZXR3b3JrMRcwFQYDVQQK 2330 Ew5WYWxpQ2VydCwgSW5jLjE1MDMGA1UECxMsVmFsaUNlcnQgQ2xhc3MgMiBQb2x 2331 pY3kgVmFsaWRhdGlvbiBBdXRob3JpdHkxITAfBgNVBAMTGGh0dHA6Ly93d3cudm 2332 FsaWNlcnQuY29tLzEgMB4GCSqGSIb3DQEJARYRaW5mb0B2YWxpY2VydC5jb22CA 2333 QEwDwYDVR0TAQH/BAUwAwEB/zAzBggrBgEFBQcBAQQnMCUwIwYIKwYBBQUHMAGG 2334 F2h0dHA6Ly9vY3NwLmdvZGFkZHkuY29tMEQGA1UdHwQ9MDswOaA3oDWGM2h0dHA 2335 6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5jb20vcmVwb3NpdG9yeS9yb290LmNybD 2336 BLBgNVHSAERDBCMEAGBFUdIAAwODA2BggrBgEFBQcCARYqaHR0cDovL2NlcnRpZ 2337 mljYXRlcy5nb2RhZGR5LmNvbS9yZXBvc2l0b3J5MA4GA1UdDwEB/wQEAwIBBjAN 2338 BgkqhkiG9w0BAQUFAAOBgQC1QPmnHfbq/qQaQlpE9xXUhUaJwL6e4+PrxeNYiY+ 2339 Sn1eocSxI0YGyeR+sBjUZsE4OWBsUs5iB0QQeyAfJg594RAoYC5jcdnplDQ1tgM 2340 QLARzLrUc+cb53S8wGd9D0VmsfSxOaFIqII6hR8INMqzW/Rn453HWkrugp++85j 2341 09VZw==", 2342 "MIIC5zCCAlACAQEwDQYJKoZIhvcNAQEFBQAwgbsxJDAiBgNVBAcTG1ZhbGlDZXJ 2343 0IFZhbGlkYXRpb24gTmV0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNT 2344 AzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0a 2345 G9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkq 2346 hkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNjAwMTk1NFoXDTE 2347 5MDYyNjAwMTk1NFowgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTm 2348 V0d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZ 2349 XJ0IENsYXNzIDIgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQD 2350 ExhodHRwOi8vd3d3LnZhbGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9 2351 AdmFsaWNlcnQuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOOnHK5a 2352 vIWZJV16vYdA757tn2VUdZZUcOBVXc65g2PFxTXdMwzzjsvUGJ7SVCCSRrCl6zf 2353 N1SLUzm1NZ9WlmpZdRJEy0kTRxQb7XBhVQ7/nHk01xC+YDgkRoKWzk2Z/M/VXwb 2354 P7RfZHM047QSv4dk+NoS/zcnwbNDu+97bi5p9wIDAQABMA0GCSqGSIb3DQEBBQU 2355 AA4GBADt/UG9vUJSZSWI4OB9L+KXIPqeCgfYrx+jFzug6EILLGACOTb2oWH+heQ 2356 C1u+mNr0HZDzTuIYEZoDJJKPTEjlbVUjP9UNV+mWwD5MlM/Mtsq2azSiGM5bUMM 2357 j4QssxsodyamEwCW/POuZ6lcg5Ktz885hZo+L7tdEy8W9ViH0Pd"] 2359 Appendix C. Notes on implementing base64url encoding without padding 2361 This appendix describes how to implement base64url encoding and 2362 decoding functions without padding based upon standard base64 2363 encoding and decoding functions that do use padding. 2365 To be concrete, example C# code implementing these functions is shown 2366 below. Similar code could be used in other languages. 2368 static string base64urlencode(byte [] arg) 2369 { 2370 string s = Convert.ToBase64String(arg); // Regular base64 encoder 2371 s = s.Split('=')[0]; // Remove any trailing '='s 2372 s = s.Replace('+', '-'); // 62nd char of encoding 2373 s = s.Replace('/', '_'); // 63rd char of encoding 2374 return s; 2375 } 2377 static byte [] base64urldecode(string arg) 2378 { 2379 string s = arg; 2380 s = s.Replace('-', '+'); // 62nd char of encoding 2381 s = s.Replace('_', '/'); // 63rd char of encoding 2382 switch (s.Length % 4) // Pad with trailing '='s 2383 { 2384 case 0: break; // No pad chars in this case 2385 case 2: s += "=="; break; // Two pad chars 2386 case 3: s += "="; break; // One pad char 2387 default: throw new System.Exception( 2388 "Illegal base64url string!"); 2389 } 2390 return Convert.FromBase64String(s); // Standard base64 decoder 2391 } 2393 As per the example code above, the number of '=' padding characters 2394 that needs to be added to the end of a base64url encoded string 2395 without padding to turn it into one with padding is a deterministic 2396 function of the length of the encoded string. Specifically, if the 2397 length mod 4 is 0, no padding is added; if the length mod 4 is 2, two 2398 '=' padding characters are added; if the length mod 4 is 3, one '=' 2399 padding character is added; if the length mod 4 is 1, the input is 2400 malformed. 2402 An example correspondence between unencoded and encoded values 2403 follows. The octet sequence below encodes into the string below, 2404 which when decoded, reproduces the octet sequence. 2405 3 236 255 224 193 2406 A-z_4ME 2408 Appendix D. Notes on Key Selection 2410 This appendix describes a set of possible algorithms for selecting 2411 the key to be used to validate the digital signature or MAC of a JWS 2412 object or for selecting the key to be used to decrypt a JWE object. 2413 This guidance describes a family of possible algorithms, rather than 2414 a single algorithm, because in different contexts, not all the 2415 sources of keys will be used, they can be tried in different orders, 2416 and sometimes not all the collected keys will be tried; hence, 2417 different algorithms will be used in different application contexts. 2419 The steps below are described for illustration purposes only; 2420 specific applications can and are likely to use different algorithms 2421 or perform some of the steps in different orders. Specific 2422 applications will frequently have a much simpler method of 2423 determining the keys to use, as there may be one or two key selection 2424 methods that are profiled for the application's use. This appendix 2425 supplements the normative information on key location in Section 6. 2427 These algorithms include the following steps. Note that the steps 2428 can be performed in any order and do not need to be treated as 2429 distinct. For example, keys can be tried as soon as they are found, 2430 rather than collecting all the keys before trying any. 2432 1. Collect the set of potentially applicable keys. Sources of keys 2433 may include: 2435 * Keys supplied by the application protocol being used. 2437 * Keys referenced by the "jku" (JWK Set URL) Header Parameter. 2439 * The key provided by the "jwk" (JSON Web Key) Header Parameter. 2441 * The key referenced by the "x5u" (X.509 URL) Header Parameter. 2443 * The key provided by the "x5c" (X.509 Certificate Chain) Header 2444 Parameter. 2446 * Other applicable keys available to the application. 2448 The order for collecting and trying keys from different key 2449 sources is typically application dependent. For example, 2450 frequently all keys from a one set of locations, such as local 2451 caches, will be tried before collecting and trying keys from 2452 other locations. 2454 2. Filter the set of collected keys. For instance, some 2455 applications will use only keys referenced by "kid" (key ID) or 2456 "x5t" (X.509 certificate SHA-1 thumbprint) parameters. If the 2457 application uses the "alg" (algorithm), "use" (public key use), 2458 or "key_ops" (key operations) parameters, keys with keys with 2459 inappropriate values of those parameters would be excluded. 2460 Additionally, keys might be filtered to include or exclude keys 2461 with certain other member values in an application specific 2462 manner. For some applications, no filtering will be applied. 2464 3. Order the set of collected keys. For instance, keys referenced 2465 by "kid" (Key ID) or "x5t" (X.509 Certificate SHA-1 Thumbprint) 2466 parameters might be tried before keys with neither of these 2467 values. Likewise, keys with certain member values might be 2468 ordered before keys with other member values. For some 2469 applications, no ordering will be applied. 2471 4. Make trust decisions about the keys. Signatures made with keys 2472 not meeting the application's trust criteria would not be 2473 accepted. Such criteria might include, but is not limited to the 2474 source of the key, whether the TLS certificate validates for keys 2475 retrieved from URLs, whether a key in an X.509 certificate is 2476 backed by a valid certificate chain, and other information known 2477 by the application. 2479 5. Attempt signature or MAC validation for a JWS object or 2480 decryption of a JWE object with some or all of the collected and 2481 possibly filtered and/or ordered keys. A limit on the number of 2482 keys to be tried might be applied. This process will normally 2483 terminate following a successful validation or decryption. 2485 Note that it is reasonable for some applications to perform signature 2486 or MAC validation prior to making a trust decision about a key, since 2487 keys for which the validation fails need no trust decision. 2489 Appendix E. Negative Test Case for "crit" Header Parameter 2491 Conforming implementations must reject input containing critical 2492 extensions that are not understood or cannot be processed. The 2493 following JWS must be rejected by all implementations, because it 2494 uses an extension Header Parameter name 2495 "http://example.invalid/UNDEFINED" that they do not understand. Any 2496 other similar input, in which the use of the value 2497 "http://example.invalid/UNDEFINED" is substituted for any other 2498 Header Parameter name not understood by the implementation, must also 2499 be rejected. 2501 The JWS Protected Header value for this JWS is: 2503 {"alg":"none", 2504 "crit":["http://example.invalid/UNDEFINED"], 2505 "http://example.invalid/UNDEFINED":true 2506 } 2508 The complete JWS that must be rejected is as follows (with line 2509 breaks for display purposes only): 2511 eyJhbGciOiJub25lIiwNCiAiY3JpdCI6WyJodHRwOi8vZXhhbXBsZS5jb20vVU5ERU 2512 ZJTkVEIl0sDQogImh0dHA6Ly9leGFtcGxlLmNvbS9VTkRFRklORUQiOnRydWUNCn0. 2513 RkFJTA. 2515 Appendix F. Detached Content 2517 In some contexts, it is useful integrity protect content that is not 2518 itself contained in a JWS object. One way to do this is create a JWS 2519 object in the normal fashion using a representation of the content as 2520 the payload, but then delete the payload representation from the JWS, 2521 and send this modified object to the recipient, rather than the JWS. 2522 When using the JWS Compact Serialization, the deletion is 2523 accomplished by replacing the second field (which contains 2524 BASE64URL(JWS Payload)) value with the empty string; when using the 2525 JWS JSON Serialization, the deletion is accomplished by deleting the 2526 "payload" member. This method assumes that the recipient can 2527 reconstruct the exact payload used in the JWS. To use the modified 2528 object, the recipient reconstructs the JWS by re-inserting the 2529 payload representation into the modified object, and uses the 2530 resulting JWS in the usual manner. Note that this method needs no 2531 support from JWS libraries, as applications can use this method by 2532 modifying the inputs and outputs of standard JWS libraries. 2534 Appendix G. Acknowledgements 2536 Solutions for signing JSON content were previously explored by Magic 2537 Signatures [MagicSignatures], JSON Simple Sign [JSS], and Canvas 2538 Applications [CanvasApp], all of which influenced this draft. 2540 Thanks to Axel Nennker for his early implementation and feedback on 2541 the JWS and JWE specifications. 2543 This specification is the work of the JOSE Working Group, which 2544 includes dozens of active and dedicated participants. In particular, 2545 the following individuals contributed ideas, feedback, and wording 2546 that influenced this specification: 2548 Dirk Balfanz, Richard Barnes, Brian Campbell, Alissa Cooper, Breno de 2549 Medeiros, Stephen Farrell, Dick Hardt, Joe Hildebrand, Jeff Hodges, 2550 Russ Housley, Edmund Jay, Tero Kivinen, Yaron Y. Goland, Ben Laurie, 2551 Ted Lemon, James Manger, Matt Miller, Kathleen Moriarty, Tony 2552 Nadalin, Hideki Nara, Axel Nennker, John Panzer, Ray Polk, Emmanuel 2553 Raviart, Eric Rescorla, Pete Resnick, Jim Schaad, Paul Tarjan, Hannes 2554 Tschofenig, and Sean Turner. 2556 Jim Schaad and Karen O'Donoghue chaired the JOSE working group and 2557 Sean Turner, Stephen Farrell, and Kathleen Moriarty served as 2558 Security area directors during the creation of this specification. 2560 Appendix H. Document History 2562 [[ to be removed by the RFC Editor before publication as an RFC ]] 2564 -37 2566 o Updated the TLS requirements language to only require 2567 implementations to support TLS when they support features using 2568 TLS. 2570 o Updated the language about integrity protecting Header Parameters 2571 when used in a trust decision. 2573 o Restricted algorithm names to using only ASCII characters. 2575 o When describing actions taken as a result of validation failures, 2576 changed statements about rejecting the JWS to statements about 2577 considering the JWS to be invalid. 2579 o Added the CRT parameter values to example RSA private key 2580 representations. 2582 o Updated the example IANA registration request subject line. 2584 -36 2586 o Defined a flattened JWS JSON Serialization syntax, which is 2587 optimized for the single digital signature or MAC case. 2589 o Clarified where white space and line breaks may occur in JSON 2590 objects by referencing Section 2 of RFC 7159. 2592 o Specified that registration reviews occur on the 2593 jose-reg-review@ietf.org mailing list. 2595 -35 2597 o Addressed AppsDir reviews by Ray Polk. 2599 o Used real values for examples in the IANA Registration Template. 2601 -34 2603 o Addressed IESG review comments by Alissa Cooper, Pete Resnick, 2604 Richard Barnes, Ted Lemon, and Stephen Farrell. 2606 o Addressed Gen-ART review comments by Russ Housley. 2608 o Referenced RFC 4945 for PEM certificate delimiter syntax. 2610 -33 2612 o Noted that certificate thumbprints are also sometimes known as 2613 certificate fingerprints. 2615 o Added an informative reference to draft-ietf-uta-tls-bcp for 2616 recommendations on improving the security of software and services 2617 using TLS. 2619 o Changed the registration review period to three weeks. 2621 o Acknowledged additional contributors. 2623 -32 2625 o Addressed Gen-ART review comments by Russ Housley. 2627 o Addressed secdir review comments by Tero Kivinen, Stephen Kent, 2628 and Scott Kelly. 2630 o Replaced the term Plaintext JWS with Unsecured JWS. 2632 -31 2634 o Reworded the language about JWS implementations ignoring the "typ" 2635 and "cty" parameters, explicitly saying that their processing is 2636 performed by JWS applications. 2638 o Added additional guidance on ciphersuites currently considered to 2639 be appropriate for use, including a reference to a recent update 2640 by the TLS working group. 2642 -30 2643 o Added subsection headings within the Overview section for the two 2644 serializations. 2646 o Added references and cleaned up the reference syntax in a few 2647 places. 2649 o Applied minor wording changes to the Security Considerations 2650 section and made other local editorial improvements. 2652 -29 2654 o Replaced the terms JWS Header, JWE Header, and JWT Header with a 2655 single JOSE Header term defined in the JWS specification. This 2656 also enabled a single Header Parameter definition to be used and 2657 reduced other areas of duplication between specifications. 2659 -28 2661 o Revised the introduction to the Security Considerations section. 2662 Also introduced additional subsection headings for security 2663 considerations items and also moved a security consideration item 2664 here from the JWA draft. 2666 o Added text about when applications typically would and would not 2667 use "typ" and "cty" header parameters. 2669 -27 2671 o Added the "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) header 2672 parameter. 2674 o Stated that any JSON inputs not conforming to the JSON-text syntax 2675 defined in RFC 7159 input MUST be rejected in their entirety. 2677 o Simplified the TLS requirements. 2679 -26 2681 o Referenced Section 6 of RFC 6125 for TLS server certificate 2682 identity validation. 2684 o Described potential sources of ambiguity in representing the JSON 2685 objects used in the examples. The octets of the actual UTF-8 2686 representations of the JSON objects used in the examples are 2687 included to remove these ambiguities. 2689 o Added a small amount of additional explanatory text to the 2690 signature validation examples to aid implementers. 2692 o Noted that octet sequences are depicted using JSON array notation. 2694 o Updated references, including to W3C specifications. 2696 -25 2698 o No changes were made, other than to the version number and date. 2700 -24 2702 o Updated the JSON reference to RFC 7159. 2704 -23 2706 o Clarified that the base64url encoding includes no line breaks, 2707 white space, or other additional characters. 2709 -22 2711 o Corrected RFC 2119 terminology usage. 2713 o Replaced references to draft-ietf-json-rfc4627bis with RFC 7158. 2715 -21 2717 o Applied review comments to the appendix "Notes on Key Selection", 2718 addressing issue #93. 2720 o Changed some references from being normative to informative, 2721 addressing issue #90. 2723 o Applied review comments to the JSON Serialization section, 2724 addressing issue #121. 2726 -20 2728 o Made terminology definitions more consistent, addressing issue 2729 #165. 2731 o Restructured the JSON Serialization section to call out the 2732 parameters used in hanging lists, addressing issue #121. 2734 o Described key filtering and refined other aspects of the text in 2735 the appendix "Notes on Key Selection", addressing issue #93. 2737 o Replaced references to RFC 4627 with draft-ietf-json-rfc4627bis, 2738 addressing issue #90. 2740 -19 2742 o Added the appendix "Notes on Validation Key Selection", addressing 2743 issue #93. 2745 o Reordered the key selection parameters. 2747 -18 2749 o Updated the mandatory-to-implement (MTI) language to say that 2750 applications using this specification need to specify what 2751 serialization and serialization features are used for that 2752 application, addressing issue #119. 2754 o Changes to address editorial and minor issues #25, #89, #97, #110, 2755 #114, #115, #116, #117, #120, and #184. 2757 o Added and used Header Parameter Description registry field. 2759 -17 2761 o Refined the "typ" and "cty" definitions to always be MIME Media 2762 Types, with the omission of "application/" prefixes recommended 2763 for brevity, addressing issue #50. 2765 o Updated the mandatory-to-implement (MTI) language to say that 2766 general-purpose implementations must implement the single 2767 signature/MAC value case for both serializations whereas special- 2768 purpose implementations can implement just one serialization if 2769 that meets the needs of the use cases the implementation is 2770 designed for, addressing issue #119. 2772 o Explicitly named all the logical components of a JWS and defined 2773 the processing rules and serializations in terms of those 2774 components, addressing issues #60, #61, and #62. 2776 o Replaced verbose repetitive phases such as "base64url encode the 2777 octets of the UTF-8 representation of X" with mathematical 2778 notation such as "BASE64URL(UTF8(X))". 2780 o Terms used in multiple documents are now defined in one place and 2781 incorporated by reference. Some lightly used or obvious terms 2782 were also removed. This addresses issue #58. 2784 -16 2786 o Changes to address editorial and minor issues #50, #98, #99, #102, 2787 #104, #106, #107, #111, and #112. 2789 -15 2791 o Clarified that it is an application decision which signatures, 2792 MACs, or plaintext values must successfully validate for the JWS 2793 to be accepted, addressing issue #35. 2795 o Corrected editorial error in "ES512" example. 2797 o Changes to address editorial and minor issues #34, #96, #100, 2798 #101, #104, #105, and #106. 2800 -14 2802 o Stated that the "signature" parameter is to be omitted in the JWS 2803 JSON Serialization when its value would be empty (which is only 2804 the case for a Plaintext JWS). 2806 -13 2808 o Made all header parameter values be per-signature/MAC, addressing 2809 issue #24. 2811 -12 2813 o Clarified that the "typ" and "cty" header parameters are used in 2814 an application-specific manner and have no effect upon the JWS 2815 processing. 2817 o Replaced the MIME types "application/jws+json" and 2818 "application/jws" with "application/jose+json" and 2819 "application/jose". 2821 o Stated that recipients MUST either reject JWSs with duplicate 2822 Header Parameter Names or use a JSON parser that returns only the 2823 lexically last duplicate member name. 2825 o Added a Serializations section with parallel treatment of the JWS 2826 Compact Serialization and the JWS JSON Serialization and also 2827 moved the former Implementation Considerations content there. 2829 -11 2831 o Added Key Identification section. 2833 o For the JWS JSON Serialization, enable header parameter values to 2834 be specified in any of three parameters: the "protected" member 2835 that is integrity protected and shared among all recipients, the 2836 "unprotected" member that is not integrity protected and shared 2837 among all recipients, and the "header" member that is not 2838 integrity protected and specific to a particular recipient. (This 2839 does not affect the JWS Compact Serialization, in which all header 2840 parameter values are in a single integrity protected JWE Header 2841 value.) 2843 o Removed suggested compact serialization for multiple digital 2844 signatures and/or MACs. 2846 o Changed the MIME type name "application/jws-js" to 2847 "application/jws+json", addressing issue #22. 2849 o Tightened the description of the "crit" (critical) header 2850 parameter. 2852 o Added a negative test case for the "crit" header parameter 2854 -10 2856 o Added an appendix suggesting a possible compact serialization for 2857 JWSs with multiple digital signatures and/or MACs. 2859 -09 2861 o Added JWS JSON Serialization, as specified by 2862 draft-jones-jose-jws-json-serialization-04. 2864 o Registered "application/jws-js" MIME type and "JWS-JS" typ header 2865 parameter value. 2867 o Defined that the default action for header parameters that are not 2868 understood is to ignore them unless specifically designated as 2869 "MUST be understood" or included in the new "crit" (critical) 2870 header parameter list. This addressed issue #6. 2872 o Changed term "JWS Secured Input" to "JWS Signing Input". 2874 o Changed from using the term "byte" to "octet" when referring to 8 2875 bit values. 2877 o Changed member name from "recipients" to "signatures" in the JWS 2878 JSON Serialization. 2880 o Added complete values using the JWS Compact Serialization for all 2881 examples. 2883 -08 2884 o Applied editorial improvements suggested by Jeff Hodges and Hannes 2885 Tschofenig. Many of these simplified the terminology used. 2887 o Clarified statements of the form "This header parameter is 2888 OPTIONAL" to "Use of this header parameter is OPTIONAL". 2890 o Added a Header Parameter Usage Location(s) field to the IANA JSON 2891 Web Signature and Encryption Header Parameters registry. 2893 o Added seriesInfo information to Internet Draft references. 2895 -07 2897 o Updated references. 2899 -06 2901 o Changed "x5c" (X.509 Certificate Chain) representation from being 2902 a single string to being an array of strings, each containing a 2903 single base64 encoded DER certificate value, representing elements 2904 of the certificate chain. 2906 o Applied changes made by the RFC Editor to RFC 6749's registry 2907 language to this specification. 2909 -05 2911 o Added statement that "StringOrURI values are compared as case- 2912 sensitive strings with no transformations or canonicalizations 2913 applied". 2915 o Indented artwork elements to better distinguish them from the body 2916 text. 2918 -04 2920 o Completed JSON Security Considerations section, including 2921 considerations about rejecting input with duplicate member names. 2923 o Completed security considerations on the use of a SHA-1 hash when 2924 computing "x5t" (x.509 certificate thumbprint) values. 2926 o Refer to the registries as the primary sources of defined values 2927 and then secondarily reference the sections defining the initial 2928 contents of the registries. 2930 o Normatively reference XML DSIG 2.0 for its security 2931 considerations. 2933 o Added this language to Registration Templates: "This name is case 2934 sensitive. Names that match other registered names in a case 2935 insensitive manner SHOULD NOT be accepted." 2937 o Reference draft-jones-jose-jws-json-serialization instead of 2938 draft-jones-json-web-signature-json-serialization. 2940 o Described additional open issues. 2942 o Applied editorial suggestions. 2944 -03 2946 o Added the "cty" (content type) header parameter for declaring type 2947 information about the secured content, as opposed to the "typ" 2948 (type) header parameter, which declares type information about 2949 this object. 2951 o Added "Collision Resistant Namespace" to the terminology section. 2953 o Reference ITU.X690.1994 for DER encoding. 2955 o Added an example JWS using ECDSA P-521 SHA-512. This has 2956 particular illustrative value because of the use of the 521 bit 2957 integers in the key and signature values. This is also an example 2958 in which the payload is not a base64url encoded JSON object. 2960 o Added an example "x5c" value. 2962 o No longer say "the UTF-8 representation of the JWS Secured Input 2963 (which is the same as the ASCII representation)". Just call it 2964 "the ASCII representation of the JWS Secured Input". 2966 o Added Registration Template sections for defined registries. 2968 o Added Registry Contents sections to populate registry values. 2970 o Changed name of the JSON Web Signature and Encryption "typ" Values 2971 registry to be the JSON Web Signature and Encryption Type Values 2972 registry, since it is used for more than just values of the "typ" 2973 parameter. 2975 o Moved registries JSON Web Signature and Encryption Header 2976 Parameters and JSON Web Signature and Encryption Type Values to 2977 the JWS specification. 2979 o Numerous editorial improvements. 2981 -02 2983 o Clarified that it is an error when a "kid" value is included and 2984 no matching key is found. 2986 o Removed assumption that "kid" (key ID) can only refer to an 2987 asymmetric key. 2989 o Clarified that JWSs with duplicate Header Parameter Names MUST be 2990 rejected. 2992 o Clarified the relationship between "typ" header parameter values 2993 and MIME types. 2995 o Registered application/jws MIME type and "JWS" typ header 2996 parameter value. 2998 o Simplified JWK terminology to get replace the "JWK Key Object" and 2999 "JWK Container Object" terms with simply "JSON Web Key (JWK)" and 3000 "JSON Web Key Set (JWK Set)" and to eliminate potential confusion 3001 between single keys and sets of keys. As part of this change, the 3002 Header Parameter Name for a public key value was changed from 3003 "jpk" (JSON Public Key) to "jwk" (JSON Web Key). 3005 o Added suggestion on defining additional header parameters such as 3006 "x5t#S256" in the future for certificate thumbprints using hash 3007 algorithms other than SHA-1. 3009 o Specify RFC 2818 server identity validation, rather than RFC 6125 3010 (paralleling the same decision in the OAuth specs). 3012 o Generalized language to refer to Message Authentication Codes 3013 (MACs) rather than Hash-based Message Authentication Codes (HMACs) 3014 unless in a context specific to HMAC algorithms. 3016 o Reformatted to give each header parameter its own section heading. 3018 -01 3020 o Moved definition of Plaintext JWSs (using "alg":"none") here from 3021 the JWT specification since this functionality is likely to be 3022 useful in more contexts that just for JWTs. 3024 o Added "jpk" and "x5c" header parameters for including JWK public 3025 keys and X.509 certificate chains directly in the header. 3027 o Clarified that this specification is defining the JWS Compact 3028 Serialization. Referenced the new JWS-JS spec, which defines the 3029 JWS JSON Serialization. 3031 o Added text "New header parameters should be introduced sparingly 3032 since an implementation that does not understand a parameter MUST 3033 reject the JWS". 3035 o Clarified that the order of the creation and validation steps is 3036 not significant in cases where there are no dependencies between 3037 the inputs and outputs of the steps. 3039 o Changed "no canonicalization is performed" to "no canonicalization 3040 need be performed". 3042 o Corrected the Magic Signatures reference. 3044 o Made other editorial improvements suggested by JOSE working group 3045 participants. 3047 -00 3049 o Created the initial IETF draft based upon 3050 draft-jones-json-web-signature-04 with no normative changes. 3052 o Changed terminology to no longer call both digital signatures and 3053 HMACs "signatures". 3055 Authors' Addresses 3057 Michael B. Jones 3058 Microsoft 3060 Email: mbj@microsoft.com 3061 URI: http://self-issued.info/ 3063 John Bradley 3064 Ping Identity 3066 Email: ve7jtb@ve7jtb.com 3067 URI: http://www.thread-safe.com/ 3068 Nat Sakimura 3069 Nomura Research Institute 3071 Email: n-sakimura@nri.co.jp 3072 URI: http://nat.sakimura.org/