diff --git a/ChangeLog.txt b/ChangeLog.txt index 66c7626f..e1602f4c 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,13 @@ ChangeLog for jsrsasign +Time stamp package update +* Changes from 10.5.18 to 10.5.19 (2022-Apr-23) + - src/asn1tsp.js + - TimeStampResp class update to statusinfo member + will be optional. If omitted, it will be "granted" by default. + - API manual update for more detail + Time stamp package update * Changes from 10.5.17 to 10.5.18 (2022-Apr-22) - src/asn1tsp.js diff --git a/README.md b/README.md index 8fc82b99..420454d2 100755 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ HIGHLIGHTS - no dependency to other library - no dependency to [W3C Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) nor [OpenSSL](https://www.openssl.org/) - no dependency on newer ECMAScirpt function. So old browsers also supported. -- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-04-02) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-04-20) INSTALL ------- diff --git a/api/files.html b/api/files.html index 38711132..9349d23e 100644 --- a/api/files.html +++ b/api/files.html @@ -643,7 +643,7 @@

asn1tsp-1.0.js

Version:
-
jsrsasign 10.5.18 asn1tsp 2.0.6 (2022-Apr-22)
+
jsrsasign 10.5.19 asn1tsp 2.0.7 (2022-Apr-23)
diff --git a/api/symbols/KJUR.asn1.tsp.TSPParser.html b/api/symbols/KJUR.asn1.tsp.TSPParser.html index b10656e9..ae2f7bfe 100644 --- a/api/symbols/KJUR.asn1.tsp.TSPParser.html +++ b/api/symbols/KJUR.asn1.tsp.TSPParser.html @@ -1145,15 +1145,14 @@

-
var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602...");
-// resulted DUMP of above 'json':
-{
- messageImprint: {
+					
var parser = new KJUR.asn1.tsp.TSPParser();
+parser.getTimeStampReq("302602...") →
+{ messageImprint: {
       alg: 'sha256',          // MessageImprint hashAlg
       hash: 'a1a2a3a4...'},   // MessageImprint hashValue
- policy: '1.2.3.4.5',         // tsaPolicy (OPTION)
- nonce: '9abcf318...',        // nonce (OPTION)
- certreq: true }              // certReq (OPTION)
+ policy: '1.2.3.4.5', // tsaPolicy (OPTION) + nonce: '9abcf318...', // nonce (OPTION) + certreq: true } // certReq (OPTION)
@@ -1171,6 +1170,12 @@

+
+
Since:
+
jsrsasign 10.5.18 asn1tsp 2.0.6
+
+ +
@@ -1185,6 +1190,8 @@

See:
+
KJUR.asn1.tsp.TimeStampReq
+
KJUR.asn1.tsp.TSPUtil.parseTimeStampReq
diff --git a/api/symbols/KJUR.asn1.tsp.TimeStampResp.html b/api/symbols/KJUR.asn1.tsp.TimeStampResp.html index 4a9fe8a4..0101d9f3 100644 --- a/api/symbols/KJUR.asn1.tsp.TimeStampResp.html +++ b/api/symbols/KJUR.asn1.tsp.TimeStampResp.html @@ -558,12 +558,11 @@

-
class for TSP TimeStampResp ASN.1 object -
-TimeStampResp ::= SEQUENCE  {
-   status                  PKIStatusInfo,
-   timeStampToken          TimeStampToken     OPTIONAL  }
-
+
class for TSP TimeStampResp ASN.1 object
+This is an ASN.1 encoder for TimeStampResp +ASN.1 structure defined in + +RFC 3161 TSP section 2.4.2.
@@ -608,17 +607,81 @@

- class for TSP TimeStampResp ASN.1 object + class for TSP TimeStampResp ASN.1 object
+This is an ASN.1 encoder for TimeStampResp +ASN.1 structure defined in + +RFC 3161 TSP section 2.4.2. +
 TimeStampResp ::= SEQUENCE  {
    status                  PKIStatusInfo,
    timeStampToken          TimeStampToken     OPTIONAL  }
+
+TimeStampToken ::= ContentInfo
+
+TSTInfo ::= SEQUENCE  {
+   version           INTEGER  { v1(1) },
+   policy            TSAPolicyId,
+   messageImprint    MessageImprint,
+   serialNumber      INTEGER,
+   genTime           GeneralizedTime,
+   accuracy          Accuracy                 OPTIONAL,
+   ordering          BOOLEAN                  DEFAULT FALSE,
+   nonce             INTEGER                  OPTIONAL,
+   tsa               [0] GeneralName          OPTIONAL,
+   extensions        [1] IMPLICIT Extensions  OPTIONAL  }
 
+ +The constructor argument "params" can be used all of +KJUR.asn1.tsp.TimeStampToken object further more +following members can be specified: +
    +
  • statusinfo: any KJUR.asn1.tsp.PKIStatusInfo parameter. +When parameters for TimeStampToken is specified and statusinfo member is omitted, +status will be "granted" by default. (OPTIONAL)
  • +
  • tst: KJUR.asn1.tsp.TimeStampToken object instead of TimeStampToken members (OPTIONAL)
  • +
+
// by TimeStampToken parameters (statusinfo will be "granted" by default)
+new KJUR.asn1.tsp.TimeStampResp({
+  version: 1,
+  hashalgs: ["sha256"],
+  econtent: {
+    type: "tstinfo",
+    content: {
+      policy: "1.2.3.4.5",
+      messageImprint: {alg:"sha256", hash:"12ab..."},
+      serial: {"int": 3},
+      genTime: {millis: true}, // current time with millis
+      accuracy: { millis: 500 }
+    }
+  }
+  certs: [...],
+  sinfos: [{
+    version: 1,
+    id: {type:"isssn", cert: ...},
+    hashalg: "sha256",
+    sattrs: {array: [{...}]},
+    sigalg: "SHA256withRSA",
+    signkey: ...
+  }]
+})
+// by TimeStampToken object
+new KJUR.asn1.tsp.TimeStampResp({
+  tst: new KJUR.asn1.tsp.TimeStapToken(...)
+})
+// error case
+new KJUR.asn1.tsp.TimeStampResp({statusinfo: "rejection"})
+// finally, encode to hexadecimal string
+new KJUR.asn1.tsp.TimeStampResp(...).tohex() → "3082..."
+ + +
@@ -643,6 +706,15 @@

+
+
See:
+ +
KJUR.asn1.tsp.TimeStampToken
+ +
KJUR.asn1.tsp.PKIStatusInfo
+ +
+ diff --git a/api/symbols/src/asn1tsp-1.0.js.html b/api/symbols/src/asn1tsp-1.0.js.html index 0e9a4a0a..d713cf65 100644 --- a/api/symbols/src/asn1tsp-1.0.js.html +++ b/api/symbols/src/asn1tsp-1.0.js.html @@ -5,7 +5,7 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
  1 /* asn1tsp-2.0.6.js (c) 2014-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* asn1tsp-2.0.7.js (c) 2014-2022 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * asn1tsp.js - ASN.1 DER encoder classes for RFC 3161 Time Stamp Protocol
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name asn1tsp-1.0.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.5.18 asn1tsp 2.0.6 (2022-Apr-22)
+ 19  * @version jsrsasign 10.5.19 asn1tsp 2.0.7 (2022-Apr-23)
  20  * @since jsrsasign 4.5.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -471,1053 +471,1132 @@
 464 extendClass(KJUR.asn1.tsp.TimeStampReq, KJUR.asn1.ASN1Object);
 465 
 466 /**
-467  * class for TSP TimeStampResp ASN.1 object
+467  * class for TSP TimeStampResp ASN.1 object<br/>
 468  * @name KJUR.asn1.tsp.TimeStampResp
 469  * @class class for TSP TimeStampResp ASN.1 object
 470  * @param {Array} params associative array of parameters
 471  * @extends KJUR.asn1.ASN1Object
 472  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
-473  * @description
-474  * <pre>
-475  * TimeStampResp ::= SEQUENCE  {
-476  *    status                  PKIStatusInfo,
-477  *    timeStampToken          TimeStampToken     OPTIONAL  }
-478  * </pre>
-479  */
-480 KJUR.asn1.tsp.TimeStampResp = function(params) {
-481     var _KJUR = KJUR,
-482 	_KJUR_asn1 = _KJUR.asn1,
-483 	_DERSequence = _KJUR_asn1.DERSequence,
-484 	_ASN1Object = _KJUR_asn1.ASN1Object,
-485 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
-486 	_PKIStatusInfo = _KJUR_asn1_tsp.PKIStatusInfo;
-487 
-488     _KJUR_asn1_tsp.TimeStampResp.superclass.constructor.call(this);
-489 
-490     this.params = null;
-491 
-492     this.tohex = function() {
-493 	var params = this.params;
-494 
-495 	var a = [new _PKIStatusInfo(params.statusinfo)];
-496 
-497 	if (params.econtent != undefined) {
-498 	    a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo());
-499 	}
-500 
-501 	if (params.tst != undefined && 
-502 	    params.tst instanceof _KJUR_asn1.ASN1Object) {
-503 	    a.push(params.tst);
-504 	}
-505 
-506 	var seq = new _DERSequence({array: a});
-507 	return seq.tohex();
-508     };
-509     this.getEncodedHex = function() { return this.tohex(); };
-510 
-511     if (params != undefined) this.setByParam(params);
-512 };
-513 extendClass(KJUR.asn1.tsp.TimeStampResp, KJUR.asn1.ASN1Object);
-514 
-515 // --- BEGIN OF RFC 2510 CMP -----------------------------------------------
-516 
-517 /**
-518  * class for TSP PKIStatusInfo ASN.1 object
-519  * @name KJUR.asn1.tsp.PKIStatusInfo
-520  * @class class for TSP PKIStatusInfo ASN.1 object
-521  * @param {Array} params associative array of parameters
-522  * @extends KJUR.asn1.ASN1Object
-523  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
-524  * @see KJUR.asn1.tsp.PKIStatus
-525  * @see KJUR.asn1.tsp.PKIFreeText
-526  * @see KJUR.asn1.tsp.PKIFailureInfo
-527  * @see KJUR.asn1.tsp.TSPParser#getPKIStatusInfo
-528  *
-529  * @description
-530  * This class provides ASN.1 PKIStatusInfo encoder
-531  * defined in 
-532  * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2">
-533  * RFC 3161 section 2.4.2</a>.
-534  * <pre>
-535  * PKIStatusInfo ::= SEQUENCE {
-536  *    status                  PKIStatus,
-537  *    statusString            PKIFreeText     OPTIONAL,
-538  *    failInfo                PKIFailureInfo  OPTIONAL  }
-539  * </pre>
-540  *
-541  * @example
-542  * new KJUR.asn1.tsp.PKIStatusInfo("granted")
-543  * new KJUR.asn1.tsp.PKIStatusInfo({status: "granted"})
-544  * new KJUR.asn1.tsp.PKIStatusInfo({
-545  *   status: 2, // rejection
-546  *   statusstr: ["unsupported algorithm"], // OPTION
-547  *   failinfo: 'badAlg' // OPTION
-548  * })
-549  */
-550 KJUR.asn1.tsp.PKIStatusInfo = function(params) {
-551     var _Error = Error,
-552 	_KJUR = KJUR,
-553 	_KJUR_asn1 = _KJUR.asn1,
-554 	_DERSequence = _KJUR_asn1.DERSequence,
-555 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
-556 	_PKIStatus = _KJUR_asn1_tsp.PKIStatus,
-557 	_PKIFreeText = _KJUR_asn1_tsp.PKIFreeText,
-558 	_PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo;
-559 
-560     _KJUR_asn1_tsp.PKIStatusInfo.superclass.constructor.call(this);
-561 
-562     this.params = null;
-563 
-564     this.tohex = function() {
-565 	var params = this.params;
-566 
-567 	var a = [];
-568 	if (typeof params == "string") {
-569 	    a.push(new _PKIStatus(params));
-570 	} else {
-571 	    if (params.status == undefined)
-572 		throw new _Error("property 'status' unspecified");
-573 
-574 	    a.push(new _PKIStatus(params.status));
-575 
-576 	    if (params.statusstr != undefined)
-577 		a.push(new _PKIFreeText(params.statusstr));
-578 
-579 	    if (params.failinfo != undefined)
-580 		a.push(new _PKIFailureInfo(params.failinfo));
-581 	}
-582 
-583 	var seq = new _DERSequence({array: a});
-584 	return seq.tohex();
-585     };
-586     this.getEncodedHex = function() { return this.tohex(); };
-587 
-588     if (params != undefined) this.setByParam(params);
-589 };
-590 extendClass(KJUR.asn1.tsp.PKIStatusInfo, KJUR.asn1.ASN1Object);
-591 
-592 /**
-593  * class for TSP PKIStatus ASN.1 object
-594  * @name KJUR.asn1.tsp.PKIStatus
-595  * @class class for TSP PKIStatus ASN.1 object
-596  * @param {Array} params associative array of parameters
-597  * @extends KJUR.asn1.ASN1Object
-598  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
-599  * @description
-600  * <pre>
-601  * PKIStatus ::= INTEGER {
-602  *    granted                (0),
-603  *    grantedWithMods        (1),
-604  *    rejection              (2),
-605  *    waiting                (3),
-606  *    revocationWarning      (4),
-607  *    revocationNotification (5) }
-608  * </pre>
-609  *
-610  * @example
-611  * new KJUR.asn1.tsp.PKIStatus('granted')
-612  * new KJUR.asn1.tsp.PKIStatus(2)
-613  */
-614 KJUR.asn1.tsp.PKIStatus = function(params) {
-615     var _Error = Error,
-616 	_KJUR = KJUR,
-617 	_KJUR_asn1 = _KJUR.asn1,
-618 	_DERInteger = _KJUR_asn1.DERInteger,
-619 	_KJUR_asn1_tsp = _KJUR_asn1.tsp;
-620 
-621     _KJUR_asn1_tsp.PKIStatus.superclass.constructor.call(this);
-622 
-623     var _nameValue = {
-624 	granted:                0,
-625 	grantedWithMods:        1,
-626 	rejection:              2,
-627 	waiting:                3,
-628 	revocationWarning:      4,
-629 	revocationNotification: 5
-630     };
-631 
-632     this.params = null;
-633 
-634     this.tohex = function() {
-635 	var params = this.params;
-636 
-637 	var dObj, value;
+473  * @see KJUR.asn1.tsp.TimeStampToken
+474  * @see KJUR.asn1.tsp.PKIStatusInfo
+475  *
+476  * @description
+477  * This is an ASN.1 encoder for TimeStampResp
+478  * ASN.1 structure defined in
+479  * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2">
+480  * RFC 3161 TSP section 2.4.2</a>.
+481  * 
+482  * <pre>
+483  * TimeStampResp ::= SEQUENCE  {
+484  *    status                  PKIStatusInfo,
+485  *    timeStampToken          TimeStampToken     OPTIONAL  }
+486  *
+487  * TimeStampToken ::= ContentInfo
+488  *
+489  * TSTInfo ::= SEQUENCE  {
+490  *    version           INTEGER  { v1(1) },
+491  *    policy            TSAPolicyId,
+492  *    messageImprint    MessageImprint,
+493  *    serialNumber      INTEGER,
+494  *    genTime           GeneralizedTime,
+495  *    accuracy          Accuracy                 OPTIONAL,
+496  *    ordering          BOOLEAN                  DEFAULT FALSE,
+497  *    nonce             INTEGER                  OPTIONAL,
+498  *    tsa               [0] GeneralName          OPTIONAL,
+499  *    extensions        [1] IMPLICIT Extensions  OPTIONAL  }
+500  * </pre>
+501  *
+502  * The constructor argument "params" can be used all of 
+503  * {@link KJUR.asn1.tsp.TimeStampToken} object further more
+504  * following members can be specified:
+505  * <ul>
+506  * <li>statusinfo: any {@link KJUR.asn1.tsp.PKIStatusInfo} parameter.
+507  * When parameters for TimeStampToken is specified and statusinfo member is omitted, 
+508  * status will be "granted" by default. (OPTIONAL)</li>
+509  * <li>tst: {@link KJUR.asn1.tsp.TimeStampToken} object instead of TimeStampToken members (OPTIONAL)</li>
+510  * </ul>
+511  *
+512  * @example
+513  * // by TimeStampToken parameters (statusinfo will be "granted" by default)
+514  * new KJUR.asn1.tsp.TimeStampResp({
+515  *   version: 1,
+516  *   hashalgs: ["sha256"],
+517  *   econtent: {
+518  *     type: "tstinfo",
+519  *     content: {
+520  *       policy: "1.2.3.4.5",
+521  *       messageImprint: {alg:"sha256", hash:"12ab..."},
+522  *       serial: {"int": 3},
+523  *       genTime: {millis: true}, // current time with millis
+524  *       accuracy: { millis: 500 }
+525  *     }
+526  *   }
+527  *   certs: [...],
+528  *   sinfos: [{
+529  *     version: 1,
+530  *     id: {type:"isssn", cert: ...},
+531  *     hashalg: "sha256",
+532  *     sattrs: {array: [{...}]},
+533  *     sigalg: "SHA256withRSA",
+534  *     signkey: ...
+535  *   }]
+536  * })
+537  * // by TimeStampToken object
+538  * new KJUR.asn1.tsp.TimeStampResp({
+539  *   tst: new KJUR.asn1.tsp.TimeStapToken(...)
+540  * })
+541  * // error case
+542  * new KJUR.asn1.tsp.TimeStampResp({statusinfo: "rejection"})
+543  * // finally, encode to hexadecimal string
+544  * new KJUR.asn1.tsp.TimeStampResp(...).tohex() → "3082..."
+545  */
+546 KJUR.asn1.tsp.TimeStampResp = function(params) {
+547     var _KJUR = KJUR,
+548 	_KJUR_asn1 = _KJUR.asn1,
+549 	_DERSequence = _KJUR_asn1.DERSequence,
+550 	_ASN1Object = _KJUR_asn1.ASN1Object,
+551 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
+552 	_PKIStatusInfo = _KJUR_asn1_tsp.PKIStatusInfo;
+553 
+554     _KJUR_asn1_tsp.TimeStampResp.superclass.constructor.call(this);
+555 
+556     this.params = null;
+557 
+558     this.tohex = function() {
+559 	var params = this.params;
+560 
+561 	var a = [];
+562 
+563 	if (params.econtent != undefined || params.tst != undefined) {
+564 	    // statusInfo
+565 	    if (params.statusinfo != undefined) {
+566 		a.push(new _PKIStatusInfo(params.statusinfo));
+567 	    } else {
+568 		a.push(new _PKIStatusInfo("granted"));
+569 	    }
+570 	    
+571 	    // TimeStampToken
+572 	    if (params.econtent != undefined) {
+573 		a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo());
+574 	    } else if (params.tst instanceof _KJUR_asn1.ASN1Object) {
+575 		a.push(params.tst);
+576 	    } else {
+577 		throw new Error("improper member tst value");
+578 	    }
+579 	} else if (params.statusinfo != undefined) {
+580 	    a.push(new _PKIStatusInfo(params.statusinfo));
+581 	} else {
+582 	    throw new Error("parameter for token nor statusinfo not specified");
+583 	}
+584 	    
+585 	var seq = new _DERSequence({array: a});
+586 	return seq.tohex();
+587     };
+588     this.getEncodedHex = function() { return this.tohex(); };
+589 
+590     if (params != undefined) this.setByParam(params);
+591 };
+592 extendClass(KJUR.asn1.tsp.TimeStampResp, KJUR.asn1.ASN1Object);
+593 
+594 // --- BEGIN OF RFC 2510 CMP -----------------------------------------------
+595 
+596 /**
+597  * class for TSP PKIStatusInfo ASN.1 object
+598  * @name KJUR.asn1.tsp.PKIStatusInfo
+599  * @class class for TSP PKIStatusInfo ASN.1 object
+600  * @param {Array} params associative array of parameters
+601  * @extends KJUR.asn1.ASN1Object
+602  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
+603  * @see KJUR.asn1.tsp.PKIStatus
+604  * @see KJUR.asn1.tsp.PKIFreeText
+605  * @see KJUR.asn1.tsp.PKIFailureInfo
+606  * @see KJUR.asn1.tsp.TSPParser#getPKIStatusInfo
+607  *
+608  * @description
+609  * This class provides ASN.1 PKIStatusInfo encoder
+610  * defined in 
+611  * <a href="https://tools.ietf.org/html/rfc3161#section-2.4.2">
+612  * RFC 3161 section 2.4.2</a>.
+613  * <pre>
+614  * PKIStatusInfo ::= SEQUENCE {
+615  *    status                  PKIStatus,
+616  *    statusString            PKIFreeText     OPTIONAL,
+617  *    failInfo                PKIFailureInfo  OPTIONAL  }
+618  * </pre>
+619  *
+620  * @example
+621  * new KJUR.asn1.tsp.PKIStatusInfo("granted")
+622  * new KJUR.asn1.tsp.PKIStatusInfo({status: "granted"})
+623  * new KJUR.asn1.tsp.PKIStatusInfo({
+624  *   status: 2, // rejection
+625  *   statusstr: ["unsupported algorithm"], // OPTION
+626  *   failinfo: 'badAlg' // OPTION
+627  * })
+628  */
+629 KJUR.asn1.tsp.PKIStatusInfo = function(params) {
+630     var _Error = Error,
+631 	_KJUR = KJUR,
+632 	_KJUR_asn1 = _KJUR.asn1,
+633 	_DERSequence = _KJUR_asn1.DERSequence,
+634 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
+635 	_PKIStatus = _KJUR_asn1_tsp.PKIStatus,
+636 	_PKIFreeText = _KJUR_asn1_tsp.PKIFreeText,
+637 	_PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo;
 638 
-639 	if (typeof params == "string") {
-640 	    try {
-641 		value = _nameValue[params];
-642 	    } catch (ex) {
-643 		throw new _Error("undefined name: " + params);
-644 		}
-645 	} else if (typeof params == "number") {
-646 	    value = params;
-647 	} else {
-648 	    throw new _Error("unsupported params");
-649 	}
-650 
-651 	return (new _DERInteger({"int": value})).tohex();
-652     };
-653     this.getEncodedHex = function() { return this.tohex(); };
+639     _KJUR_asn1_tsp.PKIStatusInfo.superclass.constructor.call(this);
+640 
+641     this.params = null;
+642 
+643     this.tohex = function() {
+644 	var params = this.params;
+645 
+646 	var a = [];
+647 	if (typeof params == "string") {
+648 	    a.push(new _PKIStatus(params));
+649 	} else {
+650 	    if (params.status == undefined)
+651 		throw new _Error("property 'status' unspecified");
+652 
+653 	    a.push(new _PKIStatus(params.status));
 654 
-655     if (params != undefined) this.setByParam(params);
-656 };
-657 extendClass(KJUR.asn1.tsp.PKIStatus, KJUR.asn1.ASN1Object);
-658 
-659 /**
-660  * class for TSP PKIFreeText ASN.1 object
-661  * @name KJUR.asn1.tsp.PKIFreeText
-662  * @class class for TSP PKIFreeText ASN.1 object
-663  * @param {Array} params associative array of parameters
-664  * @extends KJUR.asn1.ASN1Object
-665  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
-666  * @description
-667  * This class provides ASN.1 encoder for PKIFreeText
-668  * defined in <a href="https://tools.ietf.org/html/rfc4210#section-5.1.1">
-669  * RFC 4210 CMP section 5.1.1</a>.
-670  * <pre>
-671  * PKIFreeText ::= SEQUENCE { SIZE (1..MAX) OF UTF8String }
-672  * </pre>
-673  * 
-674  * @example
-675  * new KJUR.asn1.tsp.PKIFreeText([
-676  *   "aaa", "bbb", "ccc"
-677  * ])
-678  */
-679 KJUR.asn1.tsp.PKIFreeText = function(params) {
-680     var _Error = Error,
-681 	_KJUR = KJUR,
-682 	_KJUR_asn1 = _KJUR.asn1,
-683 	_DERSequence = _KJUR_asn1.DERSequence,
-684 	_DERUTF8String = _KJUR_asn1.DERUTF8String,
-685 	_KJUR_asn1_tsp = _KJUR_asn1.tsp;
-686 
-687     _KJUR_asn1_tsp.PKIFreeText.superclass.constructor.call(this);
-688 
-689     this.params = null;
-690 
-691     this.tohex = function() {
-692 	var params = this.params;
-693 
-694 	if (! params instanceof Array)
-695 	    throw new _Error("wrong params: not array");
-696 
-697 	var a = [];
-698 	for (var i = 0; i < params.length; i++) {
-699 	    a.push(new _DERUTF8String({str: params[i]}));
-700 	};
-701 	
-702 	var seq = new _DERSequence({array: a});
-703 	return seq.tohex();
-704     };
-705     this.getEncodedHex = function() { return this.tohex(); };
-706 
-707     if (params != undefined) this.setByParam(params);
-708 };
-709 extendClass(KJUR.asn1.tsp.PKIFreeText, KJUR.asn1.ASN1Object);
+655 	    if (params.statusstr != undefined)
+656 		a.push(new _PKIFreeText(params.statusstr));
+657 
+658 	    if (params.failinfo != undefined)
+659 		a.push(new _PKIFailureInfo(params.failinfo));
+660 	}
+661 
+662 	var seq = new _DERSequence({array: a});
+663 	return seq.tohex();
+664     };
+665     this.getEncodedHex = function() { return this.tohex(); };
+666 
+667     if (params != undefined) this.setByParam(params);
+668 };
+669 extendClass(KJUR.asn1.tsp.PKIStatusInfo, KJUR.asn1.ASN1Object);
+670 
+671 /**
+672  * class for TSP PKIStatus ASN.1 object
+673  * @name KJUR.asn1.tsp.PKIStatus
+674  * @class class for TSP PKIStatus ASN.1 object
+675  * @param {Array} params associative array of parameters
+676  * @extends KJUR.asn1.ASN1Object
+677  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
+678  * @description
+679  * <pre>
+680  * PKIStatus ::= INTEGER {
+681  *    granted                (0),
+682  *    grantedWithMods        (1),
+683  *    rejection              (2),
+684  *    waiting                (3),
+685  *    revocationWarning      (4),
+686  *    revocationNotification (5) }
+687  * </pre>
+688  *
+689  * @example
+690  * new KJUR.asn1.tsp.PKIStatus('granted')
+691  * new KJUR.asn1.tsp.PKIStatus(2)
+692  */
+693 KJUR.asn1.tsp.PKIStatus = function(params) {
+694     var _Error = Error,
+695 	_KJUR = KJUR,
+696 	_KJUR_asn1 = _KJUR.asn1,
+697 	_DERInteger = _KJUR_asn1.DERInteger,
+698 	_KJUR_asn1_tsp = _KJUR_asn1.tsp;
+699 
+700     _KJUR_asn1_tsp.PKIStatus.superclass.constructor.call(this);
+701 
+702     var _nameValue = {
+703 	granted:                0,
+704 	grantedWithMods:        1,
+705 	rejection:              2,
+706 	waiting:                3,
+707 	revocationWarning:      4,
+708 	revocationNotification: 5
+709     };
 710 
-711 /**
-712  * class for TSP PKIFailureInfo ASN.1 object
-713  * @name KJUR.asn1.tsp.PKIFailureInfo
-714  * @class class for TSP PKIFailureInfo ASN.1 object
-715  * @param {Array} params associative array of parameters
-716  * @extends KJUR.asn1.ASN1Object
-717  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
-718  * @description
-719  * <pre>
-720  * PKIFailureInfo ::= BIT STRING {
-721  *    badAlg                 (0),
-722  *    badRequest             (2),
-723  *    badDataFormat          (5),
-724  *    timeNotAvailable       (14),
-725  *    unacceptedPolicy       (15),
-726  *    unacceptedExtension    (16),
-727  *    addInfoNotAvailable    (17),
-728  *    systemFailure          (25) }
-729  * </pre>
-730  * 
-731  * @example
-732  * new KJUR.asn1.tsp.PKIFailureInfo('badAlg')
-733  * new KJUR.asn1.tsp.PKIFailureInfo(5)
-734  */
-735 KJUR.asn1.tsp.PKIFailureInfo = function(params) {
-736     var _Error = Error,
-737 	_KJUR = KJUR,
-738 	_KJUR_asn1 = _KJUR.asn1,
-739 	_DERBitString = _KJUR_asn1.DERBitString,
-740 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
-741 	_PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo;
-742 
-743     var _nameValue = {
-744 	badAlg:                 0,
-745 	badRequest:             2,
-746 	badDataFormat:          5,
-747 	timeNotAvailable:       14,
-748 	unacceptedPolicy:       15,
-749 	unacceptedExtension:    16,
-750 	addInfoNotAvailable:    17,
-751 	systemFailure:          25
-752     };
-753 
-754     _PKIFailureInfo.superclass.constructor.call(this);
-755 
-756     this.params = null;
-757 
-758     this.tohex = function() {
-759 	var params = this.params;
-760 
-761 	var value;
-762 	if (typeof params == "string") {
-763 	    try {
-764 		value = _nameValue[params];
-765 	    } catch(ex) {
-766 		throw new _Error("undefined name: " + params);
-767 	    }
-768 	} else if (typeof params == "number") {
-769 	    value = params;
-770 	} else {
-771 	    throw new _Error("wrong params");
-772 	}
-773 	return (new _DERBitString({"bin": value.toString(2)})).tohex();
-774     };
-775     this.getEncodedHex = function() { return this.tohex(); };
-776 
-777     if (params != undefined) this.setByParam(params);
-778 };
-779 extendClass(KJUR.asn1.tsp.PKIFailureInfo, KJUR.asn1.ASN1Object);
-780 
-781 // --- END OF RFC 2510 CMP -------------------------------------------
-782 
-783 /**
-784  * abstract class for TimeStampToken generator (DEPRECATED)<br/>
-785  * @name KJUR.asn1.tsp.AbstractTSAAdapter
-786  * @class abstract class for TimeStampToken generator
-787  * @param {Array} params associative array of parameters
-788  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
-789  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
-790  *
-791  * @description
-792  * This is abstract class for TimeStampToken generator.
-793  */
-794 KJUR.asn1.tsp.AbstractTSAAdapter = function(params) {
-795     this.getTSTHex = function(msgHex, hashAlg) {
-796         throw "not implemented yet";
-797     };
-798 };
-799 
-800 /**
-801  * class for simple TimeStampToken generator (DEPRECATED)<br/>
-802  * @name KJUR.asn1.tsp.SimpleTSAAdapter
-803  * @class class for simple TimeStampToken generator
-804  * @extends KJUR.asn1.tsp.AbstractTSAAdapter
-805  * @param {Array} params associative array of parameters
-806  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
-807  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
-808  *
-809  * @description
-810  * This is a simple TimeStampToken generator class.
-811  */
-812 KJUR.asn1.tsp.SimpleTSAAdapter = function(params) {
-813     var _KJUR = KJUR,
-814 	_KJUR_asn1 = _KJUR.asn1,
-815 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
-816 	_hashHex = _KJUR.crypto.Util.hashHex;
-817 
-818     _KJUR_asn1_tsp.SimpleTSAAdapter.superclass.constructor.call(this);
-819     this.params = null;
-820     this.serial = 0;
+711     this.params = null;
+712 
+713     this.tohex = function() {
+714 	var params = this.params;
+715 
+716 	var dObj, value;
+717 
+718 	if (typeof params == "string") {
+719 	    try {
+720 		value = _nameValue[params];
+721 	    } catch (ex) {
+722 		throw new _Error("undefined name: " + params);
+723 		}
+724 	} else if (typeof params == "number") {
+725 	    value = params;
+726 	} else {
+727 	    throw new _Error("unsupported params");
+728 	}
+729 
+730 	return (new _DERInteger({"int": value})).tohex();
+731     };
+732     this.getEncodedHex = function() { return this.tohex(); };
+733 
+734     if (params != undefined) this.setByParam(params);
+735 };
+736 extendClass(KJUR.asn1.tsp.PKIStatus, KJUR.asn1.ASN1Object);
+737 
+738 /**
+739  * class for TSP PKIFreeText ASN.1 object
+740  * @name KJUR.asn1.tsp.PKIFreeText
+741  * @class class for TSP PKIFreeText ASN.1 object
+742  * @param {Array} params associative array of parameters
+743  * @extends KJUR.asn1.ASN1Object
+744  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
+745  * @description
+746  * This class provides ASN.1 encoder for PKIFreeText
+747  * defined in <a href="https://tools.ietf.org/html/rfc4210#section-5.1.1">
+748  * RFC 4210 CMP section 5.1.1</a>.
+749  * <pre>
+750  * PKIFreeText ::= SEQUENCE { SIZE (1..MAX) OF UTF8String }
+751  * </pre>
+752  * 
+753  * @example
+754  * new KJUR.asn1.tsp.PKIFreeText([
+755  *   "aaa", "bbb", "ccc"
+756  * ])
+757  */
+758 KJUR.asn1.tsp.PKIFreeText = function(params) {
+759     var _Error = Error,
+760 	_KJUR = KJUR,
+761 	_KJUR_asn1 = _KJUR.asn1,
+762 	_DERSequence = _KJUR_asn1.DERSequence,
+763 	_DERUTF8String = _KJUR_asn1.DERUTF8String,
+764 	_KJUR_asn1_tsp = _KJUR_asn1.tsp;
+765 
+766     _KJUR_asn1_tsp.PKIFreeText.superclass.constructor.call(this);
+767 
+768     this.params = null;
+769 
+770     this.tohex = function() {
+771 	var params = this.params;
+772 
+773 	if (! params instanceof Array)
+774 	    throw new _Error("wrong params: not array");
+775 
+776 	var a = [];
+777 	for (var i = 0; i < params.length; i++) {
+778 	    a.push(new _DERUTF8String({str: params[i]}));
+779 	};
+780 	
+781 	var seq = new _DERSequence({array: a});
+782 	return seq.tohex();
+783     };
+784     this.getEncodedHex = function() { return this.tohex(); };
+785 
+786     if (params != undefined) this.setByParam(params);
+787 };
+788 extendClass(KJUR.asn1.tsp.PKIFreeText, KJUR.asn1.ASN1Object);
+789 
+790 /**
+791  * class for TSP PKIFailureInfo ASN.1 object
+792  * @name KJUR.asn1.tsp.PKIFailureInfo
+793  * @class class for TSP PKIFailureInfo ASN.1 object
+794  * @param {Array} params associative array of parameters
+795  * @extends KJUR.asn1.ASN1Object
+796  * @since jsrsasign 4.6.0 asn1tsp 1.0.0
+797  * @description
+798  * <pre>
+799  * PKIFailureInfo ::= BIT STRING {
+800  *    badAlg                 (0),
+801  *    badRequest             (2),
+802  *    badDataFormat          (5),
+803  *    timeNotAvailable       (14),
+804  *    unacceptedPolicy       (15),
+805  *    unacceptedExtension    (16),
+806  *    addInfoNotAvailable    (17),
+807  *    systemFailure          (25) }
+808  * </pre>
+809  * 
+810  * @example
+811  * new KJUR.asn1.tsp.PKIFailureInfo('badAlg')
+812  * new KJUR.asn1.tsp.PKIFailureInfo(5)
+813  */
+814 KJUR.asn1.tsp.PKIFailureInfo = function(params) {
+815     var _Error = Error,
+816 	_KJUR = KJUR,
+817 	_KJUR_asn1 = _KJUR.asn1,
+818 	_DERBitString = _KJUR_asn1.DERBitString,
+819 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
+820 	_PKIFailureInfo = _KJUR_asn1_tsp.PKIFailureInfo;
 821 
-822     this.getTSTHex = function(msgHex, hashAlg) {
-823         // messageImprint
-824         var hashHex = _hashHex(msgHex, hashAlg);
-825         this.params.econtent.content.messageImprint =
-826             {alg: hashAlg, hash: hashHex};
-827 
-828         // serial
-829         this.params.econtent.content.serial =
-830 	    {'int': this.serial++};
-831 
-832         // nonce
-833         var nonceValue = Math.floor(Math.random() * 1000000000);
-834         this.params.econtent.content.nonce =
-835 	    {'int': nonceValue};
+822     var _nameValue = {
+823 	badAlg:                 0,
+824 	badRequest:             2,
+825 	badDataFormat:          5,
+826 	timeNotAvailable:       14,
+827 	unacceptedPolicy:       15,
+828 	unacceptedExtension:    16,
+829 	addInfoNotAvailable:    17,
+830 	systemFailure:          25
+831     };
+832 
+833     _PKIFailureInfo.superclass.constructor.call(this);
+834 
+835     this.params = null;
 836 
-837         var obj = 
-838             new _KJUR_asn1_tsp.TimeStampToken(this.params);
-839         return obj.getContentInfoEncodedHex();
-840     };
-841 
-842     if (params !== undefined) this.params = params;
-843 };
-844 extendClass(KJUR.asn1.tsp.SimpleTSAAdapter,
-845             KJUR.asn1.tsp.AbstractTSAAdapter);
-846 
-847 /**
-848  * class for fixed TimeStampToken generator (DEPRECATED)<br/>
-849  * @name KJUR.asn1.tsp.FixedTSAAdapter
-850  * @class class for fixed TimeStampToken generator
-851  * @extends KJUR.asn1.tsp.AbstractTSAAdapter
-852  * @param {Array} params associative array of parameters
-853  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
-854  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
-855  *
-856  * @description
-857  * This class generates fixed TimeStampToken except messageImprint
-858  * for testing purpose.
-859  * General TSA generates TimeStampToken which varies following
-860  * fields:
-861  * <ul>
-862  * <li>genTime</li>
-863  * <li>serialNumber</li>
-864  * <li>nonce</li>
-865  * </ul>
-866  * Those values are provided by initial parameters.
-867  */
-868 KJUR.asn1.tsp.FixedTSAAdapter = function(params) {
-869     var _KJUR = KJUR,
-870 	_KJUR_asn1 = _KJUR.asn1,
-871 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
-872 	_hashHex = _KJUR.crypto.Util.hashHex;
-873 
-874     _KJUR_asn1_tsp.FixedTSAAdapter.superclass.constructor.call(this);
-875     this.params = null;
-876 
-877     this.getTSTHex = function(msgHex, hashAlg) {
-878         // fixed serialNumber
-879         // fixed nonce        
-880         var hashHex = _hashHex(msgHex, hashAlg);
-881         this.params.econtent.content.messageImprint =
-882             {alg: hashAlg, hash: hashHex};
-883         var obj = new _KJUR_asn1_tsp.TimeStampToken(this.params);
-884         return obj.getContentInfoEncodedHex();
-885     };
-886 
-887     if (params !== undefined) this.params = params;
-888 };
-889 extendClass(KJUR.asn1.tsp.FixedTSAAdapter,
-890             KJUR.asn1.tsp.AbstractTSAAdapter);
-891 
-892 // --- TSP utilities -------------------------------------------------
-893 
-894 /**
-895  * TSP utiliteis class
-896  * @name KJUR.asn1.tsp.TSPUtil
-897  * @class TSP utilities class
-898  */
-899 KJUR.asn1.tsp.TSPUtil = new function() {
-900 };
-901 /**
-902  * generate TimeStampToken ASN.1 object specified by JSON parameters (DEPRECATED)<br/>
-903  * @name newTimeStampToken
-904  * @memberOf KJUR.asn1.tsp.TSPUtil
-905  * @function
-906  * @param {Array} param JSON parameter to generate TimeStampToken
-907  * @return {KJUR.asn1.cms.SignedData} object just generated
-908  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0. Please use TimeStampToken class
-909  * @see KJUR.asn1.tsp.TimeStampToken
-910  *
-911  * @description
-912  * @example
-913  */
-914 KJUR.asn1.tsp.TSPUtil.newTimeStampToken = function(params) {
-915     return new KJUR.asn1.tsp.TimeStampToken(params);
-916 };
-917 
-918 /**
-919  * parse hexadecimal string of TimeStampReq
-920  * @name parseTimeStampReq
-921  * @memberOf KJUR.asn1.tsp.TSPUtil
-922  * @function
-923  * @param {String} hexadecimal string of TimeStampReq
-924  * @return {Array} JSON object of parsed parameters
-925  * @see KJUR.asn1.tsp.TSPParser#getTimeStampReq
-926  * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getTimeStampReq instead.
-927  *
-928  * @description
-929  * This method parses a hexadecimal string of TimeStampReq
-930  * and returns parsed their fields:
-931  *
-932  * @example
-933  * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602...");
-934  * // resulted DUMP of above 'json':
-935  * {
-936  *  messageImprint: {
-937  *       alg: 'sha256',          // MessageImprint hashAlg
-938  *       hash: 'a1a2a3a4...'},   // MessageImprint hashValue
-939  *  policy: '1.2.3.4.5',             // tsaPolicy (OPTION)
-940  *  nonce: '9abcf318...',            // nonce (OPTION)
-941  *  certreq: true}                   // certReq (OPTION)
-942  */
-943 KJUR.asn1.tsp.TSPUtil.parseTimeStampReq = function(reqHex) {
-944     var parser = new KJUR.asn1.tsp.TSPParser();
-945     return parser.getTimeStampReq(reqHex);
-946 };
-947 
-948 /**
-949  * parse hexadecimal string of MessageImprint
-950  * @name parseMessageImprint
-951  * @memberOf KJUR.asn1.tsp.TSPUtil
-952  * @function
-953  * @param {String} hexadecimal string of MessageImprint
-954  * @return {Array} JSON object of parsed parameters
-955  * @see KJUR.asn1.tsp.TSPParser#getMessageImprint
-956  * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getMessageImprint instead.
-957  *
-958  * @description
-959  * This method parses a hexadecimal string of MessageImprint
-960  * and returns parsed their fields:
-961  *
-962  * @example
-963  * KJUR.asn1.tsp.TSPUtil.parseMessageImprint("302602...") →
-964  * { alg:  'sha256', hash: 'a1a2a3a4...'}
-965  */
-966 KJUR.asn1.tsp.TSPUtil.parseMessageImprint = function(miHex) {
-967     var parser = new KJUR.asn1.tsp.TSPParser();
-968     return parser.getMessageImprint(miHex);
-969 /*
-970     var _ASN1HEX = ASN1HEX;
-971     var _getChildIdx = _ASN1HEX.getChildIdx;
-972     var _getV = _ASN1HEX.getV;
-973     var _getIdxbyList = _ASN1HEX.getIdxbyList;
-974     var json = {};
-975 
-976     if (miHex.substr(0, 2) != "30")
-977         throw "head of messageImprint hex shall be '30'";
-978 
-979     var idxList = _getChildIdx(miHex, 0);
-980     var hashAlgOidIdx = _getIdxbyList(miHex, 0, [0, 0]);
-981     var hashAlgHex = _getV(miHex, hashAlgOidIdx);
-982     var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex);
-983     var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid);
-984     if (hashAlgName == '')
-985         throw "hashAlg name undefined: " + hashAlgOid;
-986     var hashAlg = hashAlgName;
-987     var hashValueIdx = _getIdxbyList(miHex, 0, [1]);
-988 
-989     json.alg = hashAlg;
-990     json.hash = _getV(miHex, hashValueIdx); 
-991 
-992     return json;
-993 */
-994 };
-995 
-996 /**
-997  * class for parsing RFC 3161 TimeStamp protocol data<br/>
-998  * @name KJUR.asn1.tsp.TSPParser
-999  * @class RFC 3161 TimeStamp protocol parser class
-1000  * @since jsrsasign 10.1.0 asn1tsp 2.0.1
-1001  *
-1002  * @description
-1003  * This is an ASN.1 parser for 
-1004  * <a href="https://tools.ietf.org/html/rfc3161">RFC 3161</a>.
-1005  */
-1006 KJUR.asn1.tsp.TSPParser = function() {
-1007     var _Error = Error,
-1008 	_X509 = X509,
-1009 	_x509obj = new _X509(),
-1010 	_ASN1HEX = ASN1HEX,
-1011 	_getV = _ASN1HEX.getV,
-1012 	_getTLV = _ASN1HEX.getTLV,
-1013 	_getIdxbyList = _ASN1HEX.getIdxbyList,
-1014 	_getTLVbyListEx = _ASN1HEX.getTLVbyListEx,
-1015 	_getChildIdx = _ASN1HEX.getChildIdx;
-1016     var _aSTATUSSTR = [
-1017 	"granted", "grantedWithMods", "rejection", "waiting",
-1018 	"revocationWarning", "revocationNotification" ];
-1019     var _pFAILUREINFO = {
-1020 	0: "badAlg", 2: "badRequest", 5: "badDataFormat",
-1021 	14: "timeNotAvailable", 15: "unacceptedPolicy",
-1022 	16: "unacceptedExtension", 17: "addInfoNotAvailable",
-1023 	25: "systemFailure"
-1024     };
-1025     
-1026     /**
-1027      * parse ASN.1 TimeStampResp<br/>
-1028      * @name getResponse
-1029      * @memberOf KJUR.asn1.tsp.TSPParser#
-1030      * @function
-1031      * @param {String} h hexadecimal string of ASN.1 TimeStampResp
-1032      * @return {Array} JSON object of TimeStampResp parameter
-1033      * @see KJUR.asn1.tsp.TimeStampResp
-1034      * @see KJUR.asn1.tsp.TimeStampToken
-1035      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
-1036      *
-1037      * @description
-1038      * This method parses ASN.1 TimeStampRsp defined in RFC 3161.
-1039      * <pre>
-1040      * TimeStampResp ::= SEQUENCE {
-1041      *   status          PKIStatusInfo,
-1042      *   timeStampToken  TimeStampToken  OPTIONAL }
-1043      * </pre>
-1044      * When "h" is a TSP error response,
-1045      * returned parameter contains "statusinfo" only.
-1046      *
-1047      * @example
-1048      * parser = new KJUR.asn1.tsp.TSPParser();
-1049      * parser.getResponse("30...") →
-1050      * { 
-1051      *   statusinfo: 'granted',
-1052      *   ... // almost the same as CMS SignedData parameters
-1053      *   econtent: {
-1054      *     type: "tstinfo",
-1055      *     content: { // TSTInfo parameter
-1056      *       policy: '1.2.3.4.5',
-1057      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
-1058      *       serial: {'int': 3},
-1059      *       genTime: {str: '20131231235959.123Z'},
-1060      *       accuracy: {millis: 500},
-1061      *       ordering: true,
-1062      *       nonce: {int: 3}
-1063      *     }
-1064      *   },
-1065      *   ...
-1066      * }
-1067      */
-1068     this.getResponse = function(h) {
-1069 	var aIdx = _getChildIdx(h, 0);
-1070 	
-1071 	if (aIdx.length == 1) {
-1072 	    return this.getPKIStatusInfo(_getTLV(h, aIdx[0]));
-1073 	} else if (aIdx.length > 1) {
-1074 	    var pPKIStatusInfo = this.getPKIStatusInfo(_getTLV(h, aIdx[0]));
-1075 	    var hTST = _getTLV(h, aIdx[1]);
-1076 	    var pResult = this.getToken(hTST);
-1077 	    pResult.statusinfo = pPKIStatusInfo;
-1078 	    return pResult;
-1079 	}
-1080     };
-1081 
-1082     /**
-1083      * parse ASN.1 TimeStampToken<br/>
-1084      * @name getToken
-1085      * @memberOf KJUR.asn1.tsp.TSPParser#
-1086      * @function
-1087      * @param {String} h hexadecimal string of ASN.1 TimeStampToken
-1088      * @return {Array} JSON object of TimeStampToken parameter
-1089      * @see KJUR.asn1.tsp.TimeStampToken
-1090      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
-1091      * @see KJUR.asn1.tsp.TSPParser#setTSTInfo
-1092      *
-1093      * @description
-1094      * This method parses ASN.1 TimeStampRsp defined in RFC 3161.
-1095      * This method will parse "h" as CMS SigneData by
-1096      * {@link KJUR.asn1.cms.CMSParser#getCMSSignedData}, then
-1097      * parse and modify "econtent.content" parameter by
-1098      * {@link KJUR.asn1.tsp.TSPParser#setTSTInfo} method.
-1099      *
-1100      * @example
-1101      * parser = new KJUR.asn1.tsp.TSPParser();
-1102      * parser.getToken("30...") →
-1103      * { 
-1104      *   ... // almost the same as CMS SignedData parameters
-1105      *   econtent: {
-1106      *     type: "tstinfo",
-1107      *     content: { // TSTInfo parameter
-1108      *       policy: '1.2.3.4.5',
-1109      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
-1110      *       serial: {'int': 3},
-1111      *       genTime: {str: '20131231235959.123Z'},
-1112      *       accuracy: {millis: 500},
-1113      *       ordering: true,
-1114      *       nonce: {int: 3}
-1115      *     }
-1116      *   },
-1117      *   ...
-1118      * }
-1119      */
-1120     this.getToken = function(h) {
-1121 	var _CMSParser = new KJUR.asn1.cms.CMSParser;
-1122 	var p = _CMSParser.getCMSSignedData(h);
-1123 	this.setTSTInfo(p);
-1124 	return p;
-1125     };
-1126 
-1127     /**
-1128      * set ASN.1 TSTInfo parameter to CMS SignedData parameter<br/>
-1129      * @name setTSTInfo
-1130      * @memberOf KJUR.asn1.tsp.TSPParser#
-1131      * @function
-1132      * @param {Array} pCMSSignedData JSON object of CMS SignedData parameter
-1133      * @see KJUR.asn1.tsp.TimeStampToken
-1134      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
-1135      *
-1136      * @description
-1137      * This method modifies "econtent.content" of CMS SignedData parameter
-1138      * to parsed TSTInfo.
-1139      * <pre>
-1140      *
-1141      * @example
-1142      * parser = new KJUR.asn1.tsp.TSPParser();
-1143      * pCMSSignedData = { 
-1144      *   ... // almost the same as CMS SignedData parameters
-1145      *   econtent: {
-1146      *     type: "tstinfo",
-1147      *     content: { hex: "30..." }
-1148      *   },
-1149      *   ...
-1150      * };
-1151      * parser.setTSTInfo(pCMSSignedData);
-1152      * pCMSSignedData → { 
-1153      *   ... // almost the same as CMS SignedData parameters
-1154      *   econtent: {
-1155      *     type: "tstinfo",
-1156      *     content: { // TSTInfo parameter
-1157      *       policy: '1.2.3.4.5',
-1158      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
-1159      *       serial: {int: 3},
-1160      *       genTime: {str: '20131231235959.123Z'},
-1161      *       accuracy: {millis: 500},
-1162      *       ordering: true,
-1163      *       nonce: {int: 3}
-1164      *     }
-1165      *   },
-1166      *   ...
-1167      * };
-1168      */
-1169     this.setTSTInfo = function(pCMSSignedData) {
-1170 	var pEContent = pCMSSignedData.econtent;
-1171 	if (pEContent.type == "tstinfo") {
-1172 	    var hContent = pEContent.content.hex;
-1173 	    var pTSTInfo = this.getTSTInfo(hContent);
-1174 	    //pTSTInfo.hex_ = hContent;
-1175 	    pEContent.content = pTSTInfo;
-1176 	}
-1177     };
-1178 
-1179     /**
-1180      * parse ASN.1 TSTInfo<br/>
-1181      * @name getTSTInfo
-1182      * @memberOf KJUR.asn1.tsp.TSPParser#
-1183      * @function
-1184      * @param {String} h hexadecimal string of ASN.1 TSTInfo
-1185      * @return {Array} JSON object of TSTInfo parameter
-1186      * @see KJUR.asn1.tsp.TSTInfo
-1187      *
-1188      * @description
-1189      * This method parses ASN.1 TSTInfo defined in RFC 3161.
-1190      * <pre>
-1191      * TSTInfo ::= SEQUENCE  {
-1192      *    version          INTEGER  { v1(1) },
-1193      *    policy           TSAPolicyId,
-1194      *    messageImprint   MessageImprint,
-1195      *    serialNumber     INTEGER,
-1196      *    genTime          GeneralizedTime,
-1197      *    accuracy         Accuracy                 OPTIONAL,
-1198      *    ordering         BOOLEAN             DEFAULT FALSE,
-1199      *    nonce            INTEGER                  OPTIONAL,
-1200      *    tsa              [0] GeneralName          OPTIONAL,
-1201      *    extensions       [1] IMPLICIT Extensions  OPTIONAL }
-1202      * </pre>
-1203      *
-1204      * @example
-1205      * parser = new KJUR.asn1.tsp.TSPParser();
-1206      * parser.getTSTInfo("30...") →
-1207      * {
-1208      *   policy: '1.2.3.4.5',
-1209      *   messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
-1210      *   serial: {'int': 3},
-1211      *   genTime: {str: '20131231235959.123Z'},
-1212      *   accuracy: {millis: 500},
-1213      *   ordering: true,
-1214      *   nonce: {int: 3}
-1215      * }
-1216      */
-1217     this.getTSTInfo = function(h) {
-1218 	var pResult = {};
-1219 	var aIdx = _getChildIdx(h, 0);
-1220 
-1221 	var hPolicy = _getV(h, aIdx[1]);
-1222 	pResult.policy = hextooid(hPolicy);
-1223 
-1224 	var hMessageImprint = _getTLV(h, aIdx[2]);
-1225 	pResult.messageImprint = this.getMessageImprint(hMessageImprint);
-1226 
-1227 	var hSerial = _getV(h, aIdx[3]);
-1228 	pResult.serial = {hex: hSerial};
-1229 
-1230 	var hGenTime = _getV(h, aIdx[4]);
-1231 	pResult.genTime = {str: hextoutf8(hGenTime)};
-1232 
-1233 	var offset = 0;
-1234 
-1235 	if (aIdx.length > 5 && h.substr(aIdx[5], 2) == "30") {
-1236 	    var hAccuracy = _getTLV(h, aIdx[5]);
-1237 	    pResult.accuracy = this.getAccuracy(hAccuracy);
-1238 	    offset++;
-1239 	}
-1240 
-1241 	if (aIdx.length > 5 + offset && 
-1242 	    h.substr(aIdx[5 + offset], 2) == "01") {
-1243 	    var hOrdering = _getV(h, aIdx[5 + offset]);
-1244 	    if (hOrdering == "ff") pResult.ordering = true;
-1245 	    offset++;
-1246 	}
-1247 
-1248 	if (aIdx.length > 5 + offset &&
-1249 	    h.substr(aIdx[5 + offset], 2) == "02") {
-1250 	    var hNonce = _getV(h, aIdx[5 + offset]);
-1251 	    pResult.nonce = {hex: hNonce};
-1252 	    offset++;
-1253 	}
-1254 
-1255 	if (aIdx.length > 5 + offset &&
-1256 	    h.substr(aIdx[5 + offset], 2) == "a0") {
-1257 	    var hGeneralNames = _getTLV(h, aIdx[5 + offset]);
-1258 	    hGeneralNames = "30" + hGeneralNames.substr(2);
-1259 	    pGeneralNames = _x509obj.getGeneralNames(hGeneralNames);
-1260 	    var pName = pGeneralNames[0].dn;
-1261 	    pResult.tsa = pName;
-1262 	    offset++;
-1263 	}
-1264 
-1265 	if (aIdx.length > 5 + offset &&
-1266 	    h.substr(aIdx[5 + offset], 2) == "a1") {
-1267 	    var hExt = _getTLV(h, aIdx[5 + offset]);
-1268 	    hExt = "30" + hExt.substr(2);
-1269 	    var aExt = _x509obj.getExtParamArray(hExt);
-1270 	    pResult.ext = aExt;
-1271 	    offset++;
-1272 	}
-1273 
-1274 	return pResult;
-1275     };
-1276 
-1277     /**
-1278      * parse ASN.1 Accuracy<br/>
-1279      * @name getAccuracy
-1280      * @memberOf KJUR.asn1.tsp.TSPParser#
-1281      * @function
-1282      * @param {String} h hexadecimal string of ASN.1 Accuracy
-1283      * @return {Array} JSON object of Accuracy parameter
-1284      * @see KJUR.asn1.tsp.Accuracy
-1285      *
-1286      * @description
-1287      * This method parses ASN.1 Accuracy defined in RFC 3161.
-1288      * <pre>
-1289      * Accuracy ::= SEQUENCE {
-1290      *    seconds        INTEGER              OPTIONAL,
-1291      *    millis     [0] INTEGER  (1..999)    OPTIONAL,
-1292      *    micros     [1] INTEGER  (1..999)    OPTIONAL  }
-1293      * </pre>
-1294      *
-1295      * @example
-1296      * parser = new KJUR.asn1.tsp.TSPParser();
-1297      * parser.getAccuracy("30...") → {millis: 500}
-1298      */
-1299     this.getAccuracy = function(h) {
-1300 	var pResult = {};
-1301 
-1302 	var aIdx = _getChildIdx(h, 0);
-1303 
-1304 	for (var i = 0; i < aIdx.length; i++) {
-1305 	    var tag = h.substr(aIdx[i], 2);
-1306 	    var hV = _getV(h, aIdx[i]);
-1307 	    var iV = parseInt(hV, 16);
+837     this.tohex = function() {
+838 	var params = this.params;
+839 
+840 	var value;
+841 	if (typeof params == "string") {
+842 	    try {
+843 		value = _nameValue[params];
+844 	    } catch(ex) {
+845 		throw new _Error("undefined name: " + params);
+846 	    }
+847 	} else if (typeof params == "number") {
+848 	    value = params;
+849 	} else {
+850 	    throw new _Error("wrong params");
+851 	}
+852 	return (new _DERBitString({"bin": value.toString(2)})).tohex();
+853     };
+854     this.getEncodedHex = function() { return this.tohex(); };
+855 
+856     if (params != undefined) this.setByParam(params);
+857 };
+858 extendClass(KJUR.asn1.tsp.PKIFailureInfo, KJUR.asn1.ASN1Object);
+859 
+860 // --- END OF RFC 2510 CMP -------------------------------------------
+861 
+862 /**
+863  * abstract class for TimeStampToken generator (DEPRECATED)<br/>
+864  * @name KJUR.asn1.tsp.AbstractTSAAdapter
+865  * @class abstract class for TimeStampToken generator
+866  * @param {Array} params associative array of parameters
+867  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
+868  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
+869  *
+870  * @description
+871  * This is abstract class for TimeStampToken generator.
+872  */
+873 KJUR.asn1.tsp.AbstractTSAAdapter = function(params) {
+874     this.getTSTHex = function(msgHex, hashAlg) {
+875         throw "not implemented yet";
+876     };
+877 };
+878 
+879 /**
+880  * class for simple TimeStampToken generator (DEPRECATED)<br/>
+881  * @name KJUR.asn1.tsp.SimpleTSAAdapter
+882  * @class class for simple TimeStampToken generator
+883  * @extends KJUR.asn1.tsp.AbstractTSAAdapter
+884  * @param {Array} params associative array of parameters
+885  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
+886  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
+887  *
+888  * @description
+889  * This is a simple TimeStampToken generator class.
+890  */
+891 KJUR.asn1.tsp.SimpleTSAAdapter = function(params) {
+892     var _KJUR = KJUR,
+893 	_KJUR_asn1 = _KJUR.asn1,
+894 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
+895 	_hashHex = _KJUR.crypto.Util.hashHex;
+896 
+897     _KJUR_asn1_tsp.SimpleTSAAdapter.superclass.constructor.call(this);
+898     this.params = null;
+899     this.serial = 0;
+900 
+901     this.getTSTHex = function(msgHex, hashAlg) {
+902         // messageImprint
+903         var hashHex = _hashHex(msgHex, hashAlg);
+904         this.params.econtent.content.messageImprint =
+905             {alg: hashAlg, hash: hashHex};
+906 
+907         // serial
+908         this.params.econtent.content.serial =
+909 	    {'int': this.serial++};
+910 
+911         // nonce
+912         var nonceValue = Math.floor(Math.random() * 1000000000);
+913         this.params.econtent.content.nonce =
+914 	    {'int': nonceValue};
+915 
+916         var obj = 
+917             new _KJUR_asn1_tsp.TimeStampToken(this.params);
+918         return obj.getContentInfoEncodedHex();
+919     };
+920 
+921     if (params !== undefined) this.params = params;
+922 };
+923 extendClass(KJUR.asn1.tsp.SimpleTSAAdapter,
+924             KJUR.asn1.tsp.AbstractTSAAdapter);
+925 
+926 /**
+927  * class for fixed TimeStampToken generator (DEPRECATED)<br/>
+928  * @name KJUR.asn1.tsp.FixedTSAAdapter
+929  * @class class for fixed TimeStampToken generator
+930  * @extends KJUR.asn1.tsp.AbstractTSAAdapter
+931  * @param {Array} params associative array of parameters
+932  * @since jsrsasign 4.7.0 asn1tsp 1.0.1
+933  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0
+934  *
+935  * @description
+936  * This class generates fixed TimeStampToken except messageImprint
+937  * for testing purpose.
+938  * General TSA generates TimeStampToken which varies following
+939  * fields:
+940  * <ul>
+941  * <li>genTime</li>
+942  * <li>serialNumber</li>
+943  * <li>nonce</li>
+944  * </ul>
+945  * Those values are provided by initial parameters.
+946  */
+947 KJUR.asn1.tsp.FixedTSAAdapter = function(params) {
+948     var _KJUR = KJUR,
+949 	_KJUR_asn1 = _KJUR.asn1,
+950 	_KJUR_asn1_tsp = _KJUR_asn1.tsp,
+951 	_hashHex = _KJUR.crypto.Util.hashHex;
+952 
+953     _KJUR_asn1_tsp.FixedTSAAdapter.superclass.constructor.call(this);
+954     this.params = null;
+955 
+956     this.getTSTHex = function(msgHex, hashAlg) {
+957         // fixed serialNumber
+958         // fixed nonce        
+959         var hashHex = _hashHex(msgHex, hashAlg);
+960         this.params.econtent.content.messageImprint =
+961             {alg: hashAlg, hash: hashHex};
+962         var obj = new _KJUR_asn1_tsp.TimeStampToken(this.params);
+963         return obj.getContentInfoEncodedHex();
+964     };
+965 
+966     if (params !== undefined) this.params = params;
+967 };
+968 extendClass(KJUR.asn1.tsp.FixedTSAAdapter,
+969             KJUR.asn1.tsp.AbstractTSAAdapter);
+970 
+971 // --- TSP utilities -------------------------------------------------
+972 
+973 /**
+974  * TSP utiliteis class
+975  * @name KJUR.asn1.tsp.TSPUtil
+976  * @class TSP utilities class
+977  */
+978 KJUR.asn1.tsp.TSPUtil = new function() {
+979 };
+980 /**
+981  * generate TimeStampToken ASN.1 object specified by JSON parameters (DEPRECATED)<br/>
+982  * @name newTimeStampToken
+983  * @memberOf KJUR.asn1.tsp.TSPUtil
+984  * @function
+985  * @param {Array} param JSON parameter to generate TimeStampToken
+986  * @return {KJUR.asn1.cms.SignedData} object just generated
+987  * @deprecated since jsrsasign 10.0.0 asn1tsp 2.0.0. Please use TimeStampToken class
+988  * @see KJUR.asn1.tsp.TimeStampToken
+989  *
+990  * @description
+991  * @example
+992  */
+993 KJUR.asn1.tsp.TSPUtil.newTimeStampToken = function(params) {
+994     return new KJUR.asn1.tsp.TimeStampToken(params);
+995 };
+996 
+997 /**
+998  * parse hexadecimal string of TimeStampReq
+999  * @name parseTimeStampReq
+1000  * @memberOf KJUR.asn1.tsp.TSPUtil
+1001  * @function
+1002  * @param {String} hexadecimal string of TimeStampReq
+1003  * @return {Array} JSON object of parsed parameters
+1004  * @see KJUR.asn1.tsp.TSPParser#getTimeStampReq
+1005  * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getTimeStampReq instead.
+1006  *
+1007  * @description
+1008  * This method parses a hexadecimal string of TimeStampReq
+1009  * and returns parsed their fields:
+1010  *
+1011  * @example
+1012  * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602...");
+1013  * // resulted DUMP of above 'json':
+1014  * {
+1015  *  messageImprint: {
+1016  *       alg: 'sha256',          // MessageImprint hashAlg
+1017  *       hash: 'a1a2a3a4...'},   // MessageImprint hashValue
+1018  *  policy: '1.2.3.4.5',             // tsaPolicy (OPTION)
+1019  *  nonce: '9abcf318...',            // nonce (OPTION)
+1020  *  certreq: true}                   // certReq (OPTION)
+1021  */
+1022 KJUR.asn1.tsp.TSPUtil.parseTimeStampReq = function(reqHex) {
+1023     var parser = new KJUR.asn1.tsp.TSPParser();
+1024     return parser.getTimeStampReq(reqHex);
+1025 };
+1026 
+1027 /**
+1028  * parse hexadecimal string of MessageImprint
+1029  * @name parseMessageImprint
+1030  * @memberOf KJUR.asn1.tsp.TSPUtil
+1031  * @function
+1032  * @param {String} hexadecimal string of MessageImprint
+1033  * @return {Array} JSON object of parsed parameters
+1034  * @see KJUR.asn1.tsp.TSPParser#getMessageImprint
+1035  * @deprecated since jsrsasign 10.5.18 asn1tsp 2.0.6. Please use TSPParser.getMessageImprint instead.
+1036  *
+1037  * @description
+1038  * This method parses a hexadecimal string of MessageImprint
+1039  * and returns parsed their fields:
+1040  *
+1041  * @example
+1042  * KJUR.asn1.tsp.TSPUtil.parseMessageImprint("302602...") →
+1043  * { alg:  'sha256', hash: 'a1a2a3a4...'}
+1044  */
+1045 KJUR.asn1.tsp.TSPUtil.parseMessageImprint = function(miHex) {
+1046     var parser = new KJUR.asn1.tsp.TSPParser();
+1047     return parser.getMessageImprint(miHex);
+1048 /*
+1049     var _ASN1HEX = ASN1HEX;
+1050     var _getChildIdx = _ASN1HEX.getChildIdx;
+1051     var _getV = _ASN1HEX.getV;
+1052     var _getIdxbyList = _ASN1HEX.getIdxbyList;
+1053     var json = {};
+1054 
+1055     if (miHex.substr(0, 2) != "30")
+1056         throw "head of messageImprint hex shall be '30'";
+1057 
+1058     var idxList = _getChildIdx(miHex, 0);
+1059     var hashAlgOidIdx = _getIdxbyList(miHex, 0, [0, 0]);
+1060     var hashAlgHex = _getV(miHex, hashAlgOidIdx);
+1061     var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex);
+1062     var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid);
+1063     if (hashAlgName == '')
+1064         throw "hashAlg name undefined: " + hashAlgOid;
+1065     var hashAlg = hashAlgName;
+1066     var hashValueIdx = _getIdxbyList(miHex, 0, [1]);
+1067 
+1068     json.alg = hashAlg;
+1069     json.hash = _getV(miHex, hashValueIdx); 
+1070 
+1071     return json;
+1072 */
+1073 };
+1074 
+1075 /**
+1076  * class for parsing RFC 3161 TimeStamp protocol data<br/>
+1077  * @name KJUR.asn1.tsp.TSPParser
+1078  * @class RFC 3161 TimeStamp protocol parser class
+1079  * @since jsrsasign 10.1.0 asn1tsp 2.0.1
+1080  *
+1081  * @description
+1082  * This is an ASN.1 parser for 
+1083  * <a href="https://tools.ietf.org/html/rfc3161">RFC 3161</a>.
+1084  */
+1085 KJUR.asn1.tsp.TSPParser = function() {
+1086     var _Error = Error,
+1087 	_X509 = X509,
+1088 	_x509obj = new _X509(),
+1089 	_ASN1HEX = ASN1HEX,
+1090 	_getV = _ASN1HEX.getV,
+1091 	_getTLV = _ASN1HEX.getTLV,
+1092 	_getIdxbyList = _ASN1HEX.getIdxbyList,
+1093 	_getTLVbyListEx = _ASN1HEX.getTLVbyListEx,
+1094 	_getChildIdx = _ASN1HEX.getChildIdx;
+1095     var _aSTATUSSTR = [
+1096 	"granted", "grantedWithMods", "rejection", "waiting",
+1097 	"revocationWarning", "revocationNotification" ];
+1098     var _pFAILUREINFO = {
+1099 	0: "badAlg", 2: "badRequest", 5: "badDataFormat",
+1100 	14: "timeNotAvailable", 15: "unacceptedPolicy",
+1101 	16: "unacceptedExtension", 17: "addInfoNotAvailable",
+1102 	25: "systemFailure"
+1103     };
+1104     
+1105     /**
+1106      * parse ASN.1 TimeStampResp<br/>
+1107      * @name getResponse
+1108      * @memberOf KJUR.asn1.tsp.TSPParser#
+1109      * @function
+1110      * @param {String} h hexadecimal string of ASN.1 TimeStampResp
+1111      * @return {Array} JSON object of TimeStampResp parameter
+1112      * @see KJUR.asn1.tsp.TimeStampResp
+1113      * @see KJUR.asn1.tsp.TimeStampToken
+1114      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
+1115      *
+1116      * @description
+1117      * This method parses ASN.1 TimeStampRsp defined in RFC 3161.
+1118      * <pre>
+1119      * TimeStampResp ::= SEQUENCE {
+1120      *   status          PKIStatusInfo,
+1121      *   timeStampToken  TimeStampToken  OPTIONAL }
+1122      * </pre>
+1123      * When "h" is a TSP error response,
+1124      * returned parameter contains "statusinfo" only.
+1125      *
+1126      * @example
+1127      * parser = new KJUR.asn1.tsp.TSPParser();
+1128      * parser.getResponse("30...") →
+1129      * { 
+1130      *   statusinfo: 'granted',
+1131      *   ... // almost the same as CMS SignedData parameters
+1132      *   econtent: {
+1133      *     type: "tstinfo",
+1134      *     content: { // TSTInfo parameter
+1135      *       policy: '1.2.3.4.5',
+1136      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
+1137      *       serial: {'int': 3},
+1138      *       genTime: {str: '20131231235959.123Z'},
+1139      *       accuracy: {millis: 500},
+1140      *       ordering: true,
+1141      *       nonce: {int: 3}
+1142      *     }
+1143      *   },
+1144      *   ...
+1145      * }
+1146      */
+1147     this.getResponse = function(h) {
+1148 	var aIdx = _getChildIdx(h, 0);
+1149 	
+1150 	if (aIdx.length == 1) {
+1151 	    return this.getPKIStatusInfo(_getTLV(h, aIdx[0]));
+1152 	} else if (aIdx.length > 1) {
+1153 	    var pPKIStatusInfo = this.getPKIStatusInfo(_getTLV(h, aIdx[0]));
+1154 	    var hTST = _getTLV(h, aIdx[1]);
+1155 	    var pResult = this.getToken(hTST);
+1156 	    pResult.statusinfo = pPKIStatusInfo;
+1157 	    return pResult;
+1158 	}
+1159     };
+1160 
+1161     /**
+1162      * parse ASN.1 TimeStampToken<br/>
+1163      * @name getToken
+1164      * @memberOf KJUR.asn1.tsp.TSPParser#
+1165      * @function
+1166      * @param {String} h hexadecimal string of ASN.1 TimeStampToken
+1167      * @return {Array} JSON object of TimeStampToken parameter
+1168      * @see KJUR.asn1.tsp.TimeStampToken
+1169      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
+1170      * @see KJUR.asn1.tsp.TSPParser#setTSTInfo
+1171      *
+1172      * @description
+1173      * This method parses ASN.1 TimeStampRsp defined in RFC 3161.
+1174      * This method will parse "h" as CMS SigneData by
+1175      * {@link KJUR.asn1.cms.CMSParser#getCMSSignedData}, then
+1176      * parse and modify "econtent.content" parameter by
+1177      * {@link KJUR.asn1.tsp.TSPParser#setTSTInfo} method.
+1178      *
+1179      * @example
+1180      * parser = new KJUR.asn1.tsp.TSPParser();
+1181      * parser.getToken("30...") →
+1182      * { 
+1183      *   ... // almost the same as CMS SignedData parameters
+1184      *   econtent: {
+1185      *     type: "tstinfo",
+1186      *     content: { // TSTInfo parameter
+1187      *       policy: '1.2.3.4.5',
+1188      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
+1189      *       serial: {'int': 3},
+1190      *       genTime: {str: '20131231235959.123Z'},
+1191      *       accuracy: {millis: 500},
+1192      *       ordering: true,
+1193      *       nonce: {int: 3}
+1194      *     }
+1195      *   },
+1196      *   ...
+1197      * }
+1198      */
+1199     this.getToken = function(h) {
+1200 	var _CMSParser = new KJUR.asn1.cms.CMSParser;
+1201 	var p = _CMSParser.getCMSSignedData(h);
+1202 	this.setTSTInfo(p);
+1203 	return p;
+1204     };
+1205 
+1206     /**
+1207      * set ASN.1 TSTInfo parameter to CMS SignedData parameter<br/>
+1208      * @name setTSTInfo
+1209      * @memberOf KJUR.asn1.tsp.TSPParser#
+1210      * @function
+1211      * @param {Array} pCMSSignedData JSON object of CMS SignedData parameter
+1212      * @see KJUR.asn1.tsp.TimeStampToken
+1213      * @see KJUR.asn1.cms.CMSParser#getCMSSignedData
+1214      *
+1215      * @description
+1216      * This method modifies "econtent.content" of CMS SignedData parameter
+1217      * to parsed TSTInfo.
+1218      * <pre>
+1219      *
+1220      * @example
+1221      * parser = new KJUR.asn1.tsp.TSPParser();
+1222      * pCMSSignedData = { 
+1223      *   ... // almost the same as CMS SignedData parameters
+1224      *   econtent: {
+1225      *     type: "tstinfo",
+1226      *     content: { hex: "30..." }
+1227      *   },
+1228      *   ...
+1229      * };
+1230      * parser.setTSTInfo(pCMSSignedData);
+1231      * pCMSSignedData → { 
+1232      *   ... // almost the same as CMS SignedData parameters
+1233      *   econtent: {
+1234      *     type: "tstinfo",
+1235      *     content: { // TSTInfo parameter
+1236      *       policy: '1.2.3.4.5',
+1237      *       messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
+1238      *       serial: {int: 3},
+1239      *       genTime: {str: '20131231235959.123Z'},
+1240      *       accuracy: {millis: 500},
+1241      *       ordering: true,
+1242      *       nonce: {int: 3}
+1243      *     }
+1244      *   },
+1245      *   ...
+1246      * };
+1247      */
+1248     this.setTSTInfo = function(pCMSSignedData) {
+1249 	var pEContent = pCMSSignedData.econtent;
+1250 	if (pEContent.type == "tstinfo") {
+1251 	    var hContent = pEContent.content.hex;
+1252 	    var pTSTInfo = this.getTSTInfo(hContent);
+1253 	    //pTSTInfo.hex_ = hContent;
+1254 	    pEContent.content = pTSTInfo;
+1255 	}
+1256     };
+1257 
+1258     /**
+1259      * parse ASN.1 TSTInfo<br/>
+1260      * @name getTSTInfo
+1261      * @memberOf KJUR.asn1.tsp.TSPParser#
+1262      * @function
+1263      * @param {String} h hexadecimal string of ASN.1 TSTInfo
+1264      * @return {Array} JSON object of TSTInfo parameter
+1265      * @see KJUR.asn1.tsp.TSTInfo
+1266      *
+1267      * @description
+1268      * This method parses ASN.1 TSTInfo defined in RFC 3161.
+1269      * <pre>
+1270      * TSTInfo ::= SEQUENCE  {
+1271      *    version          INTEGER  { v1(1) },
+1272      *    policy           TSAPolicyId,
+1273      *    messageImprint   MessageImprint,
+1274      *    serialNumber     INTEGER,
+1275      *    genTime          GeneralizedTime,
+1276      *    accuracy         Accuracy                 OPTIONAL,
+1277      *    ordering         BOOLEAN             DEFAULT FALSE,
+1278      *    nonce            INTEGER                  OPTIONAL,
+1279      *    tsa              [0] GeneralName          OPTIONAL,
+1280      *    extensions       [1] IMPLICIT Extensions  OPTIONAL }
+1281      * </pre>
+1282      *
+1283      * @example
+1284      * parser = new KJUR.asn1.tsp.TSPParser();
+1285      * parser.getTSTInfo("30...") →
+1286      * {
+1287      *   policy: '1.2.3.4.5',
+1288      *   messageImprint: {alg: 'sha256', hash: 'a1a2a3a4...'},
+1289      *   serial: {'int': 3},
+1290      *   genTime: {str: '20131231235959.123Z'},
+1291      *   accuracy: {millis: 500},
+1292      *   ordering: true,
+1293      *   nonce: {int: 3}
+1294      * }
+1295      */
+1296     this.getTSTInfo = function(h) {
+1297 	var pResult = {};
+1298 	var aIdx = _getChildIdx(h, 0);
+1299 
+1300 	var hPolicy = _getV(h, aIdx[1]);
+1301 	pResult.policy = hextooid(hPolicy);
+1302 
+1303 	var hMessageImprint = _getTLV(h, aIdx[2]);
+1304 	pResult.messageImprint = this.getMessageImprint(hMessageImprint);
+1305 
+1306 	var hSerial = _getV(h, aIdx[3]);
+1307 	pResult.serial = {hex: hSerial};
 1308 
-1309 	    if (tag == "02") {
-1310 		pResult.seconds = iV;
-1311 	    } else if (tag == "80") {
-1312 		pResult.millis = iV;
-1313 	    } else if (tag == "81") {
-1314 		pResult.micros = iV;
-1315 	    }
-1316 	}
-1317 
-1318 	return pResult;
-1319     };
-1320 
-1321     /**
-1322      * parse ASN.1 MessageImprint<br/>
-1323      * @name getMessageImprint
-1324      * @memberOf KJUR.asn1.tsp.TSPParser#
-1325      * @function
-1326      * @param {String} h hexadecimal string of ASN.1 MessageImprint
-1327      * @return {Array} JSON object of MessageImprint parameter
-1328      * @see KJUR.asn1.tsp.MessageImprint
-1329      *
-1330      * @description
-1331      * This method parses ASN.1 MessageImprint defined in RFC 3161.
-1332      *
-1333      * @example
-1334      * parser = new KJUR.asn1.tsp.TSPParser();
-1335      * parser.getMessageImprint("30...") → 
-1336      * { alg: "sha256", hash: "12ab..." }
-1337      */
-1338     this.getMessageImprint = function(h) {
-1339 	if (h.substr(0, 2) != "30")
-1340             throw new Error("head of messageImprint hex shall be x30");
-1341 
-1342 	var json = {};
-1343 	var idxList = _getChildIdx(h, 0);
-1344 	var hashAlgOidIdx = _getIdxbyList(h, 0, [0, 0]);
-1345 	var hashAlgHex = _getV(h, hashAlgOidIdx);
-1346 	var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex);
-1347 	var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid);
-1348 	if (hashAlgName == '')
-1349             throw new Error("hashAlg name undefined: " + hashAlgOid);
-1350 	var hashAlg = hashAlgName;
-1351 	var hashValueIdx = _getIdxbyList(h, 0, [1]);
-1352 	
-1353 	json.alg = hashAlg;
-1354 	json.hash = _getV(h, hashValueIdx); 
+1309 	var hGenTime = _getV(h, aIdx[4]);
+1310 	pResult.genTime = {str: hextoutf8(hGenTime)};
+1311 
+1312 	var offset = 0;
+1313 
+1314 	if (aIdx.length > 5 && h.substr(aIdx[5], 2) == "30") {
+1315 	    var hAccuracy = _getTLV(h, aIdx[5]);
+1316 	    pResult.accuracy = this.getAccuracy(hAccuracy);
+1317 	    offset++;
+1318 	}
+1319 
+1320 	if (aIdx.length > 5 + offset && 
+1321 	    h.substr(aIdx[5 + offset], 2) == "01") {
+1322 	    var hOrdering = _getV(h, aIdx[5 + offset]);
+1323 	    if (hOrdering == "ff") pResult.ordering = true;
+1324 	    offset++;
+1325 	}
+1326 
+1327 	if (aIdx.length > 5 + offset &&
+1328 	    h.substr(aIdx[5 + offset], 2) == "02") {
+1329 	    var hNonce = _getV(h, aIdx[5 + offset]);
+1330 	    pResult.nonce = {hex: hNonce};
+1331 	    offset++;
+1332 	}
+1333 
+1334 	if (aIdx.length > 5 + offset &&
+1335 	    h.substr(aIdx[5 + offset], 2) == "a0") {
+1336 	    var hGeneralNames = _getTLV(h, aIdx[5 + offset]);
+1337 	    hGeneralNames = "30" + hGeneralNames.substr(2);
+1338 	    pGeneralNames = _x509obj.getGeneralNames(hGeneralNames);
+1339 	    var pName = pGeneralNames[0].dn;
+1340 	    pResult.tsa = pName;
+1341 	    offset++;
+1342 	}
+1343 
+1344 	if (aIdx.length > 5 + offset &&
+1345 	    h.substr(aIdx[5 + offset], 2) == "a1") {
+1346 	    var hExt = _getTLV(h, aIdx[5 + offset]);
+1347 	    hExt = "30" + hExt.substr(2);
+1348 	    var aExt = _x509obj.getExtParamArray(hExt);
+1349 	    pResult.ext = aExt;
+1350 	    offset++;
+1351 	}
+1352 
+1353 	return pResult;
+1354     };
 1355 
-1356 	return json;
-1357     };
-1358 
-1359     /**
-1360      * parse ASN.1 PKIStatusInfo<br/>
-1361      * @name getPKIStatusInfo
-1362      * @memberOf KJUR.asn1.tsp.TSPParser#
-1363      * @function
-1364      * @param {String} h hexadecimal string of ASN.1 PKIStatusInfo
-1365      * @return {Array} JSON object of PKIStatusInfo parameter
-1366      * @see KJUR.asn1.tsp.PKIStatusInfo
-1367      *
-1368      * @description
-1369      * This method parses ASN.1 PKIStatusInfo defined in RFC 3161.
-1370      *
-1371      * @example
-1372      * parser = new KJUR.asn1.tsp.TSPParser();
-1373      * parser.getPKIStatusInfo("30...") → 
-1374      * { status: "rejection",
-1375      *   statusstr: ["unsupported algorithm"],
-1376      *   failinfo: "badAlg" }
+1356     /**
+1357      * parse ASN.1 Accuracy<br/>
+1358      * @name getAccuracy
+1359      * @memberOf KJUR.asn1.tsp.TSPParser#
+1360      * @function
+1361      * @param {String} h hexadecimal string of ASN.1 Accuracy
+1362      * @return {Array} JSON object of Accuracy parameter
+1363      * @see KJUR.asn1.tsp.Accuracy
+1364      *
+1365      * @description
+1366      * This method parses ASN.1 Accuracy defined in RFC 3161.
+1367      * <pre>
+1368      * Accuracy ::= SEQUENCE {
+1369      *    seconds        INTEGER              OPTIONAL,
+1370      *    millis     [0] INTEGER  (1..999)    OPTIONAL,
+1371      *    micros     [1] INTEGER  (1..999)    OPTIONAL  }
+1372      * </pre>
+1373      *
+1374      * @example
+1375      * parser = new KJUR.asn1.tsp.TSPParser();
+1376      * parser.getAccuracy("30...") → {millis: 500}
 1377      */
-1378     this.getPKIStatusInfo = function(h) {
+1378     this.getAccuracy = function(h) {
 1379 	var pResult = {};
-1380 	var aIdx = _getChildIdx(h, 0);
-1381 	var offset = 0;
+1380 
+1381 	var aIdx = _getChildIdx(h, 0);
 1382 
-1383 	try {
-1384 	    var hStatus = _getV(h, aIdx[0]);
-1385 	    var iStatus = parseInt(hStatus, 16);
-1386 	    pResult.status = _aSTATUSSTR[iStatus];
-1387 	} catch(ex) {};
-1388 
-1389 	if (aIdx.length > 1 && h.substr(aIdx[1], 2) == "30") {
-1390 	    var hPKIFreeText = _getTLV(h, aIdx[1]);
-1391 	    pResult.statusstr = 
-1392 		this.getPKIFreeText(hPKIFreeText);
-1393 	    offset++;
-1394 	}
-1395 
-1396 	if (aIdx.length > offset &&
-1397 	    h.substr(aIdx[1 + offset], 2) == "03") {
-1398 	    var hPKIFailureInfo = _getTLV(h, aIdx[1 + offset]);
-1399 	    pResult.failinfo = 
-1400 		this.getPKIFailureInfo(hPKIFailureInfo);
-1401 	}
-1402 
-1403 	return pResult;
-1404     };
-1405 
-1406     /**
-1407      * parse ASN.1 PKIFreeText<br/>
-1408      * @name getPKIFreeText
-1409      * @memberOf KJUR.asn1.tsp.TSPParser#
-1410      * @function
-1411      * @param {String} h hexadecimal string of ASN.1 PKIFreeText
-1412      * @return {Array} array of string
-1413      * @since jsrsasign 10.1.3 asn1tsp 2.0.3
-1414      * @see KJUR.asn1.tsp.PKIFreeText
-1415      *
-1416      * @description
-1417      * This method parses ASN.1 PKIFreeText defined in RFC 3161.
-1418      *
-1419      * @example
-1420      * parser = new KJUR.asn1.tsp.TSPParser();
-1421      * parser.getPKIFreeText("300a0c036161610c03616161") → 
-1422      * ["aaa", "aaa"]
-1423      */
-1424     this.getPKIFreeText = function(h) {
-1425 	var aResult = [];
-1426 	var aIdx = _getChildIdx(h, 0);
-1427 	for (var i = 0; i < aIdx.length; i++) {
-1428 	    aResult.push(_ASN1HEX.getString(h, aIdx[i]));
-1429 	}
-1430 	return aResult;
-1431     };
-1432 
-1433     /**
-1434      * parse ASN.1 PKIFailureInfo<br/>
-1435      * @name getPKIFailureInfo
-1436      * @memberOf KJUR.asn1.tsp.TSPParser#
-1437      * @function
-1438      * @param {String} h hexadecimal string of ASN.1 PKIFailureInfo
-1439      * @return {Object} failureInfo string or number
-1440      * @since jsrsasign 10.1.3 asn1tsp 2.0.3
-1441      * @see KJUR.asn1.tsp.PKIFailureInfo
-1442      *
-1443      * @description
-1444      * This method parses ASN.1 PKIFailureInfo defined in RFC 3161.
-1445      *
-1446      * @example
-1447      * parser = new KJUR.asn1.tsp.TSPParser();
-1448      * parser.getPKIFailureInfo("03020700") → "badAlg"
-1449      * parser.getPKIFailureInfo("03020780") → 1
-1450      * parser.getPKIFailureInfo("030203c8") → "systemFailure"
-1451      */
-1452     this.getPKIFailureInfo = function(h) {
-1453 	var n = _ASN1HEX.getInt(h, 0);
-1454 	if (_pFAILUREINFO[n] != undefined) {
-1455 	    return _pFAILUREINFO[n];
-1456 	} else {
-1457 	    return n;
-1458 	}
-1459     };
-1460 
-1461     /**
-1462      * parse hexadecimal string of TimeStampReq<br/>
-1463      * @name getTimeStampReq
-1464      * @memberOf KJUR.asn1.tsp.TSPParser#
-1465      * @function
-1466      * @param {String} h hexadecimal string of TimeStampReq
-1467      * @return {Array} JSON object of parsed parameters
-1468      * @see KJUR.asn1.tsp.TSPUtil.parseTimeStampReq
-1469      *
-1470      * @description
-1471      * This method parses a hexadecimal string of TimeStampReq
-1472      * and returns parsed their fields:
-1473      *
-1474      * @example
-1475      * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602...");
-1476      * // resulted DUMP of above 'json':
-1477      * {
-1478      *  messageImprint: {
-1479      *       alg: 'sha256',          // MessageImprint hashAlg
-1480      *       hash: 'a1a2a3a4...'},   // MessageImprint hashValue
-1481      *  policy: '1.2.3.4.5',         // tsaPolicy (OPTION)
-1482      *  nonce: '9abcf318...',        // nonce (OPTION)
-1483      *  certreq: true }              // certReq (OPTION)
-1484      */
-1485     this.getTimeStampReq = function(h) {
-1486 	var json = {};
-1487 	json.certreq = false;
-1488 
-1489 	var idxList = _getChildIdx(h, 0);
-1490 
-1491 	if (idxList.length < 2)
-1492             throw new Error("TimeStampReq must have at least 2 items");
-1493 
-1494 	var miHex = _getTLV(h, idxList[1]);
-1495 	json.messageImprint = KJUR.asn1.tsp.TSPUtil.parseMessageImprint(miHex); 
-1496 	//json.messageImprint = getMessageImprint(miHex); 
-1497 
-1498 	for (var i = 2; i < idxList.length; i++) {
-1499             var idx = idxList[i];
-1500             var tag = h.substr(idx, 2);
-1501             if (tag == "06") { // case OID
-1502 		var policyHex = _getV(h, idx);
-1503 		json.policy = _ASN1HEX.hextooidstr(policyHex);
-1504             }
-1505             if (tag == "02") { // case INTEGER
-1506 		json.nonce = _getV(h, idx);
-1507             }
-1508             if (tag == "01") { // case BOOLEAN
-1509 		json.certreq = true;
-1510             }
-1511 	}
-1512 
-1513 	return json;
-1514     };
-1515 };
-1516 
\ No newline at end of file +1383
for (var i = 0; i < aIdx.length; i++) { +1384 var tag = h.substr(aIdx[i], 2); +1385 var hV = _getV(h, aIdx[i]); +1386 var iV = parseInt(hV, 16); +1387 +1388 if (tag == "02") { +1389 pResult.seconds = iV; +1390 } else if (tag == "80") { +1391 pResult.millis = iV; +1392 } else if (tag == "81") { +1393 pResult.micros = iV; +1394 } +1395 } +1396 +1397 return pResult; +1398 }; +1399 +1400 /** +1401 * parse ASN.1 MessageImprint<br/> +1402 * @name getMessageImprint +1403 * @memberOf KJUR.asn1.tsp.TSPParser# +1404 * @function +1405 * @param {String} h hexadecimal string of ASN.1 MessageImprint +1406 * @return {Array} JSON object of MessageImprint parameter +1407 * @see KJUR.asn1.tsp.MessageImprint +1408 * +1409 * @description +1410 * This method parses ASN.1 MessageImprint defined in RFC 3161. +1411 * +1412 * @example +1413 * parser = new KJUR.asn1.tsp.TSPParser(); +1414 * parser.getMessageImprint("30...") → +1415 * { alg: "sha256", hash: "12ab..." } +1416 */ +1417 this.getMessageImprint = function(h) { +1418 if (h.substr(0, 2) != "30") +1419 throw new Error("head of messageImprint hex shall be x30"); +1420 +1421 var json = {}; +1422 var idxList = _getChildIdx(h, 0); +1423 var hashAlgOidIdx = _getIdxbyList(h, 0, [0, 0]); +1424 var hashAlgHex = _getV(h, hashAlgOidIdx); +1425 var hashAlgOid = _ASN1HEX.hextooidstr(hashAlgHex); +1426 var hashAlgName = KJUR.asn1.x509.OID.oid2name(hashAlgOid); +1427 if (hashAlgName == '') +1428 throw new Error("hashAlg name undefined: " + hashAlgOid); +1429 var hashAlg = hashAlgName; +1430 var hashValueIdx = _getIdxbyList(h, 0, [1]); +1431 +1432 json.alg = hashAlg; +1433 json.hash = _getV(h, hashValueIdx); +1434 +1435 return json; +1436 }; +1437 +1438 /** +1439 * parse ASN.1 PKIStatusInfo<br/> +1440 * @name getPKIStatusInfo +1441 * @memberOf KJUR.asn1.tsp.TSPParser# +1442 * @function +1443 * @param {String} h hexadecimal string of ASN.1 PKIStatusInfo +1444 * @return {Array} JSON object of PKIStatusInfo parameter +1445 * @see KJUR.asn1.tsp.PKIStatusInfo +1446 * +1447 * @description +1448 * This method parses ASN.1 PKIStatusInfo defined in RFC 3161. +1449 * +1450 * @example +1451 * parser = new KJUR.asn1.tsp.TSPParser(); +1452 * parser.getPKIStatusInfo("30...") → +1453 * { status: "rejection", +1454 * statusstr: ["unsupported algorithm"], +1455 * failinfo: "badAlg" } +1456 */ +1457 this.getPKIStatusInfo = function(h) { +1458 var pResult = {}; +1459 var aIdx = _getChildIdx(h, 0); +1460 var offset = 0; +1461 +1462 try { +1463 var hStatus = _getV(h, aIdx[0]); +1464 var iStatus = parseInt(hStatus, 16); +1465 pResult.status = _aSTATUSSTR[iStatus]; +1466 } catch(ex) {}; +1467 +1468 if (aIdx.length > 1 && h.substr(aIdx[1], 2) == "30") { +1469 var hPKIFreeText = _getTLV(h, aIdx[1]); +1470 pResult.statusstr = +1471 this.getPKIFreeText(hPKIFreeText); +1472 offset++; +1473 } +1474 +1475 if (aIdx.length > offset && +1476 h.substr(aIdx[1 + offset], 2) == "03") { +1477 var hPKIFailureInfo = _getTLV(h, aIdx[1 + offset]); +1478 pResult.failinfo = +1479 this.getPKIFailureInfo(hPKIFailureInfo); +1480 } +1481 +1482 return pResult; +1483 }; +1484 +1485 /** +1486 * parse ASN.1 PKIFreeText<br/> +1487 * @name getPKIFreeText +1488 * @memberOf KJUR.asn1.tsp.TSPParser# +1489 * @function +1490 * @param {String} h hexadecimal string of ASN.1 PKIFreeText +1491 * @return {Array} array of string +1492 * @since jsrsasign 10.1.3 asn1tsp 2.0.3 +1493 * @see KJUR.asn1.tsp.PKIFreeText +1494 * +1495 * @description +1496 * This method parses ASN.1 PKIFreeText defined in RFC 3161. +1497 * +1498 * @example +1499 * parser = new KJUR.asn1.tsp.TSPParser(); +1500 * parser.getPKIFreeText("300a0c036161610c03616161") → +1501 * ["aaa", "aaa"] +1502 */ +1503 this.getPKIFreeText = function(h) { +1504 var aResult = []; +1505 var aIdx = _getChildIdx(h, 0); +1506 for (var i = 0; i < aIdx.length; i++) { +1507 aResult.push(_ASN1HEX.getString(h, aIdx[i])); +1508 } +1509 return aResult; +1510 }; +1511 +1512 /** +1513 * parse ASN.1 PKIFailureInfo<br/> +1514 * @name getPKIFailureInfo +1515 * @memberOf KJUR.asn1.tsp.TSPParser# +1516 * @function +1517 * @param {String} h hexadecimal string of ASN.1 PKIFailureInfo +1518 * @return {Object} failureInfo string or number +1519 * @since jsrsasign 10.1.3 asn1tsp 2.0.3 +1520 * @see KJUR.asn1.tsp.PKIFailureInfo +1521 * +1522 * @description +1523 * This method parses ASN.1 PKIFailureInfo defined in RFC 3161. +1524 * +1525 * @example +1526 * parser = new KJUR.asn1.tsp.TSPParser(); +1527 * parser.getPKIFailureInfo("03020700") → "badAlg" +1528 * parser.getPKIFailureInfo("03020780") → 1 +1529 * parser.getPKIFailureInfo("030203c8") → "systemFailure" +1530 */ +1531 this.getPKIFailureInfo = function(h) { +1532 var n = _ASN1HEX.getInt(h, 0); +1533 if (_pFAILUREINFO[n] != undefined) { +1534 return _pFAILUREINFO[n]; +1535 } else { +1536 return n; +1537 } +1538 }; +1539 +1540 /** +1541 * parse hexadecimal string of TimeStampReq<br/> +1542 * @name getTimeStampReq +1543 * @memberOf KJUR.asn1.tsp.TSPParser# +1544 * @function +1545 * @param {String} h hexadecimal string of TimeStampReq +1546 * @return {Array} JSON object of parsed parameters +1547 * @since jsrsasign 10.5.18 asn1tsp 2.0.6 +1548 * @see KJUR.asn1.tsp.TimeStampReq +1549 * @see KJUR.asn1.tsp.TSPUtil.parseTimeStampReq +1550 * +1551 * @description +1552 * This method parses a hexadecimal string of TimeStampReq +1553 * and returns parsed their fields: +1554 * +1555 * @example +1556 * var parser = new KJUR.asn1.tsp.TSPParser(); +1557 * parser.getTimeStampReq("302602...") → +1558 * { messageImprint: { +1559 * alg: 'sha256', // MessageImprint hashAlg +1560 * hash: 'a1a2a3a4...'}, // MessageImprint hashValue +1561 * policy: '1.2.3.4.5', // tsaPolicy (OPTION) +1562 * nonce: '9abcf318...', // nonce (OPTION) +1563 * certreq: true } // certReq (OPTION) +1564 */ +1565 this.getTimeStampReq = function(h) { +1566 var json = {}; +1567 json.certreq = false; +1568 +1569 var idxList = _getChildIdx(h, 0); +1570 +1571 if (idxList.length < 2) +1572 throw new Error("TimeStampReq must have at least 2 items"); +1573 +1574 var miHex = _getTLV(h, idxList[1]); +1575 json.messageImprint = KJUR.asn1.tsp.TSPUtil.parseMessageImprint(miHex); +1576 +1577 for (var i = 2; i < idxList.length; i++) { +1578 var idx = idxList[i]; +1579 var tag = h.substr(idx, 2); +1580 if (tag == "06") { // case OID +1581 var policyHex = _getV(h, idx); +1582 json.policy = _ASN1HEX.hextooidstr(policyHex); +1583 } +1584 if (tag == "02") { // case INTEGER +1585 json.nonce = _getV(h, idx); +1586 } +1587 if (tag == "01") { // case BOOLEAN +1588 json.certreq = true; +1589 } +1590 } +1591 +1592 return json; +1593 }; +1594 }; +1595
\ No newline at end of file diff --git a/bower.json b/bower.json index 55492690..0099e320 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "10.5.18", + "version": "10.5.19", "main": "jsrsasign-all-min.js", "description": "The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES, JWS and JWT in pure JavaScript.", "license": "MIT", diff --git a/jsrsasign-all-min.js b/jsrsasign-all-min.js index 9c4b200d..54d227c3 100644 --- a/jsrsasign-all-min.js +++ b/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.5.18 (2022-04-22) (c) 2010-2022 Kenji Urushima | kjur.github.io/jsrsasign/license + * jsrsasign(all) 10.5.19 (2022-04-23) (c) 2010-2022 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -221,7 +221,7 @@ if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!K var ASN1HEX=new function(){};ASN1HEX.getLblen=function(c,a){if(c.substr(a+2,1)!="8"){return 1}var b=parseInt(c.substr(a+3,1));if(b==0){return -1}if(0=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.tohex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:p}}}else{return{"enum":parseInt(p,16)}}}else{if(C=="30"||C=="31"){j[c[C]]=u(x);return j}else{if(C=="14"){var o=q(p);j[c[C]]={str:o};return j}else{if(C=="1e"){var o=n(p);j[c[C]]={str:o};return j}else{if(":0c:12:13:16:17:18:1a:".indexOf(C)!=-1){var o=k(p);j[c[C]]={str:o};return j}else{if(C.match(/^8[0-9]$/)){var o=k(p);if(o==null|o==""){return{tag:{tag:C,explicit:false,hex:p}}}else{if(o.match(/[\x00-\x1F\x7F-\x9F]/)!=null||o.match(/[\u0000-\u001F\u0080–\u009F]/)!=null){return{tag:{tag:C,explicit:false,hex:p}}}else{return{tag:{tag:C,explicit:false,str:o}}}}}else{if(C.match(/^a[0-9]$/)){try{if(!a(p)){throw new Error("not encap")}return{tag:{tag:C,explicit:true,obj:f(p)}}}catch(z){return{tag:{tag:C,explicit:true,hex:p}}}}else{var A=new KJUR.asn1.ASN1Object();A.hV=p;var w=A.getLengthHexFromValue();return{asn1:{tlv:C+w+p}}}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.tohex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.tohex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.tohex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.tohex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.tohex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.tohex()}};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.tohex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.tohex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.tohex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.tohex=function(){var p=this.getASN1Object();this.hTLV=p.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.tohex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.tohex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.tohex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.tohex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.tohex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.tohex=function(){var p=this.params;var A,y,q;var y=false;if(p.other!==undefined){A="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){A="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){A="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){A="a4";y=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){A="a4";y=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){A="a4";y=true;var n,o;var z=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){z==o}if(o.indexOf("-----BEGIN ")!=-1){z=pemtohex(o)}if(z==null){throw new Error("certsubj/certissuer not cert")}var w=new X509();w.hex=z;var s;if(n){s=w.getIssuerHex()}else{s=w.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){A="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){A="87";var v;var t=p.ip;try{if(t.match(/^[0-9a-f]+$/)){var r=t.length;if(r==8||r==16||r==32||r==64){v=t}else{throw"err"}}else{v=iptohex(t)}}catch(u){throw new j("malformed IP address: "+p.ip+":"+u.message)}q=new k({hex:v})}else{throw new j("improper params")}}}}}}}}var B=new c({tag:A,explicit:y,obj:q});return B.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.tohex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:p}}}else{return{"enum":parseInt(p,16)}}}else{if(C=="30"||C=="31"){j[c[C]]=u(x);return j}else{if(C=="14"){var o=q(p);j[c[C]]={str:o};return j}else{if(C=="1e"){var o=n(p);j[c[C]]={str:o};return j}else{if(":0c:12:13:16:17:18:1a:".indexOf(C)!=-1){var o=k(p);j[c[C]]={str:o};return j}else{if(C.match(/^8[0-9]$/)){var o=k(p);if(o==null|o==""){return{tag:{tag:C,explicit:false,hex:p}}}else{if(o.match(/[\x00-\x1F\x7F-\x9F]/)!=null||o.match(/[\u0000-\u001F\u0080–\u009F]/)!=null){return{tag:{tag:C,explicit:false,hex:p}}}else{return{tag:{tag:C,explicit:false,str:o}}}}}else{if(C.match(/^a[0-9]$/)){try{if(!a(p)){throw new Error("not encap")}return{tag:{tag:C,explicit:true,obj:f(p)}}}catch(z){return{tag:{tag:C,explicit:true,hex:p}}}}else{var A=new KJUR.asn1.ASN1Object();A.hV=p;var w=A.getLengthHexFromValue();return{asn1:{tlv:C+w+p}}}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.tohex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.tohex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.tohex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.tohex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.tohex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.tohex()}};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.tohex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.tohex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.tohex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.tohex=function(){var p=this.getASN1Object();this.hTLV=p.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.tohex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.tohex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.tohex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.tohex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.tohex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.tohex=function(){var p=this.params;var A,y,q;var y=false;if(p.other!==undefined){A="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){A="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){A="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){A="a4";y=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){A="a4";y=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){A="a4";y=true;var n,o;var z=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){z==o}if(o.indexOf("-----BEGIN ")!=-1){z=pemtohex(o)}if(z==null){throw new Error("certsubj/certissuer not cert")}var w=new X509();w.hex=z;var s;if(n){s=w.getIssuerHex()}else{s=w.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){A="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){A="87";var v;var t=p.ip;try{if(t.match(/^[0-9a-f]+$/)){var r=t.length;if(r==8||r==16||r==32||r==64){v=t}else{throw"err"}}else{v=iptohex(t)}}catch(u){throw new j("malformed IP address: "+p.ip+":"+u.message)}q=new k({hex:v})}else{throw new j("improper params")}}}}}}}}var B=new c({tag:A,explicit:y,obj:q});return B.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m=f){break}}return j};ASN1HEX.getNthChildIdx=function(d,b,e){var c=ASN1HEX.getChildIdx(d,b);return c[e]};ASN1HEX.getIdxbyList=function(e,d,c,i){var g=ASN1HEX;var f,b;if(c.length==0){if(i!==undefined){if(e.substr(d,2)!==i){return -1}}return d}f=c.shift();b=g.getChildIdx(e,d);if(f>=b.length){return -1}return g.getIdxbyList(e,b[f],c,i)};ASN1HEX.getIdxbyListEx=function(f,k,b,g){var m=ASN1HEX;var d,l;if(b.length==0){if(g!==undefined){if(f.substr(k,2)!==g){return -1}}return k}d=b.shift();l=m.getChildIdx(f,k);var j=0;for(var e=0;e=d.length){return null}return e.getTLV(d,a)};ASN1HEX.getTLVbyListEx=function(d,c,b,f){var e=ASN1HEX;var a=e.getIdxbyListEx(d,c,b,f);if(a==-1){return null}return e.getTLV(d,a)};ASN1HEX.getVbyList=function(e,c,b,g,i){var f=ASN1HEX;var a,d;a=f.getIdxbyList(e,c,b,g);if(a==-1){return null}if(a>=e.length){return null}d=f.getV(e,a);if(i===true){d=d.substr(2)}return d};ASN1HEX.getVbyListEx=function(b,e,a,d,f){var j=ASN1HEX;var g,c,i;g=j.getIdxbyListEx(b,e,a,d);if(g==-1){return null}i=j.getV(b,g);if(b.substr(g,2)=="03"&&f!==false){i=i.substr(2)}return i};ASN1HEX.getInt=function(e,b,f){if(f==undefined){f=-1}try{var c=e.substr(b,2);if(c!="02"&&c!="03"){return f}var a=ASN1HEX.getV(e,b);if(c=="02"){return parseInt(a,16)}else{return bitstrtoint(a)}}catch(d){return f}};ASN1HEX.getOID=function(c,a,d){if(d==undefined){d=null}try{if(c.substr(a,2)!="06"){return d}var e=ASN1HEX.getV(c,a);return hextooid(e)}catch(b){return d}};ASN1HEX.getOIDName=function(d,a,f){if(f==undefined){f=null}try{var e=ASN1HEX.getOID(d,a,f);if(e==f){return f}var b=KJUR.asn1.x509.OID.oid2name(e);if(b==""){return e}return b}catch(c){return f}};ASN1HEX.getString=function(d,b,e){if(e==undefined){e=null}try{var a=ASN1HEX.getV(d,b);return hextorstr(a)}catch(c){return e}};ASN1HEX.hextooidstr=function(e){var h=function(b,a){if(b.length>=a){return b}return new Array(a-b.length+1).join("0")+b};var l=[];var o=e.substr(0,2);var f=parseInt(o,16);l[0]=new String(Math.floor(f/40));l[1]=new String(f%40);var m=e.substr(2);var k=[];for(var g=0;g0){n=n+"."+j.join(".")}return n};ASN1HEX.dump=function(t,c,l,g){var p=ASN1HEX;var j=p.getV;var y=p.dump;var w=p.getChildIdx;var e=t;if(t instanceof KJUR.asn1.ASN1Object){e=t.tohex()}var q=function(A,i){if(A.length<=i*2){return A}else{var v=A.substr(0,i)+"..(total "+A.length/2+"bytes).."+A.substr(A.length-i,i);return v}};if(c===undefined){c={ommit_long_octet:32}}if(l===undefined){l=0}if(g===undefined){g=""}var x=c.ommit_long_octet;var z=e.substr(l,2);if(z=="01"){var h=j(e,l);if(h=="00"){return g+"BOOLEAN FALSE\n"}else{return g+"BOOLEAN TRUE\n"}}if(z=="02"){var h=j(e,l);return g+"INTEGER "+q(h,x)+"\n"}if(z=="03"){var h=j(e,l);if(p.isASN1HEX(h.substr(2))){var k=g+"BITSTRING, encapsulates\n";k=k+y(h.substr(2),c,0,g+" ");return k}else{return g+"BITSTRING "+q(h,x)+"\n"}}if(z=="04"){var h=j(e,l);if(p.isASN1HEX(h)){var k=g+"OCTETSTRING, encapsulates\n";k=k+y(h,c,0,g+" ");return k}else{return g+"OCTETSTRING "+q(h,x)+"\n"}}if(z=="05"){return g+"NULL\n"}if(z=="06"){var m=j(e,l);var b=KJUR.asn1.ASN1Util.oidHexToInt(m);var o=KJUR.asn1.x509.OID.oid2name(b);var a=b.replace(/\./g," ");if(o!=""){return g+"ObjectIdentifier "+o+" ("+a+")\n"}else{return g+"ObjectIdentifier ("+a+")\n"}}if(z=="0a"){return g+"ENUMERATED "+parseInt(j(e,l))+"\n"}if(z=="0c"){return g+"UTF8String '"+hextoutf8(j(e,l))+"'\n"}if(z=="13"){return g+"PrintableString '"+hextoutf8(j(e,l))+"'\n"}if(z=="14"){return g+"TeletexString '"+hextoutf8(j(e,l))+"'\n"}if(z=="16"){return g+"IA5String '"+hextoutf8(j(e,l))+"'\n"}if(z=="17"){return g+"UTCTime "+hextoutf8(j(e,l))+"\n"}if(z=="18"){return g+"GeneralizedTime "+hextoutf8(j(e,l))+"\n"}if(z=="1a"){return g+"VisualString '"+hextoutf8(j(e,l))+"'\n"}if(z=="1e"){return g+"BMPString '"+ucs2hextoutf8(j(e,l))+"'\n"}if(z=="30"){if(e.substr(l,4)=="3000"){return g+"SEQUENCE {}\n"}var k=g+"SEQUENCE\n";var d=w(e,l);var f=c;if((d.length==2||d.length==3)&&e.substr(d[0],2)=="06"&&e.substr(d[d.length-1],2)=="04"){var o=p.oidname(j(e,d[0]));var r=JSON.parse(JSON.stringify(c));r.x509ExtName=o;f=r}for(var u=0;u4){return{"enum":{hex:p}}}else{return{"enum":parseInt(p,16)}}}else{if(C=="30"||C=="31"){j[c[C]]=u(x);return j}else{if(C=="14"){var o=q(p);j[c[C]]={str:o};return j}else{if(C=="1e"){var o=n(p);j[c[C]]={str:o};return j}else{if(":0c:12:13:16:17:18:1a:".indexOf(C)!=-1){var o=k(p);j[c[C]]={str:o};return j}else{if(C.match(/^8[0-9]$/)){var o=k(p);if(o==null|o==""){return{tag:{tag:C,explicit:false,hex:p}}}else{if(o.match(/[\x00-\x1F\x7F-\x9F]/)!=null||o.match(/[\u0000-\u001F\u0080–\u009F]/)!=null){return{tag:{tag:C,explicit:false,hex:p}}}else{return{tag:{tag:C,explicit:false,str:o}}}}}else{if(C.match(/^a[0-9]$/)){try{if(!a(p)){throw new Error("not encap")}return{tag:{tag:C,explicit:true,obj:f(p)}}}catch(z){return{tag:{tag:C,explicit:true,hex:p}}}}else{var A=new KJUR.asn1.ASN1Object();A.hV=p;var w=A.getLengthHexFromValue();return{asn1:{tlv:C+w+p}}}}}}}}}}}}}}}};ASN1HEX.isContextTag=function(c,b){c=c.toLowerCase();var f,e;try{f=parseInt(c,16)}catch(d){return -1}if(b===undefined){if((f&192)==128){return true}else{return false}}try{var a=b.match(/^\[[0-9]+\]$/);if(a==null){return false}e=parseInt(b.substr(1,b.length-1),10);if(e>31){return false}if(((f&192)==128)&&((f&31)==e)){return true}return false}catch(d){return false}};ASN1HEX.isASN1HEX=function(e){var d=ASN1HEX;if(e.length%2==1){return false}var c=d.getVblen(e,0);var b=e.substr(0,2);var f=d.getL(e,0);var a=e.length-b.length-f.length;if(a==c*2){return true}return false};ASN1HEX.checkStrictDER=function(g,o,d,c,r){var s=ASN1HEX;if(d===undefined){if(typeof g!="string"){throw new Error("not hex string")}g=g.toLowerCase();if(!KJUR.lang.String.isHex(g)){throw new Error("not hex string")}d=g.length;c=g.length/2;if(c<128){r=1}else{r=Math.ceil(c.toString(16))+1}}var k=s.getL(g,o);if(k.length>r*2){throw new Error("L of TLV too long: idx="+o)}var n=s.getVblen(g,o);if(n>c){throw new Error("value of L too long than hex: idx="+o)}var q=s.getTLV(g,o);var f=q.length-2-s.getL(g,o).length;if(f!==(n*2)){throw new Error("V string length and L's value not the same:"+f+"/"+(n*2))}if(o===0){if(g.length!=q.length){throw new Error("total length and TLV length unmatch:"+g.length+"!="+q.length)}}var b=g.substr(o,2);if(b==="02"){var a=s.getVidx(g,o);if(g.substr(a,2)=="00"&&g.charCodeAt(a+2)<56){throw new Error("not least zeros for DER INTEGER")}}if(parseInt(b,16)&32){var p=s.getVblen(g,o);var m=0;var l=s.getChildIdx(g,o);for(var e=0;e0){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.TBSCertificate,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Extensions=function(d){KJUR.asn1.x509.Extensions.superclass.constructor.call(this);var c=KJUR,b=c.asn1,a=b.DERSequence,e=b.x509;this.aParam=[];this.setByParam=function(f){this.aParam=f};this.tohex=function(){var f=[];for(var h=0;h-1){i.push(new f({"int":this.pathLen}))}var h=new b({array:i});this.asn1ExtnValue=h;return this.asn1ExtnValue.tohex()};this.oid="2.5.29.19";this.cA=false;this.pathLen=-1;if(g!==undefined){if(g.cA!==undefined){this.cA=g.cA}if(g.pathLen!==undefined){this.pathLen=g.pathLen}}};extendClass(KJUR.asn1.x509.BasicConstraints,KJUR.asn1.x509.Extension);KJUR.asn1.x509.CRLDistributionPoints=function(d){KJUR.asn1.x509.CRLDistributionPoints.superclass.constructor.call(this,d);var b=KJUR,a=b.asn1,c=a.x509;this.getExtnValueHex=function(){return this.asn1ExtnValue.tohex()};this.setByDPArray=function(e){var f=[];for(var g=0;g0){f.push(new b({array:j}))}}var g=new b({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(d!==undefined){this.params=d}};extendClass(KJUR.asn1.x509.PolicyInformation,KJUR.asn1.ASN1Object);KJUR.asn1.x509.PolicyQualifierInfo=function(e){KJUR.asn1.x509.PolicyQualifierInfo.superclass.constructor.call(this,e);var c=KJUR.asn1,b=c.DERSequence,d=c.DERIA5String,f=c.DERObjectIdentifier,a=c.x509.UserNotice;this.params=null;this.tohex=function(){if(this.params.cps!==undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.1"}),new d({str:this.params.cps})]});return g.tohex()}if(this.params.unotice!=undefined){var g=new b({array:[new f({oid:"1.3.6.1.5.5.7.2.2"}),new a(this.params.unotice)]});return g.tohex()}};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.PolicyQualifierInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.UserNotice=function(e){KJUR.asn1.x509.UserNotice.superclass.constructor.call(this,e);var a=KJUR.asn1.DERSequence,d=KJUR.asn1.DERInteger,c=KJUR.asn1.x509.DisplayText,b=KJUR.asn1.x509.NoticeReference;this.params=null;this.tohex=function(){var f=[];if(this.params.noticeref!==undefined){f.push(new b(this.params.noticeref))}if(this.params.exptext!==undefined){f.push(new c(this.params.exptext))}var g=new a({array:f});return g.tohex()};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){this.params=e}};extendClass(KJUR.asn1.x509.UserNotice,KJUR.asn1.ASN1Object);KJUR.asn1.x509.NoticeReference=function(d){KJUR.asn1.x509.NoticeReference.superclass.constructor.call(this,d);var a=KJUR.asn1.DERSequence,c=KJUR.asn1.DERInteger,b=KJUR.asn1.x509.DisplayText;this.params=null;this.tohex=function(){var f=[];if(this.params.org!==undefined){f.push(new b(this.params.org))}if(this.params.noticenum!==undefined){var h=[];var e=this.params.noticenum;for(var j=0;j0){for(var g=0;g0;f++){var h=c.shift();if(e===true){var d=b.pop();var j=(d+","+h).replace(/\\,/g,",");b.push(j);e=false}else{b.push(h)}if(h.substr(-1,1)==="\\"){e=true}}b=b.map(function(a){return a.replace("/","\\/")});b.reverse();return"/"+b.join("/")};KJUR.asn1.x509.X500Name.ldapToOneline=function(a){return KJUR.asn1.x509.X500Name.ldapToCompat(a)};KJUR.asn1.x509.RDN=function(b){KJUR.asn1.x509.RDN.superclass.constructor.call(this);this.asn1Array=[];this.paramArray=[];this.sRule="utf8";var a=KJUR.asn1.x509.AttributeTypeAndValue;this.setByParam=function(c){if(c.rule!==undefined){this.sRule=c.rule}if(c.str!==undefined){this.addByMultiValuedString(c.str)}if(c.array!==undefined){this.paramArray=c.array}};this.addByString=function(c){this.asn1Array.push(new KJUR.asn1.x509.AttributeTypeAndValue({str:c,rule:this.sRule}))};this.addByMultiValuedString=function(e){var c=KJUR.asn1.x509.RDN.parseString(e);for(var d=0;d0){for(var d=0;d0;g++){var k=j.shift();if(h===true){var f=c.pop();var d=(f+"+"+k).replace(/\\\+/g,"+");c.push(d);h=false}else{c.push(k)}if(k.substr(-1,1)==="\\"){h=true}}var l=false;var b=[];for(var g=0;c.length>0;g++){var k=c.shift();if(l===true){var e=b.pop();if(k.match(/"$/)){var d=(e+"+"+k).replace(/^([^=]+)="(.*)"$/,"$1=$2");b.push(d);l=false}else{b.push(e+"+"+k)}}else{b.push(k)}if(k.match(/^[^=]+="/)){l=true}}return b};KJUR.asn1.x509.AttributeTypeAndValue=function(c){KJUR.asn1.x509.AttributeTypeAndValue.superclass.constructor.call(this);this.sRule="utf8";this.sType=null;this.sValue=null;this.dsType=null;var a=KJUR,g=a.asn1,d=g.DERSequence,l=g.DERUTF8String,i=g.DERPrintableString,h=g.DERTeletexString,b=g.DERIA5String,e=g.DERVisibleString,k=g.DERBMPString,f=a.lang.String.isMail,j=a.lang.String.isPrintable;this.setByParam=function(o){if(o.rule!==undefined){this.sRule=o.rule}if(o.ds!==undefined){this.dsType=o.ds}if(o.value===undefined&&o.str!==undefined){var n=o.str;var m=n.match(/^([^=]+)=(.+)$/);if(m){this.sType=m[1];this.sValue=m[2]}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}}else{this.sType=o.type;this.sValue=o.value}};this.setByString=function(n,o){if(o!==undefined){this.sRule=o}var m=n.match(/^([^=]+)=(.+)$/);if(m){this.setByAttrTypeAndValueStr(m[1],m[2])}else{throw new Error("malformed attrTypeAndValueStr: "+attrTypeAndValueStr)}};this._getDsType=function(){var o=this.sType;var n=this.sValue;var m=this.sRule;if(m==="prn"){if(o=="CN"&&f(n)){return"ia5"}if(j(n)){return"prn"}return"utf8"}else{if(m==="utf8"){if(o=="CN"&&f(n)){return"ia5"}if(o=="C"){return"prn"}return"utf8"}}return"utf8"};this.setByAttrTypeAndValueStr=function(o,n,m){if(m!==undefined){this.sRule=m}this.sType=o;this.sValue=n};this.getValueObj=function(n,m){if(n=="utf8"){return new l({str:m})}if(n=="prn"){return new i({str:m})}if(n=="tel"){return new h({str:m})}if(n=="ia5"){return new b({str:m})}if(n=="vis"){return new e({str:m})}if(n=="bmp"){return new k({str:m})}throw new Error("unsupported directory string type: type="+n+" value="+m)};this.tohex=function(){if(this.dsType==null){this.dsType=this._getDsType()}var n=KJUR.asn1.x509.OID.atype2obj(this.sType);var m=this.getValueObj(this.dsType,this.sValue);var p=new d({array:[n,m]});this.TLV=p.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(c!==undefined){this.setByParam(c)}};extendClass(KJUR.asn1.x509.AttributeTypeAndValue,KJUR.asn1.ASN1Object);KJUR.asn1.x509.SubjectPublicKeyInfo=function(f){KJUR.asn1.x509.SubjectPublicKeyInfo.superclass.constructor.call(this);var l=null,k=null,a=KJUR,j=a.asn1,i=j.DERInteger,b=j.DERBitString,m=j.DERObjectIdentifier,e=j.DERSequence,h=j.ASN1Util.newObject,d=j.x509,o=d.AlgorithmIdentifier,g=a.crypto,n=g.ECDSA,c=g.DSA;this.getASN1Object=function(){if(this.asn1AlgId==null||this.asn1SubjPKey==null){throw"algId and/or subjPubKey not set"}var p=new e({array:[this.asn1AlgId,this.asn1SubjPKey]});return p};this.tohex=function(){var p=this.getASN1Object();this.hTLV=p.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.tohex();this.asn1AlgId=new o({name:"rsaEncryption"});this.asn1SubjPKey=new b({hex:"00"+s})}}catch(p){}try{if(q instanceof KJUR.crypto.ECDSA){var r=new m({name:q.curveName});this.asn1AlgId=new o({name:"ecPublicKey",asn1params:r});this.asn1SubjPKey=new b({hex:"00"+q.pubKeyHex})}}catch(p){}try{if(q instanceof KJUR.crypto.DSA){var r=new h({seq:[{"int":{bigint:q.p}},{"int":{bigint:q.q}},{"int":{bigint:q.g}}]});this.asn1AlgId=new o({name:"dsa",asn1params:r});var t=new i({bigint:q.y});this.asn1SubjPKey=new b({hex:"00"+t.tohex()})}}catch(p){}};if(f!==undefined){this.setPubKey(f)}};extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo,KJUR.asn1.ASN1Object);KJUR.asn1.x509.Time=function(f){KJUR.asn1.x509.Time.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.params=null;this.type=null;this.setTimeParams=function(h){this.timeParams=h};this.setByParam=function(h){this.params=h};this.getType=function(h){if(h.match(/^[0-9]{12}Z$/)){return"utc"}if(h.match(/^[0-9]{14}Z$/)){return"gen"}if(h.match(/^[0-9]{12}\.[0-9]+Z$/)){return"utc"}if(h.match(/^[0-9]{14}\.[0-9]+Z$/)){return"gen"}return null};this.tohex=function(){var i=this.params;var h=null;if(typeof i=="string"){i={str:i}}if(i!=null&&i.str&&(i.type==null||i.type==undefined)){i.type=this.getType(i.str)}if(i!=null&&i.str){if(i.type=="utc"){h=new b(i.str)}if(i.type=="gen"){h=new g(i.str)}}else{if(this.type=="gen"){h=new g()}else{h=new b()}}if(h==null){throw new Error("wrong setting for Time")}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};if(f!=undefined){this.setByParam(f)}};KJUR.asn1.x509.Time_bak=function(f){KJUR.asn1.x509.Time_bak.superclass.constructor.call(this);var e=null,a=null,d=KJUR,c=d.asn1,b=c.DERUTCTime,g=c.DERGeneralizedTime;this.setTimeParams=function(h){this.timeParams=h};this.tohex=function(){var h=null;if(this.timeParams!=null){if(this.type=="utc"){h=new b(this.timeParams)}else{h=new g(this.timeParams)}}else{if(this.type=="utc"){h=new b()}else{h=new g()}}this.TLV=h.tohex();return this.TLV};this.getEncodedHex=function(){return this.tohex()};this.type="utc";if(f!==undefined){if(f.type!==undefined){this.type=f.type}else{if(f.str!==undefined){if(f.str.match(/^[0-9]{12}Z$/)){this.type="utc"}if(f.str.match(/^[0-9]{14}Z$/)){this.type="gen"}}}this.timeParams=f}};extendClass(KJUR.asn1.x509.Time,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier=function(e){KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this);this.nameAlg=null;this.asn1Alg=null;this.asn1Params=null;this.paramEmpty=false;var b=KJUR,a=b.asn1,c=a.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV;this.tohex=function(){if(this.nameAlg===null&&this.asn1Alg===null){throw new Error("algorithm not specified")}if(this.nameAlg!==null){var f=null;for(var h in c){if(h===this.nameAlg){f=c[h]}}if(f!==null){this.hTLV=f;return this.hTLV}}if(this.nameAlg!==null&&this.asn1Alg===null){this.asn1Alg=a.x509.OID.name2obj(this.nameAlg)}var g=[this.asn1Alg];if(this.asn1Params!==null){g.push(this.asn1Params)}var i=new a.DERSequence({array:g});this.hTLV=i.tohex();return this.hTLV};this.getEncodedHex=function(){return this.tohex()};if(e!==undefined){if(e.name!==undefined){this.nameAlg=e.name}if(e.asn1params!==undefined){this.asn1Params=e.asn1params}if(e.paramempty!==undefined){this.paramEmpty=e.paramempty}}if(this.asn1Params===null&&this.paramEmpty===false&&this.nameAlg!==null){if(this.nameAlg.name!==undefined){this.nameAlg=this.nameAlg.name}var d=this.nameAlg.toLowerCase();if(d.substr(-7,7)!=="withdsa"&&d.substr(-9,9)!=="withecdsa"){this.asn1Params=new a.DERNull()}}};extendClass(KJUR.asn1.x509.AlgorithmIdentifier,KJUR.asn1.ASN1Object);KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV={SHAwithRSAandMGF1:"300d06092a864886f70d01010a3000",SHA256withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120",SHA384withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130",SHA512withRSAandMGF1:"303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140"};KJUR.asn1.x509.GeneralName=function(f){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var l={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87",otherName:"a0"},b=KJUR,h=b.asn1,d=h.x509,a=d.X500Name,g=d.OtherName,e=h.DERIA5String,i=h.DERPrintableString,k=h.DEROctetString,c=h.DERTaggedObject,m=h.ASN1Object,j=Error;this.params=null;this.setByParam=function(n){this.params=n};this.tohex=function(){var p=this.params;var A,y,q;var y=false;if(p.other!==undefined){A="a0",q=new g(p.other)}else{if(p.rfc822!==undefined){A="81";q=new e({str:p.rfc822})}else{if(p.dns!==undefined){A="82";q=new e({str:p.dns})}else{if(p.dn!==undefined){A="a4";y=true;if(typeof p.dn==="string"){q=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){q=p.dn}else{q=new a(p.dn)}}}else{if(p.ldapdn!==undefined){A="a4";y=true;q=new a({ldapstr:p.ldapdn})}else{if(p.certissuer!==undefined||p.certsubj!==undefined){A="a4";y=true;var n,o;var z=null;if(p.certsubj!==undefined){n=false;o=p.certsubj}else{n=true;o=p.certissuer}if(o.match(/^[0-9A-Fa-f]+$/)){z==o}if(o.indexOf("-----BEGIN ")!=-1){z=pemtohex(o)}if(z==null){throw new Error("certsubj/certissuer not cert")}var w=new X509();w.hex=z;var s;if(n){s=w.getIssuerHex()}else{s=w.getSubjectHex()}q=new m();q.hTLV=s}else{if(p.uri!==undefined){A="86";q=new e({str:p.uri})}else{if(p.ip!==undefined){A="87";var v;var t=p.ip;try{if(t.match(/^[0-9a-f]+$/)){var r=t.length;if(r==8||r==16||r==32||r==64){v=t}else{throw"err"}}else{v=iptohex(t)}}catch(u){throw new j("malformed IP address: "+p.ip+":"+u.message)}q=new k({hex:v})}else{throw new j("improper params")}}}}}}}}var B=new c({tag:A,explicit:y,obj:q});return B.tohex()};this.getEncodedHex=function(){return this.tohex()};if(f!==undefined){this.setByParam(f)}};extendClass(KJUR.asn1.x509.GeneralName,KJUR.asn1.ASN1Object);KJUR.asn1.x509.GeneralNames=function(d){KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this);var a=null,c=KJUR,b=c.asn1;this.setByParamArray=function(g){for(var e=0;e0){var m=b(n.valhex,q[0]);var p=j(m,0);var t=[];for(var o=0;o1){var r=b(n.valhex,q[1]);n.polhex=r}delete n.valhex};this.setSignaturePolicyIdentifier=function(s){var q=j(s.valhex,0);if(q.length>0){var r=l.getOID(s.valhex,q[0]);s.oid=r}if(q.length>1){var m=new a();var t=j(s.valhex,q[1]);var p=b(s.valhex,t[0]);var o=m.getAlgorithmIdentifierName(p);s.alg=o;var n=i(s.valhex,t[1]);s.hash=n}delete s.valhex};this.setSigningCertificateV2=function(o){var s=j(o.valhex,0);if(s.length>0){var n=b(o.valhex,s[0]);var r=j(n,0);var u=[];for(var q=0;q1){var t=b(o.valhex,s[1]);o.polhex=t}delete o.valhex};this.getESSCertID=function(o){var p={};var n=j(o,0);if(n.length>0){var q=i(o,n[0]);p.hash=q}if(n.length>1){var m=b(o,n[1]);var r=this.getIssuerSerial(m);if(r.serial!=undefined){p.serial=r.serial}if(r.issuer!=undefined){p.issuer=r.issuer}}return p};this.getESSCertIDv2=function(q){var s={};var p=j(q,0);if(p.length<1||3r+1){var m=b(q,p[r+1]);var t=this.getIssuerSerial(m);s.issuer=t.issuer;s.serial=t.serial}return s};this.getIssuerSerial=function(q){var r={};var n=j(q,0);var m=b(q,n[0]);var p=h.getGeneralNames(m);var o=p[0].dn;r.issuer=o;var s=i(q,n[1]);r.serial={hex:s};return r};this.getCertificateSet=function(p){var n=j(p,0);var m=[];for(var o=0;o1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;m1){var o=this.getPKIStatusInfo(b(n,l[0]));var m=b(n,l[1]);var p=this.getToken(m);p.statusinfo=o;return p}}};this.getToken=function(m){var l=new KJUR.asn1.cms.CMSParser;var n=l.getCMSSignedData(m);this.setTSTInfo(n);return n};this.setTSTInfo=function(l){var o=l.econtent;if(o.type=="tstinfo"){var n=o.content.hex;var m=this.getTSTInfo(n);o.content=m}};this.getTSTInfo=function(r){var x={};var s=i(r,0);var p=g(r,s[1]);x.policy=hextooid(p);var o=b(r,s[2]);x.messageImprint=this.getMessageImprint(o);var u=g(r,s[3]);x.serial={hex:u};var y=g(r,s[4]);x.genTime={str:hextoutf8(y)};var q=0;if(s.length>5&&r.substr(s[5],2)=="30"){var v=b(r,s[5]);x.accuracy=this.getAccuracy(v);q++}if(s.length>5+q&&r.substr(s[5+q],2)=="01"){var z=g(r,s[5+q]);if(z=="ff"){x.ordering=true}q++}if(s.length>5+q&&r.substr(s[5+q],2)=="02"){var n=g(r,s[5+q]);x.nonce={hex:n};q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a0"){var m=b(r,s[5+q]);m="30"+m.substr(2);pGeneralNames=f.getGeneralNames(m);var t=pGeneralNames[0].dn;x.tsa=t;q++}if(s.length>5+q&&r.substr(s[5+q],2)=="a1"){var l=b(r,s[5+q]);l="30"+l.substr(2);var w=f.getExtParamArray(l);x.ext=w;q++}return x};this.getAccuracy=function(q){var r={};var o=i(q,0);for(var p=0;p1&&o.substr(r[1],2)=="30"){var m=b(o,r[1]);t.statusstr=this.getPKIFreeText(m);n++}if(r.length>n&&o.substr(r[1+n],2)=="03"){var q=b(o,r[1+n]);t.failinfo=this.getPKIFailureInfo(q)}return t};this.getPKIFreeText=function(n){var o=[];var l=i(n,0);for(var m=0;mMIT License */ @@ -464,18 +464,84 @@ KJUR.asn1.tsp.TimeStampReq = function(params) { extendClass(KJUR.asn1.tsp.TimeStampReq, KJUR.asn1.ASN1Object); /** - * class for TSP TimeStampResp ASN.1 object + * class for TSP TimeStampResp ASN.1 object
* @name KJUR.asn1.tsp.TimeStampResp * @class class for TSP TimeStampResp ASN.1 object * @param {Array} params associative array of parameters * @extends KJUR.asn1.ASN1Object * @since jsrsasign 4.6.0 asn1tsp 1.0.0 + * @see KJUR.asn1.tsp.TimeStampToken + * @see KJUR.asn1.tsp.PKIStatusInfo + * * @description + * This is an ASN.1 encoder for TimeStampResp + * ASN.1 structure defined in + * + * RFC 3161 TSP section 2.4.2. + * *
  * TimeStampResp ::= SEQUENCE  {
  *    status                  PKIStatusInfo,
  *    timeStampToken          TimeStampToken     OPTIONAL  }
+ *
+ * TimeStampToken ::= ContentInfo
+ *
+ * TSTInfo ::= SEQUENCE  {
+ *    version           INTEGER  { v1(1) },
+ *    policy            TSAPolicyId,
+ *    messageImprint    MessageImprint,
+ *    serialNumber      INTEGER,
+ *    genTime           GeneralizedTime,
+ *    accuracy          Accuracy                 OPTIONAL,
+ *    ordering          BOOLEAN                  DEFAULT FALSE,
+ *    nonce             INTEGER                  OPTIONAL,
+ *    tsa               [0] GeneralName          OPTIONAL,
+ *    extensions        [1] IMPLICIT Extensions  OPTIONAL  }
  * 
+ * + * The constructor argument "params" can be used all of + * {@link KJUR.asn1.tsp.TimeStampToken} object further more + * following members can be specified: + *
    + *
  • statusinfo: any {@link KJUR.asn1.tsp.PKIStatusInfo} parameter. + * When parameters for TimeStampToken is specified and statusinfo member is omitted, + * status will be "granted" by default. (OPTIONAL)
  • + *
  • tst: {@link KJUR.asn1.tsp.TimeStampToken} object instead of TimeStampToken members (OPTIONAL)
  • + *
+ * + * @example + * // by TimeStampToken parameters (statusinfo will be "granted" by default) + * new KJUR.asn1.tsp.TimeStampResp({ + * version: 1, + * hashalgs: ["sha256"], + * econtent: { + * type: "tstinfo", + * content: { + * policy: "1.2.3.4.5", + * messageImprint: {alg:"sha256", hash:"12ab..."}, + * serial: {"int": 3}, + * genTime: {millis: true}, // current time with millis + * accuracy: { millis: 500 } + * } + * } + * certs: [...], + * sinfos: [{ + * version: 1, + * id: {type:"isssn", cert: ...}, + * hashalg: "sha256", + * sattrs: {array: [{...}]}, + * sigalg: "SHA256withRSA", + * signkey: ... + * }] + * }) + * // by TimeStampToken object + * new KJUR.asn1.tsp.TimeStampResp({ + * tst: new KJUR.asn1.tsp.TimeStapToken(...) + * }) + * // error case + * new KJUR.asn1.tsp.TimeStampResp({statusinfo: "rejection"}) + * // finally, encode to hexadecimal string + * new KJUR.asn1.tsp.TimeStampResp(...).tohex() → "3082..." */ KJUR.asn1.tsp.TimeStampResp = function(params) { var _KJUR = KJUR, @@ -492,17 +558,30 @@ KJUR.asn1.tsp.TimeStampResp = function(params) { this.tohex = function() { var params = this.params; - var a = [new _PKIStatusInfo(params.statusinfo)]; - - if (params.econtent != undefined) { - a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo()); - } + var a = []; - if (params.tst != undefined && - params.tst instanceof _KJUR_asn1.ASN1Object) { - a.push(params.tst); + if (params.econtent != undefined || params.tst != undefined) { + // statusInfo + if (params.statusinfo != undefined) { + a.push(new _PKIStatusInfo(params.statusinfo)); + } else { + a.push(new _PKIStatusInfo("granted")); + } + + // TimeStampToken + if (params.econtent != undefined) { + a.push((new _KJUR_asn1_tsp.TimeStampToken(params)).getContentInfo()); + } else if (params.tst instanceof _KJUR_asn1.ASN1Object) { + a.push(params.tst); + } else { + throw new Error("improper member tst value"); + } + } else if (params.statusinfo != undefined) { + a.push(new _PKIStatusInfo(params.statusinfo)); + } else { + throw new Error("parameter for token nor statusinfo not specified"); } - + var seq = new _DERSequence({array: a}); return seq.tohex(); }; @@ -1465,6 +1544,8 @@ KJUR.asn1.tsp.TSPParser = function() { * @function * @param {String} h hexadecimal string of TimeStampReq * @return {Array} JSON object of parsed parameters + * @since jsrsasign 10.5.18 asn1tsp 2.0.6 + * @see KJUR.asn1.tsp.TimeStampReq * @see KJUR.asn1.tsp.TSPUtil.parseTimeStampReq * * @description @@ -1472,15 +1553,14 @@ KJUR.asn1.tsp.TSPParser = function() { * and returns parsed their fields: * * @example - * var json = KJUR.asn1.tsp.TSPUtil.parseTimeStampReq("302602..."); - * // resulted DUMP of above 'json': - * { - * messageImprint: { + * var parser = new KJUR.asn1.tsp.TSPParser(); + * parser.getTimeStampReq("302602...") → + * { messageImprint: { * alg: 'sha256', // MessageImprint hashAlg * hash: 'a1a2a3a4...'}, // MessageImprint hashValue - * policy: '1.2.3.4.5', // tsaPolicy (OPTION) - * nonce: '9abcf318...', // nonce (OPTION) - * certreq: true } // certReq (OPTION) + * policy: '1.2.3.4.5', // tsaPolicy (OPTION) + * nonce: '9abcf318...', // nonce (OPTION) + * certreq: true } // certReq (OPTION) */ this.getTimeStampReq = function(h) { var json = {}; @@ -1493,7 +1573,6 @@ KJUR.asn1.tsp.TSPParser = function() { var miHex = _getTLV(h, idxList[1]); json.messageImprint = KJUR.asn1.tsp.TSPUtil.parseMessageImprint(miHex); - //json.messageImprint = getMessageImprint(miHex); for (var i = 2; i < idxList.length; i++) { var idx = idxList[i];