1 /* jws-3.3.10 (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
  2  */
  3 /*
  4  * jws.js - JSON Web Signature(JWS) and JSON Web Token(JWT) Class
  5  *
  6  * Copyright (c) 2010-2017 Kenji Urushima (kenji.urushima@gmail.com)
  7  *
  8  * This software is licensed under the terms of the MIT License.
  9  * https://kjur.github.io/jsrsasign/license/
 10  *
 11  * The above copyright and license notice shall be 
 12  * included in all copies or substantial portions of the Software.
 13  */
 14 
 15 /**
 16  * @fileOverview
 17  * @name jws-3.3.js
 18  * @author Kenji Urushima kenji.urushima@gmail.com
 19  * @version jsrsasign 8.0.3 jws 3.3.10 (2017-Jul-11)
 20  * @since jsjws 1.0, jsrsasign 4.8.0
 21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
 22  */
 23 
 24 if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
 25 
 26 /**
 27  * kjur's JSON Web Signature/Token(JWS/JWT) library name space
 28  * <p>
 29  * This namespace privides following JWS/JWS related classes.
 30  * <ul>
 31  * <li>{@link KJUR.jws.JWS} - JSON Web Signature/Token(JWS/JWT) class</li>
 32  * <li>{@link KJUR.jws.JWSJS} - JWS JSON Serialization(JWSJS) class</li>
 33  * <li>{@link KJUR.jws.IntDate} - UNIX origin time utility class</li>
 34  * </ul>
 35  * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
 36  * </p>
 37  * @name KJUR.jws
 38  * @namespace
 39  */
 40 if (typeof KJUR.jws == "undefined" || !KJUR.jws) KJUR.jws = {};
 41 
 42 /**
 43  * JSON Web Signature(JWS) class.<br/>
 44  * @name KJUR.jws.JWS
 45  * @class JSON Web Signature(JWS) class
 46  * @see <a href="https://kjur.github.io/jsjws/">'jwjws'(JWS JavaScript Library) home page https://kjur.github.io/jsjws/</a>
 47  * @see <a href="https://kjur.github.io/jsrsasigns/">'jwrsasign'(RSA Sign JavaScript Library) home page https://kjur.github.io/jsrsasign/</a>
 48  * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-14">IETF I-D JSON Web Algorithms (JWA)</a>
 49  * @since jsjws 1.0
 50  * @description
 51  * This class provides JSON Web Signature(JWS)/JSON Web Token(JWT) signing and validation.
 52  *
 53  * <h4>METHOD SUMMARY</h4>
 54  * Here is major methods of {@link KJUR.jws.JWS} class.
 55  * <ul>
 56  * <li><b>SIGN</b><br/>
 57  * <li>{@link KJUR.jws.JWS.sign} - sign JWS</li>
 58  * </li>
 59  * <li><b>VERIFY</b><br/>
 60  * <li>{@link KJUR.jws.JWS.verify} - verify JWS signature</li>
 61  * <li>{@link KJUR.jws.JWS.verifyJWT} - verify properties of JWT token at specified time</li>
 62  * </li>
 63  * <li><b>UTILITY</b><br/>
 64  * <li>{@link KJUR.jws.JWS.getJWKthumbprint} - get RFC 7638 JWK thumbprint</li>
 65  * <li>{@link KJUR.jws.JWS.isSafeJSONString} - check whether safe JSON string or not</li>
 66  * <li>{@link KJUR.jws.JWS.readSafeJSONString} - read safe JSON string only</li>
 67  * </li>
 68  * </ul> 
 69  *
 70  * <h4>SUPPORTED SIGNATURE ALGORITHMS</h4>
 71  * Here is supported algorithm names for {@link KJUR.jws.JWS.sign} and
 72  * {@link KJUR.jws.JWS.verify} methods.
 73  * <table>
 74  * <tr><th>alg value</th><th>spec requirement</th><th>jsjws support</th></tr>
 75  * <tr><td>HS256</td><td>REQUIRED</td><td>SUPPORTED</td></tr>
 76  * <tr><td>HS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 77  * <tr><td>HS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 78  * <tr><td>RS256</td><td>RECOMMENDED</td><td>SUPPORTED</td></tr>
 79  * <tr><td>RS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 80  * <tr><td>RS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 81  * <tr><td>ES256</td><td>RECOMMENDED+</td><td>SUPPORTED</td></tr>
 82  * <tr><td>ES384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 83  * <tr><td>ES512</td><td>OPTIONAL</td><td>-</td></tr>
 84  * <tr><td>PS256</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 85  * <tr><td>PS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 86  * <tr><td>PS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
 87  * <tr><td>none</td><td>REQUIRED</td><td>SUPPORTED(signature generation only)</td></tr>
 88  * </table>
 89  * <dl>
 90  * <dt><b>NOTE1</b>
 91  * <dd>HS384 is supported since jsjws 3.0.2 with jsrsasign 4.1.4.
 92  * <dt><b>NOTE2</b>
 93  * <dd>Some deprecated methods have been removed since jws 3.3 of jsrsasign 4.10.0.
 94  * Removed methods are following:
 95  * <ul>
 96  * <li>JWS.verifyJWSByNE</li>
 97  * <li>JWS.verifyJWSByKey</li>
 98  * <li>JWS.generateJWSByNED</li>
 99  * <li>JWS.generateJWSByKey</li>
100  * <li>JWS.generateJWSByP1PrvKey</li>
101  * </ul>
102  * </dl>
103  * <b>EXAMPLE</b><br/>
104  * @example
105  * // JWS signing 
106  * sJWS = KJUR.jws.JWS.sign(null, '{"alg":"HS256", "cty":"JWT"}', '{"age": 21}', {"utf8": "password"});
107  * // JWS validation
108  * isValid = KJUR.jws.JWS.verify('eyJjdHkiOiJKV1QiLCJhbGc...', {"utf8": "password"});
109  * // JWT validation
110  * isValid = KJUR.jws.JWS.verifyJWT('eyJh...', {"utf8": "password"}, {
111  *   alg: ['HS256', 'HS384'],
112  *   iss: ['http://foo.com']
113  * });
114  */
115 KJUR.jws.JWS = function() {
116     var _KJUR = KJUR,
117 	_KJUR_jws_JWS = _KJUR.jws.JWS,
118 	_isSafeJSONString = _KJUR_jws_JWS.isSafeJSONString;
119 
120     // === utility =============================================================
121 
122     /**
123      * parse JWS string and set public property 'parsedJWS' dictionary.<br/>
124      * @name parseJWS
125      * @memberOf KJUR.jws.JWS
126      * @function
127      * @param {String} sJWS JWS signature string to be parsed.
128      * @throws if sJWS is not comma separated string such like "Header.Payload.Signature".
129      * @throws if JWS Header is a malformed JSON string.
130      * @since jws 1.1
131      */
132     this.parseJWS = function(sJWS, sigValNotNeeded) {
133 	if ((this.parsedJWS !== undefined) &&
134 	    (sigValNotNeeded || (this.parsedJWS.sigvalH !== undefined))) {
135 	    return;
136 	}
137 	var matchResult = sJWS.match(/^([^.]+)\.([^.]+)\.([^.]+)$/);
138 	if (matchResult == null) {
139 	    throw "JWS signature is not a form of 'Head.Payload.SigValue'.";
140 	}
141 	var b6Head = matchResult[1];
142 	var b6Payload = matchResult[2];
143 	var b6SigVal = matchResult[3];
144 	var sSI = b6Head + "." + b6Payload;
145 	this.parsedJWS = {};
146 	this.parsedJWS.headB64U = b6Head;
147 	this.parsedJWS.payloadB64U = b6Payload;
148 	this.parsedJWS.sigvalB64U = b6SigVal;
149 	this.parsedJWS.si = sSI;
150 
151 	if (!sigValNotNeeded) {
152 	    var hSigVal = b64utohex(b6SigVal);
153 	    var biSigVal = parseBigInt(hSigVal, 16);
154 	    this.parsedJWS.sigvalH = hSigVal;
155 	    this.parsedJWS.sigvalBI = biSigVal;
156 	}
157 
158 	var sHead = b64utoutf8(b6Head);
159 	var sPayload = b64utoutf8(b6Payload);
160 	this.parsedJWS.headS = sHead;
161 	this.parsedJWS.payloadS = sPayload;
162 
163 	if (! _isSafeJSONString(sHead, this.parsedJWS, 'headP'))
164 	    throw "malformed JSON string for JWS Head: " + sHead;
165     };
166 };
167 
168 // === major static method ========================================================
169 
170 /**
171  * generate JWS signature by specified key<br/>
172  * @name sign
173  * @memberOf KJUR.jws.JWS
174  * @function
175  * @static
176  * @param {String} alg JWS algorithm name to sign and force set to sHead or null 
177  * @param {String} spHead string or object of JWS Header
178  * @param {String} spPayload string or object of JWS Payload
179  * @param {String} key string of private key or mac key object to sign
180  * @param {String} pass (OPTION)passcode to use encrypted asymmetric private key 
181  * @return {String} JWS signature string
182  * @since jws 3.0.0
183  * @see <a href="https://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.Signature.html">jsrsasign KJUR.crypto.Signature method</a>
184  * @see <a href="https://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.Mac.html">jsrsasign KJUR.crypto.Mac method</a>
185  * @description
186  * This method supports following algorithms.
187  * <table>
188  * <tr><th>alg value</th><th>spec requirement</th><th>jsjws support</th></tr>
189  * <tr><td>HS256</td><td>REQUIRED</td><td>SUPPORTED</td></tr>
190  * <tr><td>HS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
191  * <tr><td>HS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
192  * <tr><td>RS256</td><td>RECOMMENDED</td><td>SUPPORTED</td></tr>
193  * <tr><td>RS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
194  * <tr><td>RS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
195  * <tr><td>ES256</td><td>RECOMMENDED+</td><td>SUPPORTED</td></tr>
196  * <tr><td>ES384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
197  * <tr><td>ES512</td><td>OPTIONAL</td><td>-</td></tr>
198  * <tr><td>PS256</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
199  * <tr><td>PS384</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
200  * <tr><td>PS512</td><td>OPTIONAL</td><td>SUPPORTED</td></tr>
201  * <tr><td>none</td><td>REQUIRED</td><td>SUPPORTED(signature generation only)</td></tr>
202  * </table>
203  * <dl>
204  * <dt>NOTE1:
205  * <dd>salt length of RSAPSS signature is the same as the hash algorithm length
206  * because of <a href="http://www.ietf.org/mail-archive/web/jose/current/msg02901.html">IETF JOSE ML discussion</a>.
207  * <dt>NOTE2:
208  * <dd>To support HS384, patched version of CryptoJS is used.
209  * <a href="https://code.google.com/p/crypto-js/issues/detail?id=84">See here for detail</a>.
210  * <dt>NOTE3:
211  * From jsrsasign 4.10.0 jws 3.3.0, Way to provide password
212  * for HS* algorithm is changed. The 'key' attribute value is
213  * passed to {@link KJUR.crypto.Mac.setPassword} so please see
214  * {@link KJUR.crypto.Mac.setPassword} for detail.
215  * As for backword compatibility, if key is a string, has even length and
216  * 0..9, A-F or a-f characters, key string is treated as a hexadecimal
217  * otherwise it is treated as a raw string.
218  * <dd>
219  * </dl>
220  * <b>EXAMPLE</b><br/>
221  * @example
222  * // sign HS256 signature with password "aaa" implicitly handled as string
223  * sJWS = KJUR.jws.JWS.sign(null, {alg: "HS256", cty: "JWT"}, {age: 21}, "aaa");
224  * // sign HS256 signature with password "6161" implicitly handled as hex
225  * sJWS = KJUR.jws.JWS.sign(null, {alg: "HS256", cty: "JWT"}, {age: 21}, "6161");
226  * // sign HS256 signature with base64 password
227  * sJWS = KJUR.jws.JWS.sign(null, {alg: "HS256"}, {age: 21}, {b64: "Mi/8..a="});
228  * // sign RS256 signature with PKCS#8 PEM RSA private key
229  * sJWS = KJUR.jws.JWS.sign(null, {alg: "RS256"}, {age: 21}, "-----BEGIN PRIVATE KEY...");
230  * // sign RS256 signature with PKCS#8 PEM ECC private key with passcode
231  * sJWS = KJUR.jws.JWS.sign(null, {alg: "ES256"}, {age: 21}, 
232  *                          "-----BEGIN PRIVATE KEY...", "keypass");
233  * // header and payload can be passed by both string and object
234  * sJWS = KJUR.jws.JWS.sign(null, '{alg:"HS256",cty:"JWT"}', '{age:21}', "aaa");
235  */
236 KJUR.jws.JWS.sign = function(alg, spHeader, spPayload, key, pass) {
237     var _KJUR = KJUR,
238 	_KJUR_jws = _KJUR.jws,
239 	_KJUR_jws_JWS = _KJUR_jws.JWS,
240 	_readSafeJSONString = _KJUR_jws_JWS.readSafeJSONString,
241 	_isSafeJSONString = _KJUR_jws_JWS.isSafeJSONString,
242 	_KJUR_crypto = _KJUR.crypto,
243 	_ECDSA = _KJUR_crypto.ECDSA,
244 	_Mac = _KJUR_crypto.Mac,
245 	_Signature = _KJUR_crypto.Signature,
246 	_JSON = JSON;
247 
248     var sHeader, pHeader, sPayload;
249 
250     // 1. check signatureInput(Header, Payload) is string or object
251     if (typeof spHeader != 'string' && typeof spHeader != 'object')
252 	throw "spHeader must be JSON string or object: " + spHeader;
253 
254     if (typeof spHeader == 'object') {
255 	pHeader = spHeader;
256 	sHeader = _JSON.stringify(pHeader);
257     }
258 
259     if (typeof spHeader == 'string') {
260 	sHeader = spHeader;
261 	if (! _isSafeJSONString(sHeader))
262 	    throw "JWS Head is not safe JSON string: " + sHeader;
263 	pHeader = _readSafeJSONString(sHeader);
264 
265     }
266 
267     sPayload = spPayload;
268     if (typeof spPayload == 'object') sPayload = _JSON.stringify(spPayload);
269 
270     // 2. use alg if defined in sHeader
271     if ((alg == '' || alg == null) &&
272 	pHeader['alg'] !== undefined) {
273 	alg = pHeader['alg'];
274     }
275 
276     // 3. update sHeader to add alg if alg undefined
277     if ((alg != '' && alg != null) &&
278 	pHeader['alg'] === undefined) {
279 	pHeader['alg'] = alg;
280 	sHeader = _JSON.stringify(pHeader);
281     }
282 
283     // 4. check explicit algorithm doesn't match with JWS header.
284     if (alg !== pHeader.alg)
285 	throw "alg and sHeader.alg doesn't match: " + alg + "!=" + pHeader.alg;
286 
287     // 5. set signature algorithm like SHA1withRSA
288     var sigAlg = null;
289     if (_KJUR_jws_JWS.jwsalg2sigalg[alg] === undefined) {
290 	throw "unsupported alg name: " + alg;
291     } else {
292 	sigAlg = _KJUR_jws_JWS.jwsalg2sigalg[alg];
293     }
294     
295     var uHeader = utf8tob64u(sHeader);
296     var uPayload = utf8tob64u(sPayload);
297     var uSignatureInput = uHeader + "." + uPayload
298     // 6. sign
299     var hSig = "";
300     if (sigAlg.substr(0, 4) == "Hmac") {
301 	if (key === undefined)
302 	    throw "mac key shall be specified for HS* alg";
303 	//alert("sigAlg=" + sigAlg);
304 	var mac = new _Mac({'alg': sigAlg, 'prov': 'cryptojs', 'pass': key});
305 	mac.updateString(uSignatureInput);
306 	hSig = mac.doFinal();
307     } else if (sigAlg.indexOf("withECDSA") != -1) {
308 	var sig = new _Signature({'alg': sigAlg});
309 	sig.init(key, pass);
310 	sig.updateString(uSignatureInput);
311 	hASN1Sig = sig.sign();
312 	hSig = KJUR.crypto.ECDSA.asn1SigToConcatSig(hASN1Sig);
313     } else if (sigAlg != "none") {
314 	var sig = new _Signature({'alg': sigAlg});
315 	sig.init(key, pass);
316 	sig.updateString(uSignatureInput);
317 	hSig = sig.sign();
318     }
319 
320     var uSig = hextob64u(hSig);
321     return uSignatureInput + "." + uSig;
322 };
323 
324 /**
325  * verify JWS signature by specified key or certificate<br/>
326  * @name verify
327  * @memberOf KJUR.jws.JWS
328  * @function
329  * @static
330  * @param {String} sJWS string of JWS signature to verify
331  * @param {Object} key string of public key, certificate or key object to verify
332  * @param {String} acceptAlgs array of algorithm name strings (OPTION)
333  * @return {Boolean} true if the signature is valid otherwise false
334  * @since jws 3.0.0
335  * @see <a href="https://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.Signature.html">jsrsasign KJUR.crypto.Signature method</a>
336  * @see <a href="https://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.Mac.html">jsrsasign KJUR.crypto.Mac method</a>
337  * @description
338  * <p>
339  * This method verifies a JSON Web Signature Compact Serialization string by the validation 
340  * algorithm as described in 
341  * <a href="http://self-issued.info/docs/draft-jones-json-web-signature-04.html#anchor5">
342  * the section 5 of Internet Draft draft-jones-json-web-signature-04.</a>
343  * </p>
344  * <p>
345  * Since 3.2.0 strict key checking has been provided against a JWS algorithm
346  * in a JWS header.
347  * <ul>
348  * <li>In case 'alg' is 'HS*' in the JWS header,
349  * 'key' shall be hexadecimal string for Hmac{256,384,512} shared secret key.
350  * Otherwise it raise an error.</li>
351  * <li>In case 'alg' is 'RS*' or 'PS*' in the JWS header,
352  * 'key' shall be a RSAKey object or a PEM string of
353  * X.509 RSA public key certificate or PKCS#8 RSA public key.
354  * Otherwise it raise an error.</li>
355  * <li>In case 'alg' is 'ES*' in the JWS header,
356  * 'key' shall be a KJUR.crypto.ECDSA object or a PEM string of
357  * X.509 ECC public key certificate or PKCS#8 ECC public key.
358  * Otherwise it raise an error.</li>
359  * <li>In case 'alg' is 'none' in the JWS header,
360  * validation not supported after jsjws 3.1.0.</li>
361  * </ul>
362  * </p>
363  * <p>
364  * NOTE1: The argument 'acceptAlgs' is supported since 3.2.0.
365  * Strongly recommended to provide acceptAlgs to mitigate
366  * signature replacement attacks.<br/>
367  * </p>
368  * <p>
369  * NOTE2: From jsrsasign 4.9.0 jws 3.2.5, Way to provide password
370  * for HS* algorithm is changed. The 'key' attribute value is
371  * passed to {@link KJUR.crypto.Mac.setPassword} so please see
372  * {@link KJUR.crypto.Mac.setPassword} for detail.
373  * As for backword compatibility, if key is a string, has even length and
374  * 0..9, A-F or a-f characters, key string is treated as a hexadecimal
375  * otherwise it is treated as a raw string.
376  * </p>
377  * @example
378  * // 1) verify a RS256 JWS signature by a certificate string.
379  * isValid = KJUR.jws.JWS.verify('eyJh...', '-----BEGIN...', ['RS256']);
380  * 
381  * // 2) verify a HS256 JWS signature by a certificate string.
382  * isValid = KJUR.jws.JWS.verify('eyJh...', {hex: '6f62ad...'}, ['HS256']);
383  * isValid = KJUR.jws.JWS.verify('eyJh...', {b64: 'Mi/ab8...a=='}, ['HS256']);
384  * isValid = KJUR.jws.JWS.verify('eyJh...', {utf8: 'Secret秘密'}, ['HS256']);
385  * isValid = KJUR.jws.JWS.verify('eyJh...', '6f62ad', ['HS256']); // implicit hex
386  * isValid = KJUR.jws.JWS.verify('eyJh...', '6f62ada', ['HS256']); // implicit raw string
387  *
388  * // 3) verify a ES256 JWS signature by a KJUR.crypto.ECDSA key object.
389  * var pubkey = KEYUTIL.getKey('-----BEGIN CERT...');
390  * var isValid = KJUR.jws.JWS.verify('eyJh...', pubkey);
391  */
392 KJUR.jws.JWS.verify = function(sJWS, key, acceptAlgs) {
393     var _KJUR = KJUR,
394 	_KJUR_jws = _KJUR.jws,
395 	_KJUR_jws_JWS = _KJUR_jws.JWS,
396 	_readSafeJSONString = _KJUR_jws_JWS.readSafeJSONString,
397 	_KJUR_crypto = _KJUR.crypto,
398 	_ECDSA = _KJUR_crypto.ECDSA,
399 	_Mac = _KJUR_crypto.Mac,
400 	_Signature = _KJUR_crypto.Signature,
401 	_RSAKey;
402     
403     if (typeof RSAKey !== undefined) _RSAKey = RSAKey;
404 
405     var a = sJWS.split(".");
406     var uHeader = a[0];
407     var uPayload = a[1];
408     var uSignatureInput = uHeader + "." + uPayload;
409     var hSig = b64utohex(a[2]);
410 
411     // 1. parse JWS header
412     var pHeader = _readSafeJSONString(b64utoutf8(a[0]));
413     var alg = null;
414     var algType = null; // HS|RS|PS|ES|no
415     if (pHeader.alg === undefined) {
416 	throw "algorithm not specified in header";
417     } else {
418 	alg = pHeader.alg;
419 	algType = alg.substr(0, 2);
420     }
421 
422     // 2. check whether alg is acceptable algorithms
423     if (acceptAlgs != null &&
424         Object.prototype.toString.call(acceptAlgs) === '[object Array]' &&
425         acceptAlgs.length > 0) {
426 	var acceptAlgStr = ":" + acceptAlgs.join(":") + ":";
427 	if (acceptAlgStr.indexOf(":" + alg + ":") == -1) {
428 	    throw "algorithm '" + alg + "' not accepted in the list";
429 	}
430     }
431 
432     // 3. check whether key is a proper key for alg.
433     if (alg != "none" && key === null) {
434 	throw "key shall be specified to verify.";
435     }
436 
437     // 3.1. There is no key check for HS* because Mac will check it.
438     //      since jsrsasign 5.0.0.
439 
440     // 3.2. convert key object if key is a public key or cert PEM string
441     if (typeof key == "string" &&
442 	key.indexOf("-----BEGIN ") != -1) {
443 	key = KEYUTIL.getKey(key);
444     }
445 
446     // 3.3. check whether key is RSAKey obj if alg is RS* or PS*.
447     if (algType == "RS" || algType == "PS") {
448 	if (!(key instanceof _RSAKey)) {
449 	    throw "key shall be a RSAKey obj for RS* and PS* algs";
450 	}
451     }
452 
453     // 3.4. check whether key is ECDSA obj if alg is ES*.
454     if (algType == "ES") {
455 	if (!(key instanceof _ECDSA)) {
456 	    throw "key shall be a ECDSA obj for ES* algs";
457 	}
458     }
459 
460     // 3.5. check when alg is 'none'
461     if (alg == "none") {
462     }
463 
464     // 4. check whether alg is supported alg in jsjws.
465     var sigAlg = null;
466     if (_KJUR_jws_JWS.jwsalg2sigalg[pHeader.alg] === undefined) {
467 	throw "unsupported alg name: " + alg;
468     } else {
469 	sigAlg = _KJUR_jws_JWS.jwsalg2sigalg[alg];
470     }
471 
472     // 5. verify
473     if (sigAlg == "none") {
474         throw "not supported";
475     } else if (sigAlg.substr(0, 4) == "Hmac") {
476 	var hSig2 = null;
477 	if (key === undefined)
478 	    throw "hexadecimal key shall be specified for HMAC";
479 	//try {
480 	    var mac = new _Mac({'alg': sigAlg, 'pass': key});
481 	    mac.updateString(uSignatureInput);
482 	    hSig2 = mac.doFinal();
483 	//} catch(ex) {};
484 	return hSig == hSig2;
485     } else if (sigAlg.indexOf("withECDSA") != -1) {
486 	var hASN1Sig = null;
487         try {
488 	    hASN1Sig = _ECDSA.concatSigToASN1Sig(hSig);
489 	} catch (ex) {
490 	    return false;
491 	}
492 	var sig = new _Signature({'alg': sigAlg});
493 	sig.init(key)
494 	sig.updateString(uSignatureInput);
495 	return sig.verify(hASN1Sig);
496     } else {
497 	var sig = new _Signature({'alg': sigAlg});
498 	sig.init(key)
499 	sig.updateString(uSignatureInput);
500 	return sig.verify(hSig);
501     }
502 };
503 
504 /**
505  * parse header and payload of JWS signature<br/>
506  * @name parse
507  * @memberOf KJUR.jws.JWS
508  * @function
509  * @static
510  * @param {String} sJWS string of JWS signature to parse
511  * @return {Array} associative array of parsed header and payload. See below.
512  * @throws if sJWS is malformed JWS signature
513  * @since jws 3.3.3
514  * @description
515  * This method parses JWS signature string. 
516  * Resulted associative array has following properties:
517  * <ul>
518  * <li>headerObj - JSON object of header</li>
519  * <li>payloadObj - JSON object of payload if payload is JSON string otherwise undefined</li>
520  * <li>headerPP - pretty printed JSON header by stringify</li>
521  * <li>payloadPP - pretty printed JSON payload by stringify if payload is JSON otherwise Base64URL decoded raw string of payload</li>
522  * <li>sigHex - hexadecimal string of signature</li>
523  * </ul>
524  * @example
525  * KJUR.jws.JWS.parse(sJWS) ->
526  * { 
527  *   headerObj: {"alg": "RS256", "typ": "JWS"},
528  *   payloadObj: {"product": "orange", "quantity": 100},
529  *   headerPP: 
530  *   '{
531  *     "alg": "RS256",
532  *     "typ": "JWS"
533  *   }',
534  *   payloadPP: 
535  *   '{
536  *     "product": "orange",
537  *     "quantity": 100
538  *   }',
539  *   sigHex: "91f3cd..." 
540  * }
541  */
542 KJUR.jws.JWS.parse = function(sJWS) {
543     var a = sJWS.split(".");
544     var result = {};
545     var uHeader, uPayload, uSig;
546     if (a.length != 2 && a.length != 3)
547 	throw "malformed sJWS: wrong number of '.' splitted elements";
548 
549     uHeader = a[0];
550     uPayload = a[1];
551     if (a.length == 3) uSig = a[2]; 
552 
553     result.headerObj = KJUR.jws.JWS.readSafeJSONString(b64utoutf8(uHeader));
554     result.payloadObj = KJUR.jws.JWS.readSafeJSONString(b64utoutf8(uPayload));
555 
556     result.headerPP = JSON.stringify(result.headerObj, null, "  ");
557     if (result.payloadObj == null) {
558 	result.payloadPP = b64utoutf8(uPayload);
559     } else {
560 	result.payloadPP = JSON.stringify(result.payloadObj, null, "  ");
561     }
562 
563     if (uSig !== undefined) {
564 	result.sigHex = b64utohex(uSig);
565     }
566 
567     return result;
568 };
569 
570 /**
571  * @name verifyJWT
572  * @memberOf KJUR.jws.JWS
573  * @function
574  * @static
575  * @param {String} sJWT string of JSON Web Token(JWT) to verify
576  * @param {Object} key string of public key, certificate or key object to verify
577  * @param {Array} acceptField associative array of acceptable fields (OPTION)
578  * @return {Boolean} true if the JWT token is valid otherwise false
579  * @since jws 3.2.3 jsrsasign 4.8.0
580  *
581  * @description
582  * This method verifies a
583  * <a href="https://tools.ietf.org/html/rfc7519">RFC 7519</a> 
584  * JSON Web Token(JWT).
585  * It will verify following:
586  * <ul>
587  * <li>Header.alg
588  * <ul>
589  * <li>alg is specified in JWT header.</li>
590  * <li>alg is included in acceptField.alg array. (MANDATORY)</li>
591  * <li>alg is proper for key.</li>
592  * </ul>
593  * </li>
594  * <li>Payload.iss (issuer) - Payload.iss is included in acceptField.iss array if specified. (OPTION)</li>
595  * <li>Payload.sub (subject) - Payload.sub is included in acceptField.sub array if specified. (OPTION)</li>
596  * <li>Payload.aud (audience) - Payload.aud is included in acceptField.aud array or 
597  *     the same as value if specified. (OPTION)</li>
598  * <li>Time validity
599  * <ul>
600  * <li>
601  * If acceptField.verifyAt as number of UNIX origin time is specifed for validation time, 
602  * this method will verify at the time for it, otherwise current time will be used to verify.
603  * </li>
604  * <li>
605  * Clock of JWT generator or verifier can be fast or slow. If these clocks are
606  * very different, JWT validation may fail. To avoid such case, 'jsrsasign' supports
607  * 'acceptField.gracePeriod' parameter which specifies acceptable time difference
608  * of those clocks in seconds. So if you want to accept slow or fast in 2 hours,
609  * you can specify <code>acceptField.gracePeriod = 2 * 60 * 60;</code>.
610  * "gracePeriod" is zero by default.
611  * "gracePeriod" is supported since jsrsasign 5.0.12.
612  * </li>
613  * <li>Payload.exp (expire) - Validation time is smaller than Payload.exp + gracePeriod.</li>
614  * <li>Payload.nbf (not before) - Validation time is greater than Payload.nbf - gracePeriod.</li>
615  * <li>Payload.iat (issued at) - Validation time is greater than Payload.iat - gracePeriod.</li>
616  * </ul>
617  * </li>
618  * <li>Payload.jti (JWT id) - Payload.jti is included in acceptField.jti if specified. (OPTION)</li>
619  * <li>JWS signature of JWS is valid for specified key.</li>
620  * </ul>
621  *
622  * <h4>acceptField parameters</h4>
623  * Here is available acceptField argument parameters:
624  * <ul>
625  * <li>alg - array of acceptable signature algorithm names (ex. ["HS256", "HS384"])</li>
626  * <li>iss - array of acceptable issuer names (ex. ['http://foo.com'])</li>
627  * <li>sub - array of acceptable subject names (ex. ['mailto:john@foo.com'])</li>
628  * <li>aud - array or string of acceptable audience name(s) (ex. ['http://foo.com'])</li>
629  * <li>jti - string of acceptable JWT ID (OPTION) (ex. 'id1234')</li>
630  * <li>
631  * verifyAt - time to verify 'nbf', 'iat' and 'exp' in UNIX seconds 
632  * (OPTION) (ex. 1377663900).  
633  * If this is not specified, current time of verifier will be used. 
634  * {@link KJUR.jws.IntDate} may be useful to specify it.
635  * </li>
636  * <li>gracePeriod - acceptable time difference between signer and verifier
637  * in seconds (ex. 3600). If this is not specified, zero will be used.</li>
638  * </ul>
639  *
640  * @example
641  * // simple validation for HS256
642  * isValid = KJUR.jws.JWS.verifyJWT("eyJhbG...", "616161", {alg: ["HS256"]}),
643  *
644  * // full validation for RS or PS
645  * pubkey = KEYUTIL.getKey('-----BEGIN CERT...');
646  * isValid = KJUR.jws.JWS.verifyJWT('eyJh...', pubkey, {
647  *   alg: ['RS256', 'RS512', 'PS256', 'PS512'],
648  *   iss: ['http://foo.com'],
649  *   sub: ['mailto:john@foo.com', 'mailto:alice@foo.com'],
650  *   verifyAt: KJUR.jws.IntDate.get('20150520235959Z'),
651  *   aud: ['http://foo.com'], // aud: 'http://foo.com' is fine too.
652  *   jti: 'id123456',
653  *   gracePeriod: 1 * 60 * 60 // accept 1 hour slow or fast
654  * });
655  */
656 KJUR.jws.JWS.verifyJWT = function(sJWT, key, acceptField) {
657     var _KJUR = KJUR,
658 	_KJUR_jws = _KJUR.jws,
659 	_KJUR_jws_JWS = _KJUR_jws.JWS,
660 	_readSafeJSONString = _KJUR_jws_JWS.readSafeJSONString,
661 	_inArray = _KJUR_jws_JWS.inArray,
662 	_includedArray = _KJUR_jws_JWS.includedArray;
663 
664     // 1. parse JWT
665     var a = sJWT.split(".");
666     var uHeader = a[0];
667     var uPayload = a[1];
668     var uSignatureInput = uHeader + "." + uPayload;
669     var hSig = b64utohex(a[2]);
670 
671     // 2. parse JWS header
672     var pHeader = _readSafeJSONString(b64utoutf8(uHeader));
673 
674     // 3. parse JWS payload
675     var pPayload = _readSafeJSONString(b64utoutf8(uPayload));
676 
677     // 4. algorithm ('alg' in header) check
678     if (pHeader.alg === undefined) return false;
679     if (acceptField.alg === undefined)
680 	throw "acceptField.alg shall be specified";
681     if (! _inArray(pHeader.alg, acceptField.alg)) return false;
682 
683     // 5. issuer ('iss' in payload) check
684     if (pPayload.iss !== undefined && typeof acceptField.iss === "object") {
685 	if (! _inArray(pPayload.iss, acceptField.iss)) return false;
686     }
687 
688     // 6. subject ('sub' in payload) check
689     if (pPayload.sub !== undefined && typeof acceptField.sub === "object") {
690 	if (! _inArray(pPayload.sub, acceptField.sub)) return false;
691     }
692 
693     // 7. audience ('aud' in payload) check
694     if (pPayload.aud !== undefined && typeof acceptField.aud === "object") {
695 	if (typeof pPayload.aud == "string") {
696 	    if (! _inArray(pPayload.aud, acceptField.aud))
697 		return false;
698 	} else if (typeof pPayload.aud == "object") {
699 	    if (! _includedArray(pPayload.aud, acceptField.aud))
700 		return false;
701 	}
702     }
703 
704     // 8. time validity 
705     //   (nbf - gracePeriod < now < exp + gracePeriod) && (iat - gracePeriod < now)
706     var now = _KJUR_jws.IntDate.getNow();
707     if (acceptField.verifyAt !== undefined && typeof acceptField.verifyAt === "number") {
708 	now = acceptField.verifyAt;
709     }
710     if (acceptField.gracePeriod === undefined || 
711         typeof acceptField.gracePeriod !== "number") {
712 	acceptField.gracePeriod = 0;
713     }
714 
715     // 8.1 expired time 'exp' check
716     if (pPayload.exp !== undefined && typeof pPayload.exp == "number") {
717 	if (pPayload.exp + acceptField.gracePeriod < now) return false;
718     }
719 
720     // 8.2 not before time 'nbf' check
721     if (pPayload.nbf !== undefined && typeof pPayload.nbf == "number") {
722 	if (now < pPayload.nbf - acceptField.gracePeriod) return false;
723     }
724     
725     // 8.3 issued at time 'iat' check
726     if (pPayload.iat !== undefined && typeof pPayload.iat == "number") {
727 	if (now < pPayload.iat - acceptField.gracePeriod) return false;
728     }
729 
730     // 9 JWT id 'jti' check
731     if (pPayload.jti !== undefined && acceptField.jti !== undefined) {
732       if (pPayload.jti !== acceptField.jti) return false;
733     }
734 
735     // 10 JWS signature check
736     if (! _KJUR_jws_JWS.verify(sJWT, key, acceptField.alg)) return false;
737 
738     // 11 passed all check
739     return true;
740 };
741 
742 /**
743  * check whether array is included by another array
744  * @name includedArray
745  * @memberOf KJUR.jws.JWS
746  * @function
747  * @static
748  * @param {Array} a1 check whether set a1 is included by a2
749  * @param {Array} a2 check whether set a1 is included by a2
750  * @return {Boolean} check whether set a1 is included by a2
751  * @since jws 3.2.3
752  * This method verifies whether an array is included by another array.
753  * It doesn't care about item ordering in a array.
754  * @example
755  * KJUR.jws.JWS.includedArray(['b'], ['b', 'c', 'a']) => true
756  * KJUR.jws.JWS.includedArray(['a', 'b'], ['b', 'c', 'a']) => true
757  * KJUR.jws.JWS.includedArray(['a', 'b'], ['b', 'c']) => false
758  */
759 KJUR.jws.JWS.includedArray = function(a1, a2) {
760     var _inArray = KJUR.jws.JWS.inArray;
761     if (a1 === null) return false;
762     if (typeof a1 !== "object") return false;
763     if (typeof a1.length !== "number") return false;
764 
765     for (var i = 0; i < a1.length; i++) {
766 	if (! _inArray(a1[i], a2)) return false;
767     }
768     return true;
769 };
770 
771 /**
772  * check whether item is included by array
773  * @name inArray
774  * @memberOf KJUR.jws.JWS
775  * @function
776  * @static
777  * @param {String} item check whether item is included by array
778  * @param {Array} a check whether item is included by array
779  * @return {Boolean} check whether item is included by array
780  * @since jws 3.2.3
781  * This method verifies whether an item is included by an array.
782  * It doesn't care about item ordering in an array.
783  * @example
784  * KJUR.jws.JWS.inArray('b', ['b', 'c', 'a']) => true
785  * KJUR.jws.JWS.inArray('a', ['b', 'c', 'a']) => true
786  * KJUR.jws.JWS.inArray('a', ['b', 'c']) => false
787  */
788 KJUR.jws.JWS.inArray = function(item, a) {
789     if (a === null) return false;
790     if (typeof a !== "object") return false;
791     if (typeof a.length !== "number") return false;
792     for (var i = 0; i < a.length; i++) {
793 	if (a[i] == item) return true;
794     }
795     return false;
796 };
797 
798 /**
799  * static associative array of general signature algorithm name from JWS algorithm name
800  * @since jws 3.0.0
801  */
802 KJUR.jws.JWS.jwsalg2sigalg = {
803     "HS256":	"HmacSHA256",
804     "HS384":	"HmacSHA384",
805     "HS512":	"HmacSHA512",
806     "RS256":	"SHA256withRSA",
807     "RS384":	"SHA384withRSA",
808     "RS512":	"SHA512withRSA",
809     "ES256":	"SHA256withECDSA",
810     "ES384":	"SHA384withECDSA",
811     //"ES512":	"SHA512withECDSA", // unsupported because of jsrsasign's bug
812     "PS256":	"SHA256withRSAandMGF1",
813     "PS384":	"SHA384withRSAandMGF1",
814     "PS512":	"SHA512withRSAandMGF1",
815     "none":	"none",
816 };
817 
818 // === utility static method ==================================================
819 
820 /**
821  * check whether a String "s" is a safe JSON string or not.<br/>
822  * If a String "s" is a malformed JSON string or an other object type
823  * this returns 0, otherwise this returns 1.
824  * @name isSafeJSONString
825  * @memberOf KJUR.jws.JWS
826  * @function
827  * @static
828  * @param {String} s JSON string
829  * @return {Number} 1 or 0
830  */
831 KJUR.jws.JWS.isSafeJSONString = function(s, h, p) {
832     var o = null;
833     try {
834 	o = jsonParse(s);
835 	if (typeof o != "object") return 0;
836 	if (o.constructor === Array) return 0;
837 	if (h) h[p] = o;
838 	return 1;
839     } catch (ex) {
840 	return 0;
841     }
842 };
843 
844 /**
845  * read a String "s" as JSON object if it is safe.<br/>
846  * If a String "s" is a malformed JSON string or not JSON string,
847  * this returns null, otherwise returns JSON object.
848  * @name readSafeJSONString
849  * @memberOf KJUR.jws.JWS
850  * @function
851  * @static
852  * @param {String} s JSON string
853  * @return {Object} JSON object or null
854  * @since 1.1.1
855  */
856 KJUR.jws.JWS.readSafeJSONString = function(s) {
857     var o = null;
858     try {
859 	o = jsonParse(s);
860 	if (typeof o != "object") return null;
861 	if (o.constructor === Array) return null;
862 	return o;
863     } catch (ex) {
864 	return null;
865     }
866 };
867 
868 /**
869  * get Encoed Signature Value from JWS string.<br/>
870  * @name getEncodedSignatureValueFromJWS
871  * @memberOf KJUR.jws.JWS
872  * @function
873  * @static
874  * @param {String} sJWS JWS signature string to be verified
875  * @return {String} string of Encoded Signature Value 
876  * @throws if sJWS is not comma separated string such like "Header.Payload.Signature".
877  */
878 KJUR.jws.JWS.getEncodedSignatureValueFromJWS = function(sJWS) {
879     var matchResult = sJWS.match(/^[^.]+\.[^.]+\.([^.]+)$/);
880     if (matchResult == null) {
881 	throw "JWS signature is not a form of 'Head.Payload.SigValue'.";
882     }
883     return matchResult[1];
884 };
885 
886 /**
887  * get RFC 7638 JWK thumbprint from JWK object
888  * @name getJWKthumbprint
889  * @memberOf KJUR.jws.JWS
890  * @function
891  * @static
892  * @param {Object} o JWK object to be calculated thumbprint
893  * @return {String} Base64 URL encoded JWK thumbprint value
894  * @since jsrsasign 5.0.2 jws 3.3.2
895  * @description
896  * This method calculates JWK thmubprint for specified JWK object
897  * as described in 
898  * <a href="https://tools.ietf.org/html/rfc7638">RFC 7638</a>.
899  * It supports all type of "kty". (i.e. "RSA", "EC" and "oct"
900  * (for symmetric key))
901  * Working sample is 
902  * <a href="https://kjur.github.io/jsrsasign/sample/tool_jwktp.html">here</a>.
903  * @example
904  * jwk = {"kty":"RSA", "n":"0vx...", "e":"AQAB", ...};
905  * thumbprint = KJUR.jws.JWS.getJWKthumbprint(jwk);
906  */
907 KJUR.jws.JWS.getJWKthumbprint = function(o) {
908     if (o.kty !== "RSA" &&
909 	o.kty !== "EC" &&
910 	o.kty !== "oct")
911 	throw "unsupported algorithm for JWK Thumprint";
912 
913     // 1. get canonically ordered json string
914     var s = '{';
915     if (o.kty === "RSA") {
916 	if (typeof o.n != "string" || typeof o.e != "string")
917 	    throw "wrong n and e value for RSA key";
918 	s += '"' + 'e' + '":"' + o.e + '",';
919 	s += '"' + 'kty' + '":"' + o.kty + '",';
920 	s += '"' + 'n' + '":"' + o.n + '"}';
921     } else if (o.kty === "EC") {
922 	if (typeof o.crv != "string" || 
923 	    typeof o.x != "string" ||
924 	    typeof o.y != "string")
925 	    throw "wrong crv, x and y value for EC key";
926 	s += '"' + 'crv' + '":"' + o.crv + '",';
927 	s += '"' + 'kty' + '":"' + o.kty + '",';
928 	s += '"' + 'x' + '":"' + o.x + '",';
929 	s += '"' + 'y' + '":"' + o.y + '"}';
930     } else if (o.kty === "oct") {
931 	if (typeof o.k != "string")
932 	    throw "wrong k value for oct(symmetric) key";
933 	s += '"' + 'kty' + '":"' + o.kty + '",';
934 	s += '"' + 'k' + '":"' + o.k + '"}';
935     }
936     //alert(s);
937 
938     // 2. get thumb print
939     var hJWK = rstrtohex(s);
940     var hash = KJUR.crypto.Util.hashHex(hJWK, "sha256");
941     var hashB64U = hextob64u(hash);
942 
943     return hashB64U;
944 };
945 
946 /**
947  * IntDate class for time representation for JSON Web Token(JWT)
948  * @class KJUR.jws.IntDate class
949  * @name KJUR.jws.IntDate
950  * @since jws 3.0.1
951  * @description
952  * Utility class for IntDate which is integer representation of UNIX origin time
953  * used in JSON Web Token(JWT).
954  */
955 KJUR.jws.IntDate = {};
956 
957 /**
958  * get UNIX origin time from by string
959  * @name get
960  * @memberOf KJUR.jws.IntDate
961  * @function
962  * @static
963  * @param {String} s string of time representation
964  * @return {Integer} UNIX origin time in seconds for argument 's'
965  * @since jws 3.0.1
966  * @throws "unsupported format: s" when malformed format
967  * @description
968  * This method will accept following representation of time.
969  * <ul>
970  * <li>now - current time</li>
971  * <li>now + 1hour - after 1 hour from now</li>
972  * <li>now + 1day - after 1 day from now</li>
973  * <li>now + 1month - after 30 days from now</li>
974  * <li>now + 1year - after 365 days from now</li>
975  * <li>YYYYmmDDHHMMSSZ - UTC time (ex. 20130828235959Z)</li>
976  * <li>number - UNIX origin time (seconds from 1970-01-01 00:00:00) (ex. 1377714748)</li>
977  * </ul>
978  */
979 KJUR.jws.IntDate.get = function(s) {
980     var _KJUR_jws_IntDate = KJUR.jws.IntDate,
981 	_getNow = _KJUR_jws_IntDate.getNow,
982 	_getZulu = _KJUR_jws_IntDate.getZulu;
983 
984     if (s == "now") {
985 	return _getNow();
986     } else if (s == "now + 1hour") {
987 	return _getNow() + 60 * 60;
988     } else if (s == "now + 1day") {
989 	return _getNow() + 60 * 60 * 24;
990     } else if (s == "now + 1month") {
991 	return _getNow() + 60 * 60 * 24 * 30;
992     } else if (s == "now + 1year") {
993 	return _getNow() + 60 * 60 * 24 * 365;
994     } else if (s.match(/Z$/)) {
995 	return _getZulu(s);
996     } else if (s.match(/^[0-9]+$/)) {
997 	return parseInt(s);
998     }
999     throw "unsupported format: " + s;
1000 };
1001 
1002 /**
1003  * get UNIX origin time from Zulu time representation string
1004  * @name getZulu
1005  * @memberOf KJUR.jws.IntDate
1006  * @function
1007  * @static
1008  * @param {String} s string of Zulu time representation (ex. 20151012125959Z)
1009  * @return {Integer} UNIX origin time in seconds for argument 's'
1010  * @since jws 3.0.1
1011  * @throws "unsupported format: s" when malformed format
1012  * @description
1013  * This method provides UNIX origin time from Zulu time.
1014  * Following representations are supported:
1015  * <ul>
1016  * <li>YYYYMMDDHHmmSSZ - GeneralizedTime format</li>
1017  * <li>YYMMDDHHmmSSZ - UTCTime format. If YY is greater or equal to 
1018  * 50 then it represents 19YY otherwise 20YY.</li>
1019  * </ul>
1020  * @example
1021  * KJUR.jws.IntDate.getZulu("20151012125959Z") => 1478...
1022  * KJUR.jws.IntDate.getZulu("151012125959Z") => 1478...
1023  */
1024 KJUR.jws.IntDate.getZulu = function(s) {
1025     return zulutosec(s);
1026 };
1027 
1028 /**
1029  * get UNIX origin time of current time
1030  * @name getNow
1031  * @memberOf KJUR.jws.IntDate
1032  * @function
1033  * @static
1034  * @return {Integer} UNIX origin time for current time
1035  * @since jws 3.0.1
1036  * @description
1037  * This method provides UNIX origin time for current time
1038  * @example
1039  * KJUR.jws.IntDate.getNow() => 1478...
1040  */
1041 KJUR.jws.IntDate.getNow = function() {
1042     var d = ~~(new Date() / 1000);
1043     return d;
1044 };
1045 
1046 /**
1047  * get UTC time string from UNIX origin time value
1048  * @name intDate2UTCString
1049  * @memberOf KJUR.jws.IntDate
1050  * @function
1051  * @static
1052  * @param {Integer} intDate UNIX origin time value (ex. 1478...)
1053  * @return {String} UTC time string
1054  * @since jws 3.0.1
1055  * @description
1056  * This method provides UTC time string for UNIX origin time value.
1057  * @example
1058  * KJUR.jws.IntDate.intDate2UTCString(1478...) => "2015 Oct ..."
1059  */
1060 KJUR.jws.IntDate.intDate2UTCString = function(intDate) {
1061     var d = new Date(intDate * 1000);
1062     return d.toUTCString();
1063 };
1064 
1065 /**
1066  * get UTC time string from UNIX origin time value
1067  * @name intDate2Zulu
1068  * @memberOf KJUR.jws.IntDate
1069  * @function
1070  * @static
1071  * @param {Integer} intDate UNIX origin time value (ex. 1478...)
1072  * @return {String} Zulu time string
1073  * @since jws 3.0.1
1074  * @description
1075  * This method provides Zulu time string for UNIX origin time value.
1076  * @example
1077  * KJUR.jws.IntDate.intDate2UTCString(1478...) => "20151012...Z"
1078  */
1079 KJUR.jws.IntDate.intDate2Zulu = function(intDate) {
1080     var d = new Date(intDate * 1000),
1081 	year = ("0000" + d.getUTCFullYear()).slice(-4),
1082 	mon =  ("00" + (d.getUTCMonth() + 1)).slice(-2),
1083 	day =  ("00" + d.getUTCDate()).slice(-2),
1084 	hour = ("00" + d.getUTCHours()).slice(-2),
1085 	min =  ("00" + d.getUTCMinutes()).slice(-2),
1086         sec =  ("00" + d.getUTCSeconds()).slice(-2);
1087     return year + mon + day + hour + min + sec + "Z";
1088 };
1089 
1090