idnits 2.17.1 draft-ietf-jose-json-web-signature-06.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (October 15, 2012) is 4183 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '123' on line 1329 -- Looks like a reference, but probably isn't: '34' on line 1329 -- Looks like a reference, but probably isn't: '97' on line 1338 -- Looks like a reference, but probably isn't: '108' on line 1338 -- Looks like a reference, but probably isn't: '103' on line 1329 -- Looks like a reference, but probably isn't: '58' on line 1329 -- Looks like a reference, but probably isn't: '82' on line 1043 -- Looks like a reference, but probably isn't: '83' on line 1329 -- Looks like a reference, but probably isn't: '50' on line 1329 -- Looks like a reference, but probably isn't: '53' on line 1329 -- Looks like a reference, but probably isn't: '54' on line 1205 -- Looks like a reference, but probably isn't: '125' on line 1329 -- Looks like a reference, but probably isn't: '1' on line 1109 -- Looks like a reference, but probably isn't: '0' on line 1572 -- Looks like a reference, but probably isn't: '69' on line 1329 -- Looks like a reference, but probably isn't: '49' on line 1329 -- Looks like a reference, but probably isn't: '80' on line 1338 -- Looks like a reference, but probably isn't: '121' on line 1338 -- Looks like a reference, but probably isn't: '111' on line 1338 -- Looks like a reference, but probably isn't: '100' on line 1338 -- Possible downref: Non-RFC (?) normative reference: ref. 'ITU.X690.1994' -- Possible downref: Non-RFC (?) normative reference: ref. 'JWA' -- Possible downref: Non-RFC (?) normative reference: ref. 'JWK' ** Downref: Normative reference to an Historic RFC: RFC 1421 ** Obsolete normative reference: RFC 2818 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 4288 (Obsoleted by RFC 6838) ** Obsolete normative reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) -- Possible downref: Non-RFC (?) normative reference: ref. 'USA15' -- Possible downref: Non-RFC (?) normative reference: ref. 'USASCII' Summary: 6 errors (**), 0 flaws (~~), 1 warning (==), 26 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: April 18, 2013 Ping Identity 6 N. Sakimura 7 NRI 8 October 15, 2012 10 JSON Web Signature (JWS) 11 draft-ietf-jose-json-web-signature-06 13 Abstract 15 JSON Web Signature (JWS) is a means of representing content secured 16 with digital signatures or Message Authentication Codes (MACs) using 17 JavaScript Object Notation (JSON) data structures. Cryptographic 18 algorithms and identifiers for use with this specification are 19 described in the separate JSON Web Algorithms (JWA) specification. 20 Related encryption capabilities are described in the separate JSON 21 Web Encryption (JWE) specification. 23 Status of this Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at http://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on April 18, 2013. 40 Copyright Notice 42 Copyright (c) 2012 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents 47 (http://trustee.ietf.org/license-info) in effect on the date of 48 publication of this document. Please review these documents 49 carefully, as they describe your rights and restrictions with respect 50 to this document. Code Components extracted from this document must 51 include Simplified BSD License text as described in Section 4.e of 52 the Trust Legal Provisions and are provided without warranty as 53 described in the Simplified BSD License. 55 Table of Contents 57 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4 58 1.1. Notational Conventions . . . . . . . . . . . . . . . . . . 4 59 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 4 60 3. JSON Web Signature (JWS) Overview . . . . . . . . . . . . . . 5 61 3.1. Example JWS . . . . . . . . . . . . . . . . . . . . . . . 6 62 4. JWS Header . . . . . . . . . . . . . . . . . . . . . . . . . . 7 63 4.1. Reserved Header Parameter Names . . . . . . . . . . . . . 7 64 4.1.1. "alg" (Algorithm) Header Parameter . . . . . . . . . . 7 65 4.1.2. "jku" (JWK Set URL) Header Parameter . . . . . . . . . 8 66 4.1.3. "jwk" (JSON Web Key) Header Parameter . . . . . . . . 8 67 4.1.4. "x5u" (X.509 URL) Header Parameter . . . . . . . . . . 8 68 4.1.5. "x5t" (X.509 Certificate Thumbprint) Header 69 Parameter . . . . . . . . . . . . . . . . . . . . . . 8 70 4.1.6. "x5c" (X.509 Certificate Chain) Header Parameter . . . 9 71 4.1.7. "kid" (Key ID) Header Parameter . . . . . . . . . . . 9 72 4.1.8. "typ" (Type) Header Parameter . . . . . . . . . . . . 9 73 4.1.9. "cty" (Content Type) Header Parameter . . . . . . . . 10 74 4.2. Public Header Parameter Names . . . . . . . . . . . . . . 10 75 4.3. Private Header Parameter Names . . . . . . . . . . . . . . 10 76 5. Rules for Creating and Validating a JWS . . . . . . . . . . . 10 77 6. Securing JWSs with Cryptographic Algorithms . . . . . . . . . 12 78 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 79 7.1. JSON Web Signature and Encryption Header Parameters 80 Registry . . . . . . . . . . . . . . . . . . . . . . . . . 13 81 7.1.1. Registration Template . . . . . . . . . . . . . . . . 13 82 7.1.2. Initial Registry Contents . . . . . . . . . . . . . . 14 83 7.2. JSON Web Signature and Encryption Type Values Registry . . 15 84 7.2.1. Registration Template . . . . . . . . . . . . . . . . 15 85 7.2.2. Initial Registry Contents . . . . . . . . . . . . . . 15 86 7.3. Media Type Registration . . . . . . . . . . . . . . . . . 16 87 7.3.1. Registry Contents . . . . . . . . . . . . . . . . . . 16 88 8. Security Considerations . . . . . . . . . . . . . . . . . . . 16 89 8.1. Cryptographic Security Considerations . . . . . . . . . . 16 90 8.2. JSON Security Considerations . . . . . . . . . . . . . . . 17 91 8.3. Unicode Comparison Security Considerations . . . . . . . . 18 92 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 18 93 9.1. Normative References . . . . . . . . . . . . . . . . . . . 18 94 9.2. Informative References . . . . . . . . . . . . . . . . . . 20 95 Appendix A. JWS Examples . . . . . . . . . . . . . . . . . . . . 20 96 A.1. JWS using HMAC SHA-256 . . . . . . . . . . . . . . . . . . 20 97 A.1.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 20 98 A.1.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 22 99 A.1.3. Validating . . . . . . . . . . . . . . . . . . . . . . 22 100 A.2. JWS using RSA SHA-256 . . . . . . . . . . . . . . . . . . 23 101 A.2.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 23 102 A.2.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 26 103 A.2.3. Validating . . . . . . . . . . . . . . . . . . . . . . 26 104 A.3. JWS using ECDSA P-256 SHA-256 . . . . . . . . . . . . . . 26 105 A.3.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 26 106 A.3.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 28 107 A.3.3. Validating . . . . . . . . . . . . . . . . . . . . . . 28 108 A.4. JWS using ECDSA P-521 SHA-512 . . . . . . . . . . . . . . 29 109 A.4.1. Encoding . . . . . . . . . . . . . . . . . . . . . . . 29 110 A.4.2. Decoding . . . . . . . . . . . . . . . . . . . . . . . 31 111 A.4.3. Validating . . . . . . . . . . . . . . . . . . . . . . 31 112 A.5. Example Plaintext JWS . . . . . . . . . . . . . . . . . . 32 113 Appendix B. "x5c" (X.509 Certificate Chain) Example . . . . . . . 32 114 Appendix C. Notes on implementing base64url encoding without 115 padding . . . . . . . . . . . . . . . . . . . . . . . 34 116 Appendix D. Acknowledgements . . . . . . . . . . . . . . . . . . 35 117 Appendix E. Open Issues . . . . . . . . . . . . . . . . . . . . . 36 118 Appendix F. Document History . . . . . . . . . . . . . . . . . . 36 119 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 39 121 1. Introduction 123 JSON Web Signature (JWS) is a compact format for representing content 124 secured with digital signatures or Message Authentication Codes 125 (MACs) intended for space constrained environments such as HTTP 126 Authorization headers and URI query parameters. It represents this 127 content using JavaScript Object Notation (JSON) [RFC4627] based data 128 structures. The JWS cryptographic mechanisms provide integrity 129 protection for arbitrary sequences of bytes. 131 Cryptographic algorithms and identifiers for use with this 132 specification are described in the separate JSON Web Algorithms (JWA) 133 [JWA] specification. Related encryption capabilities are described 134 in the separate JSON Web Encryption (JWE) [JWE] specification. 136 1.1. Notational Conventions 138 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 139 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 140 document are to be interpreted as described in Key words for use in 141 RFCs to Indicate Requirement Levels [RFC2119]. 143 2. Terminology 145 JSON Web Signature (JWS) A data structure cryptographically securing 146 a JWS Header and a JWS Payload with a JWS Signature value. 148 JWS Header A string representing a JSON object that describes the 149 digital signature or MAC operation applied to create the JWS 150 Signature value. 152 JWS Payload The bytes to be secured -- a.k.a., the message. The 153 payload can contain an arbitrary sequence of bytes. 155 JWS Signature A byte array containing the cryptographic material 156 that secures the JWS Header and the JWS Payload. 158 Base64url Encoding The URL- and filename-safe Base64 encoding 159 described in RFC 4648 [RFC4648], Section 5, with the (non URL- 160 safe) '=' padding characters omitted, as permitted by Section 3.2. 161 (See Appendix C for notes on implementing base64url encoding 162 without padding.) 164 Encoded JWS Header Base64url encoding of the bytes of the UTF-8 165 [RFC3629] representation of the JWS Header. 167 Encoded JWS Payload Base64url encoding of the JWS Payload. 169 Encoded JWS Signature Base64url encoding of the JWS Signature. 171 JWS Secured Input The concatenation of the Encoded JWS Header, a 172 period ('.') character, and the Encoded JWS Payload. 174 Header Parameter Name The name of a member of the JSON object 175 representing a JWS Header. 177 Header Parameter Value The value of a member of the JSON object 178 representing a JWS Header. 180 JWS Compact Serialization A representation of the JWS as the 181 concatenation of the Encoded JWS Header, the Encoded JWS Payload, 182 and the Encoded JWS Signature in that order, with the three 183 strings being separated by two period ('.') characters. 185 Collision Resistant Namespace A namespace that allows names to be 186 allocated in a manner such that they are highly unlikely to 187 collide with other names. For instance, collision resistance can 188 be achieved through administrative delegation of portions of the 189 namespace or through use of collision-resistant name allocation 190 functions. Examples of Collision Resistant Namespaces include: 191 Domain Names, Object Identifiers (OIDs) as defined in the ITU-T 192 X.660 and X.670 Recommendation series, and Universally Unique 193 IDentifiers (UUIDs) [RFC4122]. When using an administratively 194 delegated namespace, the definer of a name needs to take 195 reasonable precautions to ensure they are in control of the 196 portion of the namespace they use to define the name. 198 StringOrURI A JSON string value, with the additional requirement 199 that while arbitrary string values MAY be used, any value 200 containing a ":" character MUST be a URI [RFC3986]. StringOrURI 201 values are compared as case-sensitive strings with no 202 transformations or canonicalizations applied. 204 3. JSON Web Signature (JWS) Overview 206 JWS represents digitally signed or MACed content using JSON data 207 structures and base64url encoding. The representation consists of 208 three parts: the JWS Header, the JWS Payload, and the JWS Signature. 209 In the Compact Serialization, the three parts are base64url-encoded 210 for transmission, and represented as the concatenation of the encoded 211 strings in that order, with the three strings being separated by two 212 period ('.') characters. (A JSON Serialization for this information 213 is defined in the separate JSON Web Signature JSON Serialization 214 (JWS-JS) [JWS-JS] specification.) 216 The JWS Header describes the signature or MAC method and parameters 217 employed. The JWS Payload is the message content to be secured. The 218 JWS Signature ensures the integrity of both the JWS Header and the 219 JWS Payload. 221 3.1. Example JWS 223 The following example JWS Header declares that the encoded object is 224 a JSON Web Token (JWT) [JWT] and the JWS Header and the JWS Payload 225 are secured using the HMAC SHA-256 algorithm: 227 {"typ":"JWT", 228 "alg":"HS256"} 230 Base64url encoding the bytes of the UTF-8 representation of the JWS 231 Header yields this Encoded JWS Header value: 233 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 235 The following is an example of a JSON object that can be used as a 236 JWS Payload. (Note that the payload can be any content, and need not 237 be a representation of a JSON object.) 239 {"iss":"joe", 240 "exp":1300819380, 241 "http://example.com/is_root":true} 243 Base64url encoding the bytes of the UTF-8 representation of the JSON 244 object yields the following Encoded JWS Payload (with line breaks for 245 display purposes only): 247 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 248 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 250 Computing the HMAC of the bytes of the ASCII [USASCII] representation 251 of the JWS Secured Input (the concatenation of the Encoded JWS 252 Header, a period ('.') character, and the Encoded JWS Payload) with 253 the HMAC SHA-256 algorithm using the key specified in Appendix A.1 254 and base64url encoding the result yields this Encoded JWS Signature 255 value: 257 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 259 Concatenating these parts in the order Header.Payload.Signature with 260 period ('.') characters between the parts yields this complete JWS 261 representation (with line breaks for display purposes only): 263 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 264 . 265 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 266 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 267 . 268 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 270 This computation is illustrated in more detail in Appendix A.1. 272 4. JWS Header 274 The members of the JSON object represented by the JWS Header describe 275 the digital signature or MAC applied to the Encoded JWS Header and 276 the Encoded JWS Payload and optionally additional properties of the 277 JWS. The Header Parameter Names within this object MUST be unique; 278 JWSs with duplicate Header Parameter Names MUST be rejected. 279 Implementations MUST understand the entire contents of the header; 280 otherwise, the JWS MUST be rejected. 282 There are three classes of Header Parameter Names: Reserved Header 283 Parameter Names, Public Header Parameter Names, and Private Header 284 Parameter Names. 286 4.1. Reserved Header Parameter Names 288 The following header parameter names are reserved with meanings as 289 defined below. All the names are short because a core goal of JWSs 290 is for the representations to be compact. 292 Additional reserved header parameter names MAY be defined via the 293 IANA JSON Web Signature and Encryption Header Parameters registry 294 Section 7.1. As indicated by the common registry, JWSs and JWEs 295 share a common header parameter space; when a parameter is used by 296 both specifications, its usage must be compatible between the 297 specifications. 299 4.1.1. "alg" (Algorithm) Header Parameter 301 The "alg" (algorithm) header parameter identifies the cryptographic 302 algorithm used to secure the JWS. The algorithm specified by the 303 "alg" value MUST be supported by the implementation and there MUST be 304 a key for use with that algorithm associated with the party that 305 digitally signed or MACed the content or the JWS MUST be rejected. 306 "alg" values SHOULD either be registered in the IANA JSON Web 307 Signature and Encryption Algorithms registry [JWA] or be a URI that 308 contains a Collision Resistant Namespace. The "alg" value is a case 309 sensitive string containing a StringOrURI value. This header 310 parameter is REQUIRED. 312 A list of defined "alg" values can be found in the IANA JSON Web 313 Signature and Encryption Algorithms registry [JWA]; the initial 314 contents of this registry are the values defined in Section 3.1 of 315 the JSON Web Algorithms (JWA) [JWA] specification. 317 4.1.2. "jku" (JWK Set URL) Header Parameter 319 The "jku" (JWK Set URL) header parameter is a URI [RFC3986] that 320 refers to a resource for a set of JSON-encoded public keys, one of 321 which corresponds to the key used to digitally sign the JWS. The 322 keys MUST be encoded as a JSON Web Key Set (JWK Set) [JWK]. The 323 protocol used to acquire the resource MUST provide integrity 324 protection; an HTTP GET request to retrieve the certificate MUST use 325 TLS [RFC2818] [RFC5246]; the identity of the server MUST be 326 validated, as per Section 3.1 of HTTP Over TLS [RFC2818]. This 327 header parameter is OPTIONAL. 329 4.1.3. "jwk" (JSON Web Key) Header Parameter 331 The "jwk" (JSON Web Key) header parameter is a public key that 332 corresponds to the key used to digitally sign the JWS. This key is 333 represented as a JSON Web Key [JWK]. This header parameter is 334 OPTIONAL. 336 4.1.4. "x5u" (X.509 URL) Header Parameter 338 The "x5u" (X.509 URL) header parameter is a URI [RFC3986] that refers 339 to a resource for the X.509 public key certificate or certificate 340 chain [RFC5280] corresponding to the key used to digitally sign the 341 JWS. The identified resource MUST provide a representation of the 342 certificate or certificate chain that conforms to RFC 5280 [RFC5280] 343 in PEM encoded form [RFC1421]. The certificate containing the public 344 key of the entity that digitally signed the JWS MUST be the first 345 certificate. This MAY be followed by additional certificates, with 346 each subsequent certificate being the one used to certify the 347 previous one. The protocol used to acquire the resource MUST provide 348 integrity protection; an HTTP GET request to retrieve the certificate 349 MUST use TLS [RFC2818] [RFC5246]; the identity of the server MUST be 350 validated, as per Section 3.1 of HTTP Over TLS [RFC2818]. This 351 header parameter is OPTIONAL. 353 4.1.5. "x5t" (X.509 Certificate Thumbprint) Header Parameter 355 The "x5t" (X.509 Certificate Thumbprint) header parameter provides a 356 base64url encoded SHA-1 thumbprint (a.k.a. digest) of the DER 357 encoding of the X.509 certificate [RFC5280] corresponding to the key 358 used to digitally sign the JWS. This header parameter is OPTIONAL. 360 If, in the future, certificate thumbprints need to be computed using 361 hash functions other than SHA-1, it is suggested that additional 362 related header parameters be defined for that purpose. For example, 363 it is suggested that a new "x5t#S256" (X.509 Certificate Thumbprint 364 using SHA-256) header parameter could be defined by registering it in 365 the IANA JSON Web Signature and Encryption Header Parameters registry 366 Section 7.1. 368 4.1.6. "x5c" (X.509 Certificate Chain) Header Parameter 370 The "x5c" (X.509 Certificate Chain) header parameter contains the 371 X.509 public key certificate or certificate chain [RFC5280] 372 corresponding to the key used to digitally sign the JWS. The 373 certificate or certificate chain is represented as an array of 374 certificate value strings. Each string is a base64 encoded 375 ([RFC4648] Section 4 -- not base64url encoded) DER [ITU.X690.1994] 376 PKIX certificate value. The certificate containing the public key of 377 the entity that digitally signed the JWS MUST be the first 378 certificate. This MAY be followed by additional certificates, with 379 each subsequent certificate being the one used to certify the 380 previous one. The recipient MUST verify the certificate chain 381 according to [RFC5280] and reject the JWS if any validation failure 382 occurs. This header parameter is OPTIONAL. 384 See Appendix B for an example "x5c" value. 386 4.1.7. "kid" (Key ID) Header Parameter 388 The "kid" (key ID) header parameter is a hint indicating which key 389 was used to secure the JWS. This parameter allows originators to 390 explicitly signal a change of key to recipients. Should the 391 recipient be unable to locate a key corresponding to the "kid" value, 392 they SHOULD treat that condition as an error. The interpretation of 393 the "kid" value is unspecified. Its value MUST be a string. This 394 header parameter is OPTIONAL. 396 When used with a JWK, the "kid" value MAY be used to match a JWK 397 "kid" parameter value. 399 4.1.8. "typ" (Type) Header Parameter 401 The "typ" (type) header parameter is used to declare the type of this 402 object. The type value "JWS" MAY be used to indicate that this 403 object is a JWS. The "typ" value is a case sensitive string. This 404 header parameter is OPTIONAL. 406 MIME Media Type [RFC2046] values MAY be used as "typ" values. 408 "typ" values SHOULD either be registered in the IANA JSON Web 409 Signature and Encryption Type Values registry Section 7.2 or be a URI 410 that contains a Collision Resistant Namespace. 412 4.1.9. "cty" (Content Type) Header Parameter 414 The "cty" (content type) header parameter is used to declare the type 415 of the secured content (the Payload). The "cty" value is a case 416 sensitive string. This header parameter is OPTIONAL. 418 The values used for the "cty" header parameter come from the same 419 value space as the "typ" header parameter, with the same rules 420 applying. 422 4.2. Public Header Parameter Names 424 Additional header parameter names can be defined by those using JWSs. 425 However, in order to prevent collisions, any new header parameter 426 name SHOULD either be registered in the IANA JSON Web Signature and 427 Encryption Header Parameters registry Section 7.1 or be a URI that 428 contains a Collision Resistant Namespace. In each case, the definer 429 of the name or value needs to take reasonable precautions to make 430 sure they are in control of the part of the namespace they use to 431 define the header parameter name. 433 New header parameters should be introduced sparingly, as they can 434 result in non-interoperable JWSs. 436 4.3. Private Header Parameter Names 438 A producer and consumer of a JWS may agree to any header parameter 439 name that is not a Reserved Name Section 4.1 or a Public Name 440 Section 4.2. Unlike Public Names, these private names are subject to 441 collision and should be used with caution. 443 5. Rules for Creating and Validating a JWS 445 To create a JWS, one MUST perform these steps. The order of the 446 steps is not significant in cases where there are no dependencies 447 between the inputs and outputs of the steps. 449 1. Create the content to be used as the JWS Payload. 451 2. Base64url encode the bytes of the JWS Payload. This encoding 452 becomes the Encoded JWS Payload. 454 3. Create a JWS Header containing the desired set of header 455 parameters. Note that white space is explicitly allowed in the 456 representation and no canonicalization need be performed before 457 encoding. 459 4. Base64url encode the bytes of the UTF-8 representation of the JWS 460 Header to create the Encoded JWS Header. 462 5. Compute the JWS Signature in the manner defined for the 463 particular algorithm being used. The JWS Secured Input is always 464 the concatenation of the Encoded JWS Header, a period ('.') 465 character, and the Encoded JWS Payload. The "alg" (algorithm) 466 header parameter MUST be present in the JSON Header, with the 467 algorithm value accurately representing the algorithm used to 468 construct the JWS Signature. 470 6. Base64url encode the representation of the JWS Signature to 471 create the Encoded JWS Signature. 473 7. The three encoded parts, taken together, are the result. The 474 Compact Serialization of this result is the concatenation of the 475 Encoded JWS Header, the Encoded JWS Payload, and the Encoded JWS 476 Signature in that order, with the three strings being separated 477 by two period ('.') characters. 479 When validating a JWS, the following steps MUST be taken. The order 480 of the steps is not significant in cases where there are no 481 dependencies between the inputs and outputs of the steps. If any of 482 the listed steps fails, then the JWS MUST be rejected. 484 1. Parse the three parts of the input (which are separated by period 485 ('.') characters when using the JWS Compact Serialization) into 486 the Encoded JWS Header, the Encoded JWS Payload, and the Encoded 487 JWS Signature. 489 2. The Encoded JWS Header MUST be successfully base64url decoded 490 following the restriction given in this specification that no 491 padding characters have been used. 493 3. The resulting JWS Header MUST be completely valid JSON syntax 494 conforming to RFC 4627 [RFC4627]. 496 4. The resulting JWS Header MUST be validated to only include 497 parameters and values whose syntax and semantics are both 498 understood and supported. 500 5. The Encoded JWS Payload MUST be successfully base64url decoded 501 following the restriction given in this specification that no 502 padding characters have been used. 504 6. The Encoded JWS Signature MUST be successfully base64url decoded 505 following the restriction given in this specification that no 506 padding characters have been used. 508 7. The JWS Signature MUST be successfully validated against the JWS 509 Secured Input (the concatenation of the Encoded JWS Header, a 510 period ('.') character, and the Encoded JWS Payload) in the 511 manner defined for the algorithm being used, which MUST be 512 accurately represented by the value of the "alg" (algorithm) 513 header parameter, which MUST be present. 515 Processing a JWS inevitably requires comparing known strings to 516 values in the header. For example, in checking what the algorithm 517 is, the Unicode string encoding "alg" will be checked against the 518 member names in the JWS Header to see if there is a matching header 519 parameter name. A similar process occurs when determining if the 520 value of the "alg" header parameter represents a supported algorithm. 522 Comparisons between JSON strings and other Unicode strings MUST be 523 performed as specified below: 525 1. Remove any JSON applied escaping to produce an array of Unicode 526 code points. 528 2. Unicode Normalization [USA15] MUST NOT be applied at any point to 529 either the JSON string or to the string it is to be compared 530 against. 532 3. Comparisons between the two strings MUST be performed as a 533 Unicode code point to code point equality comparison. 535 6. Securing JWSs with Cryptographic Algorithms 537 JWS uses cryptographic algorithms to digitally sign or MAC the JWS 538 Header and the JWS Payload. The JSON Web Algorithms (JWA) [JWA] 539 specification describes a set of cryptographic algorithms and 540 identifiers to be used with this specification. Specifically, 541 Section 3.1 specifies a set of "alg" (algorithm) header parameter 542 values intended for use this specification. It also describes the 543 semantics and operations that are specific to these algorithms and 544 algorithm families. 546 Public keys employed for digital signing can be identified using the 547 Header Parameter methods described in Section 4.1 or can be 548 distributed using methods that are outside the scope of this 549 specification. 551 7. IANA Considerations 553 The following registration procedure is used for all the registries 554 established by this specification. 556 Values are registered with a Specification Required [RFC5226] after a 557 two-week review period on the [TBD]@ietf.org mailing list, on the 558 advice of one or more Designated Experts. However, to allow for the 559 allocation of values prior to publication, the Designated Expert(s) 560 may approve registration once they are satisfied that such a 561 specification will be published. 563 Registration requests must be sent to the [TBD]@ietf.org mailing list 564 for review and comment, with an appropriate subject (e.g., "Request 565 for access token type: example"). [[ Note to RFC-EDITOR: The name of 566 the mailing list should be determined in consultation with the IESG 567 and IANA. Suggested name: jose-reg-review. ]] 569 Within the review period, the Designated Expert(s) will either 570 approve or deny the registration request, communicating this decision 571 to the review list and IANA. Denials should include an explanation 572 and, if applicable, suggestions as to how to make the request 573 successful. 575 IANA must only accept registry updates from the Designated Expert(s) 576 and should direct all requests for registration to the review mailing 577 list. 579 7.1. JSON Web Signature and Encryption Header Parameters Registry 581 This specification establishes the IANA JSON Web Signature and 582 Encryption Header Parameters registry for reserved JWS and JWE header 583 parameter names. The registry records the reserved header parameter 584 name and a reference to the specification that defines it. The same 585 Header Parameter Name may be registered multiple times, provided that 586 the parameter usage is compatible between the specifications. 588 7.1.1. Registration Template 590 Header Parameter Name: 591 The name requested (e.g., "example"). This name is case 592 sensitive. Names that match other registered names in a case 593 insensitive manner SHOULD NOT be accepted. 595 Change Controller: 596 For Standards Track RFCs, state "IETF". For others, give the name 597 of the responsible party. Other details (e.g., postal address, 598 email address, home page URI) may also be included. 600 Specification Document(s): 601 Reference to the document(s) that specify the parameter, 602 preferably including URI(s) that can be used to retrieve copies of 603 the document(s). An indication of the relevant sections may also 604 be included but is not required. 606 7.1.2. Initial Registry Contents 608 This specification registers the Header Parameter Names defined in 609 Section 4.1 in this registry. 611 o Header Parameter Name: "alg" 612 o Change Controller: IETF 613 o Specification Document(s): Section 4.1.1 of [[ this document ]] 615 o Header Parameter Name: "jku" 616 o Change Controller: IETF 617 o Specification Document(s): Section 4.1.2 of [[ this document ]] 619 o Header Parameter Name: "jwk" 620 o Change Controller: IETF 621 o Specification document(s): Section 4.1.3 of [[ this document ]] 623 o Header Parameter Name: "x5u" 624 o Change Controller: IETF 625 o Specification Document(s): Section 4.1.4 of [[ this document ]] 627 o Header Parameter Name: "x5t" 628 o Change Controller: IETF 629 o Specification Document(s): Section 4.1.5 of [[ this document ]] 631 o Header Parameter Name: "x5c" 632 o Change Controller: IETF 633 o Specification Document(s): Section 4.1.6 of [[ this document ]] 635 o Header Parameter Name: "kid" 636 o Change Controller: IETF 637 o Specification Document(s): Section 4.1.7 of [[ this document ]] 639 o Header Parameter Name: "typ" 640 o Change Controller: IETF 641 o Specification Document(s): Section 4.1.8 of [[ this document ]] 643 o Header Parameter Name: "cty" 644 o Change Controller: IETF 645 o Specification Document(s): Section 4.1.9 of [[ this document ]] 647 7.2. JSON Web Signature and Encryption Type Values Registry 649 This specification establishes the IANA JSON Web Signature and 650 Encryption Type Values registry for values of the JWS and JWE "typ" 651 (type) header parameter. It is RECOMMENDED that all registered "typ" 652 values also include a MIME Media Type [RFC2046] value that the 653 registered value is a short name for. The registry records the "typ" 654 value, the MIME type value that it is an abbreviation for (if any), 655 and a reference to the specification that defines it. 657 MIME Media Type [RFC2046] values MUST NOT be directly registered as 658 new "typ" values; rather, new "typ" values MAY be registered as short 659 names for MIME types. 661 7.2.1. Registration Template 663 "typ" Header Parameter Value: 664 The name requested (e.g., "example"). This name is case 665 sensitive. Names that match other registered names in a case 666 insensitive manner SHOULD NOT be accepted. 668 Abbreviation for MIME Type: 669 The MIME type that this name is an abbreviation for (e.g., 670 "application/example"). 672 Change Controller: 673 For Standards Track RFCs, state "IETF". For others, give the name 674 of the responsible party. Other details (e.g., postal address, 675 email address, home page URI) may also be included. 677 Specification Document(s): 678 Reference to the document(s) that specify the parameter, 679 preferably including URI(s) that can be used to retrieve copies of 680 the document(s). An indication of the relevant sections may also 681 be included but is not required. 683 7.2.2. Initial Registry Contents 685 This specification registers the "JWS" type value in this registry: 687 o "typ" Header Parameter Value: "JWS" 688 o Abbreviation for MIME type: application/jws 689 o Change Controller: IETF 690 o Specification Document(s): Section 4.1.8 of [[ this document ]] 692 7.3. Media Type Registration 694 7.3.1. Registry Contents 696 This specification registers the "application/jws" Media Type 697 [RFC2046] in the MIME Media Type registry [RFC4288] to indicate that 698 the content is a JWS using the Compact Serialization. 700 o Type name: application 701 o Subtype name: jws 702 o Required parameters: n/a 703 o Optional parameters: n/a 704 o Encoding considerations: JWS values are encoded as a series of 705 base64url encoded values (some of which may be the empty string) 706 separated by period ('.') characters 707 o Security considerations: See the Security Considerations section 708 of this document 709 o Interoperability considerations: n/a 710 o Published specification: [[ this document ]] 711 o Applications that use this media type: OpenID Connect, Mozilla 712 Browser ID, Salesforce, Google, numerous others that use signed 713 JWTs 714 o Additional information: Magic number(s): n/a, File extension(s): 715 n/a, Macintosh file type code(s): n/a 716 o Person & email address to contact for further information: Michael 717 B. Jones, mbj@microsoft.com 718 o Intended usage: COMMON 719 o Restrictions on usage: none 720 o Author: Michael B. Jones, mbj@microsoft.com 721 o Change Controller: IETF 723 8. Security Considerations 725 8.1. Cryptographic Security Considerations 727 All of the security issues faced by any cryptographic application 728 must be faced by a JWS/JWE/JWK agent. Among these issues are 729 protecting the user's private key, preventing various attacks, and 730 helping the user avoid mistakes such as inadvertently encrypting a 731 message for the wrong recipient. The entire list of security 732 considerations is beyond the scope of this document, but some 733 significant concerns are listed here. 735 All the security considerations in XML DSIG 2.0 736 [W3C.CR-xmldsig-core2-20120124], also apply to this specification, 737 other than those that are XML specific. Likewise, many of the best 738 practices documented in XML Signature Best Practices 739 [W3C.WD-xmldsig-bestpractices-20110809] also apply to this 740 specification, other than those that are XML specific. 742 Keys are only as strong as the amount of entropy used to generate 743 them. A minimum of 128 bits of entropy should be used for all keys, 744 and depending upon the application context, more may be required. In 745 particular, it may be difficult to generate sufficiently random 746 values in some browsers and application environments. 748 When utilizing TLS to retrieve information, the authority providing 749 the resource MUST be authenticated and the information retrieved MUST 750 be free from modification. 752 When cryptographic algorithms are implemented in such a way that 753 successful operations take a different amount of time than 754 unsuccessful operations, attackers may be able to use the time 755 difference to obtain information about the keys employed. Therefore, 756 such timing differences must be avoided. 758 A SHA-1 hash is used when computing "x5t" (x.509 certificate 759 thumbprint) values, for compatibility reasons. Should an effective 760 means of producing SHA-1 hash collisions be developed, and should an 761 attacker wish to interfere with the use of a known certificate on a 762 given system, this could be accomplished by creating another 763 certificate whose SHA-1 hash value is the same and adding it to the 764 certificate store used by the intended victim. A prerequisite to 765 this attack succeeding is the attacker having write access to the 766 intended victim's certificate store. 768 If, in the future, certificate thumbprints need to be computed using 769 hash functions other than SHA-1, it is suggested that additional 770 related header parameters be defined for that purpose. For example, 771 it is suggested that a new "x5t#S256" (X.509 Certificate Thumbprint 772 using SHA-256) header parameter could be defined and used. 774 8.2. JSON Security Considerations 776 Strict JSON validation is a security requirement. If malformed JSON 777 is received, then the intent of the sender is impossible to reliably 778 discern. Ambiguous and potentially exploitable situations could 779 arise if the JSON parser used does not reject malformed JSON syntax. 781 Section 2.2 of the JavaScript Object Notation (JSON) specification 782 [RFC4627] states "The names within an object SHOULD be unique", 783 whereas this specification states that "Header Parameter Names within 784 this object MUST be unique; JWSs with duplicate Header Parameter 785 Names MUST be rejected". Thus, this specification requires that the 786 Section 2.2 "SHOULD" be treated as a "MUST". Ambiguous and 787 potentially exploitable situations could arise if the JSON parser 788 used does not enforce the uniqueness of member names. 790 8.3. Unicode Comparison Security Considerations 792 Header parameter names and algorithm names are Unicode strings. For 793 security reasons, the representations of these names must be compared 794 verbatim after performing any escape processing (as per RFC 4627 795 [RFC4627], Section 2.5). This means, for instance, that these JSON 796 strings must compare as being equal ("sig", "\u0073ig"), whereas 797 these must all compare as being not equal to the first set or to each 798 other ("SIG", "Sig", "si\u0047"). 800 JSON strings MAY contain characters outside the Unicode Basic 801 Multilingual Plane. For instance, the G clef character (U+1D11E) may 802 be represented in a JSON string as "\uD834\uDD1E". Ideally, JWS 803 implementations SHOULD ensure that characters outside the Basic 804 Multilingual Plane are preserved and compared correctly; 805 alternatively, if this is not possible due to these characters 806 exercising limitations present in the underlying JSON implementation, 807 then input containing them MUST be rejected. 809 9. References 811 9.1. Normative References 813 [ITU.X690.1994] 814 International Telecommunications Union, "Information 815 Technology - ASN.1 encoding rules: Specification of Basic 816 Encoding Rules (BER), Canonical Encoding Rules (CER) and 817 Distinguished Encoding Rules (DER)", ITU-T Recommendation 818 X.690, 1994. 820 [JWA] Jones, M., "JSON Web Algorithms (JWA)", October 2012. 822 [JWK] Jones, M., "JSON Web Key (JWK)", October 2012. 824 [RFC1421] Linn, J., "Privacy Enhancement for Internet Electronic 825 Mail: Part I: Message Encryption and Authentication 826 Procedures", RFC 1421, February 1993. 828 [RFC2046] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 829 Extensions (MIME) Part Two: Media Types", RFC 2046, 830 November 1996. 832 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 833 Requirement Levels", BCP 14, RFC 2119, March 1997. 835 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 837 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 838 10646", STD 63, RFC 3629, November 2003. 840 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 841 Resource Identifier (URI): Generic Syntax", STD 66, 842 RFC 3986, January 2005. 844 [RFC4288] Freed, N. and J. Klensin, "Media Type Specifications and 845 Registration Procedures", BCP 13, RFC 4288, December 2005. 847 [RFC4627] Crockford, D., "The application/json Media Type for 848 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 850 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 851 Encodings", RFC 4648, October 2006. 853 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 854 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 855 May 2008. 857 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 858 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 860 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 861 Housley, R., and W. Polk, "Internet X.509 Public Key 862 Infrastructure Certificate and Certificate Revocation List 863 (CRL) Profile", RFC 5280, May 2008. 865 [USA15] Davis, M., Whistler, K., and M. Duerst, "Unicode 866 Normalization Forms", Unicode Standard Annex 15, 09 2009. 868 [USASCII] American National Standards Institute, "Coded Character 869 Set -- 7-bit American Standard Code for Information 870 Interchange", ANSI X3.4, 1986. 872 [W3C.WD-xmldsig-bestpractices-20110809] 873 Datta, P. and F. Hirsch, "XML Signature Best Practices", 874 World Wide Web Consortium WD WD-xmldsig-bestpractices- 875 20110809, August 2011, . 878 9.2. Informative References 880 [CanvasApp] 881 Facebook, "Canvas Applications", 2010. 883 [JSS] Bradley, J. and N. Sakimura (editor), "JSON Simple Sign", 884 September 2010. 886 [JWE] Jones, M., Rescorla, E., and J. Hildebrand, "JSON Web 887 Encryption (JWE)", October 2012. 889 [JWS-JS] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 890 Signature JSON Serialization (JWS-JS)", October 2012. 892 [JWT] Jones, M., Bradley, J., and N. Sakimura, "JSON Web Token 893 (JWT)", October 2012. 895 [MagicSignatures] 896 Panzer (editor), J., Laurie, B., and D. Balfanz, "Magic 897 Signatures", January 2011. 899 [RFC4122] Leach, P., Mealling, M., and R. Salz, "A Universally 900 Unique IDentifier (UUID) URN Namespace", RFC 4122, 901 July 2005. 903 [W3C.CR-xmldsig-core2-20120124] 904 Roessler, T., Yiu, K., Solo, D., Reagle, J., Datta, P., 905 Eastlake, D., Hirsch, F., and S. Cantor, "XML Signature 906 Syntax and Processing Version 2.0", World Wide Web 907 Consortium CR CR-xmldsig-core2-20120124, January 2012, 908 . 910 Appendix A. JWS Examples 912 This section provides several examples of JWSs. While these examples 913 all represent JSON Web Tokens (JWTs) [JWT], the payload can be any 914 base64url encoded content. 916 A.1. JWS using HMAC SHA-256 918 A.1.1. Encoding 920 The following example JWS Header declares that the data structure is 921 a JSON Web Token (JWT) [JWT] and the JWS Secured Input is secured 922 using the HMAC SHA-256 algorithm. 924 {"typ":"JWT", 925 "alg":"HS256"} 927 The following byte array contains the UTF-8 representation of the JWS 928 Header: 930 [123, 34, 116, 121, 112, 34, 58, 34, 74, 87, 84, 34, 44, 13, 10, 32, 931 34, 97, 108, 103, 34, 58, 34, 72, 83, 50, 53, 54, 34, 125] 933 Base64url encoding these bytes yields this Encoded JWS Header value: 935 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 937 The JWS Payload used in this example is the bytes of the UTF-8 938 representation of the JSON object below. (Note that the payload can 939 be any base64url encoded sequence of bytes, and need not be a 940 base64url encoded JSON object.) 942 {"iss":"joe", 943 "exp":1300819380, 944 "http://example.com/is_root":true} 946 The following byte array, which is the UTF-8 representation of the 947 JSON object above, is the JWS Payload: 949 [123, 34, 105, 115, 115, 34, 58, 34, 106, 111, 101, 34, 44, 13, 10, 950 32, 34, 101, 120, 112, 34, 58, 49, 51, 48, 48, 56, 49, 57, 51, 56, 951 48, 44, 13, 10, 32, 34, 104, 116, 116, 112, 58, 47, 47, 101, 120, 97, 952 109, 112, 108, 101, 46, 99, 111, 109, 47, 105, 115, 95, 114, 111, 953 111, 116, 34, 58, 116, 114, 117, 101, 125] 955 Base64url encoding the above yields the Encoded JWS Payload value 956 (with line breaks for display purposes only): 958 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 959 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 961 Concatenating the Encoded JWS Header, a period ('.') character, and 962 the Encoded JWS Payload yields this JWS Secured Input value (with 963 line breaks for display purposes only): 965 eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9 966 . 967 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 968 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 970 The ASCII representation of the JWS Secured Input is the following 971 byte array: 973 [101, 121, 74, 48, 101, 88, 65, 105, 79, 105, 74, 75, 86, 49, 81, 974 105, 76, 65, 48, 75, 73, 67, 74, 104, 98, 71, 99, 105, 79, 105, 74, 975 73, 85, 122, 73, 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 976 77, 105, 79, 105, 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 977 74, 108, 101, 72, 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 978 107, 122, 79, 68, 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 979 72, 65, 54, 76, 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 980 109, 78, 118, 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 981 106, 112, 48, 99, 110, 86, 108, 102, 81] 983 HMACs are generated using keys. This example uses the key 984 represented by the following byte array: 986 [3, 35, 53, 75, 43, 15, 165, 188, 131, 126, 6, 101, 119, 123, 166, 987 143, 90, 179, 40, 230, 240, 84, 201, 40, 169, 15, 132, 178, 210, 80, 988 46, 191, 211, 251, 90, 146, 210, 6, 71, 239, 150, 138, 180, 195, 119, 989 98, 61, 34, 61, 46, 33, 114, 5, 46, 79, 8, 192, 205, 154, 245, 103, 990 208, 128, 163] 992 Running the HMAC SHA-256 algorithm on the bytes of the ASCII 993 representation of the JWS Secured Input with this key yields the 994 following byte array: 996 [116, 24, 223, 180, 151, 153, 224, 37, 79, 250, 96, 125, 216, 173, 997 187, 186, 22, 212, 37, 77, 105, 214, 191, 240, 91, 88, 5, 88, 83, 998 132, 141, 121] 1000 Base64url encoding the above HMAC output yields the Encoded JWS 1001 Signature value: 1003 dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk 1005 A.1.2. Decoding 1007 Decoding the JWS requires base64url decoding the Encoded JWS Header, 1008 Encoded JWS Payload, and Encoded JWS Signature to produce the JWS 1009 Header, JWS Payload, and JWS Signature byte arrays. The byte array 1010 containing the UTF-8 representation of the JWS Header is decoded into 1011 the JWS Header string. 1013 A.1.3. Validating 1015 Next we validate the decoded results. Since the "alg" parameter in 1016 the header is "HS256", we validate the HMAC SHA-256 value contained 1017 in the JWS Signature. If any of the validation steps fail, the JWS 1018 MUST be rejected. 1020 First, we validate that the JWS Header string is legal JSON. 1022 To validate the HMAC value, we repeat the previous process of using 1023 the correct key and the ASCII representation of the JWS Secured Input 1024 as input to the HMAC SHA-256 function and then taking the output and 1025 determining if it matches the JWS Signature. If it matches exactly, 1026 the HMAC has been validated. 1028 A.2. JWS using RSA SHA-256 1030 A.2.1. Encoding 1032 The JWS Header in this example is different from the previous example 1033 in two ways: First, because a different algorithm is being used, the 1034 "alg" value is different. Second, for illustration purposes only, 1035 the optional "typ" parameter is not used. (This difference is not 1036 related to the algorithm employed.) The JWS Header used is: 1038 {"alg":"RS256"} 1040 The following byte array contains the UTF-8 representation of the JWS 1041 Header: 1043 [123, 34, 97, 108, 103, 34, 58, 34, 82, 83, 50, 53, 54, 34, 125] 1045 Base64url encoding these bytes yields this Encoded JWS Header value: 1047 eyJhbGciOiJSUzI1NiJ9 1049 The JWS Payload used in this example, which follows, is the same as 1050 in the previous example. Since the Encoded JWS Payload will 1051 therefore be the same, its computation is not repeated here. 1053 {"iss":"joe", 1054 "exp":1300819380, 1055 "http://example.com/is_root":true} 1057 Concatenating the Encoded JWS Header, a period ('.') character, and 1058 the Encoded JWS Payload yields this JWS Secured Input value (with 1059 line breaks for display purposes only): 1061 eyJhbGciOiJSUzI1NiJ9 1062 . 1063 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1064 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1066 The ASCII representation of the JWS Secured Input is the following 1067 byte array: 1069 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 1070 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1071 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1072 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1073 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1074 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1075 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1076 99, 110, 86, 108, 102, 81] 1078 The RSA key consists of a public part (Modulus, Exponent), and a 1079 Private Exponent. The values of the RSA key used in this example, 1080 presented as the byte arrays representing big endian integers are: 1082 +-----------+-------------------------------------------------------+ 1083 | Parameter | Value | 1084 | Name | | 1085 +-----------+-------------------------------------------------------+ 1086 | Modulus | [161, 248, 22, 10, 226, 227, 201, 180, 101, 206, 141, | 1087 | | 45, 101, 98, 99, 54, 43, 146, 125, 190, 41, 225, 240, | 1088 | | 36, 119, 252, 22, 37, 204, 144, 161, 54, 227, 139, | 1089 | | 217, 52, 151, 197, 182, 234, 99, 221, 119, 17, 230, | 1090 | | 124, 116, 41, 249, 86, 176, 251, 138, 143, 8, 154, | 1091 | | 220, 75, 105, 137, 60, 193, 51, 63, 83, 237, 208, 25, | 1092 | | 184, 119, 132, 37, 47, 236, 145, 79, 228, 133, 119, | 1093 | | 105, 89, 75, 234, 66, 128, 211, 44, 15, 85, 191, 98, | 1094 | | 148, 79, 19, 3, 150, 188, 110, 155, 223, 110, 189, | 1095 | | 210, 189, 163, 103, 142, 236, 160, 198, 104, 247, 1, | 1096 | | 179, 141, 191, 251, 56, 200, 52, 44, 226, 254, 109, | 1097 | | 39, 250, 222, 74, 90, 72, 116, 151, 157, 212, 185, | 1098 | | 207, 154, 222, 196, 199, 91, 5, 133, 44, 44, 15, 94, | 1099 | | 248, 165, 193, 117, 3, 146, 249, 68, 232, 237, 100, | 1100 | | 193, 16, 198, 182, 71, 96, 154, 164, 120, 58, 235, | 1101 | | 156, 108, 154, 215, 85, 49, 48, 80, 99, 139, 131, | 1102 | | 102, 92, 111, 111, 122, 130, 163, 150, 112, 42, 31, | 1103 | | 100, 27, 130, 211, 235, 242, 57, 34, 25, 73, 31, 182, | 1104 | | 134, 135, 44, 87, 22, 245, 10, 248, 53, 141, 154, | 1105 | | 139, 157, 23, 195, 64, 114, 143, 127, 135, 216, 154, | 1106 | | 24, 216, 252, 171, 103, 173, 132, 89, 12, 46, 207, | 1107 | | 117, 147, 57, 54, 60, 7, 3, 77, 111, 96, 111, 158, | 1108 | | 33, 224, 84, 86, 202, 229, 233, 161] | 1109 | Exponent | [1, 0, 1] | 1110 | Private | [18, 174, 113, 164, 105, 205, 10, 43, 195, 126, 82, | 1111 | Exponent | 108, 69, 0, 87, 31, 29, 97, 117, 29, 100, 233, 73, | 1112 | | 112, 123, 98, 89, 15, 157, 11, 165, 124, 150, 60, 64, | 1113 | | 30, 63, 207, 47, 44, 211, 189, 236, 136, 229, 3, 191, | 1114 | | 198, 67, 155, 11, 40, 200, 47, 125, 55, 151, 103, 31, | 1115 | | 82, 19, 238, 216, 193, 90, 37, 216, 213, 206, 160, 2, | 1116 | | 94, 227, 171, 46, 139, 127, 121, 33, 111, 198, 59, | 1117 | | 234, 86, 39, 83, 180, 6, 68, 198, 161, 81, 39, 217, | 1118 | | 178, 149, 69, 64, 160, 187, 225, 163, 5, 86, 152, 45, | 1119 | | 78, 159, 222, 95, 100, 37, 241, 77, 75, 113, 52, 65, | 1120 | | 181, 93, 199, 59, 155, 74, 237, 204, 146, 172, 227, | 1121 | | 146, 126, 55, 245, 125, 12, 253, 94, 117, 129, 250, | 1122 | | 81, 44, 143, 73, 97, 169, 235, 11, 128, 248, 168, 7, | 1123 | | 70, 114, 138, 85, 255, 70, 71, 31, 52, 37, 6, 59, | 1124 | | 157, 83, 100, 47, 94, 222, 30, 132, 214, 19, 8, 26, | 1125 | | 250, 92, 34, 208, 81, 40, 91, 214, 59, 148, 59, 86, | 1126 | | 93, 137, 138, 5, 104, 84, 19, 229, 60, 60, 108, 101, | 1127 | | 37, 255, 31, 227, 78, 61, 220, 112, 240, 213, 100, | 1128 | | 80, 253, 164, 139, 161, 46, 16, 78, 157, 235, 159, | 1129 | | 184, 24, 129, 225, 196, 189, 242, 93, 146, 71, 244, | 1130 | | 80, 200, 101, 146, 121, 104, 231, 115, 52, 244, 65, | 1131 | | 79, 117, 167, 80, 225, 57, 84, 110, 58, 138, 115, | 1132 | | 157] | 1133 +-----------+-------------------------------------------------------+ 1135 The RSA private key (Modulus, Private Exponent) is then passed to the 1136 RSA signing function, which also takes the hash type, SHA-256, and 1137 the bytes of the ASCII representation of the JWS Secured Input as 1138 inputs. The result of the digital signature is a byte array, which 1139 represents a big endian integer. In this example, it is: 1141 [112, 46, 33, 137, 67, 232, 143, 209, 30, 181, 216, 45, 191, 120, 69, 1142 243, 65, 6, 174, 27, 129, 255, 247, 115, 17, 22, 173, 209, 113, 125, 1143 131, 101, 109, 66, 10, 253, 60, 150, 238, 221, 115, 162, 102, 62, 81, 1144 102, 104, 123, 0, 11, 135, 34, 110, 1, 135, 237, 16, 115, 249, 69, 1145 229, 130, 173, 252, 239, 22, 216, 90, 121, 142, 232, 198, 109, 219, 1146 61, 184, 151, 91, 23, 208, 148, 2, 190, 237, 213, 217, 217, 112, 7, 1147 16, 141, 178, 129, 96, 213, 248, 4, 12, 167, 68, 87, 98, 184, 31, 1148 190, 127, 249, 217, 46, 10, 231, 111, 36, 242, 91, 51, 187, 230, 244, 1149 74, 230, 30, 177, 4, 10, 203, 32, 4, 77, 62, 249, 18, 142, 212, 1, 1150 48, 121, 91, 212, 189, 59, 65, 238, 202, 208, 102, 171, 101, 25, 129, 1151 253, 228, 141, 247, 127, 55, 45, 195, 139, 159, 175, 221, 59, 239, 1152 177, 139, 93, 163, 204, 60, 46, 176, 47, 158, 58, 65, 214, 18, 202, 1153 173, 21, 145, 18, 115, 160, 95, 35, 185, 232, 56, 250, 175, 132, 157, 1154 105, 132, 41, 239, 90, 30, 136, 121, 130, 54, 195, 212, 14, 96, 69, 1155 34, 165, 68, 200, 242, 122, 122, 45, 184, 6, 99, 209, 108, 247, 202, 1156 234, 86, 222, 64, 92, 178, 33, 90, 69, 178, 194, 85, 102, 181, 90, 1157 193, 167, 72, 160, 112, 223, 200, 163, 42, 70, 149, 67, 208, 25, 238, 1158 251, 71] 1160 Base64url encoding the digital signature produces this value for the 1161 Encoded JWS Signature (with line breaks for display purposes only): 1163 cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7 1164 AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4 1165 BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K 1166 0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqv 1167 hJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrB 1168 p0igcN_IoypGlUPQGe77Rw 1170 A.2.2. Decoding 1172 Decoding the JWS requires base64url decoding the Encoded JWS Header, 1173 Encoded JWS Payload, and Encoded JWS Signature to produce the JWS 1174 Header, JWS Payload, and JWS Signature byte arrays. The byte array 1175 containing the UTF-8 representation of the JWS Header is decoded into 1176 the JWS Header string. 1178 A.2.3. Validating 1180 Since the "alg" parameter in the header is "RS256", we validate the 1181 RSA SHA-256 digital signature contained in the JWS Signature. If any 1182 of the validation steps fail, the JWS MUST be rejected. 1184 First, we validate that the JWS Header string is legal JSON. 1186 Validating the JWS Signature is a little different from the previous 1187 example. First, we base64url decode the Encoded JWS Signature to 1188 produce a digital signature S to check. We then pass (n, e), S and 1189 the bytes of the ASCII representation of the JWS Secured Input to an 1190 RSA signature verifier that has been configured to use the SHA-256 1191 hash function. 1193 A.3. JWS using ECDSA P-256 SHA-256 1195 A.3.1. Encoding 1197 The JWS Header for this example differs from the previous example 1198 because a different algorithm is being used. The JWS Header used is: 1200 {"alg":"ES256"} 1202 The following byte array contains the UTF-8 representation of the JWS 1203 Header: 1205 [123, 34, 97, 108, 103, 34, 58, 34, 69, 83, 50, 53, 54, 34, 125] 1206 Base64url encoding these bytes yields this Encoded JWS Header value: 1208 eyJhbGciOiJFUzI1NiJ9 1210 The JWS Payload used in this example, which follows, is the same as 1211 in the previous examples. Since the Encoded JWS Payload will 1212 therefore be the same, its computation is not repeated here. 1214 {"iss":"joe", 1215 "exp":1300819380, 1216 "http://example.com/is_root":true} 1218 Concatenating the Encoded JWS Header, a period ('.') character, and 1219 the Encoded JWS Payload yields this JWS Secured Input value (with 1220 line breaks for display purposes only): 1222 eyJhbGciOiJFUzI1NiJ9 1223 . 1224 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1225 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1227 The ASCII representation of the JWS Secured Input is the following 1228 byte array: 1230 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 70, 85, 122, 73, 1231 49, 78, 105, 74, 57, 46, 101, 121, 74, 112, 99, 51, 77, 105, 79, 105, 1232 74, 113, 98, 50, 85, 105, 76, 65, 48, 75, 73, 67, 74, 108, 101, 72, 1233 65, 105, 79, 106, 69, 122, 77, 68, 65, 52, 77, 84, 107, 122, 79, 68, 1234 65, 115, 68, 81, 111, 103, 73, 109, 104, 48, 100, 72, 65, 54, 76, 1235 121, 57, 108, 101, 71, 70, 116, 99, 71, 120, 108, 76, 109, 78, 118, 1236 98, 83, 57, 112, 99, 49, 57, 121, 98, 50, 57, 48, 73, 106, 112, 48, 1237 99, 110, 86, 108, 102, 81] 1239 The ECDSA key consists of a public part, the EC point (x, y), and a 1240 private part d. The values of the ECDSA key used in this example, 1241 presented as the byte arrays representing three 256 bit big endian 1242 integers are: 1244 +-----------+-------------------------------------------------------+ 1245 | Parameter | Value | 1246 | Name | | 1247 +-----------+-------------------------------------------------------+ 1248 | x | [127, 205, 206, 39, 112, 246, 196, 93, 65, 131, 203, | 1249 | | 238, 111, 219, 75, 123, 88, 7, 51, 53, 123, 233, 239, | 1250 | | 19, 186, 207, 110, 60, 123, 209, 84, 69] | 1251 | y | [199, 241, 68, 205, 27, 189, 155, 126, 135, 44, 223, | 1252 | | 237, 185, 238, 185, 244, 179, 105, 93, 110, 169, 11, | 1253 | | 36, 173, 138, 70, 35, 40, 133, 136, 229, 173] | 1254 | d | [142, 155, 16, 158, 113, 144, 152, 191, 152, 4, 135, | 1255 | | 223, 31, 93, 119, 233, 203, 41, 96, 110, 190, 210, | 1256 | | 38, 59, 95, 87, 194, 19, 223, 132, 244, 178] | 1257 +-----------+-------------------------------------------------------+ 1259 The ECDSA private part d is then passed to an ECDSA signing function, 1260 which also takes the curve type, P-256, the hash type, SHA-256, and 1261 the bytes of the ASCII representation of the JWS Secured Input as 1262 inputs. The result of the digital signature is the EC point (R, S), 1263 where R and S are unsigned integers. In this example, the R and S 1264 values, given as byte arrays representing big endian integers are: 1266 +--------+----------------------------------------------------------+ 1267 | Result | Value | 1268 | Name | | 1269 +--------+----------------------------------------------------------+ 1270 | R | [14, 209, 33, 83, 121, 99, 108, 72, 60, 47, 127, 21, 88, | 1271 | | 7, 212, 2, 163, 178, 40, 3, 58, 249, 124, 126, 23, 129, | 1272 | | 154, 195, 22, 158, 166, 101] | 1273 | S | [197, 10, 7, 211, 140, 60, 112, 229, 216, 241, 45, 175, | 1274 | | 8, 74, 84, 128, 166, 101, 144, 197, 242, 147, 80, 154, | 1275 | | 143, 63, 127, 138, 131, 163, 84, 213] | 1276 +--------+----------------------------------------------------------+ 1278 Concatenating the S array to the end of the R array and base64url 1279 encoding the result produces this value for the Encoded JWS Signature 1280 (with line breaks for display purposes only): 1282 DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8ISlSA 1283 pmWQxfKTUJqPP3-Kg6NU1Q 1285 A.3.2. Decoding 1287 Decoding the JWS requires base64url decoding the Encoded JWS Header, 1288 Encoded JWS Payload, and Encoded JWS Signature to produce the JWS 1289 Header, JWS Payload, and JWS Signature byte arrays. The byte array 1290 containing the UTF-8 representation of the JWS Header is decoded into 1291 the JWS Header string. 1293 A.3.3. Validating 1295 Since the "alg" parameter in the header is "ES256", we validate the 1296 ECDSA P-256 SHA-256 digital signature contained in the JWS Signature. 1297 If any of the validation steps fail, the JWS MUST be rejected. 1299 First, we validate that the JWS Header string is legal JSON. 1301 Validating the JWS Signature is a little different from the first 1302 example. First, we base64url decode the Encoded JWS Signature as in 1303 the previous examples but we then need to split the 64 member byte 1304 array that must result into two 32 byte arrays, the first R and the 1305 second S. We then pass (x, y), (R, S) and the bytes of the ASCII 1306 representation of the JWS Secured Input to an ECDSA signature 1307 verifier that has been configured to use the P-256 curve with the 1308 SHA-256 hash function. 1310 As explained in Section 3.4 of the JSON Web Algorithms (JWA) [JWA] 1311 specification, the use of the K value in ECDSA means that we cannot 1312 validate the correctness of the digital signature in the same way we 1313 validated the correctness of the HMAC. Instead, implementations MUST 1314 use an ECDSA validator to validate the digital signature. 1316 A.4. JWS using ECDSA P-521 SHA-512 1318 A.4.1. Encoding 1320 The JWS Header for this example differs from the previous example 1321 because a different ECDSA curve and hash function are used. The JWS 1322 Header used is: 1324 {"alg":"ES512"} 1326 The following byte array contains the UTF-8 representation of the JWS 1327 Header: 1329 [123, 34, 97, 108, 103, 34, 58, 34, 69, 83, 53, 49, 50, 34, 125] 1331 Base64url encoding these bytes yields this Encoded JWS Header value: 1333 eyJhbGciOiJFUzUxMiJ9 1335 The JWS Payload used in this example, is the ASCII string "Payload". 1336 The representation of this string is the byte array: 1338 [80, 97, 121, 108, 111, 97, 100] 1340 Base64url encoding these bytes yields the Encoded JWS Payload value: 1342 UGF5bG9hZA 1344 Concatenating the Encoded JWS Header, a period ('.') character, and 1345 the Encoded JWS Payload yields this JWS Secured Input value: 1347 eyJhbGciOiJFUzUxMiJ9.UGF5bG9hZA 1349 The ASCII representation of the JWS Secured Input is the following 1350 byte array: 1352 [101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 70, 85, 122, 85, 1353 120, 77, 105, 74, 57, 46, 85, 71, 70, 53, 98, 71, 57, 104, 90, 65] 1355 The ECDSA key consists of a public part, the EC point (x, y), and a 1356 private part d. The values of the ECDSA key used in this example, 1357 presented as the byte arrays representing three 521 bit big endian 1358 integers are: 1360 +-----------+-------------------------------------------------------+ 1361 | Parameter | Value | 1362 | Name | | 1363 +-----------+-------------------------------------------------------+ 1364 | x | [1, 233, 41, 5, 15, 18, 79, 198, 188, 85, 199, 213, | 1365 | | 57, 51, 101, 223, 157, 239, 74, 176, 194, 44, 178, | 1366 | | 87, 152, 249, 52, 235, 4, 227, 198, 186, 227, 112, | 1367 | | 26, 87, 167, 145, 14, 157, 129, 191, 54, 49, 89, 232, | 1368 | | 235, 203, 21, 93, 99, 73, 244, 189, 182, 204, 248, | 1369 | | 169, 76, 92, 89, 199, 170, 193, 1, 164] | 1370 | y | [0, 52, 166, 68, 14, 55, 103, 80, 210, 55, 31, 209, | 1371 | | 189, 194, 200, 243, 183, 29, 47, 78, 229, 234, 52, | 1372 | | 50, 200, 21, 204, 163, 21, 96, 254, 93, 147, 135, | 1373 | | 236, 119, 75, 85, 131, 134, 48, 229, 203, 191, 90, | 1374 | | 140, 190, 10, 145, 221, 0, 100, 198, 153, 154, 31, | 1375 | | 110, 110, 103, 250, 221, 237, 228, 200, 200, 246] | 1376 | d | [1, 142, 105, 111, 176, 52, 80, 88, 129, 221, 17, 11, | 1377 | | 72, 62, 184, 125, 50, 206, 73, 95, 227, 107, 55, 69, | 1378 | | 237, 242, 216, 202, 228, 240, 242, 83, 159, 70, 21, | 1379 | | 160, 233, 142, 171, 82, 179, 192, 197, 234, 196, 206, | 1380 | | 7, 81, 133, 168, 231, 187, 71, 222, 172, 29, 29, 231, | 1381 | | 123, 204, 246, 97, 53, 230, 61, 130] | 1382 +-----------+-------------------------------------------------------+ 1384 The ECDSA private part d is then passed to an ECDSA signing function, 1385 which also takes the curve type, P-521, the hash type, SHA-512, and 1386 the bytes of the ASCII representation of the JWS Secured Input as 1387 inputs. The result of the digital signature is the EC point (R, S), 1388 where R and S are unsigned integers. In this example, the R and S 1389 values, given as byte arrays representing big endian integers are: 1391 +--------+----------------------------------------------------------+ 1392 | Result | Value | 1393 | Name | | 1394 +--------+----------------------------------------------------------+ 1395 | R | [1, 220, 12, 129, 231, 171, 194, 209, 232, 135, 233, | 1396 | | 117, 247, 105, 122, 210, 26, 125, 192, 1, 217, 21, 82, | 1397 | | 91, 45, 240, 255, 83, 19, 34, 239, 71, 48, 157, 147, | 1398 | | 152, 105, 18, 53, 108, 163, 214, 68, 231, 62, 153, 150, | 1399 | | 106, 194, 164, 246, 72, 143, 138, 24, 50, 129, 223, 133, | 1400 | | 206, 209, 172, 63, 237, 119, 109] | 1401 | S | [0, 111, 6, 105, 44, 5, 41, 208, 128, 61, 152, 40, 92, | 1402 | | 61, 152, 4, 150, 66, 60, 69, 247, 196, 170, 81, 193, | 1403 | | 199, 78, 59, 194, 169, 16, 124, 9, 143, 42, 142, 131, | 1404 | | 48, 206, 238, 34, 175, 83, 203, 220, 159, 3, 107, 155, | 1405 | | 22, 27, 73, 111, 68, 68, 21, 238, 144, 229, 232, 148, | 1406 | | 188, 222, 59, 242, 103] | 1407 +--------+----------------------------------------------------------+ 1409 Concatenating the S array to the end of the R array and base64url 1410 encoding the result produces this value for the Encoded JWS Signature 1411 (with line breaks for display purposes only): 1413 AdwMgeerwtHoh-l192l60hp9wAHZFVJbLfD_UxMi70cwnZOYaRI1bKPWROc-mZZq 1414 wqT2SI-KGDKB34XO0aw_7XdtAG8GaSwFKdCAPZgoXD2YBJZCPEX3xKpRwcdOO8Kp 1415 EHwJjyqOgzDO7iKvU8vcnwNrmxYbSW9ERBXukOXolLzeO_Jn 1417 A.4.2. Decoding 1419 Decoding the JWS requires base64url decoding the Encoded JWS Header, 1420 Encoded JWS Payload, and Encoded JWS Signature to produce the JWS 1421 Header, JWS Payload, and JWS Signature byte arrays. The byte array 1422 containing the UTF-8 representation of the JWS Header is decoded into 1423 the JWS Header string. 1425 A.4.3. Validating 1427 Since the "alg" parameter in the header is "ES512", we validate the 1428 ECDSA P-521 SHA-512 digital signature contained in the JWS Signature. 1429 If any of the validation steps fail, the JWS MUST be rejected. 1431 First, we validate that the JWS Header string is legal JSON. 1433 Validating the JWS Signature is similar to the previous example. 1434 First, we base64url decode the Encoded JWS Signature as in the 1435 previous examples but we then need to split the 132 member byte array 1436 that must result into two 66 byte arrays, the first R and the second 1437 S. We then pass (x, y), (R, S) and the bytes of the ASCII 1438 representation of the JWS Secured Input to an ECDSA signature 1439 verifier that has been configured to use the P-521 curve with the 1440 SHA-512 hash function. 1442 As explained in Section 3.4 of the JSON Web Algorithms (JWA) [JWA] 1443 specification, the use of the K value in ECDSA means that we cannot 1444 validate the correctness of the digital signature in the same way we 1445 validated the correctness of the HMAC. Instead, implementations MUST 1446 use an ECDSA validator to validate the digital signature. 1448 A.5. Example Plaintext JWS 1450 The following example JWS Header declares that the encoded object is 1451 a Plaintext JWS: 1453 {"alg":"none"} 1455 Base64url encoding the bytes of the UTF-8 representation of the JWS 1456 Header yields this Encoded JWS Header: 1458 eyJhbGciOiJub25lIn0 1460 The JWS Payload used in this example, which follows, is the same as 1461 in the previous examples. Since the Encoded JWS Payload will 1462 therefore be the same, its computation is not repeated here. 1464 {"iss":"joe", 1465 "exp":1300819380, 1466 "http://example.com/is_root":true} 1468 The Encoded JWS Signature is the empty string. 1470 Concatenating these parts in the order Header.Payload.Signature with 1471 period ('.') characters between the parts yields this complete JWS 1472 (with line breaks for display purposes only): 1474 eyJhbGciOiJub25lIn0 1475 . 1476 eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt 1477 cGxlLmNvbS9pc19yb290Ijp0cnVlfQ 1478 . 1480 Appendix B. "x5c" (X.509 Certificate Chain) Example 1482 The JSON array below is an example of a certificate chain that could 1483 be used as the value of an "x5c" (X.509 Certificate Chain) header 1484 parameter, per Section 4.1.6. Note that since these strings contain 1485 base64 encoded (not base64url encoded) values, they are allowed to 1486 contain white space and line breaks. 1488 ["MIIE3jCCA8agAwIBAgICAwEwDQYJKoZIhvcNAQEFBQAwYzELMAkGA1UEBhMCVVM 1489 xITAfBgNVBAoTGFRoZSBHbyBEYWRkeSBHcm91cCwgSW5jLjExMC8GA1UECxMoR2 1490 8gRGFkZHkgQ2xhc3MgMiBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wN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oS/zcnwbNDu+97bi5p9wIDAQABMA0GCSqGSIb3DQEBBQU 1556 AA4GBADt/UG9vUJSZSWI4OB9L+KXIPqeCgfYrx+jFzug6EILLGACOTb2oWH+heQ 1557 C1u+mNr0HZDzTuIYEZoDJJKPTEjlbVUjP9UNV+mWwD5MlM/Mtsq2azSiGM5bUMM 1558 j4QssxsodyamEwCW/POuZ6lcg5Ktz885hZo+L7tdEy8W9ViH0Pd"] 1560 Appendix C. Notes on implementing base64url encoding without padding 1562 This appendix describes how to implement base64url encoding and 1563 decoding functions without padding based upon standard base64 1564 encoding and decoding functions that do use padding. 1566 To be concrete, example C# code implementing these functions is shown 1567 below. Similar code could be used in other languages. 1569 static string base64urlencode(byte [] arg) 1570 { 1571 string s = Convert.ToBase64String(arg); // Standard base64 encoder 1572 s = s.Split('=')[0]; // Remove any trailing '='s 1573 s = s.Replace('+', '-'); // 62nd char of encoding 1574 s = s.Replace('/', '_'); // 63rd char of encoding 1575 return s; 1576 } 1578 static byte [] base64urldecode(string arg) 1579 { 1580 string s = arg; 1581 s = s.Replace('-', '+'); // 62nd char of encoding 1582 s = s.Replace('_', '/'); // 63rd char of encoding 1583 switch (s.Length % 4) // Pad with trailing '='s 1584 { 1585 case 0: break; // No pad chars in this case 1586 case 2: s += "=="; break; // Two pad chars 1587 case 3: s += "="; break; // One pad char 1588 default: throw new System.Exception( 1589 "Illegal base64url string!"); 1590 } 1591 return Convert.FromBase64String(s); // Standard base64 decoder 1592 } 1594 As per the example code above, the number of '=' padding characters 1595 that needs to be added to the end of a base64url encoded string 1596 without padding to turn it into one with padding is a deterministic 1597 function of the length of the encoded string. Specifically, if the 1598 length mod 4 is 0, no padding is added; if the length mod 4 is 2, two 1599 '=' padding characters are added; if the length mod 4 is 3, one '=' 1600 padding character is added; if the length mod 4 is 1, the input is 1601 malformed. 1603 An example correspondence between unencoded and encoded values 1604 follows. The byte sequence below encodes into the string below, 1605 which when decoded, reproduces the byte sequence. 1606 3 236 255 224 193 1607 A-z_4ME 1609 Appendix D. Acknowledgements 1611 Solutions for signing JSON content were previously explored by Magic 1612 Signatures [MagicSignatures], JSON Simple Sign [JSS], and Canvas 1613 Applications [CanvasApp], all of which influenced this draft. Dirk 1614 Balfanz, Yaron Y. Goland, John Panzer, and Paul Tarjan all made 1615 significant contributions to the design of this specification. 1617 Thanks to Axel Nennker for his early implementation and feedback on 1618 the JWS and JWE specifications. 1620 Jim Schaad and Karen O'Donoghue chaired the JOSE working group and 1621 Sean Turner and Stephen Farrell served as Security area directors 1622 during the creation of this specification. 1624 Appendix E. Open Issues 1626 [[ to be removed by the RFC editor before publication as an RFC ]] 1628 The following items remain to be considered or done in this draft: 1630 o Should we define optional nonce, timestamp, and/or uninterpreted 1631 string header parameter(s)? 1633 Appendix F. Document History 1635 [[ to be removed by the RFC editor before publication as an RFC ]] 1637 -06 1639 o Changed "x5c" (X.509 Certificate Chain) representation from being 1640 a single string to being an array of strings, each containing a 1641 single base64 encoded DER certificate value, representing elements 1642 of the certificate chain. 1644 o Applied changes made by the RFC Editor to RFC 6749's registry 1645 language to this specification. 1647 -05 1649 o Added statement that "StringOrURI values are compared as case- 1650 sensitive strings with no transformations or canonicalizations 1651 applied". 1653 o Indented artwork elements to better distinguish them from the body 1654 text. 1656 -04 1658 o Completed JSON Security Considerations section, including 1659 considerations about rejecting input with duplicate member names. 1661 o Completed security considerations on the use of a SHA-1 hash when 1662 computing "x5t" (x.509 certificate thumbprint) values. 1664 o Refer to the registries as the primary sources of defined values 1665 and then secondarily reference the sections defining the initial 1666 contents of the registries. 1668 o Normatively reference XML DSIG 2.0 [W3C.CR-xmldsig-core2-20120124] 1669 for its security considerations. 1671 o Added this language to Registration Templates: "This name is case 1672 sensitive. Names that match other registered names in a case 1673 insensitive manner SHOULD NOT be accepted." 1675 o Reference draft-jones-jose-jws-json-serialization instead of 1676 draft-jones-json-web-signature-json-serialization. 1678 o Described additional open issues. 1680 o Applied editorial suggestions. 1682 -03 1684 o Added the "cty" (content type) header parameter for declaring type 1685 information about the secured content, as opposed to the "typ" 1686 (type) header parameter, which declares type information about 1687 this object. 1689 o Added "Collision Resistant Namespace" to the terminology section. 1691 o Reference ITU.X690.1994 for DER encoding. 1693 o Added an example JWS using ECDSA P-521 SHA-512. This has 1694 particular illustrative value because of the use of the 521 bit 1695 integers in the key and signature values. This is also an example 1696 in which the payload is not a base64url encoded JSON object. 1698 o Added an example "x5c" value. 1700 o No longer say "the UTF-8 representation of the JWS Secured Input 1701 (which is the same as the ASCII representation)". Just call it 1702 "the ASCII representation of the JWS Secured Input". 1704 o Added Registration Template sections for defined registries. 1706 o Added Registry Contents sections to populate registry values. 1708 o Changed name of the JSON Web Signature and Encryption "typ" Values 1709 registry to be the JSON Web Signature and Encryption Type Values 1710 registry, since it is used for more than just values of the "typ" 1711 parameter. 1713 o Moved registries JSON Web Signature and Encryption Header 1714 Parameters and JSON Web Signature and Encryption Type Values to 1715 the JWS specification. 1717 o Numerous editorial improvements. 1719 -02 1721 o Clarified that it is an error when a "kid" value is included and 1722 no matching key is found. 1724 o Removed assumption that "kid" (key ID) can only refer to an 1725 asymmetric key. 1727 o Clarified that JWSs with duplicate Header Parameter Names MUST be 1728 rejected. 1730 o Clarified the relationship between "typ" header parameter values 1731 and MIME types. 1733 o Registered application/jws MIME type and "JWS" typ header 1734 parameter value. 1736 o Simplified JWK terminology to get replace the "JWK Key Object" and 1737 "JWK Container Object" terms with simply "JSON Web Key (JWK)" and 1738 "JSON Web Key Set (JWK Set)" and to eliminate potential confusion 1739 between single keys and sets of keys. As part of this change, the 1740 header parameter name for a public key value was changed from 1741 "jpk" (JSON Public Key) to "jwk" (JSON Web Key). 1743 o Added suggestion on defining additional header parameters such as 1744 "x5t#S256" in the future for certificate thumbprints using hash 1745 algorithms other than SHA-1. 1747 o Specify RFC 2818 server identity validation, rather than RFC 6125 1748 (paralleling the same decision in the OAuth specs). 1750 o Generalized language to refer to Message Authentication Codes 1751 (MACs) rather than Hash-based Message Authentication Codes (HMACs) 1752 unless in a context specific to HMAC algorithms. 1754 o Reformatted to give each header parameter its own section heading. 1756 -01 1758 o Moved definition of Plaintext JWSs (using "alg":"none") here from 1759 the JWT specification since this functionality is likely to be 1760 useful in more contexts that just for JWTs. 1762 o Added "jpk" and "x5c" header parameters for including JWK public 1763 keys and X.509 certificate chains directly in the header. 1765 o Clarified that this specification is defining the JWS Compact 1766 Serialization. Referenced the new JWS-JS spec, which defines the 1767 JWS JSON Serialization. 1769 o Added text "New header parameters should be introduced sparingly 1770 since an implementation that does not understand a parameter MUST 1771 reject the JWS". 1773 o Clarified that the order of the creation and validation steps is 1774 not significant in cases where there are no dependencies between 1775 the inputs and outputs of the steps. 1777 o Changed "no canonicalization is performed" to "no canonicalization 1778 need be performed". 1780 o Corrected the Magic Signatures reference. 1782 o Made other editorial improvements suggested by JOSE working group 1783 participants. 1785 -00 1787 o Created the initial IETF draft based upon 1788 draft-jones-json-web-signature-04 with no normative changes. 1790 o Changed terminology to no longer call both digital signatures and 1791 HMACs "signatures". 1793 Authors' Addresses 1795 Michael B. Jones 1796 Microsoft 1798 Email: mbj@microsoft.com 1799 URI: http://self-issued.info/ 1801 John Bradley 1802 Ping Identity 1804 Email: ve7jtb@ve7jtb.com 1805 Nat Sakimura 1806 Nomura Research Institute 1808 Email: n-sakimura@nri.co.jp