From 0ef94ca1290e51aad3a0f09b4a06006b10bb864c Mon Sep 17 00:00:00 2001 From: Kenji Urushima Date: Thu, 30 Sep 2021 23:27:47 +0900 Subject: [PATCH] 10.4.1 release --- ChangeLog.txt | 11 +- README.md | 3 +- api/files.html | 2 +- api/symbols/KJUR.asn1.DERAbstractTime.html | 153 +- api/symbols/KJUR.asn1.DERGeneralizedTime.html | 98 +- api/symbols/KJUR.asn1.DERUTCTime.html | 99 +- api/symbols/KJUR.asn1.html | 45 - api/symbols/KJUR.asn1.x509.html | 45 + api/symbols/src/asn1-1.0.js.html | 2302 +++++++++-------- api/symbols/src/asn1x509-1.0.js.html | 1736 +++++++------ bower.json | 2 +- jsrsasign-all-min.js | 6 +- jsrsasign-jwths-min.js | 2 +- jsrsasign-rsa-min.js | 4 +- min/asn1-1.0.min.js | 2 +- min/asn1x509-1.0.min.js | 2 +- npm/README.md | 3 +- npm/lib/jsrsasign-all-min.js | 6 +- npm/lib/jsrsasign-jwths-min.js | 2 +- npm/lib/jsrsasign-rsa-min.js | 4 +- npm/lib/jsrsasign.js | 6 +- npm/package.json | 2 +- src/asn1-1.0.js | 250 +- src/asn1x509-1.0.js | 62 +- test/qunit-do-asn1.html | 215 +- test/qunit-do-asn1tsp.html | 3 +- test/qunit-do-asn1x509.html | 42 +- 27 files changed, 2772 insertions(+), 2335 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index ad67111d..b9a6e36f 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,7 +1,13 @@ ChangeLog for jsrsasign -* Changes from 10.4.0 to next release +GeneralizedTime, UTCTime refactoring and some bug fix +* Changes from 10.4.0 to 10.4.1 release + - src/asn1.js + - refactoring of DERUTCTime, DERGeneralizedTime and DERAbstractTime + - now DERUTCTime support fraction of second + - src/asn1x509.js + - update Time class to follow DER{UTC,Generalized}Time update - tool/tool_tsreq.html - messageImprint bug fix (#504) - tool/tool_tsres.html @@ -9,6 +15,9 @@ ChangeLog for jsrsasign - jsrsasign-*-min.js - header URL fix to kjur.github.io (#503) (will be fixed in next release while rebuild) + - test/qunit-do-{asn1,asn1x509}.html updated + - KJUR.asn1.DER{UTC,Generalized}Time, KJUR.asn1.x509.Time class + test case added and updated. Full support for parsing OCSP response * Changes from 10.3.2 to 10.4.0 (2021-08-17) diff --git a/README.md b/README.md index 4a872fb6..101a73e7 100755 --- a/README.md +++ b/README.md @@ -29,13 +29,14 @@ HIGHLIGHTS ---------- - Swiss Army Knife style all in one package crypto and PKI library - available on [Node.js](https://www.npmjs.com/package/jsrsasign) and browsers +- Long live open source software from 2010 - very easy API to use - powerful various format key loader and ASN.1 API - rich document and samples - 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=2021-08-10) +- very popular crypto library with [0.6M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2021-09-28) INSTALL ------- diff --git a/api/files.html b/api/files.html index f2ec4fd9..09edad4b 100644 --- a/api/files.html +++ b/api/files.html @@ -523,7 +523,7 @@

asn1-1.0.js

Version:
-
jsrsasign 10.1.0 asn1 1.0.21 (2020-Nov-18)
+
jsrsasign 10.4.1 asn1 1.0.22 (2021-Sep-30)
diff --git a/api/symbols/KJUR.asn1.DERAbstractTime.html b/api/symbols/KJUR.asn1.DERAbstractTime.html index ed92d69d..ee4008b4 100644 --- a/api/symbols/KJUR.asn1.DERAbstractTime.html +++ b/api/symbols/KJUR.asn1.DERAbstractTime.html @@ -591,7 +591,16 @@

-
get string value of this string object
+
get string value of this string object (DEPRECATED)
+ + + + +   + +
setByDate(dateObject) +
+
set value by a Date object
@@ -604,12 +613,21 @@

+ +   + +
setByParam(params) +
+
set parameter of time
+ + +  
setString(newS)
-
set value by a string
+
set value by a string (DEPRECATED)
@@ -669,6 +687,12 @@

KJUR.asn1.ASN1Object - superclass
+
KJUR.asn1.DERGeneralizedTime
+ +
KJUR.asn1.DERUTCTime
+ +
KJUR.asn1.x509.Time
+ @@ -692,7 +716,7 @@

- get string value of this string object + get string value of this string object (DEPRECATED)
@@ -701,6 +725,13 @@

+
+
Deprecated:
+
+ from jsrsasign 10.4.1 asn1 1.0.22. +
+
+ @@ -714,6 +745,55 @@

+
+ + +
+ + + setByDate(dateObject) + +
+
+ set value by a Date object
+ + +
+ + + +
o = new KJUR.asn1.DERUTCTime();
+o.setByDate(new Date("2016/12/31 23:59:59.12"));
+// 2015-Jan-31 23:59:59.12
+o.setByDate(new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)));
+ + + + +
+
Parameters:
+ +
+ {Date} dateObject + +
+
Date object to set ASN.1 value(V)
+ +
+ + + +
+
Since:
+
jsrsasign 10.4.1 asn1 1.0.22
+
+ + + + + + +
@@ -780,6 +860,64 @@

+
+ + +
+ + + setByParam(params) + +
+
+ set parameter of time + + +
+ + + +
d1 = new KJUR.asn1.DERGeneralizedTime();
+d1.setByParam("20210930235959.123Z");
+d1.setByParam({str: "20210930235959.123Z"});
+
+d1.setByParam(new Date("2013/12/31 23:59:59.12"));
+date1 = new Date(Date.UTC(2021,8,31,23,59,59,123));
+d1.setByParam(date1);
+d1.setByParam({date: date1});
+d1.setByParam({date: date1, millis: true});
+ + + + +
+
Parameters:
+ +
+ {Object} params + +
+
JSON object, Date object or string of time
+ +
+ + + +
+
Since:
+
jsrsasign 10.4.1 asn1 1.0.22 + +NOTE: If a member "millis" has a value "true", +a fraction of second will be specified for this object. +This default is "false".
+
+ + + + + + +
@@ -790,7 +928,7 @@

- set value by a string + set value by a string (DEPRECATED)
@@ -810,6 +948,13 @@

+
+
Deprecated:
+
+ from jsrsasign 10.4.1 asn1 1.0.22. +
+
+ diff --git a/api/symbols/KJUR.asn1.DERGeneralizedTime.html b/api/symbols/KJUR.asn1.DERGeneralizedTime.html index 739cab02..24e56906 100644 --- a/api/symbols/KJUR.asn1.DERGeneralizedTime.html +++ b/api/symbols/KJUR.asn1.DERGeneralizedTime.html @@ -603,32 +603,10 @@

- - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
setByDate(dateObject) -
-
set value by a Date object
-
-
-
Methods borrowed from class KJUR.asn1.DERAbstractTime:
getString, setByDateValue, setString
Methods borrowed from class KJUR.asn1.ASN1Object:
getEncodedHex, getLengthHexFromValue, getValueHex
+
Methods borrowed from class KJUR.asn1.DERAbstractTime:
getString, setByDate, setByDateValue, setByParam, setString
Methods borrowed from class KJUR.asn1.ASN1Object:
getEncodedHex, getLengthHexFromValue, getValueHex
@@ -653,17 +631,29 @@

following properties: NOTE1: 'params' can be omitted. -NOTE2: 'withMillis' property is supported from asn1 1.0.6. +NOTE2: 'millis' property is supported from asn1 1.0.6. + +

EXAMPLES

+
new DERGeneralizedTime("20151231235959Z")
+new DERGeneralizedTime("20151231235959.123Z")
+new DERGeneralizedTime(new Date())
+new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
+new DERGeneralizedTime({str: "20151231235959.123Z"})
+new DERGeneralizedTime({date: new Date()})
+new DERGeneralizedTime({date: new Date(), millis: true})
+new DERGeneralizedTime({millis: true})
+ + +
@@ -683,6 +673,15 @@

+
+
See:
+ +
KJUR.asn1.DERUTCTime
+ +
KJUR.asn1.x509.Time
+ +
+ @@ -719,55 +718,6 @@

-
- Method Detail -
- - -
- - - setByDate(dateObject) - -
-
- set value by a Date object - - -
- - - -
When you specify UTC time, use 'Date.UTC' method like this:
-o1 = new DERUTCTime(); -o1.setByDate(date); - -date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59
- - - - -
-
Parameters:
- -
- {Date} dateObject - -
-
Date object to set ASN.1 value(V)
- -
- - - - - - - - - - - diff --git a/api/symbols/KJUR.asn1.DERUTCTime.html b/api/symbols/KJUR.asn1.DERUTCTime.html index 95fcb455..01ca651b 100644 --- a/api/symbols/KJUR.asn1.DERUTCTime.html +++ b/api/symbols/KJUR.asn1.DERUTCTime.html @@ -580,32 +580,10 @@

- - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
setByDate(dateObject) -
-
set value by a Date object
-
-
-
Methods borrowed from class KJUR.asn1.DERAbstractTime:
getString, setByDateValue, setString
Methods borrowed from class KJUR.asn1.ASN1Object:
getEncodedHex, getLengthHexFromValue, getValueHex
+
Methods borrowed from class KJUR.asn1.DERAbstractTime:
getString, setByDate, setByDateValue, setByParam, setString
Methods borrowed from class KJUR.asn1.ASN1Object:
getEncodedHex, getLengthHexFromValue, getValueHex
@@ -630,22 +608,26 @@

following properties:
  • str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')
  • -
  • hex - specify initial ASN.1 value(V) by a hexadecimal string
  • date - specify Date object.
  • +
  • millis - specify flag to show milliseconds (from 1.0.6)
-NOTE: 'params' can be omitted. +NOTE1: 'params' can be omitted. +NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22. +

EXAMPLES

-
d1 = new KJUR.asn1.DERUTCTime();
-d1.setString('130430125959Z');
-
-d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'});
-d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))});
-d4 = new KJUR.asn1.DERUTCTime('130430125959Z');
+
new DERUTCTime("20151231235959Z")
+new DERUTCTime("20151231235959.123Z")
+new DERUTCTime(new Date())
+new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
+new DERUTCTime({str: "20151231235959.123Z"})
+new DERUTCTime({date: new Date()})
+new DERUTCTime({date: new Date(), millis: true})
+new DERUTCTime({millis: true})
@@ -668,6 +650,15 @@

EXAMPLES

+
+
See:
+ +
KJUR.asn1.DERGeneralizedTime
+ +
KJUR.asn1.x509.Time
+ +
+ @@ -677,52 +668,6 @@

EXAMPLES

-
- Method Detail -
- - -
- - - setByDate(dateObject) - -
-
- set value by a Date object
- - -
- - - -
o = new KJUR.asn1.DERUTCTime();
-o.setByDate(new Date("2016/12/31"));
- - - - -
-
Parameters:
- -
- {Date} dateObject - -
-
Date object to set ASN.1 value(V)
- -
- - - - - - - - - - - diff --git a/api/symbols/KJUR.asn1.html b/api/symbols/KJUR.asn1.html index 8f7d0a3c..62cd7496 100644 --- a/api/symbols/KJUR.asn1.html +++ b/api/symbols/KJUR.asn1.html @@ -611,15 +611,6 @@

- - <static>   - -
KJUR.asn1.setByDate(dateObject) -
-
- - - <static>   @@ -834,42 +825,6 @@

SUB NAME SPACES

-
- - -
<static> - - - KJUR.asn1.setByDate(dateObject) - -
-
- - - -
- - - - -
-
Parameters:
- -
- dateObject - -
-
- -
- - - - - - - -
diff --git a/api/symbols/KJUR.asn1.x509.html b/api/symbols/KJUR.asn1.x509.html index 181bef8e..70966759 100644 --- a/api/symbols/KJUR.asn1.x509.html +++ b/api/symbols/KJUR.asn1.x509.html @@ -642,6 +642,15 @@

FEATURES

+ + <static>   + +
KJUR.asn1.x509.setTimeParams(timeParams) +
+
+ + + <static>   @@ -980,6 +989,42 @@

SUPPORTED EXTENSIONS

+
+ + +
<static> + + + KJUR.asn1.x509.setTimeParams(timeParams) + +
+
+ + + +
+ + + + +
+
Parameters:
+ +
+ timeParams + +
+
+ +
+ + + + + + + +
diff --git a/api/symbols/src/asn1-1.0.js.html b/api/symbols/src/asn1-1.0.js.html index a95ea0ce..6b96f087 100644 --- a/api/symbols/src/asn1-1.0.js.html +++ b/api/symbols/src/asn1-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 /* asn1-1.0.21.js (c) 2013-2020 Kenji Urushima | kjur.github.io/jsrsasign/license
+	
  1 /* asn1-1.0.22.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license
   2  */
   3 /*
   4  * asn1.js - ASN.1 DER encoder classes
@@ -23,7 +23,7 @@
  16  * @fileOverview
  17  * @name asn1-1.0.js
  18  * @author Kenji Urushima kenji.urushima@gmail.com
- 19  * @version jsrsasign 10.1.0 asn1 1.0.21 (2020-Nov-18)
+ 19  * @version jsrsasign 10.4.1 asn1 1.0.22 (2021-Sep-30)
  20  * @since jsrsasign 2.1
  21  * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  22  */
@@ -639,1132 +639,1192 @@
 632  * @extends KJUR.asn1.ASN1Object
 633  * @description
 634  * @see KJUR.asn1.ASN1Object - superclass
-635  */
-636 KJUR.asn1.DERAbstractTime = function(params) {
-637     KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
-638     var s = null;
-639     var date = null;
-640 
-641     // --- PRIVATE METHODS --------------------
-642     this.localDateToUTC = function(d) {
-643         var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
-644         var utcDate = new Date(utc);
-645         return utcDate;
-646     };
-647 
-648     /*
-649      * format date string by Data object
-650      * @name formatDate
-651      * @memberOf KJUR.asn1.AbstractTime;
-652      * @param {Date} dateObject 
-653      * @param {string} type 'utc' or 'gen'
-654      * @param {boolean} withMillis flag for with millisections or not
-655      * @description
-656      * 'withMillis' flag is supported from asn1 1.0.6.
-657      */
-658     this.formatDate = function(dateObject, type, withMillis) {
-659         var pad = this.zeroPadding;
-660         var d = this.localDateToUTC(dateObject);
-661         var year = String(d.getFullYear());
-662         if (type == 'utc') year = year.substr(2, 2);
-663         var month = pad(String(d.getMonth() + 1), 2);
-664         var day = pad(String(d.getDate()), 2);
-665         var hour = pad(String(d.getHours()), 2);
-666         var min = pad(String(d.getMinutes()), 2);
-667         var sec = pad(String(d.getSeconds()), 2);
-668         var s = year + month + day + hour + min + sec;
-669         if (withMillis === true) {
-670             var millis = d.getMilliseconds();
-671             if (millis != 0) {
-672                 var sMillis = pad(String(millis), 3);
-673                 sMillis = sMillis.replace(/[0]+$/, "");
-674                 s = s + "." + sMillis;
-675             }
-676         }
-677         return s + "Z";
-678     };
-679 
-680     this.zeroPadding = function(s, len) {
-681         if (s.length >= len) return s;
-682         return new Array(len - s.length + 1).join('0') + s;
-683     };
-684 
-685     // --- PUBLIC METHODS --------------------
-686     /**
-687      * get string value of this string object
-688      * @name getString
-689      * @memberOf KJUR.asn1.DERAbstractTime#
-690      * @function
-691      * @return {String} string value of this time object
-692      */
-693     this.getString = function() {
-694         return this.s;
-695     };
-696 
-697     /**
-698      * set value by a string
-699      * @name setString
-700      * @memberOf KJUR.asn1.DERAbstractTime#
-701      * @function
-702      * @param {String} newS value by a string to set such like "130430235959Z"
-703      */
-704     this.setString = function(newS) {
-705         this.hTLV = null;
-706         this.isModified = true;
-707         this.s = newS;
-708         this.hV = stohex(newS);
-709     };
-710 
-711     /**
-712      * set value by a Date object
-713      * @name setByDateValue
-714      * @memberOf KJUR.asn1.DERAbstractTime#
-715      * @function
-716      * @param {Integer} year year of date (ex. 2013)
-717      * @param {Integer} month month of date between 1 and 12 (ex. 12)
-718      * @param {Integer} day day of month
-719      * @param {Integer} hour hours of date
-720      * @param {Integer} min minutes of date
-721      * @param {Integer} sec seconds of date
-722      */
-723     this.setByDateValue = function(year, month, day, hour, min, sec) {
-724         var dateObject = new Date(Date.UTC(year, month - 1, day, hour, min, sec, 0));
-725         this.setByDate(dateObject);
-726     };
-727 
-728     this.getFreshValueHex = function() {
-729         return this.hV;
-730     };
-731 };
-732 extendClass(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
-733 // == END   DERAbstractTime ==================================================
-734 
-735 // == BEGIN DERAbstractStructured ============================================
-736 /**
-737  * base class for ASN.1 DER structured class
-738  * @name KJUR.asn1.DERAbstractStructured
-739  * @class base class for ASN.1 DER structured class
-740  * @property {Array} asn1Array internal array of ASN1Object
-741  * @extends KJUR.asn1.ASN1Object
-742  * @description
-743  * @see KJUR.asn1.ASN1Object - superclass
-744  */
-745 KJUR.asn1.DERAbstractStructured = function(params) {
-746     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
-747     var asn1Array = null;
-748 
-749     /**
-750      * set value by array of ASN1Object
-751      * @name setByASN1ObjectArray
-752      * @memberOf KJUR.asn1.DERAbstractStructured#
-753      * @function
-754      * @param {array} asn1ObjectArray array of ASN1Object to set
-755      */
-756     this.setByASN1ObjectArray = function(asn1ObjectArray) {
-757         this.hTLV = null;
-758         this.isModified = true;
-759         this.asn1Array = asn1ObjectArray;
-760     };
-761 
-762     /**
-763      * append an ASN1Object to internal array
-764      * @name appendASN1Object
-765      * @memberOf KJUR.asn1.DERAbstractStructured#
-766      * @function
-767      * @param {ASN1Object} asn1Object to add
-768      */
-769     this.appendASN1Object = function(asn1Object) {
-770         this.hTLV = null;
-771         this.isModified = true;
-772         this.asn1Array.push(asn1Object);
-773     };
-774 
-775     this.asn1Array = new Array();
-776     if (typeof params != "undefined") {
-777         if (typeof params['array'] != "undefined") {
-778             this.asn1Array = params['array'];
-779         }
-780     }
-781 };
-782 extendClass(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
-783 
+635  * @see KJUR.asn1.DERGeneralizedTime
+636  * @see KJUR.asn1.DERUTCTime
+637  * @see KJUR.asn1.x509.Time
+638  */
+639 KJUR.asn1.DERAbstractTime = function(params) {
+640     KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
+641     var s = null;
+642     var date = null;
+643 
+644     // --- PRIVATE METHODS --------------------
+645     this.localDateToUTC = function(d) {
+646         var utc = d.getTime() + (d.getTimezoneOffset() * 60000);
+647         var utcDate = new Date(utc);
+648         return utcDate;
+649     };
+650 
+651     /*
+652      * format date string by Data object
+653      * @name formatDate
+654      * @memberOf KJUR.asn1.AbstractTime;
+655      * @param {Date} dateObject 
+656      * @param {string} type 'utc' or 'gen'
+657      * @param {boolean} withMillis flag for with millisections or not
+658      * @description
+659      * 'withMillis' flag is supported from asn1 1.0.6.
+660      */
+661     this.formatDate = function(dateObject, type, withMillis) {
+662         var pad = this.zeroPadding;
+663         var d = this.localDateToUTC(dateObject);
+664         var year = String(d.getFullYear());
+665         if (type == 'utc') year = year.substr(2, 2);
+666         var month = pad(String(d.getMonth() + 1), 2);
+667         var day = pad(String(d.getDate()), 2);
+668         var hour = pad(String(d.getHours()), 2);
+669         var min = pad(String(d.getMinutes()), 2);
+670         var sec = pad(String(d.getSeconds()), 2);
+671         var s = year + month + day + hour + min + sec;
+672         if (withMillis === true) {
+673             var millis = d.getMilliseconds();
+674             if (millis != 0) {
+675                 var sMillis = pad(String(millis), 3);
+676                 sMillis = sMillis.replace(/[0]+$/, "");
+677                 s = s + "." + sMillis;
+678             }
+679         }
+680         return s + "Z";
+681     };
+682 
+683     this.zeroPadding = function(s, len) {
+684         if (s.length >= len) return s;
+685         return new Array(len - s.length + 1).join('0') + s;
+686     };
+687 
+688     // --- PUBLIC METHODS --------------------
+689 
+690     /**
+691      * set parameter of time
+692      * @name setByParam
+693      * @memberOf KJUR.asn1.DERAbstractTime#
+694      * @function
+695      * @param {Object} params JSON object, Date object or string of time
+696      * @since jsrsasign 10.4.1 asn1 1.0.22
+697      *
+698      * NOTE: If a member "millis" has a value "true",
+699      * a fraction of second will be specified for this object. 
+700      * This default is "false".
+701      *
+702      * @example
+703      * d1 = new KJUR.asn1.DERGeneralizedTime();
+704      * d1.setByParam("20210930235959.123Z");
+705      * d1.setByParam({str: "20210930235959.123Z"});
+706      *
+707      * d1.setByParam(new Date("2013/12/31 23:59:59.12"));
+708      * date1 = new Date(Date.UTC(2021,8,31,23,59,59,123));
+709      * d1.setByParam(date1);
+710      * d1.setByParam({date: date1});
+711      * d1.setByParam({date: date1, millis: true});
+712      */
+713     this.setByParam = function(params) {
+714 	this.hV = null;
+715 	this.hTLV = null;
+716 	this.params = params;
+717     };
+718 
+719     /**
+720      * get string value of this string object (DEPRECATED)
+721      * @name getString
+722      * @memberOf KJUR.asn1.DERAbstractTime#
+723      * @function
+724      * @return {String} string value of this time object
+725      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
+726      */
+727     this.getString = function() {
+728         return undefined;
+729     };
+730 
+731     /**
+732      * set value by a string (DEPRECATED)
+733      * @name setString
+734      * @memberOf KJUR.asn1.DERAbstractTime#
+735      * @function
+736      * @param {String} newS value by a string to set such like "130430235959Z"
+737      * @deprecated from jsrsasign 10.4.1 asn1 1.0.22.
+738      */
+739     this.setString = function(newS) {
+740         this.hTLV = null;
+741         this.isModified = true;
+742 	if (this.params == undefined) this.params = {};
+743 	this.params.str = newS;
+744     };
+745 
+746     /**
+747      * set value by a Date object<br/>
+748      * @name setByDate
+749      * @memberOf KJUR.asn1.DERAbstractTime#
+750      * @function
+751      * @param {Date} dateObject Date object to set ASN.1 value(V)
+752      * @since jsrsasign 10.4.1 asn1 1.0.22
+753      *
+754      * @example
+755      * o = new KJUR.asn1.DERUTCTime();
+756      * o.setByDate(new Date("2016/12/31 23:59:59.12"));
+757      * // 2015-Jan-31 23:59:59.12
+758      * o.setByDate(new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)));
+759      */
+760     this.setByDate = function(dateObject) {
+761         this.hTLV = null;
+762         this.isModified = true;
+763 	if (this.params == undefined) this.params = {};
+764 	this.params.date = dateObject;
+765     };
+766 
+767     /**
+768      * set value by a Date object
+769      * @name setByDateValue
+770      * @memberOf KJUR.asn1.DERAbstractTime#
+771      * @function
+772      * @param {Integer} year year of date (ex. 2013)
+773      * @param {Integer} month month of date between 1 and 12 (ex. 12)
+774      * @param {Integer} day day of month
+775      * @param {Integer} hour hours of date
+776      * @param {Integer} min minutes of date
+777      * @param {Integer} sec seconds of date
+778      */
+779     this.setByDateValue = function(year, month, day, hour, min, sec) {
+780         var dateObject = new Date(Date.UTC(year, month - 1, day, 
+781 					   hour, min, sec, 0));
+782         this.setByDate(dateObject);
+783     };
 784 
-785 // ********************************************************************
-786 //  ASN.1 Object Classes
-787 // ********************************************************************
-788 
-789 // ********************************************************************
-790 /**
-791  * class for ASN.1 DER Boolean
-792  * @name KJUR.asn1.DERBoolean
-793  * @class class for ASN.1 DER Boolean
-794  * @extends KJUR.asn1.ASN1Object
-795  * @see KJUR.asn1.ASN1Object - superclass
-796  * @description
-797  * In ASN.1 DER, DER Boolean "false" shall be omitted.
-798  * However this supports boolean false for future BER support.
-799  * @example
-800  * new KJUR.asn1.DERBoolean(true)
-801  * new KJUR.asn1.DERBoolean(false)
-802  */
-803 KJUR.asn1.DERBoolean = function(params) {
-804     KJUR.asn1.DERBoolean.superclass.constructor.call(this);
-805     this.hT = "01";
-806     if (params == false)
-807 	this.hTLV = "010100";
-808     else 
-809 	this.hTLV = "0101ff";
-810 };
-811 extendClass(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
-812 
-813 // ********************************************************************
-814 /**
-815  * class for ASN.1 DER Integer
-816  * @name KJUR.asn1.DERInteger
-817  * @class class for ASN.1 DER Integer
-818  * @extends KJUR.asn1.ASN1Object
-819  * @description
-820  * <br/>
-821  * As for argument 'params' for constructor, you can specify one of
-822  * following properties:
-823  * <ul>
-824  * <li>int - specify initial ASN.1 value(V) by integer value</li>
-825  * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li>
-826  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
-827  * </ul>
-828  * NOTE: 'params' can be omitted.
-829  */
-830 KJUR.asn1.DERInteger = function(params) {
-831     KJUR.asn1.DERInteger.superclass.constructor.call(this);
-832     this.hT = "02";
-833 
-834     /**
-835      * set value by Tom Wu's BigInteger object
-836      * @name setByBigInteger
-837      * @memberOf KJUR.asn1.DERInteger#
-838      * @function
-839      * @param {BigInteger} bigIntegerValue to set
-840      */
-841     this.setByBigInteger = function(bigIntegerValue) {
-842         this.hTLV = null;
-843         this.isModified = true;
-844         this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
-845     };
-846 
-847     /**
-848      * set value by integer value
-849      * @name setByInteger
-850      * @memberOf KJUR.asn1.DERInteger
-851      * @function
-852      * @param {Integer} integer value to set
-853      */
-854     this.setByInteger = function(intValue) {
-855         var bi = new BigInteger(String(intValue), 10);
-856         this.setByBigInteger(bi);
-857     };
-858 
-859     /**
-860      * set value by integer value
-861      * @name setValueHex
-862      * @memberOf KJUR.asn1.DERInteger#
-863      * @function
-864      * @param {String} hexadecimal string of integer value
-865      * @description
-866      * <br/>
-867      * NOTE: Value shall be represented by minimum octet length of
-868      * two's complement representation.
-869      * @example
-870      * new KJUR.asn1.DERInteger(123);
-871      * new KJUR.asn1.DERInteger({'int': 123});
-872      * new KJUR.asn1.DERInteger({'hex': '1fad'});
-873      */
-874     this.setValueHex = function(newHexString) {
-875         this.hV = newHexString;
-876     };
-877 
-878     this.getFreshValueHex = function() {
-879         return this.hV;
-880     };
-881 
-882     if (typeof params != "undefined") {
-883         if (typeof params['bigint'] != "undefined") {
-884             this.setByBigInteger(params['bigint']);
-885         } else if (typeof params['int'] != "undefined") {
-886             this.setByInteger(params['int']);
-887         } else if (typeof params == "number") {
-888             this.setByInteger(params);
-889         } else if (typeof params['hex'] != "undefined") {
-890             this.setValueHex(params['hex']);
-891         }
-892     }
-893 };
-894 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
-895 
-896 // ********************************************************************
-897 /**
-898  * class for ASN.1 DER encoded BitString primitive
-899  * @name KJUR.asn1.DERBitString
-900  * @class class for ASN.1 DER encoded BitString primitive
-901  * @extends KJUR.asn1.ASN1Object
-902  * @description 
-903  * <br/>
-904  * As for argument 'params' for constructor, you can specify one of
-905  * following properties:
-906  * <ul>
-907  * <li>bin - specify binary string (ex. '10111')</li>
-908  * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
-909  * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
-910  * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} 
-911  * argument for "BitString encapsulates" structure.</li>
-912  * </ul>
-913  * NOTE1: 'params' can be omitted.<br/>
-914  * NOTE2: 'obj' parameter have been supported since
-915  * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
-916  * @example
-917  * // default constructor
-918  * o = new KJUR.asn1.DERBitString();
-919  * // initialize with binary string
-920  * o = new KJUR.asn1.DERBitString({bin: "1011"});
-921  * // initialize with boolean array
-922  * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
-923  * // initialize with hexadecimal string (04 is unused bits)
-924  * o = new KJUR.asn1.DEROctetString({hex: "04bac0"});
-925  * // initialize with ASN1Util.newObject argument for encapsulated
-926  * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
-927  * // above generates a ASN.1 data like this:
-928  * // BIT STRING, encapsulates {
-929  * //   SEQUENCE {
-930  * //     INTEGER 3
-931  * //     PrintableString 'aaa'
-932  * //     }
-933  * //   } 
-934  */
-935 KJUR.asn1.DERBitString = function(params) {
-936     if (params !== undefined && typeof params.obj !== "undefined") {
-937 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
-938 	params.hex = "00" + o.getEncodedHex();
-939     }
-940     KJUR.asn1.DERBitString.superclass.constructor.call(this);
-941     this.hT = "03";
-942 
-943     /**
-944      * set ASN.1 value(V) by a hexadecimal string including unused bits
-945      * @name setHexValueIncludingUnusedBits
-946      * @memberOf KJUR.asn1.DERBitString#
-947      * @function
-948      * @param {String} newHexStringIncludingUnusedBits
-949      */
-950     this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) {
-951         this.hTLV = null;
-952         this.isModified = true;
-953         this.hV = newHexStringIncludingUnusedBits;
-954     };
-955 
-956     /**
-957      * set ASN.1 value(V) by unused bit and hexadecimal string of value
-958      * @name setUnusedBitsAndHexValue
-959      * @memberOf KJUR.asn1.DERBitString#
-960      * @function
-961      * @param {Integer} unusedBits
-962      * @param {String} hValue
-963      */
-964     this.setUnusedBitsAndHexValue = function(unusedBits, hValue) {
-965         if (unusedBits < 0 || 7 < unusedBits) {
-966             throw "unused bits shall be from 0 to 7: u = " + unusedBits;
-967         }
-968         var hUnusedBits = "0" + unusedBits;
-969         this.hTLV = null;
-970         this.isModified = true;
-971         this.hV = hUnusedBits + hValue;
-972     };
-973 
-974     /**
-975      * set ASN.1 DER BitString by binary string<br/>
-976      * @name setByBinaryString
-977      * @memberOf KJUR.asn1.DERBitString#
-978      * @function
-979      * @param {String} binaryString binary value string (i.e. '10111')
-980      * @description
-981      * Its unused bits will be calculated automatically by length of 
-982      * 'binaryValue'. <br/>
-983      * NOTE: Trailing zeros '0' will be ignored.
-984      * @example
-985      * o = new KJUR.asn1.DERBitString();
-986      * o.setByBooleanArray("01011");
-987      */
-988     this.setByBinaryString = function(binaryString) {
-989         binaryString = binaryString.replace(/0+$/, '');
-990         var unusedBits = 8 - binaryString.length % 8;
-991         if (unusedBits == 8) unusedBits = 0;
-992         for (var i = 0; i <= unusedBits; i++) {
-993             binaryString += '0';
-994         }
-995         var h = '';
-996         for (var i = 0; i < binaryString.length - 1; i += 8) {
-997             var b = binaryString.substr(i, 8);
-998             var x = parseInt(b, 2).toString(16);
-999             if (x.length == 1) x = '0' + x;
-1000             h += x;  
-1001         }
-1002         this.hTLV = null;
-1003         this.isModified = true;
-1004         this.hV = '0' + unusedBits + h;
-1005     };
-1006 
-1007     /**
-1008      * set ASN.1 TLV value(V) by an array of boolean<br/>
-1009      * @name setByBooleanArray
-1010      * @memberOf KJUR.asn1.DERBitString#
-1011      * @function
-1012      * @param {array} booleanArray array of boolean (ex. [true, false, true])
-1013      * @description
-1014      * NOTE: Trailing falses will be ignored in the ASN.1 DER Object.
-1015      * @example
-1016      * o = new KJUR.asn1.DERBitString();
-1017      * o.setByBooleanArray([false, true, false, true, true]);
-1018      */
-1019     this.setByBooleanArray = function(booleanArray) {
-1020         var s = '';
-1021         for (var i = 0; i < booleanArray.length; i++) {
-1022             if (booleanArray[i] == true) {
-1023                 s += '1';
-1024             } else {
-1025                 s += '0';
-1026             }
-1027         }
-1028         this.setByBinaryString(s);
+785     this.getFreshValueHex = function() {
+786         return this.hV;
+787     };
+788 };
+789 extendClass(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
+790 // == END   DERAbstractTime ==================================================
+791 
+792 // == BEGIN DERAbstractStructured ============================================
+793 /**
+794  * base class for ASN.1 DER structured class
+795  * @name KJUR.asn1.DERAbstractStructured
+796  * @class base class for ASN.1 DER structured class
+797  * @property {Array} asn1Array internal array of ASN1Object
+798  * @extends KJUR.asn1.ASN1Object
+799  * @description
+800  * @see KJUR.asn1.ASN1Object - superclass
+801  */
+802 KJUR.asn1.DERAbstractStructured = function(params) {
+803     KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
+804     var asn1Array = null;
+805 
+806     /**
+807      * set value by array of ASN1Object
+808      * @name setByASN1ObjectArray
+809      * @memberOf KJUR.asn1.DERAbstractStructured#
+810      * @function
+811      * @param {array} asn1ObjectArray array of ASN1Object to set
+812      */
+813     this.setByASN1ObjectArray = function(asn1ObjectArray) {
+814         this.hTLV = null;
+815         this.isModified = true;
+816         this.asn1Array = asn1ObjectArray;
+817     };
+818 
+819     /**
+820      * append an ASN1Object to internal array
+821      * @name appendASN1Object
+822      * @memberOf KJUR.asn1.DERAbstractStructured#
+823      * @function
+824      * @param {ASN1Object} asn1Object to add
+825      */
+826     this.appendASN1Object = function(asn1Object) {
+827         this.hTLV = null;
+828         this.isModified = true;
+829         this.asn1Array.push(asn1Object);
+830     };
+831 
+832     this.asn1Array = new Array();
+833     if (typeof params != "undefined") {
+834         if (typeof params['array'] != "undefined") {
+835             this.asn1Array = params['array'];
+836         }
+837     }
+838 };
+839 extendClass(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
+840 
+841 
+842 // ********************************************************************
+843 //  ASN.1 Object Classes
+844 // ********************************************************************
+845 
+846 // ********************************************************************
+847 /**
+848  * class for ASN.1 DER Boolean
+849  * @name KJUR.asn1.DERBoolean
+850  * @class class for ASN.1 DER Boolean
+851  * @extends KJUR.asn1.ASN1Object
+852  * @see KJUR.asn1.ASN1Object - superclass
+853  * @description
+854  * In ASN.1 DER, DER Boolean "false" shall be omitted.
+855  * However this supports boolean false for future BER support.
+856  * @example
+857  * new KJUR.asn1.DERBoolean(true)
+858  * new KJUR.asn1.DERBoolean(false)
+859  */
+860 KJUR.asn1.DERBoolean = function(params) {
+861     KJUR.asn1.DERBoolean.superclass.constructor.call(this);
+862     this.hT = "01";
+863     if (params == false)
+864 	this.hTLV = "010100";
+865     else 
+866 	this.hTLV = "0101ff";
+867 };
+868 extendClass(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
+869 
+870 // ********************************************************************
+871 /**
+872  * class for ASN.1 DER Integer
+873  * @name KJUR.asn1.DERInteger
+874  * @class class for ASN.1 DER Integer
+875  * @extends KJUR.asn1.ASN1Object
+876  * @description
+877  * <br/>
+878  * As for argument 'params' for constructor, you can specify one of
+879  * following properties:
+880  * <ul>
+881  * <li>int - specify initial ASN.1 value(V) by integer value</li>
+882  * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li>
+883  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
+884  * </ul>
+885  * NOTE: 'params' can be omitted.
+886  */
+887 KJUR.asn1.DERInteger = function(params) {
+888     KJUR.asn1.DERInteger.superclass.constructor.call(this);
+889     this.hT = "02";
+890 
+891     /**
+892      * set value by Tom Wu's BigInteger object
+893      * @name setByBigInteger
+894      * @memberOf KJUR.asn1.DERInteger#
+895      * @function
+896      * @param {BigInteger} bigIntegerValue to set
+897      */
+898     this.setByBigInteger = function(bigIntegerValue) {
+899         this.hTLV = null;
+900         this.isModified = true;
+901         this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
+902     };
+903 
+904     /**
+905      * set value by integer value
+906      * @name setByInteger
+907      * @memberOf KJUR.asn1.DERInteger
+908      * @function
+909      * @param {Integer} integer value to set
+910      */
+911     this.setByInteger = function(intValue) {
+912         var bi = new BigInteger(String(intValue), 10);
+913         this.setByBigInteger(bi);
+914     };
+915 
+916     /**
+917      * set value by integer value
+918      * @name setValueHex
+919      * @memberOf KJUR.asn1.DERInteger#
+920      * @function
+921      * @param {String} hexadecimal string of integer value
+922      * @description
+923      * <br/>
+924      * NOTE: Value shall be represented by minimum octet length of
+925      * two's complement representation.
+926      * @example
+927      * new KJUR.asn1.DERInteger(123);
+928      * new KJUR.asn1.DERInteger({'int': 123});
+929      * new KJUR.asn1.DERInteger({'hex': '1fad'});
+930      */
+931     this.setValueHex = function(newHexString) {
+932         this.hV = newHexString;
+933     };
+934 
+935     this.getFreshValueHex = function() {
+936         return this.hV;
+937     };
+938 
+939     if (typeof params != "undefined") {
+940         if (typeof params['bigint'] != "undefined") {
+941             this.setByBigInteger(params['bigint']);
+942         } else if (typeof params['int'] != "undefined") {
+943             this.setByInteger(params['int']);
+944         } else if (typeof params == "number") {
+945             this.setByInteger(params);
+946         } else if (typeof params['hex'] != "undefined") {
+947             this.setValueHex(params['hex']);
+948         }
+949     }
+950 };
+951 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
+952 
+953 // ********************************************************************
+954 /**
+955  * class for ASN.1 DER encoded BitString primitive
+956  * @name KJUR.asn1.DERBitString
+957  * @class class for ASN.1 DER encoded BitString primitive
+958  * @extends KJUR.asn1.ASN1Object
+959  * @description 
+960  * <br/>
+961  * As for argument 'params' for constructor, you can specify one of
+962  * following properties:
+963  * <ul>
+964  * <li>bin - specify binary string (ex. '10111')</li>
+965  * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
+966  * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
+967  * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} 
+968  * argument for "BitString encapsulates" structure.</li>
+969  * </ul>
+970  * NOTE1: 'params' can be omitted.<br/>
+971  * NOTE2: 'obj' parameter have been supported since
+972  * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
+973  * @example
+974  * // default constructor
+975  * o = new KJUR.asn1.DERBitString();
+976  * // initialize with binary string
+977  * o = new KJUR.asn1.DERBitString({bin: "1011"});
+978  * // initialize with boolean array
+979  * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
+980  * // initialize with hexadecimal string (04 is unused bits)
+981  * o = new KJUR.asn1.DEROctetString({hex: "04bac0"});
+982  * // initialize with ASN1Util.newObject argument for encapsulated
+983  * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
+984  * // above generates a ASN.1 data like this:
+985  * // BIT STRING, encapsulates {
+986  * //   SEQUENCE {
+987  * //     INTEGER 3
+988  * //     PrintableString 'aaa'
+989  * //     }
+990  * //   } 
+991  */
+992 KJUR.asn1.DERBitString = function(params) {
+993     if (params !== undefined && typeof params.obj !== "undefined") {
+994 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
+995 	params.hex = "00" + o.getEncodedHex();
+996     }
+997     KJUR.asn1.DERBitString.superclass.constructor.call(this);
+998     this.hT = "03";
+999 
+1000     /**
+1001      * set ASN.1 value(V) by a hexadecimal string including unused bits
+1002      * @name setHexValueIncludingUnusedBits
+1003      * @memberOf KJUR.asn1.DERBitString#
+1004      * @function
+1005      * @param {String} newHexStringIncludingUnusedBits
+1006      */
+1007     this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) {
+1008         this.hTLV = null;
+1009         this.isModified = true;
+1010         this.hV = newHexStringIncludingUnusedBits;
+1011     };
+1012 
+1013     /**
+1014      * set ASN.1 value(V) by unused bit and hexadecimal string of value
+1015      * @name setUnusedBitsAndHexValue
+1016      * @memberOf KJUR.asn1.DERBitString#
+1017      * @function
+1018      * @param {Integer} unusedBits
+1019      * @param {String} hValue
+1020      */
+1021     this.setUnusedBitsAndHexValue = function(unusedBits, hValue) {
+1022         if (unusedBits < 0 || 7 < unusedBits) {
+1023             throw "unused bits shall be from 0 to 7: u = " + unusedBits;
+1024         }
+1025         var hUnusedBits = "0" + unusedBits;
+1026         this.hTLV = null;
+1027         this.isModified = true;
+1028         this.hV = hUnusedBits + hValue;
 1029     };
 1030 
 1031     /**
-1032      * generate an array of falses with specified length<br/>
-1033      * @name newFalseArray
-1034      * @memberOf KJUR.asn1.DERBitString
+1032      * set ASN.1 DER BitString by binary string<br/>
+1033      * @name setByBinaryString
+1034      * @memberOf KJUR.asn1.DERBitString#
 1035      * @function
-1036      * @param {Integer} nLength length of array to generate
-1037      * @return {array} array of boolean falses
-1038      * @description
-1039      * This static method may be useful to initialize boolean array.
-1040      * @example
-1041      * o = new KJUR.asn1.DERBitString();
-1042      * o.newFalseArray(3) → [false, false, false]
-1043      */
-1044     this.newFalseArray = function(nLength) {
-1045         var a = new Array(nLength);
-1046         for (var i = 0; i < nLength; i++) {
-1047             a[i] = false;
-1048         }
-1049         return a;
-1050     };
-1051 
-1052     this.getFreshValueHex = function() {
-1053         return this.hV;
-1054     };
-1055 
-1056     if (typeof params != "undefined") {
-1057         if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
-1058             this.setHexValueIncludingUnusedBits(params);
-1059         } else if (typeof params['hex'] != "undefined") {
-1060             this.setHexValueIncludingUnusedBits(params['hex']);
-1061         } else if (typeof params['bin'] != "undefined") {
-1062             this.setByBinaryString(params['bin']);
-1063         } else if (typeof params['array'] != "undefined") {
-1064             this.setByBooleanArray(params['array']);
-1065         }
-1066     }
-1067 };
-1068 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
-1069 
-1070 // ********************************************************************
-1071 /**
-1072  * class for ASN.1 DER OctetString<br/>
-1073  * @name KJUR.asn1.DEROctetString
-1074  * @class class for ASN.1 DER OctetString
-1075  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1076  * @extends KJUR.asn1.DERAbstractString
-1077  * @description
-1078  * This class provides ASN.1 OctetString simple type.<br/>
-1079  * Supported "params" attributes are:
-1080  * <ul>
-1081  * <li>str - to set a string as a value</li>
-1082  * <li>hex - to set a hexadecimal string as a value</li>
-1083  * <li>obj - to set a encapsulated ASN.1 value by JSON object 
-1084  * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li>
-1085  * </ul>
-1086  * NOTE: A parameter 'obj' have been supported 
-1087  * for "OCTET STRING, encapsulates" structure.
-1088  * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
-1089  * @see KJUR.asn1.DERAbstractString - superclass
-1090  * @example
-1091  * // default constructor
-1092  * o = new KJUR.asn1.DEROctetString();
-1093  * // initialize with string
-1094  * o = new KJUR.asn1.DEROctetString({str: "aaa"});
-1095  * // initialize with hexadecimal string
-1096  * o = new KJUR.asn1.DEROctetString({hex: "616161"});
-1097  * // initialize with ASN1Util.newObject argument 
-1098  * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
-1099  * // above generates a ASN.1 data like this:
-1100  * // OCTET STRING, encapsulates {
-1101  * //   SEQUENCE {
-1102  * //     INTEGER 3
-1103  * //     PrintableString 'aaa'
-1104  * //     }
-1105  * //   } 
-1106  */
-1107 KJUR.asn1.DEROctetString = function(params) {
-1108     if (params !== undefined && typeof params.obj !== "undefined") {
-1109 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
-1110 	params.hex = o.getEncodedHex();
-1111     }
-1112     KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
-1113     this.hT = "04";
-1114 };
-1115 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
-1116 
-1117 // ********************************************************************
-1118 /**
-1119  * class for ASN.1 DER Null
-1120  * @name KJUR.asn1.DERNull
-1121  * @class class for ASN.1 DER Null
-1122  * @extends KJUR.asn1.ASN1Object
-1123  * @description
-1124  * @see KJUR.asn1.ASN1Object - superclass
-1125  */
-1126 KJUR.asn1.DERNull = function() {
-1127     KJUR.asn1.DERNull.superclass.constructor.call(this);
-1128     this.hT = "05";
-1129     this.hTLV = "0500";
-1130 };
-1131 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
-1132 
-1133 // ********************************************************************
-1134 /**
-1135  * class for ASN.1 DER ObjectIdentifier
-1136  * @name KJUR.asn1.DERObjectIdentifier
-1137  * @class class for ASN.1 DER ObjectIdentifier
-1138  * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'})
-1139  * @extends KJUR.asn1.ASN1Object
-1140  * @see oidtohex
-1141  * 
-1142  * @description
-1143  * <br/>
-1144  * As for argument 'params' for constructor, you can specify one of
-1145  * following properties:
-1146  * <ul>
-1147  * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li>
-1148  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
-1149  * </ul>
-1150  * NOTE: 'params' can be omitted.
-1151  * @example
-1152  * new DERObjectIdentifier({"name": "sha1"})
-1153  * new DERObjectIdentifier({"oid": "1.2.3.4"})
-1154  * new DERObjectIdentifier({"hex": "2d..."})
-1155  * new DERObjectIdentifier("1.2.3.4")
-1156  * new DERObjectIdentifier("SHA1withRSA")
-1157  */
-1158 KJUR.asn1.DERObjectIdentifier = function(params) {
-1159     KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
-1160     this.hT = "06";
-1161 
-1162     /**
-1163      * set value by a hexadecimal string
-1164      * @name setValueHex
-1165      * @memberOf KJUR.asn1.DERObjectIdentifier#
-1166      * @function
-1167      * @param {String} newHexString hexadecimal value of OID bytes
-1168      */
-1169     this.setValueHex = function(newHexString) {
-1170         this.hTLV = null;
-1171         this.isModified = true;
-1172         this.s = null;
-1173         this.hV = newHexString;
-1174     };
-1175 
-1176     /**
-1177      * set value by a OID string<br/>
-1178      * @name setValueOidString
-1179      * @memberOf KJUR.asn1.DERObjectIdentifier#
-1180      * @function
-1181      * @param {String} oidString OID string (ex. 2.5.4.13)
-1182      * @example
-1183      * o = new KJUR.asn1.DERObjectIdentifier();
-1184      * o.setValueOidString("2.5.4.13");
-1185      */
-1186     this.setValueOidString = function(oidString) {
-1187 	var h = oidtohex(oidString);
-1188 	if (h == null)
-1189             throw new Error("malformed oid string: " + oidString);
-1190         this.hTLV = null;
-1191         this.isModified = true;
-1192         this.s = null;
-1193         this.hV = h;
-1194     };
-1195 
-1196     /**
-1197      * set value by a OID name
-1198      * @name setValueName
-1199      * @memberOf KJUR.asn1.DERObjectIdentifier#
-1200      * @function
-1201      * @param {String} oidName OID name (ex. 'serverAuth')
-1202      * @since 1.0.1
-1203      * @description
-1204      * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'.
-1205      * Otherwise raise error.
-1206      * @example
-1207      * o = new KJUR.asn1.DERObjectIdentifier();
-1208      * o.setValueName("serverAuth");
-1209      */
-1210     this.setValueName = function(oidName) {
-1211 	var oid = KJUR.asn1.x509.OID.name2oid(oidName);
-1212 	if (oid !== '') {
-1213             this.setValueOidString(oid);
-1214         } else {
-1215             throw new Error("DERObjectIdentifier oidName undefined: " + oidName);
-1216         }
-1217     };
+1036      * @param {String} binaryString binary value string (i.e. '10111')
+1037      * @description
+1038      * Its unused bits will be calculated automatically by length of 
+1039      * 'binaryValue'. <br/>
+1040      * NOTE: Trailing zeros '0' will be ignored.
+1041      * @example
+1042      * o = new KJUR.asn1.DERBitString();
+1043      * o.setByBooleanArray("01011");
+1044      */
+1045     this.setByBinaryString = function(binaryString) {
+1046         binaryString = binaryString.replace(/0+$/, '');
+1047         var unusedBits = 8 - binaryString.length % 8;
+1048         if (unusedBits == 8) unusedBits = 0;
+1049         for (var i = 0; i <= unusedBits; i++) {
+1050             binaryString += '0';
+1051         }
+1052         var h = '';
+1053         for (var i = 0; i < binaryString.length - 1; i += 8) {
+1054             var b = binaryString.substr(i, 8);
+1055             var x = parseInt(b, 2).toString(16);
+1056             if (x.length == 1) x = '0' + x;
+1057             h += x;  
+1058         }
+1059         this.hTLV = null;
+1060         this.isModified = true;
+1061         this.hV = '0' + unusedBits + h;
+1062     };
+1063 
+1064     /**
+1065      * set ASN.1 TLV value(V) by an array of boolean<br/>
+1066      * @name setByBooleanArray
+1067      * @memberOf KJUR.asn1.DERBitString#
+1068      * @function
+1069      * @param {array} booleanArray array of boolean (ex. [true, false, true])
+1070      * @description
+1071      * NOTE: Trailing falses will be ignored in the ASN.1 DER Object.
+1072      * @example
+1073      * o = new KJUR.asn1.DERBitString();
+1074      * o.setByBooleanArray([false, true, false, true, true]);
+1075      */
+1076     this.setByBooleanArray = function(booleanArray) {
+1077         var s = '';
+1078         for (var i = 0; i < booleanArray.length; i++) {
+1079             if (booleanArray[i] == true) {
+1080                 s += '1';
+1081             } else {
+1082                 s += '0';
+1083             }
+1084         }
+1085         this.setByBinaryString(s);
+1086     };
+1087 
+1088     /**
+1089      * generate an array of falses with specified length<br/>
+1090      * @name newFalseArray
+1091      * @memberOf KJUR.asn1.DERBitString
+1092      * @function
+1093      * @param {Integer} nLength length of array to generate
+1094      * @return {array} array of boolean falses
+1095      * @description
+1096      * This static method may be useful to initialize boolean array.
+1097      * @example
+1098      * o = new KJUR.asn1.DERBitString();
+1099      * o.newFalseArray(3) → [false, false, false]
+1100      */
+1101     this.newFalseArray = function(nLength) {
+1102         var a = new Array(nLength);
+1103         for (var i = 0; i < nLength; i++) {
+1104             a[i] = false;
+1105         }
+1106         return a;
+1107     };
+1108 
+1109     this.getFreshValueHex = function() {
+1110         return this.hV;
+1111     };
+1112 
+1113     if (typeof params != "undefined") {
+1114         if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
+1115             this.setHexValueIncludingUnusedBits(params);
+1116         } else if (typeof params['hex'] != "undefined") {
+1117             this.setHexValueIncludingUnusedBits(params['hex']);
+1118         } else if (typeof params['bin'] != "undefined") {
+1119             this.setByBinaryString(params['bin']);
+1120         } else if (typeof params['array'] != "undefined") {
+1121             this.setByBooleanArray(params['array']);
+1122         }
+1123     }
+1124 };
+1125 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
+1126 
+1127 // ********************************************************************
+1128 /**
+1129  * class for ASN.1 DER OctetString<br/>
+1130  * @name KJUR.asn1.DEROctetString
+1131  * @class class for ASN.1 DER OctetString
+1132  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1133  * @extends KJUR.asn1.DERAbstractString
+1134  * @description
+1135  * This class provides ASN.1 OctetString simple type.<br/>
+1136  * Supported "params" attributes are:
+1137  * <ul>
+1138  * <li>str - to set a string as a value</li>
+1139  * <li>hex - to set a hexadecimal string as a value</li>
+1140  * <li>obj - to set a encapsulated ASN.1 value by JSON object 
+1141  * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li>
+1142  * </ul>
+1143  * NOTE: A parameter 'obj' have been supported 
+1144  * for "OCTET STRING, encapsulates" structure.
+1145  * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
+1146  * @see KJUR.asn1.DERAbstractString - superclass
+1147  * @example
+1148  * // default constructor
+1149  * o = new KJUR.asn1.DEROctetString();
+1150  * // initialize with string
+1151  * o = new KJUR.asn1.DEROctetString({str: "aaa"});
+1152  * // initialize with hexadecimal string
+1153  * o = new KJUR.asn1.DEROctetString({hex: "616161"});
+1154  * // initialize with ASN1Util.newObject argument 
+1155  * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
+1156  * // above generates a ASN.1 data like this:
+1157  * // OCTET STRING, encapsulates {
+1158  * //   SEQUENCE {
+1159  * //     INTEGER 3
+1160  * //     PrintableString 'aaa'
+1161  * //     }
+1162  * //   } 
+1163  */
+1164 KJUR.asn1.DEROctetString = function(params) {
+1165     if (params !== undefined && typeof params.obj !== "undefined") {
+1166 	var o = KJUR.asn1.ASN1Util.newObject(params.obj);
+1167 	params.hex = o.getEncodedHex();
+1168     }
+1169     KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
+1170     this.hT = "04";
+1171 };
+1172 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
+1173 
+1174 // ********************************************************************
+1175 /**
+1176  * class for ASN.1 DER Null
+1177  * @name KJUR.asn1.DERNull
+1178  * @class class for ASN.1 DER Null
+1179  * @extends KJUR.asn1.ASN1Object
+1180  * @description
+1181  * @see KJUR.asn1.ASN1Object - superclass
+1182  */
+1183 KJUR.asn1.DERNull = function() {
+1184     KJUR.asn1.DERNull.superclass.constructor.call(this);
+1185     this.hT = "05";
+1186     this.hTLV = "0500";
+1187 };
+1188 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
+1189 
+1190 // ********************************************************************
+1191 /**
+1192  * class for ASN.1 DER ObjectIdentifier
+1193  * @name KJUR.asn1.DERObjectIdentifier
+1194  * @class class for ASN.1 DER ObjectIdentifier
+1195  * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'})
+1196  * @extends KJUR.asn1.ASN1Object
+1197  * @see oidtohex
+1198  * 
+1199  * @description
+1200  * <br/>
+1201  * As for argument 'params' for constructor, you can specify one of
+1202  * following properties:
+1203  * <ul>
+1204  * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li>
+1205  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
+1206  * </ul>
+1207  * NOTE: 'params' can be omitted.
+1208  * @example
+1209  * new DERObjectIdentifier({"name": "sha1"})
+1210  * new DERObjectIdentifier({"oid": "1.2.3.4"})
+1211  * new DERObjectIdentifier({"hex": "2d..."})
+1212  * new DERObjectIdentifier("1.2.3.4")
+1213  * new DERObjectIdentifier("SHA1withRSA")
+1214  */
+1215 KJUR.asn1.DERObjectIdentifier = function(params) {
+1216     KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
+1217     this.hT = "06";
 1218 
-1219     this.setValueNameOrOid = function(nameOrOid) {
-1220 	if (nameOrOid.match(/^[0-2].[0-9.]+$/)) {
-1221 	    this.setValueOidString(nameOrOid);
-1222 	} else {
-1223 	    this.setValueName(nameOrOid);
-1224 	}
-1225     }
-1226 
-1227     this.getFreshValueHex = function() {
-1228         return this.hV;
-1229     };
-1230 
-1231     this.setByParam = function(params) {
-1232         if (typeof params === "string") {
-1233 	    this.setValueNameOrOid(params);
-1234         } else if (params.oid !== undefined) {
-1235 	    this.setValueNameOrOid(params.oid);
-1236         } else if (params.name !== undefined) {
-1237             this.setValueNameOrOid(params.name);
-1238         } else if (params.hex !== undefined) {
-1239             this.setValueHex(params.hex);
-1240         }
-1241     };
-1242 
-1243     if (params !== undefined) this.setByParam(params);
-1244 };
-1245 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
-1246 
-1247 // ********************************************************************
-1248 /**
-1249  * class for ASN.1 DER Enumerated
-1250  * @name KJUR.asn1.DEREnumerated
-1251  * @class class for ASN.1 DER Enumerated
-1252  * @extends KJUR.asn1.ASN1Object
-1253  * @description
-1254  * <br/>
-1255  * As for argument 'params' for constructor, you can specify one of
-1256  * following properties:
-1257  * <ul>
-1258  * <li>int - specify initial ASN.1 value(V) by integer value</li>
-1259  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
-1260  * </ul>
-1261  * NOTE: 'params' can be omitted.
-1262  * @example
-1263  * new KJUR.asn1.DEREnumerated(123);
-1264  * new KJUR.asn1.DEREnumerated({int: 123});
-1265  * new KJUR.asn1.DEREnumerated({hex: '1fad'});
-1266  */
-1267 KJUR.asn1.DEREnumerated = function(params) {
-1268     KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
-1269     this.hT = "0a";
-1270 
-1271     /**
-1272      * set value by Tom Wu's BigInteger object
-1273      * @name setByBigInteger
-1274      * @memberOf KJUR.asn1.DEREnumerated#
-1275      * @function
-1276      * @param {BigInteger} bigIntegerValue to set
-1277      */
-1278     this.setByBigInteger = function(bigIntegerValue) {
-1279         this.hTLV = null;
-1280         this.isModified = true;
-1281         this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
-1282     };
+1219     /**
+1220      * set value by a hexadecimal string
+1221      * @name setValueHex
+1222      * @memberOf KJUR.asn1.DERObjectIdentifier#
+1223      * @function
+1224      * @param {String} newHexString hexadecimal value of OID bytes
+1225      */
+1226     this.setValueHex = function(newHexString) {
+1227         this.hTLV = null;
+1228         this.isModified = true;
+1229         this.s = null;
+1230         this.hV = newHexString;
+1231     };
+1232 
+1233     /**
+1234      * set value by a OID string<br/>
+1235      * @name setValueOidString
+1236      * @memberOf KJUR.asn1.DERObjectIdentifier#
+1237      * @function
+1238      * @param {String} oidString OID string (ex. 2.5.4.13)
+1239      * @example
+1240      * o = new KJUR.asn1.DERObjectIdentifier();
+1241      * o.setValueOidString("2.5.4.13");
+1242      */
+1243     this.setValueOidString = function(oidString) {
+1244 	var h = oidtohex(oidString);
+1245 	if (h == null)
+1246             throw new Error("malformed oid string: " + oidString);
+1247         this.hTLV = null;
+1248         this.isModified = true;
+1249         this.s = null;
+1250         this.hV = h;
+1251     };
+1252 
+1253     /**
+1254      * set value by a OID name
+1255      * @name setValueName
+1256      * @memberOf KJUR.asn1.DERObjectIdentifier#
+1257      * @function
+1258      * @param {String} oidName OID name (ex. 'serverAuth')
+1259      * @since 1.0.1
+1260      * @description
+1261      * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'.
+1262      * Otherwise raise error.
+1263      * @example
+1264      * o = new KJUR.asn1.DERObjectIdentifier();
+1265      * o.setValueName("serverAuth");
+1266      */
+1267     this.setValueName = function(oidName) {
+1268 	var oid = KJUR.asn1.x509.OID.name2oid(oidName);
+1269 	if (oid !== '') {
+1270             this.setValueOidString(oid);
+1271         } else {
+1272             throw new Error("DERObjectIdentifier oidName undefined: " + oidName);
+1273         }
+1274     };
+1275 
+1276     this.setValueNameOrOid = function(nameOrOid) {
+1277 	if (nameOrOid.match(/^[0-2].[0-9.]+$/)) {
+1278 	    this.setValueOidString(nameOrOid);
+1279 	} else {
+1280 	    this.setValueName(nameOrOid);
+1281 	}
+1282     }
 1283 
-1284     /**
-1285      * set value by integer value
-1286      * @name setByInteger
-1287      * @memberOf KJUR.asn1.DEREnumerated#
-1288      * @function
-1289      * @param {Integer} integer value to set
-1290      */
-1291     this.setByInteger = function(intValue) {
-1292         var bi = new BigInteger(String(intValue), 10);
-1293         this.setByBigInteger(bi);
-1294     };
-1295 
-1296     /**
-1297      * set value by integer value
-1298      * @name setValueHex
-1299      * @memberOf KJUR.asn1.DEREnumerated#
-1300      * @function
-1301      * @param {String} hexadecimal string of integer value
-1302      * @description
-1303      * <br/>
-1304      * NOTE: Value shall be represented by minimum octet length of
-1305      * two's complement representation.
-1306      */
-1307     this.setValueHex = function(newHexString) {
-1308         this.hV = newHexString;
-1309     };
-1310 
-1311     this.getFreshValueHex = function() {
-1312         return this.hV;
-1313     };
-1314 
-1315     if (typeof params != "undefined") {
-1316         if (typeof params['int'] != "undefined") {
-1317             this.setByInteger(params['int']);
-1318         } else if (typeof params == "number") {
-1319             this.setByInteger(params);
-1320         } else if (typeof params['hex'] != "undefined") {
-1321             this.setValueHex(params['hex']);
-1322         }
-1323     }
-1324 };
-1325 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
-1326 
-1327 // ********************************************************************
-1328 /**
-1329  * class for ASN.1 DER UTF8String
-1330  * @name KJUR.asn1.DERUTF8String
-1331  * @class class for ASN.1 DER UTF8String
-1332  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1333  * @extends KJUR.asn1.DERAbstractString
-1334  * @description
-1335  * @see KJUR.asn1.DERAbstractString - superclass
-1336  */
-1337 KJUR.asn1.DERUTF8String = function(params) {
-1338     KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
-1339     this.hT = "0c";
-1340 };
-1341 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
-1342 
-1343 // ********************************************************************
-1344 /**
-1345  * class for ASN.1 DER NumericString
-1346  * @name KJUR.asn1.DERNumericString
-1347  * @class class for ASN.1 DER NumericString
-1348  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1349  * @extends KJUR.asn1.DERAbstractString
-1350  * @description
-1351  * @see KJUR.asn1.DERAbstractString - superclass
-1352  */
-1353 KJUR.asn1.DERNumericString = function(params) {
-1354     KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
-1355     this.hT = "12";
-1356 };
-1357 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
-1358 
-1359 // ********************************************************************
-1360 /**
-1361  * class for ASN.1 DER PrintableString
-1362  * @name KJUR.asn1.DERPrintableString
-1363  * @class class for ASN.1 DER PrintableString
-1364  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1365  * @extends KJUR.asn1.DERAbstractString
-1366  * @description
-1367  * @see KJUR.asn1.DERAbstractString - superclass
-1368  */
-1369 KJUR.asn1.DERPrintableString = function(params) {
-1370     KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
-1371     this.hT = "13";
-1372 };
-1373 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
-1374 
-1375 // ********************************************************************
-1376 /**
-1377  * class for ASN.1 DER TeletexString
-1378  * @name KJUR.asn1.DERTeletexString
-1379  * @class class for ASN.1 DER TeletexString
-1380  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1381  * @extends KJUR.asn1.DERAbstractString
-1382  * @description
-1383  * @see KJUR.asn1.DERAbstractString - superclass
-1384  */
-1385 KJUR.asn1.DERTeletexString = function(params) {
-1386     KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
-1387     this.hT = "14";
-1388 };
-1389 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
-1390 
-1391 // ********************************************************************
-1392 /**
-1393  * class for ASN.1 DER IA5String
-1394  * @name KJUR.asn1.DERIA5String
-1395  * @class class for ASN.1 DER IA5String
-1396  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1397  * @extends KJUR.asn1.DERAbstractString
-1398  * @description
-1399  * @see KJUR.asn1.DERAbstractString - superclass
-1400  */
-1401 KJUR.asn1.DERIA5String = function(params) {
-1402     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
-1403     this.hT = "16";
-1404 };
-1405 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
-1406 
-1407 // ********************************************************************
-1408 /**
-1409  * class for ASN.1 DER VisibleString
-1410  * @name KJUR.asn1.DERVisibleString
-1411  * @class class for ASN.1 DER VisibleString
-1412  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1413  * @extends KJUR.asn1.DERAbstractString
-1414  * @since jsrsasign 8.0.23 asn1 1.0.15
-1415  * @description
-1416  * @see KJUR.asn1.DERAbstractString - superclass
-1417  */
-1418 KJUR.asn1.DERVisibleString = function(params) {
-1419     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
-1420     this.hT = "1a";
-1421 };
-1422 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString);
-1423 
-1424 // ********************************************************************
-1425 /**
-1426  * class for ASN.1 DER BMPString
-1427  * @name KJUR.asn1.DERBMPString
-1428  * @class class for ASN.1 DER BMPString
-1429  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
-1430  * @extends KJUR.asn1.DERAbstractString
-1431  * @since jsrsasign 8.0.23 asn1 1.0.15
-1432  * @description
-1433  * @see KJUR.asn1.DERAbstractString - superclass
-1434  */
-1435 KJUR.asn1.DERBMPString = function(params) {
-1436     KJUR.asn1.DERBMPString.superclass.constructor.call(this, params);
-1437     this.hT = "1e";
-1438 };
-1439 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString);
-1440 
-1441 // ********************************************************************
-1442 /**
-1443  * class for ASN.1 DER UTCTime
-1444  * @name KJUR.asn1.DERUTCTime
-1445  * @class class for ASN.1 DER UTCTime
-1446  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
-1447  * @extends KJUR.asn1.DERAbstractTime
-1448  * @description
-1449  * <br/>
-1450  * As for argument 'params' for constructor, you can specify one of
-1451  * following properties:
-1452  * <ul>
-1453  * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li>
-1454  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
-1455  * <li>date - specify Date object.</li>
-1456  * </ul>
-1457  * NOTE: 'params' can be omitted.
-1458  * <h4>EXAMPLES</h4>
-1459  * @example
-1460  * d1 = new KJUR.asn1.DERUTCTime();
-1461  * d1.setString('130430125959Z');
-1462  *
-1463  * d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'});
-1464  * d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))});
-1465  * d4 = new KJUR.asn1.DERUTCTime('130430125959Z');
-1466  */
-1467 KJUR.asn1.DERUTCTime = function(params) {
-1468     KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
-1469     this.hT = "17";
-1470 
-1471     /**
-1472      * set value by a Date object<br/>
-1473      * @name setByDate
-1474      * @memberOf KJUR.asn1.DERUTCTime#
-1475      * @function
-1476      * @param {Date} dateObject Date object to set ASN.1 value(V)
-1477      * @example
-1478      * o = new KJUR.asn1.DERUTCTime();
-1479      * o.setByDate(new Date("2016/12/31"));
-1480      */
-1481     this.setByDate = function(dateObject) {
-1482         this.hTLV = null;
-1483         this.isModified = true;
-1484         this.date = dateObject;
-1485         this.s = this.formatDate(this.date, 'utc');
-1486         this.hV = stohex(this.s);
-1487     };
-1488 
-1489     this.getFreshValueHex = function() {
-1490         if (typeof this.date == "undefined" && typeof this.s == "undefined") {
-1491             this.date = new Date();
-1492             this.s = this.formatDate(this.date, 'utc');
-1493             this.hV = stohex(this.s);
-1494         }
-1495         return this.hV;
-1496     };
+1284     this.getFreshValueHex = function() {
+1285         return this.hV;
+1286     };
+1287 
+1288     this.setByParam = function(params) {
+1289         if (typeof params === "string") {
+1290 	    this.setValueNameOrOid(params);
+1291         } else if (params.oid !== undefined) {
+1292 	    this.setValueNameOrOid(params.oid);
+1293         } else if (params.name !== undefined) {
+1294             this.setValueNameOrOid(params.name);
+1295         } else if (params.hex !== undefined) {
+1296             this.setValueHex(params.hex);
+1297         }
+1298     };
+1299 
+1300     if (params !== undefined) this.setByParam(params);
+1301 };
+1302 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
+1303 
+1304 // ********************************************************************
+1305 /**
+1306  * class for ASN.1 DER Enumerated
+1307  * @name KJUR.asn1.DEREnumerated
+1308  * @class class for ASN.1 DER Enumerated
+1309  * @extends KJUR.asn1.ASN1Object
+1310  * @description
+1311  * <br/>
+1312  * As for argument 'params' for constructor, you can specify one of
+1313  * following properties:
+1314  * <ul>
+1315  * <li>int - specify initial ASN.1 value(V) by integer value</li>
+1316  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
+1317  * </ul>
+1318  * NOTE: 'params' can be omitted.
+1319  * @example
+1320  * new KJUR.asn1.DEREnumerated(123);
+1321  * new KJUR.asn1.DEREnumerated({int: 123});
+1322  * new KJUR.asn1.DEREnumerated({hex: '1fad'});
+1323  */
+1324 KJUR.asn1.DEREnumerated = function(params) {
+1325     KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
+1326     this.hT = "0a";
+1327 
+1328     /**
+1329      * set value by Tom Wu's BigInteger object
+1330      * @name setByBigInteger
+1331      * @memberOf KJUR.asn1.DEREnumerated#
+1332      * @function
+1333      * @param {BigInteger} bigIntegerValue to set
+1334      */
+1335     this.setByBigInteger = function(bigIntegerValue) {
+1336         this.hTLV = null;
+1337         this.isModified = true;
+1338         this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
+1339     };
+1340 
+1341     /**
+1342      * set value by integer value
+1343      * @name setByInteger
+1344      * @memberOf KJUR.asn1.DEREnumerated#
+1345      * @function
+1346      * @param {Integer} integer value to set
+1347      */
+1348     this.setByInteger = function(intValue) {
+1349         var bi = new BigInteger(String(intValue), 10);
+1350         this.setByBigInteger(bi);
+1351     };
+1352 
+1353     /**
+1354      * set value by integer value
+1355      * @name setValueHex
+1356      * @memberOf KJUR.asn1.DEREnumerated#
+1357      * @function
+1358      * @param {String} hexadecimal string of integer value
+1359      * @description
+1360      * <br/>
+1361      * NOTE: Value shall be represented by minimum octet length of
+1362      * two's complement representation.
+1363      */
+1364     this.setValueHex = function(newHexString) {
+1365         this.hV = newHexString;
+1366     };
+1367 
+1368     this.getFreshValueHex = function() {
+1369         return this.hV;
+1370     };
+1371 
+1372     if (typeof params != "undefined") {
+1373         if (typeof params['int'] != "undefined") {
+1374             this.setByInteger(params['int']);
+1375         } else if (typeof params == "number") {
+1376             this.setByInteger(params);
+1377         } else if (typeof params['hex'] != "undefined") {
+1378             this.setValueHex(params['hex']);
+1379         }
+1380     }
+1381 };
+1382 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
+1383 
+1384 // ********************************************************************
+1385 /**
+1386  * class for ASN.1 DER UTF8String
+1387  * @name KJUR.asn1.DERUTF8String
+1388  * @class class for ASN.1 DER UTF8String
+1389  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1390  * @extends KJUR.asn1.DERAbstractString
+1391  * @description
+1392  * @see KJUR.asn1.DERAbstractString - superclass
+1393  */
+1394 KJUR.asn1.DERUTF8String = function(params) {
+1395     KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
+1396     this.hT = "0c";
+1397 };
+1398 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
+1399 
+1400 // ********************************************************************
+1401 /**
+1402  * class for ASN.1 DER NumericString
+1403  * @name KJUR.asn1.DERNumericString
+1404  * @class class for ASN.1 DER NumericString
+1405  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1406  * @extends KJUR.asn1.DERAbstractString
+1407  * @description
+1408  * @see KJUR.asn1.DERAbstractString - superclass
+1409  */
+1410 KJUR.asn1.DERNumericString = function(params) {
+1411     KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
+1412     this.hT = "12";
+1413 };
+1414 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
+1415 
+1416 // ********************************************************************
+1417 /**
+1418  * class for ASN.1 DER PrintableString
+1419  * @name KJUR.asn1.DERPrintableString
+1420  * @class class for ASN.1 DER PrintableString
+1421  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1422  * @extends KJUR.asn1.DERAbstractString
+1423  * @description
+1424  * @see KJUR.asn1.DERAbstractString - superclass
+1425  */
+1426 KJUR.asn1.DERPrintableString = function(params) {
+1427     KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
+1428     this.hT = "13";
+1429 };
+1430 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
+1431 
+1432 // ********************************************************************
+1433 /**
+1434  * class for ASN.1 DER TeletexString
+1435  * @name KJUR.asn1.DERTeletexString
+1436  * @class class for ASN.1 DER TeletexString
+1437  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1438  * @extends KJUR.asn1.DERAbstractString
+1439  * @description
+1440  * @see KJUR.asn1.DERAbstractString - superclass
+1441  */
+1442 KJUR.asn1.DERTeletexString = function(params) {
+1443     KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
+1444     this.hT = "14";
+1445 };
+1446 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
+1447 
+1448 // ********************************************************************
+1449 /**
+1450  * class for ASN.1 DER IA5String
+1451  * @name KJUR.asn1.DERIA5String
+1452  * @class class for ASN.1 DER IA5String
+1453  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1454  * @extends KJUR.asn1.DERAbstractString
+1455  * @description
+1456  * @see KJUR.asn1.DERAbstractString - superclass
+1457  */
+1458 KJUR.asn1.DERIA5String = function(params) {
+1459     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
+1460     this.hT = "16";
+1461 };
+1462 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
+1463 
+1464 // ********************************************************************
+1465 /**
+1466  * class for ASN.1 DER VisibleString
+1467  * @name KJUR.asn1.DERVisibleString
+1468  * @class class for ASN.1 DER VisibleString
+1469  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1470  * @extends KJUR.asn1.DERAbstractString
+1471  * @since jsrsasign 8.0.23 asn1 1.0.15
+1472  * @description
+1473  * @see KJUR.asn1.DERAbstractString - superclass
+1474  */
+1475 KJUR.asn1.DERVisibleString = function(params) {
+1476     KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
+1477     this.hT = "1a";
+1478 };
+1479 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString);
+1480 
+1481 // ********************************************************************
+1482 /**
+1483  * class for ASN.1 DER BMPString
+1484  * @name KJUR.asn1.DERBMPString
+1485  * @class class for ASN.1 DER BMPString
+1486  * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
+1487  * @extends KJUR.asn1.DERAbstractString
+1488  * @since jsrsasign 8.0.23 asn1 1.0.15
+1489  * @description
+1490  * @see KJUR.asn1.DERAbstractString - superclass
+1491  */
+1492 KJUR.asn1.DERBMPString = function(params) {
+1493     KJUR.asn1.DERBMPString.superclass.constructor.call(this, params);
+1494     this.hT = "1e";
+1495 };
+1496 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString);
 1497 
-1498     if (params !== undefined) {
-1499         if (params.str !== undefined) {
-1500             this.setString(params.str);
-1501         } else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) {
-1502             this.setString(params);
-1503         } else if (params.hex !== undefined) {
-1504             this.setStringHex(params.hex);
-1505         } else if (params.date !== undefined) {
-1506             this.setByDate(params.date);
-1507         }
-1508     }
-1509 };
-1510 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
-1511 
-1512 // ********************************************************************
-1513 /**
-1514  * class for ASN.1 DER GeneralizedTime
-1515  * @name KJUR.asn1.DERGeneralizedTime
-1516  * @class class for ASN.1 DER GeneralizedTime
-1517  * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'})
-1518  * @property {Boolean} withMillis flag to show milliseconds or not
-1519  * @extends KJUR.asn1.DERAbstractTime
-1520  * @description
-1521  * <br/>
-1522  * As for argument 'params' for constructor, you can specify one of
-1523  * following properties:
-1524  * <ul>
-1525  * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li>
-1526  * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
-1527  * <li>date - specify Date object.</li>
-1528  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
-1529  * </ul>
-1530  * NOTE1: 'params' can be omitted.
-1531  * NOTE2: 'withMillis' property is supported from asn1 1.0.6.
-1532  */
-1533 KJUR.asn1.DERGeneralizedTime = function(params) {
-1534     KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
-1535     this.hT = "18";
-1536     this.withMillis = false;
-1537 
-1538     /**
-1539      * set value by a Date object
-1540      * @name setByDate
-1541      * @memberOf KJUR.asn1.DERGeneralizedTime#
-1542      * @function
-1543      * @param {Date} dateObject Date object to set ASN.1 value(V)
-1544      * @example
-1545      * When you specify UTC time, use 'Date.UTC' method like this:<br/>
-1546      * o1 = new DERUTCTime();
-1547      * o1.setByDate(date);
-1548      *
-1549      * date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59
-1550      */
-1551     this.setByDate = function(dateObject) {
-1552         this.hTLV = null;
-1553         this.isModified = true;
-1554         this.date = dateObject;
-1555         this.s = this.formatDate(this.date, 'gen', this.withMillis);
-1556         this.hV = stohex(this.s);
-1557     };
-1558 
-1559     this.getFreshValueHex = function() {
-1560         if (this.date === undefined && this.s === undefined) {
-1561             this.date = new Date();
-1562             this.s = this.formatDate(this.date, 'gen', this.withMillis);
-1563             this.hV = stohex(this.s);
-1564         }
-1565         return this.hV;
-1566     };
-1567 
-1568     if (params !== undefined) {
-1569         if (params.str !== undefined) {
-1570             this.setString(params.str);
-1571         } else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) {
-1572             this.setString(params);
-1573         } else if (params.hex !== undefined) {
-1574             this.setStringHex(params.hex);
-1575         } else if (params.date !== undefined) {
-1576             this.setByDate(params.date);
-1577         }
-1578         if (params.millis === true) {
-1579             this.withMillis = true;
-1580         }
-1581     }
-1582 };
-1583 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
-1584 
-1585 // ********************************************************************
-1586 /**
-1587  * class for ASN.1 DER Sequence
-1588  * @name KJUR.asn1.DERSequence
-1589  * @class class for ASN.1 DER Sequence
-1590  * @extends KJUR.asn1.DERAbstractStructured
-1591  * @description
-1592  * <br/>
-1593  * As for argument 'params' for constructor, you can specify one of
-1594  * following properties:
-1595  * <ul>
-1596  * <li>array - specify array of ASN1Object to set elements of content</li>
-1597  * </ul>
-1598  * NOTE: 'params' can be omitted.
-1599  */
-1600 KJUR.asn1.DERSequence = function(params) {
-1601     KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
-1602     this.hT = "30";
-1603     this.getFreshValueHex = function() {
-1604         var h = '';
-1605         for (var i = 0; i < this.asn1Array.length; i++) {
-1606             var asn1Obj = this.asn1Array[i];
-1607             h += asn1Obj.getEncodedHex();
-1608         }
-1609         this.hV = h;
-1610         return this.hV;
-1611     };
-1612 };
-1613 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
+1498 // ********************************************************************
+1499 /**
+1500  * class for ASN.1 DER UTCTime
+1501  * @name KJUR.asn1.DERUTCTime
+1502  * @class class for ASN.1 DER UTCTime
+1503  * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
+1504  * @extends KJUR.asn1.DERAbstractTime
+1505  * @see KJUR.asn1.DERGeneralizedTime
+1506  * @see KJUR.asn1.x509.Time
+1507  *
+1508  * @description
+1509  * <br/>
+1510  * As for argument 'params' for constructor, you can specify one of
+1511  * following properties:
+1512  * <ul>
+1513  * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li>
+1514  * <li>date - specify Date object.</li>
+1515  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
+1516  * </ul>
+1517  * NOTE1: 'params' can be omitted.
+1518  * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22.
+1519  *
+1520  * <h4>EXAMPLES</h4>
+1521  * @example
+1522  * new DERUTCTime("20151231235959Z")
+1523  * new DERUTCTime("20151231235959.123Z")
+1524  * new DERUTCTime(new Date())
+1525  * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
+1526  * new DERUTCTime({str: "20151231235959.123Z"})
+1527  * new DERUTCTime({date: new Date()})
+1528  * new DERUTCTime({date: new Date(), millis: true})
+1529  * new DERUTCTime({millis: true})
+1530  */
+1531 KJUR.asn1.DERUTCTime = function(params) {
+1532     KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
+1533     this.hT = "17";
+1534     this.params = undefined;
+1535 
+1536     this.getFreshValueHex = function() {
+1537 	var params = this.params;
+1538 
+1539 	if (this.params == undefined) params = { date: new Date() };
+1540 
+1541 	if (typeof params == "string") {
+1542 	    if (params.match(/^[0-9]{12}Z$/) ||
+1543 		params.match(/^[0-9]{12}\.[0-9]+Z$/)) {
+1544 		this.hV = stohex(params);
+1545 	    } else {
+1546 		throw new Error("malformed string for GeneralizedTime: " + params);
+1547 	    }
+1548 	} else if (params.str != undefined) {
+1549 	    this.hV = stohex(params.str);
+1550 	} else if (params.date == undefined && params.millis == true) {
+1551 	    var date = new Date();
+1552 	    this.hV = stohex(this.formatDate(date, 'utc', true));
+1553 	} else if (params.date != undefined &&
+1554 		   params.date instanceof Date) {
+1555 	    var withMillis = (params.millis === true);
+1556 	    this.hV = stohex(this.formatDate(params.date, 'utc', withMillis));
+1557 	} else if (params instanceof Date) {
+1558 	    this.hV = stohex(this.formatDate(params, 'utc'));
+1559 	}
+1560 
+1561 	if (this.hV == undefined) {
+1562 	    throw new Error("parameter not specified properly for UTCTime");
+1563 	}
+1564 	return this.hV;
+1565     };
+1566 
+1567     if (params != undefined) this.setByParam(params);
+1568 };
+1569 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
+1570 
+1571 // ********************************************************************
+1572 /**
+1573  * class for ASN.1 DER GeneralizedTime
+1574  * @name KJUR.asn1.DERGeneralizedTime
+1575  * @class class for ASN.1 DER GeneralizedTime
+1576  * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'})
+1577  * @property {Boolean} withMillis flag to show milliseconds or not
+1578  * @extends KJUR.asn1.DERAbstractTime
+1579  * @see KJUR.asn1.DERUTCTime
+1580  * @see KJUR.asn1.x509.Time
+1581  *
+1582  * @description
+1583  * <br/>
+1584  * As for argument 'params' for constructor, you can specify one of
+1585  * following properties:
+1586  * <ul>
+1587  * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li>
+1588  * <li>date - specify Date object.</li>
+1589  * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
+1590  * </ul>
+1591  * NOTE1: 'params' can be omitted.
+1592  * NOTE2: 'millis' property is supported from asn1 1.0.6.
+1593  *
+1594  * <h4>EXAMPLES</h4>
+1595  * @example
+1596  * new DERGeneralizedTime("20151231235959Z")
+1597  * new DERGeneralizedTime("20151231235959.123Z")
+1598  * new DERGeneralizedTime(new Date())
+1599  * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123)))
+1600  * new DERGeneralizedTime({str: "20151231235959.123Z"})
+1601  * new DERGeneralizedTime({date: new Date()})
+1602  * new DERGeneralizedTime({date: new Date(), millis: true})
+1603  * new DERGeneralizedTime({millis: true})
+1604  */
+1605 KJUR.asn1.DERGeneralizedTime = function(params) {
+1606     KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
+1607     this.hT = "18";
+1608     this.params = params;
+1609 
+1610     this.getFreshValueHex = function() {
+1611 	var params = this.params;
+1612 
+1613 	if (this.params == undefined) params = { date: new Date() };
 1614 
-1615 // ********************************************************************
-1616 /**
-1617  * class for ASN.1 DER Set
-1618  * @name KJUR.asn1.DERSet
-1619  * @class class for ASN.1 DER Set
-1620  * @extends KJUR.asn1.DERAbstractStructured
-1621  * @description
-1622  * <br/>
-1623  * As for argument 'params' for constructor, you can specify one of
-1624  * following properties:
-1625  * <ul>
-1626  * <li>array - specify array of ASN1Object to set elements of content</li>
-1627  * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li>
-1628  * </ul>
-1629  * NOTE1: 'params' can be omitted.<br/>
-1630  * NOTE2: sortflag is supported since 1.0.5.
-1631  */
-1632 KJUR.asn1.DERSet = function(params) {
-1633     KJUR.asn1.DERSet.superclass.constructor.call(this, params);
-1634     this.hT = "31";
-1635     this.sortFlag = true; // item shall be sorted only in ASN.1 DER
-1636     this.getFreshValueHex = function() {
-1637         var a = new Array();
-1638         for (var i = 0; i < this.asn1Array.length; i++) {
-1639             var asn1Obj = this.asn1Array[i];
-1640             a.push(asn1Obj.getEncodedHex());
-1641         }
-1642         if (this.sortFlag == true) a.sort();
-1643         this.hV = a.join('');
-1644         return this.hV;
-1645     };
-1646 
-1647     if (typeof params != "undefined") {
-1648         if (typeof params.sortflag != "undefined" &&
-1649             params.sortflag == false)
-1650             this.sortFlag = false;
-1651     }
-1652 };
-1653 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
-1654 
-1655 // ********************************************************************
-1656 /**
-1657  * class for ASN.1 DER TaggedObject
-1658  * @name KJUR.asn1.DERTaggedObject
-1659  * @class class for ASN.1 DER TaggedObject
-1660  * @extends KJUR.asn1.ASN1Object
-1661  *
-1662  * @description
-1663  * <br/>
-1664  * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object.
-1665  * For example, if you find '[1]' tag in a ASN.1 dump, 
-1666  * 'tagNoHex' will be 'a1'.
-1667  * <br/>
-1668  * As for optional argument 'params' for constructor, you can specify *ANY* of
-1669  * following properties:
-1670  * <ul>
-1671  * <li>tag - specify tag (default is 'a0' which means [0])</li>
-1672  * <li>explicit - specify true if this is explicit tag otherwise false 
-1673  *     (default is 'true').</li>
-1674  * <li>obj - specify ASN1Object which is tagged</li>
-1675  * <li>tage - specify tag with explicit</li>
-1676  * <li>tagi - specify tag with implicit</li>
-1677  * </ul>
-1678  *
-1679  * @example
-1680  * new KJUR.asn1.DERTaggedObject({
-1681  *  tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
-1682  * }) 
-1683  * new KJUR.asn1.DERTaggedObject({
-1684  *  tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit
-1685  * }) 
-1686  * new KJUR.asn1.DERTaggedObject({
-1687  *  tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
-1688  * }) 
-1689  *
-1690  * // to hexadecimal
-1691  * d1 = new KJUR.asn1.DERUTF8String({str':'a'})
-1692  * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1});
-1693  * hex = d2.getEncodedHex();
-1694  */
-1695 KJUR.asn1.DERTaggedObject = function(params) {
-1696     KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
-1697 
-1698     var _KJUR_asn1 = KJUR.asn1;
-1699 
-1700     this.hT = "a0";
-1701     this.hV = '';
-1702     this.isExplicit = true;
-1703     this.asn1Object = null;
-1704 
-1705     /**
-1706      * set value by an ASN1Object
-1707      * @name setString
-1708      * @memberOf KJUR.asn1.DERTaggedObject#
-1709      * @function
-1710      * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
-1711      * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
-1712      * @param {ASN1Object} asn1Object ASN.1 to encapsulate
-1713      */
-1714     this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) {
-1715         this.hT = tagNoHex;
-1716         this.isExplicit = isExplicitFlag;
-1717         this.asn1Object = asn1Object;
-1718         if (this.isExplicit) {
-1719             this.hV = this.asn1Object.getEncodedHex();
-1720             this.hTLV = null;
-1721             this.isModified = true;
-1722         } else {
-1723             this.hV = null;
-1724             this.hTLV = asn1Object.getEncodedHex();
-1725             this.hTLV = this.hTLV.replace(/^../, tagNoHex);
-1726             this.isModified = false;
-1727         }
-1728     };
-1729 
-1730     this.getFreshValueHex = function() {
-1731         return this.hV;
-1732     };
-1733 
-1734     this.setByParam = function(params) {
-1735         if (params.tag != undefined) {
-1736             this.hT = params.tag;
-1737         }
-1738         if (params.explicit != undefined) {
-1739             this.isExplicit = params.explicit;
-1740         }
-1741 	if (params.tage != undefined) {
-1742 	    this.hT = params.tage;
-1743             this.isExplicit = true;
-1744 	}
-1745 	if (params.tagi != undefined) {
-1746 	    this.hT = params.tagi;
-1747             this.isExplicit = false;
-1748 	}
-1749         if (params.obj != undefined) {
-1750 	    if (params.obj instanceof _KJUR_asn1.ASN1Object) {
-1751 		this.asn1Object = params.obj;
-1752 		this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
-1753 	    } else if (typeof params.obj == "object") {
-1754 		this.asn1Object = _KJUR_asn1.ASN1Util.newObject(params.obj);
-1755 		this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
-1756 	    }
-1757         }
-1758     };
+1615 	if (typeof params == "string") {
+1616 	    if (params.match(/^[0-9]{14}Z$/) ||
+1617 		params.match(/^[0-9]{14}\.[0-9]+Z$/)) {
+1618 		this.hV = stohex(params);
+1619 	    } else {
+1620 		throw new Error("malformed string for GeneralizedTime: " + params);
+1621 	    }
+1622 	} else if (params.str != undefined) {
+1623 	    this.hV = stohex(params.str);
+1624 	} else if (params.date == undefined && params.millis == true) {
+1625 	    var date = new Date();
+1626 	    this.hV = stohex(this.formatDate(date, 'gen', true));
+1627 	} else if (params.date != undefined &&
+1628 		   params.date instanceof Date) {
+1629 	    var withMillis = (params.millis === true);
+1630 	    this.hV = stohex(this.formatDate(params.date, 'gen', withMillis));
+1631 	} else if (params instanceof Date) {
+1632 	    this.hV = stohex(this.formatDate(params, 'gen'));
+1633 	}
+1634 
+1635 	if (this.hV == undefined) {
+1636 	    throw new Error("parameter not specified properly for GeneralizedTime");
+1637 	}
+1638 	return this.hV;
+1639     };
+1640 
+1641     if (params != undefined) this.setByParam(params);
+1642 };
+1643 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
+1644 
+1645 // ********************************************************************
+1646 /**
+1647  * class for ASN.1 DER Sequence
+1648  * @name KJUR.asn1.DERSequence
+1649  * @class class for ASN.1 DER Sequence
+1650  * @extends KJUR.asn1.DERAbstractStructured
+1651  * @description
+1652  * <br/>
+1653  * As for argument 'params' for constructor, you can specify one of
+1654  * following properties:
+1655  * <ul>
+1656  * <li>array - specify array of ASN1Object to set elements of content</li>
+1657  * </ul>
+1658  * NOTE: 'params' can be omitted.
+1659  */
+1660 KJUR.asn1.DERSequence = function(params) {
+1661     KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
+1662     this.hT = "30";
+1663     this.getFreshValueHex = function() {
+1664         var h = '';
+1665         for (var i = 0; i < this.asn1Array.length; i++) {
+1666             var asn1Obj = this.asn1Array[i];
+1667             h += asn1Obj.getEncodedHex();
+1668         }
+1669         this.hV = h;
+1670         return this.hV;
+1671     };
+1672 };
+1673 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
+1674 
+1675 // ********************************************************************
+1676 /**
+1677  * class for ASN.1 DER Set
+1678  * @name KJUR.asn1.DERSet
+1679  * @class class for ASN.1 DER Set
+1680  * @extends KJUR.asn1.DERAbstractStructured
+1681  * @description
+1682  * <br/>
+1683  * As for argument 'params' for constructor, you can specify one of
+1684  * following properties:
+1685  * <ul>
+1686  * <li>array - specify array of ASN1Object to set elements of content</li>
+1687  * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li>
+1688  * </ul>
+1689  * NOTE1: 'params' can be omitted.<br/>
+1690  * NOTE2: sortflag is supported since 1.0.5.
+1691  */
+1692 KJUR.asn1.DERSet = function(params) {
+1693     KJUR.asn1.DERSet.superclass.constructor.call(this, params);
+1694     this.hT = "31";
+1695     this.sortFlag = true; // item shall be sorted only in ASN.1 DER
+1696     this.getFreshValueHex = function() {
+1697         var a = new Array();
+1698         for (var i = 0; i < this.asn1Array.length; i++) {
+1699             var asn1Obj = this.asn1Array[i];
+1700             a.push(asn1Obj.getEncodedHex());
+1701         }
+1702         if (this.sortFlag == true) a.sort();
+1703         this.hV = a.join('');
+1704         return this.hV;
+1705     };
+1706 
+1707     if (typeof params != "undefined") {
+1708         if (typeof params.sortflag != "undefined" &&
+1709             params.sortflag == false)
+1710             this.sortFlag = false;
+1711     }
+1712 };
+1713 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
+1714 
+1715 // ********************************************************************
+1716 /**
+1717  * class for ASN.1 DER TaggedObject
+1718  * @name KJUR.asn1.DERTaggedObject
+1719  * @class class for ASN.1 DER TaggedObject
+1720  * @extends KJUR.asn1.ASN1Object
+1721  *
+1722  * @description
+1723  * <br/>
+1724  * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object.
+1725  * For example, if you find '[1]' tag in a ASN.1 dump, 
+1726  * 'tagNoHex' will be 'a1'.
+1727  * <br/>
+1728  * As for optional argument 'params' for constructor, you can specify *ANY* of
+1729  * following properties:
+1730  * <ul>
+1731  * <li>tag - specify tag (default is 'a0' which means [0])</li>
+1732  * <li>explicit - specify true if this is explicit tag otherwise false 
+1733  *     (default is 'true').</li>
+1734  * <li>obj - specify ASN1Object which is tagged</li>
+1735  * <li>tage - specify tag with explicit</li>
+1736  * <li>tagi - specify tag with implicit</li>
+1737  * </ul>
+1738  *
+1739  * @example
+1740  * new KJUR.asn1.DERTaggedObject({
+1741  *  tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
+1742  * }) 
+1743  * new KJUR.asn1.DERTaggedObject({
+1744  *  tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit
+1745  * }) 
+1746  * new KJUR.asn1.DERTaggedObject({
+1747  *  tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit
+1748  * }) 
+1749  *
+1750  * // to hexadecimal
+1751  * d1 = new KJUR.asn1.DERUTF8String({str':'a'})
+1752  * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1});
+1753  * hex = d2.getEncodedHex();
+1754  */
+1755 KJUR.asn1.DERTaggedObject = function(params) {
+1756     KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
+1757 
+1758     var _KJUR_asn1 = KJUR.asn1;
 1759 
-1760     if (params != undefined) this.setByParam(params);
-1761 };
-1762 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
-1763 
\ No newline at end of file +1760
this.hT = "a0"; +1761 this.hV = ''; +1762 this.isExplicit = true; +1763 this.asn1Object = null; +1764 +1765 /** +1766 * set value by an ASN1Object +1767 * @name setString +1768 * @memberOf KJUR.asn1.DERTaggedObject# +1769 * @function +1770 * @param {Boolean} isExplicitFlag flag for explicit/implicit tag +1771 * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag +1772 * @param {ASN1Object} asn1Object ASN.1 to encapsulate +1773 */ +1774 this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { +1775 this.hT = tagNoHex; +1776 this.isExplicit = isExplicitFlag; +1777 this.asn1Object = asn1Object; +1778 if (this.isExplicit) { +1779 this.hV = this.asn1Object.getEncodedHex(); +1780 this.hTLV = null; +1781 this.isModified = true; +1782 } else { +1783 this.hV = null; +1784 this.hTLV = asn1Object.getEncodedHex(); +1785 this.hTLV = this.hTLV.replace(/^../, tagNoHex); +1786 this.isModified = false; +1787 } +1788 }; +1789 +1790 this.getFreshValueHex = function() { +1791 return this.hV; +1792 }; +1793 +1794 this.setByParam = function(params) { +1795 if (params.tag != undefined) { +1796 this.hT = params.tag; +1797 } +1798 if (params.explicit != undefined) { +1799 this.isExplicit = params.explicit; +1800 } +1801 if (params.tage != undefined) { +1802 this.hT = params.tage; +1803 this.isExplicit = true; +1804 } +1805 if (params.tagi != undefined) { +1806 this.hT = params.tagi; +1807 this.isExplicit = false; +1808 } +1809 if (params.obj != undefined) { +1810 if (params.obj instanceof _KJUR_asn1.ASN1Object) { +1811 this.asn1Object = params.obj; +1812 this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); +1813 } else if (typeof params.obj == "object") { +1814 this.asn1Object = _KJUR_asn1.ASN1Util.newObject(params.obj); +1815 this.setASN1Object(this.isExplicit, this.hT, this.asn1Object); +1816 } +1817 } +1818 }; +1819 +1820 if (params != undefined) this.setByParam(params); +1821 }; +1822 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); +1823
\ No newline at end of file diff --git a/api/symbols/src/asn1x509-1.0.js.html b/api/symbols/src/asn1x509-1.0.js.html index ff2a7113..efca573e 100644 --- a/api/symbols/src/asn1x509-1.0.js.html +++ b/api/symbols/src/asn1x509-1.0.js.html @@ -3521,846 +3521,904 @@ 3514 _KJUR_asn1 = _KJUR.asn1, 3515 _DERUTCTime = _KJUR_asn1.DERUTCTime, 3516 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; -3517 -3518 this.setTimeParams = function(timeParams) { -3519 this.timeParams = timeParams; -3520 } -3521 -3522 this.getEncodedHex = function() { -3523 var o = null; +3517 this.params = null; +3518 this.type = null; +3519 +3520 // deprecated +3521 this.setTimeParams = function(timeParams) { +3522 this.timeParams = timeParams; +3523 } 3524 -3525 if (this.timeParams != null) { -3526 if (this.type == "utc") { -3527 o = new _DERUTCTime(this.timeParams); -3528 } else { -3529 o = new _DERGeneralizedTime(this.timeParams); -3530 } -3531 } else { -3532 if (this.type == "utc") { -3533 o = new _DERUTCTime(); -3534 } else { -3535 o = new _DERGeneralizedTime(); -3536 } -3537 } -3538 this.TLV = o.getEncodedHex(); -3539 return this.TLV; -3540 }; -3541 -3542 this.type = "utc"; -3543 if (params !== undefined) { -3544 if (params.type !== undefined) { -3545 this.type = params.type; -3546 } else { -3547 if (params.str !== undefined) { -3548 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; -3549 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; -3550 } -3551 } -3552 this.timeParams = params; -3553 } -3554 }; -3555 extendClass(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); -3556 -3557 /** -3558 * AlgorithmIdentifier ASN.1 structure class -3559 * @name KJUR.asn1.x509.AlgorithmIdentifier -3560 * @class AlgorithmIdentifier ASN.1 structure class -3561 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) -3562 * @extends KJUR.asn1.ASN1Object -3563 * @description -3564 * The 'params' argument is an associative array and has following parameters: -3565 * <ul> -3566 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> -3567 * <li>asn1params: explicitly specify ASN.1 object for algorithm. -3568 * (OPTION)</li> -3569 * <li>paramempty: set algorithm parameter to NULL by force. -3570 * If paramempty is false, algorithm parameter will be set automatically. -3571 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of -3572 * AlgorithmIdentifier will be ommitted otherwise -3573 * it will be NULL by default. -3574 * (OPTION, DEFAULT = false)</li> -3575 * </ul> -3576 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are -3577 * special names. They will set a suite of algorithm OID and multiple algorithm -3578 * parameters. Its ASN.1 schema is defined in -3579 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 -3580 * section A.2.3</a>. -3581 * <blockquote><pre> -3582 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } -3583 * RSASSA-PSS-params ::= SEQUENCE { -3584 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, -3585 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, -3586 * saltLength [2] INTEGER DEFAULT 20, -3587 * trailerField [3] TrailerField DEFAULT trailerFieldBC } -3588 * mgf1SHA1 MaskGenAlgorithm ::= { -3589 * algorithm id-mgf1, -3590 * parameters HashAlgorithm : sha1 } -3591 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } -3592 * TrailerField ::= INTEGER { trailerFieldBC(1) } -3593 * </pre></blockquote> -3594 * Here is a table for PSS parameters: -3595 * <table> -3596 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> -3597 * <tr><td>SHAwithRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>default(sha1)</td><td>default(mgf1sha1)</td><td>default(20)</td><td>default(1)</td></tr> -3598 * <tr><td>SHA256withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha256</td><td>mgf1sha256</td><td>32</td><td>default(1)</td></tr> -3599 * <tr><td>SHA384withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha384</td><td>mgf1sha384</td><td>48</td><td>default(1)</td></tr> -3600 * <tr><td>SHA512withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha512</td><td>mgf1sha512</td><td>64</td><td>default(1)</td></tr> -3601 * </table> -3602 * Default value is omitted as defined in ASN.1 schema. -3603 * These parameters are interoperable to OpenSSL or IAIK toolkit. -3604 * <br/> -3605 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. -3606 * @example -3607 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) -3608 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) -3609 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically -3610 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) -3611 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) -3612 */ -3613 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { -3614 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); -3615 this.nameAlg = null; -3616 this.asn1Alg = null; -3617 this.asn1Params = null; -3618 this.paramEmpty = false; -3619 -3620 var _KJUR = KJUR, -3621 _KJUR_asn1 = _KJUR.asn1, -3622 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; -3623 -3624 this.getEncodedHex = function() { -3625 if (this.nameAlg === null && this.asn1Alg === null) { -3626 throw new Error("algorithm not specified"); -3627 } -3628 -3629 // for RSAPSS algorithm name -3630 // && this.hTLV === null -3631 if (this.nameAlg !== null) { -3632 var hTLV = null; -3633 for (var key in _PSSNAME2ASN1TLV) { -3634 if (key === this.nameAlg) { -3635 hTLV = _PSSNAME2ASN1TLV[key]; -3636 } -3637 } -3638 if (hTLV !== null) { -3639 this.hTLV = hTLV; -3640 return this.hTLV; -3641 } -3642 } -3643 -3644 if (this.nameAlg !== null && this.asn1Alg === null) { -3645 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); -3646 } -3647 var a = [this.asn1Alg]; -3648 if (this.asn1Params !== null) a.push(this.asn1Params); -3649 -3650 var o = new _KJUR_asn1.DERSequence({'array': a}); -3651 this.hTLV = o.getEncodedHex(); -3652 return this.hTLV; -3653 }; -3654 -3655 if (params !== undefined) { -3656 if (params.name !== undefined) { -3657 this.nameAlg = params.name; -3658 } -3659 if (params.asn1params !== undefined) { -3660 this.asn1Params = params.asn1params; -3661 } -3662 if (params.paramempty !== undefined) { -3663 this.paramEmpty = params.paramempty; -3664 } -3665 } -3666 -3667 // set algorithm parameters will be ommitted for -3668 // "*withDSA" or "*withECDSA" otherwise will be NULL. -3669 if (this.asn1Params === null && -3670 this.paramEmpty === false && -3671 this.nameAlg !== null) { -3672 -3673 if (this.nameAlg.name !== undefined) { -3674 this.nameAlg = this.nameAlg.name; -3675 } -3676 var lcNameAlg = this.nameAlg.toLowerCase(); +3525 this.setByParam = function(params) { +3526 this.params = params; +3527 }; +3528 +3529 this.getType = function(s) { +3530 if (s.match(/^[0-9]{12}Z$/)) return "utc"; +3531 if (s.match(/^[0-9]{14}Z$/)) return "gen"; +3532 if (s.match(/^[0-9]{12}\.[0-9]+Z$/)) return "utc"; +3533 if (s.match(/^[0-9]{14}\.[0-9]+Z$/)) return "gen"; +3534 return null; +3535 }; +3536 +3537 this.getEncodedHex = function() { +3538 var params = this.params; +3539 var o = null; +3540 +3541 if (typeof params == "string") params = {str: params}; +3542 if (params != null && +3543 params.str && +3544 (params.type == null || params.type == undefined)) { +3545 params.type = this.getType(params.str); +3546 } +3547 +3548 if (params != null && params.str) { +3549 if (params.type == "utc") o = new _DERUTCTime(params.str); +3550 if (params.type == "gen") o = new _DERGeneralizedTime(params.str); +3551 } else { +3552 if (this.type == "gen") { +3553 o = new _DERGeneralizedTime(); +3554 } else { +3555 o = new _DERUTCTime(); +3556 } +3557 } +3558 +3559 if (o == null) throw new Error("wrong setting for Time"); +3560 this.TLV = o.getEncodedHex(); +3561 return this.TLV; +3562 }; +3563 +3564 if (params != undefined) this.setByParam(params); +3565 }; +3566 +3567 KJUR.asn1.x509.Time_bak = function(params) { +3568 KJUR.asn1.x509.Time_bak.superclass.constructor.call(this); +3569 var type = null, +3570 timeParams = null, +3571 _KJUR = KJUR, +3572 _KJUR_asn1 = _KJUR.asn1, +3573 _DERUTCTime = _KJUR_asn1.DERUTCTime, +3574 _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; +3575 +3576 this.setTimeParams = function(timeParams) { +3577 this.timeParams = timeParams; +3578 } +3579 +3580 this.getEncodedHex = function() { +3581 var o = null; +3582 +3583 if (this.timeParams != null) { +3584 if (this.type == "utc") { +3585 o = new _DERUTCTime(this.timeParams); +3586 } else { +3587 o = new _DERGeneralizedTime(this.timeParams); +3588 } +3589 } else { +3590 if (this.type == "utc") { +3591 o = new _DERUTCTime(); +3592 } else { +3593 o = new _DERGeneralizedTime(); +3594 } +3595 } +3596 this.TLV = o.getEncodedHex(); +3597 return this.TLV; +3598 }; +3599 +3600 this.type = "utc"; +3601 if (params !== undefined) { +3602 if (params.type !== undefined) { +3603 this.type = params.type; +3604 } else { +3605 if (params.str !== undefined) { +3606 if (params.str.match(/^[0-9]{12}Z$/)) this.type = "utc"; +3607 if (params.str.match(/^[0-9]{14}Z$/)) this.type = "gen"; +3608 } +3609 } +3610 this.timeParams = params; +3611 } +3612 }; +3613 extendClass(KJUR.asn1.x509.Time, KJUR.asn1.ASN1Object); +3614 +3615 /** +3616 * AlgorithmIdentifier ASN.1 structure class +3617 * @name KJUR.asn1.x509.AlgorithmIdentifier +3618 * @class AlgorithmIdentifier ASN.1 structure class +3619 * @param {Array} params associative array of parameters (ex. {'name': 'SHA1withRSA'}) +3620 * @extends KJUR.asn1.ASN1Object +3621 * @description +3622 * The 'params' argument is an associative array and has following parameters: +3623 * <ul> +3624 * <li>name: algorithm name (MANDATORY, ex. sha1, SHA256withRSA)</li> +3625 * <li>asn1params: explicitly specify ASN.1 object for algorithm. +3626 * (OPTION)</li> +3627 * <li>paramempty: set algorithm parameter to NULL by force. +3628 * If paramempty is false, algorithm parameter will be set automatically. +3629 * If paramempty is false and algorithm name is "*withDSA" or "withECDSA" parameter field of +3630 * AlgorithmIdentifier will be ommitted otherwise +3631 * it will be NULL by default. +3632 * (OPTION, DEFAULT = false)</li> +3633 * </ul> +3634 * RSA-PSS algorithm names such as SHA{,256,384,512}withRSAandMGF1 are +3635 * special names. They will set a suite of algorithm OID and multiple algorithm +3636 * parameters. Its ASN.1 schema is defined in +3637 * <a href="https://tools.ietf.org/html/rfc3447#appendix-A.2.3">RFC 3447 PKCS#1 2.1 +3638 * section A.2.3</a>. +3639 * <blockquote><pre> +3640 * id-RSASSA-PSS OBJECT IDENTIFIER ::= { pkcs-1 10 } +3641 * RSASSA-PSS-params ::= SEQUENCE { +3642 * hashAlgorithm [0] HashAlgorithm DEFAULT sha1, +3643 * maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1, +3644 * saltLength [2] INTEGER DEFAULT 20, +3645 * trailerField [3] TrailerField DEFAULT trailerFieldBC } +3646 * mgf1SHA1 MaskGenAlgorithm ::= { +3647 * algorithm id-mgf1, +3648 * parameters HashAlgorithm : sha1 } +3649 * id-mgf1 OBJECT IDENTIFIER ::= { pkcs-1 8 } +3650 * TrailerField ::= INTEGER { trailerFieldBC(1) } +3651 * </pre></blockquote> +3652 * Here is a table for PSS parameters: +3653 * <table> +3654 * <tr><th>Name</th><th>alg oid</th><th>pss hash</th><th>maskgen</th></th><th>pss saltlen</th><th>trailer</th></tr> +3655 * <tr><td>SHAwithRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>default(sha1)</td><td>default(mgf1sha1)</td><td>default(20)</td><td>default(1)</td></tr> +3656 * <tr><td>SHA256withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha256</td><td>mgf1sha256</td><td>32</td><td>default(1)</td></tr> +3657 * <tr><td>SHA384withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha384</td><td>mgf1sha384</td><td>48</td><td>default(1)</td></tr> +3658 * <tr><td>SHA512withRSAandMGF1</td><td>1.2.840.113549.1.1.10(rsapss)</td><td>sha512</td><td>mgf1sha512</td><td>64</td><td>default(1)</td></tr> +3659 * </table> +3660 * Default value is omitted as defined in ASN.1 schema. +3661 * These parameters are interoperable to OpenSSL or IAIK toolkit. +3662 * <br/> +3663 * NOTE: RSA-PSS algorihtm names are supported since jsrsasign 8.0.21. +3664 * @example +3665 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "sha1"}) +3666 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA"}) +3667 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA512withRSAandMGF1"}) // set parameters automatically +3668 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "SHA256withRSA", paramempty: true}) +3669 * new KJUR.asn1.x509.AlgorithmIdentifier({name: "rsaEncryption"}) +3670 */ +3671 KJUR.asn1.x509.AlgorithmIdentifier = function(params) { +3672 KJUR.asn1.x509.AlgorithmIdentifier.superclass.constructor.call(this); +3673 this.nameAlg = null; +3674 this.asn1Alg = null; +3675 this.asn1Params = null; +3676 this.paramEmpty = false; 3677 -3678 if (lcNameAlg.substr(-7, 7) !== "withdsa" && -3679 lcNameAlg.substr(-9, 9) !== "withecdsa") { -3680 this.asn1Params = new _KJUR_asn1.DERNull(); -3681 } -3682 } -3683 }; -3684 extendClass(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); -3685 -3686 /** -3687 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names -3688 * @const -3689 */ -3690 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { -3691 "SHAwithRSAandMGF1": -3692 "300d06092a864886f70d01010a3000", -3693 "SHA256withRSAandMGF1": -3694 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", -3695 "SHA384withRSAandMGF1": -3696 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", -3697 "SHA512withRSAandMGF1": -3698 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" -3699 }; -3700 -3701 /** -3702 * GeneralName ASN.1 structure class<br/> -3703 * @name KJUR.asn1.x509.GeneralName -3704 * @class GeneralName ASN.1 structure class -3705 * @description -3706 * <br/> -3707 * As for argument 'params' for constructor, you can specify one of -3708 * following properties: -3709 * <ul> -3710 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> -3711 * <li>dns - dNSName[2] (ex. foo.com)</li> -3712 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> -3713 * <li>dn - directoryName[4] -3714 * distinguished name string or X500Name class parameters can be -3715 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> -3716 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> -3717 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> -3718 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> -3719 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> -3720 * </ul> -3721 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> -3722 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> -3723 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> -3724 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> -3725 * -3726 * Here is definition of the ASN.1 syntax: -3727 * <pre> -3728 * -- NOTE: under the CHOICE, it will always be explicit. -3729 * GeneralName ::= CHOICE { -3730 * otherName [0] OtherName, -3731 * rfc822Name [1] IA5String, -3732 * dNSName [2] IA5String, -3733 * x400Address [3] ORAddress, -3734 * directoryName [4] Name, -3735 * ediPartyName [5] EDIPartyName, -3736 * uniformResourceIdentifier [6] IA5String, -3737 * iPAddress [7] OCTET STRING, -3738 * registeredID [8] OBJECT IDENTIFIER } -3739 * </pre> -3740 * -3741 * @example -3742 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); -3743 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); -3744 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); -3745 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); -3746 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); -3747 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); -3748 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); -3749 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); -3750 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); -3751 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); -3752 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); -3753 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); -3754 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); -3755 * -3756 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED -3757 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED -3758 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED -3759 */ -3760 KJUR.asn1.x509.GeneralName = function(params) { -3761 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); -3762 var asn1Obj = null, -3763 type = null, -3764 pTag = {rfc822: '81', dns: '82', dn: 'a4', uri: '86', ip: '87'}, -3765 _KJUR = KJUR, -3766 _KJUR_asn1 = _KJUR.asn1, -3767 _DERSequence = _KJUR_asn1.DERSequence, -3768 _DEROctetString = _KJUR_asn1.DEROctetString, -3769 _DERIA5String = _KJUR_asn1.DERIA5String, -3770 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, -3771 _ASN1Object = _KJUR_asn1.ASN1Object, -3772 _X500Name = _KJUR_asn1.x509.X500Name, -3773 _pemtohex = pemtohex; -3774 -3775 this.explicit = false; -3776 -3777 this.setByParam = function(params) { -3778 var str = null; -3779 var v = null; -3780 -3781 if (params === undefined) return; -3782 -3783 if (params.rfc822 !== undefined) { -3784 this.type = 'rfc822'; -3785 v = new _DERIA5String({str: params[this.type]}); -3786 } -3787 -3788 if (params.dns !== undefined) { -3789 this.type = 'dns'; -3790 v = new _DERIA5String({str: params[this.type]}); -3791 } -3792 -3793 if (params.uri !== undefined) { -3794 this.type = 'uri'; -3795 v = new _DERIA5String({str: params[this.type]}); -3796 } -3797 -3798 if (params.dn !== undefined) { -3799 this.type = 'dn'; -3800 this.explicit = true; -3801 if (typeof params.dn === "string") { -3802 v = new _X500Name({str: params.dn}); -3803 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { -3804 v = params.dn; -3805 } else { -3806 v = new _X500Name(params.dn); -3807 } -3808 } -3809 -3810 if (params.ldapdn !== undefined) { -3811 this.type = 'dn'; -3812 this.explicit = true; -3813 v = new _X500Name({ldapstr: params.ldapdn}); -3814 } -3815 -3816 if (params.certissuer !== undefined) { -3817 this.type = 'dn'; -3818 this.explicit = true; -3819 var certStr = params.certissuer; -3820 var certHex = null; -3821 -3822 if (certStr.match(/^[0-9A-Fa-f]+$/)) { -3823 certHex == certStr; -3824 } -3825 -3826 if (certStr.indexOf("-----BEGIN ") != -1) { -3827 certHex = _pemtohex(certStr); -3828 } -3829 -3830 if (certHex == null) throw "certissuer param not cert"; -3831 var x = new X509(); -3832 x.hex = certHex; -3833 var dnHex = x.getIssuerHex(); -3834 v = new _ASN1Object(); -3835 v.hTLV = dnHex; -3836 } -3837 -3838 if (params.certsubj !== undefined) { -3839 this.type = 'dn'; -3840 this.explicit = true; -3841 var certStr = params.certsubj; -3842 var certHex = null; -3843 if (certStr.match(/^[0-9A-Fa-f]+$/)) { -3844 certHex == certStr; -3845 } -3846 if (certStr.indexOf("-----BEGIN ") != -1) { -3847 certHex = _pemtohex(certStr); -3848 } -3849 if (certHex == null) throw "certsubj param not cert"; -3850 var x = new X509(); -3851 x.hex = certHex; -3852 var dnHex = x.getSubjectHex(); -3853 v = new _ASN1Object(); -3854 v.hTLV = dnHex; -3855 } -3856 -3857 if (params.ip !== undefined) { -3858 this.type = 'ip'; -3859 this.explicit = false; -3860 var ip = params.ip; -3861 var hIP; -3862 var malformedIPMsg = "malformed IP address"; -3863 if (ip.match(/^[0-9.]+[.][0-9.]+$/)) { // ipv4 -3864 hIP = intarystrtohex("[" + ip.split(".").join(",") + "]"); -3865 if (hIP.length !== 8) throw malformedIPMsg; -3866 } else if (ip.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)) { // ipv6 -3867 hIP = ipv6tohex(ip); -3868 } else if (ip.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)) { // hex -3869 hIP = ip; -3870 } else { -3871 throw malformedIPMsg; -3872 } -3873 v = new _DEROctetString({hex: hIP}); -3874 } -3875 -3876 if (this.type == null) -3877 throw "unsupported type in params=" + params; -3878 this.asn1Obj = new _DERTaggedObject({'explicit': this.explicit, -3879 'tag': pTag[this.type], -3880 'obj': v}); -3881 }; -3882 -3883 this.getEncodedHex = function() { -3884 return this.asn1Obj.getEncodedHex(); -3885 } -3886 -3887 if (params !== undefined) { -3888 this.setByParam(params); -3889 } -3890 -3891 }; -3892 extendClass(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); -3893 -3894 /** -3895 * GeneralNames ASN.1 structure class<br/> -3896 * @name KJUR.asn1.x509.GeneralNames -3897 * @class GeneralNames ASN.1 structure class -3898 * @description -3899 * <br/> -3900 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> -3901 * @example -3902 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); -3903 * -3904 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName -3905 */ -3906 KJUR.asn1.x509.GeneralNames = function(paramsArray) { -3907 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); -3908 var asn1Array = null, -3909 _KJUR = KJUR, -3910 _KJUR_asn1 = _KJUR.asn1; -3911 -3912 /** -3913 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> -3914 * @name setByParamArray -3915 * @memberOf KJUR.asn1.x509.GeneralNames# -3916 * @function -3917 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} -3918 * @description -3919 * <br/> -3920 * <h4>EXAMPLES</h4> -3921 * @example -3922 * gns = new KJUR.asn1.x509.GeneralNames(); -3923 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); -3924 */ -3925 this.setByParamArray = function(paramsArray) { -3926 for (var i = 0; i < paramsArray.length; i++) { -3927 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); -3928 this.asn1Array.push(o); -3929 } -3930 }; -3931 -3932 this.getEncodedHex = function() { -3933 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); -3934 return o.getEncodedHex(); -3935 }; -3936 -3937 this.asn1Array = new Array(); -3938 if (typeof paramsArray != "undefined") { -3939 this.setByParamArray(paramsArray); -3940 } -3941 }; -3942 extendClass(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); -3943 -3944 /** -3945 * static object for OID -3946 * @name KJUR.asn1.x509.OID -3947 * @class static object for OID -3948 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') -3949 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') -3950 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object -3951 * @description -3952 * This class defines OID name and values. -3953 * AttributeType names registered in OID.atype2oidList are following: -3954 * <table style="border-width: thin; border-style: solid; witdh: 100%"> -3955 * <tr><th>short</th><th>long</th><th>OID</th></tr> -3956 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> -3957 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> -3958 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> -3959 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> -3960 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> -3961 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> -3962 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> -3963 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> -3964 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> -3965 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> -3966 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> -3967 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> -3968 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> -3969 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> -3970 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> -3971 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> -3972 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> -3973 * </table> -3974 * -3975 * @example -3976 */ -3977 KJUR.asn1.x509.OID = new function(params) { -3978 this.atype2oidList = { -3979 // RFC 4514 AttributeType name string (MUST recognized) -3980 'CN': '2.5.4.3', -3981 'L': '2.5.4.7', -3982 'ST': '2.5.4.8', -3983 'O': '2.5.4.10', -3984 'OU': '2.5.4.11', -3985 'C': '2.5.4.6', -3986 'STREET': '2.5.4.9', -3987 'DC': '0.9.2342.19200300.100.1.25', -3988 'UID': '0.9.2342.19200300.100.1.1', -3989 // other AttributeType name string -3990 // http://blog.livedoor.jp/k_urushima/archives/656114.html -3991 'SN': '2.5.4.4', // surname -3992 'T': '2.5.4.12', // title -3993 'DN': '2.5.4.49', // distinguishedName -3994 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy -3995 // other AttributeType name string (no short name) -3996 'description': '2.5.4.13', -3997 'businessCategory': '2.5.4.15', -3998 'postalCode': '2.5.4.17', -3999 'serialNumber': '2.5.4.5', -4000 'uniqueIdentifier': '2.5.4.45', -4001 'organizationIdentifier': '2.5.4.97', -4002 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -4003 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -4004 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' -4005 }; -4006 this.name2oidList = { -4007 'sha1': '1.3.14.3.2.26', -4008 'sha256': '2.16.840.1.101.3.4.2.1', -4009 'sha384': '2.16.840.1.101.3.4.2.2', -4010 'sha512': '2.16.840.1.101.3.4.2.3', -4011 'sha224': '2.16.840.1.101.3.4.2.4', -4012 'md5': '1.2.840.113549.2.5', -4013 'md2': '1.3.14.7.2.2.1', -4014 'ripemd160': '1.3.36.3.2.1', -4015 -4016 'MD2withRSA': '1.2.840.113549.1.1.2', -4017 'MD4withRSA': '1.2.840.113549.1.1.3', -4018 'MD5withRSA': '1.2.840.113549.1.1.4', -4019 'SHA1withRSA': '1.2.840.113549.1.1.5', -4020 'pkcs1-MGF': '1.2.840.113549.1.1.8', -4021 'rsaPSS': '1.2.840.113549.1.1.10', -4022 'SHA224withRSA': '1.2.840.113549.1.1.14', -4023 'SHA256withRSA': '1.2.840.113549.1.1.11', -4024 'SHA384withRSA': '1.2.840.113549.1.1.12', -4025 'SHA512withRSA': '1.2.840.113549.1.1.13', -4026 -4027 'SHA1withECDSA': '1.2.840.10045.4.1', -4028 'SHA224withECDSA': '1.2.840.10045.4.3.1', -4029 'SHA256withECDSA': '1.2.840.10045.4.3.2', -4030 'SHA384withECDSA': '1.2.840.10045.4.3.3', -4031 'SHA512withECDSA': '1.2.840.10045.4.3.4', -4032 -4033 'dsa': '1.2.840.10040.4.1', -4034 'SHA1withDSA': '1.2.840.10040.4.3', -4035 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', -4036 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', -4037 -4038 'rsaEncryption': '1.2.840.113549.1.1.1', -4039 -4040 // X.500 AttributeType defined in RFC 4514 -4041 'commonName': '2.5.4.3', -4042 'countryName': '2.5.4.6', -4043 'localityName': '2.5.4.7', -4044 'stateOrProvinceName': '2.5.4.8', -4045 'streetAddress': '2.5.4.9', -4046 'organizationName': '2.5.4.10', -4047 'organizationalUnitName': '2.5.4.11', -4048 'domainComponent': '0.9.2342.19200300.100.1.25', -4049 'userId': '0.9.2342.19200300.100.1.1', -4050 // other AttributeType name string -4051 'surname': '2.5.4.4', -4052 'givenName': '2.5.4.42', -4053 'title': '2.5.4.12', -4054 'distinguishedName': '2.5.4.49', -4055 'emailAddress': '1.2.840.113549.1.9.1', -4056 // other AttributeType name string (no short name) -4057 'description': '2.5.4.13', -4058 'businessCategory': '2.5.4.15', -4059 'postalCode': '2.5.4.17', -4060 'uniqueIdentifier': '2.5.4.45', -4061 'organizationIdentifier': '2.5.4.97', -4062 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', -4063 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', -4064 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', -4065 -4066 'subjectDirectoryAttributes': '2.5.29.9', -4067 'subjectKeyIdentifier': '2.5.29.14', -4068 'keyUsage': '2.5.29.15', -4069 'subjectAltName': '2.5.29.17', -4070 'issuerAltName': '2.5.29.18', -4071 'basicConstraints': '2.5.29.19', -4072 'cRLNumber': '2.5.29.20', -4073 'cRLReason': '2.5.29.21', -4074 'nameConstraints': '2.5.29.30', -4075 'cRLDistributionPoints':'2.5.29.31', -4076 'certificatePolicies': '2.5.29.32', -4077 'anyPolicy': '2.5.29.32.0', -4078 'authorityKeyIdentifier':'2.5.29.35', -4079 'policyConstraints': '2.5.29.36', -4080 'extKeyUsage': '2.5.29.37', -4081 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', -4082 'ocsp': '1.3.6.1.5.5.7.48.1', -4083 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', -4084 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', -4085 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', -4086 'caIssuers': '1.3.6.1.5.5.7.48.2', -4087 -4088 'anyExtendedKeyUsage': '2.5.29.37.0', -4089 'serverAuth': '1.3.6.1.5.5.7.3.1', -4090 'clientAuth': '1.3.6.1.5.5.7.3.2', -4091 'codeSigning': '1.3.6.1.5.5.7.3.3', -4092 'emailProtection': '1.3.6.1.5.5.7.3.4', -4093 'timeStamping': '1.3.6.1.5.5.7.3.8', -4094 'ocspSigning': '1.3.6.1.5.5.7.3.9', +3678 var _KJUR = KJUR, +3679 _KJUR_asn1 = _KJUR.asn1, +3680 _PSSNAME2ASN1TLV = _KJUR_asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV; +3681 +3682 this.getEncodedHex = function() { +3683 if (this.nameAlg === null && this.asn1Alg === null) { +3684 throw new Error("algorithm not specified"); +3685 } +3686 +3687 // for RSAPSS algorithm name +3688 // && this.hTLV === null +3689 if (this.nameAlg !== null) { +3690 var hTLV = null; +3691 for (var key in _PSSNAME2ASN1TLV) { +3692 if (key === this.nameAlg) { +3693 hTLV = _PSSNAME2ASN1TLV[key]; +3694 } +3695 } +3696 if (hTLV !== null) { +3697 this.hTLV = hTLV; +3698 return this.hTLV; +3699 } +3700 } +3701 +3702 if (this.nameAlg !== null && this.asn1Alg === null) { +3703 this.asn1Alg = _KJUR_asn1.x509.OID.name2obj(this.nameAlg); +3704 } +3705 var a = [this.asn1Alg]; +3706 if (this.asn1Params !== null) a.push(this.asn1Params); +3707 +3708 var o = new _KJUR_asn1.DERSequence({'array': a}); +3709 this.hTLV = o.getEncodedHex(); +3710 return this.hTLV; +3711 }; +3712 +3713 if (params !== undefined) { +3714 if (params.name !== undefined) { +3715 this.nameAlg = params.name; +3716 } +3717 if (params.asn1params !== undefined) { +3718 this.asn1Params = params.asn1params; +3719 } +3720 if (params.paramempty !== undefined) { +3721 this.paramEmpty = params.paramempty; +3722 } +3723 } +3724 +3725 // set algorithm parameters will be ommitted for +3726 // "*withDSA" or "*withECDSA" otherwise will be NULL. +3727 if (this.asn1Params === null && +3728 this.paramEmpty === false && +3729 this.nameAlg !== null) { +3730 +3731 if (this.nameAlg.name !== undefined) { +3732 this.nameAlg = this.nameAlg.name; +3733 } +3734 var lcNameAlg = this.nameAlg.toLowerCase(); +3735 +3736 if (lcNameAlg.substr(-7, 7) !== "withdsa" && +3737 lcNameAlg.substr(-9, 9) !== "withecdsa") { +3738 this.asn1Params = new _KJUR_asn1.DERNull(); +3739 } +3740 } +3741 }; +3742 extendClass(KJUR.asn1.x509.AlgorithmIdentifier, KJUR.asn1.ASN1Object); +3743 +3744 /** +3745 * AlgorithmIdentifier ASN.1 TLV string associative array for RSA-PSS algorithm names +3746 * @const +3747 */ +3748 KJUR.asn1.x509.AlgorithmIdentifier.PSSNAME2ASN1TLV = { +3749 "SHAwithRSAandMGF1": +3750 "300d06092a864886f70d01010a3000", +3751 "SHA256withRSAandMGF1": +3752 "303d06092a864886f70d01010a3030a00d300b0609608648016503040201a11a301806092a864886f70d010108300b0609608648016503040201a203020120", +3753 "SHA384withRSAandMGF1": +3754 "303d06092a864886f70d01010a3030a00d300b0609608648016503040202a11a301806092a864886f70d010108300b0609608648016503040202a203020130", +3755 "SHA512withRSAandMGF1": +3756 "303d06092a864886f70d01010a3030a00d300b0609608648016503040203a11a301806092a864886f70d010108300b0609608648016503040203a203020140" +3757 }; +3758 +3759 /** +3760 * GeneralName ASN.1 structure class<br/> +3761 * @name KJUR.asn1.x509.GeneralName +3762 * @class GeneralName ASN.1 structure class +3763 * @description +3764 * <br/> +3765 * As for argument 'params' for constructor, you can specify one of +3766 * following properties: +3767 * <ul> +3768 * <li>rfc822 - rfc822Name[1] (ex. user1@foo.com)</li> +3769 * <li>dns - dNSName[2] (ex. foo.com)</li> +3770 * <li>uri - uniformResourceIdentifier[6] (ex. http://foo.com/)</li> +3771 * <li>dn - directoryName[4] +3772 * distinguished name string or X500Name class parameters can be +3773 * specified (ex. "/C=US/O=Test", {hex: '301c...')</li> +3774 * <li>ldapdn - directoryName[4] (ex. O=Test,C=US)</li> +3775 * <li>certissuer - directoryName[4] (PEM or hex string of cert)</li> +3776 * <li>certsubj - directoryName[4] (PEM or hex string of cert)</li> +3777 * <li>ip - iPAddress[7] (ex. 192.168.1.1, 2001:db3::43, 3faa0101...)</li> +3778 * </ul> +3779 * NOTE1: certissuer and certsubj were supported since asn1x509 1.0.10.<br/> +3780 * NOTE2: dn and ldapdn were supported since jsrsasign 6.2.3 asn1x509 1.0.19.<br/> +3781 * NOTE3: ip were supported since jsrsasign 8.0.10 asn1x509 1.1.4.<br/> +3782 * NOTE4: X500Name parameters in dn were supported since jsrsasign 8.0.16.<br/> +3783 * +3784 * Here is definition of the ASN.1 syntax: +3785 * <pre> +3786 * -- NOTE: under the CHOICE, it will always be explicit. +3787 * GeneralName ::= CHOICE { +3788 * otherName [0] OtherName, +3789 * rfc822Name [1] IA5String, +3790 * dNSName [2] IA5String, +3791 * x400Address [3] ORAddress, +3792 * directoryName [4] Name, +3793 * ediPartyName [5] EDIPartyName, +3794 * uniformResourceIdentifier [6] IA5String, +3795 * iPAddress [7] OCTET STRING, +3796 * registeredID [8] OBJECT IDENTIFIER } +3797 * </pre> +3798 * +3799 * @example +3800 * gn = new KJUR.asn1.x509.GeneralName({dn: '/C=US/O=Test'}); +3801 * gn = new KJUR.asn1.x509.GeneralName({dn: X500NameObject); +3802 * gn = new KJUR.asn1.x509.GeneralName({dn: {str: /C=US/O=Test'}); +3803 * gn = new KJUR.asn1.x509.GeneralName({dn: {ldapstr: 'O=Test,C=US'}); +3804 * gn = new KJUR.asn1.x509.GeneralName({dn: {hex: '301c...'}); +3805 * gn = new KJUR.asn1.x509.GeneralName({dn: {certissuer: PEMCERTSTRING}); +3806 * gn = new KJUR.asn1.x509.GeneralName({dn: {certsubject: PEMCERTSTRING}); +3807 * gn = new KJUR.asn1.x509.GeneralName({ip: '192.168.1.1'}); +3808 * gn = new KJUR.asn1.x509.GeneralName({ip: '2001:db4::4:1'}); +3809 * gn = new KJUR.asn1.x509.GeneralName({ip: 'c0a80101'}); +3810 * gn = new KJUR.asn1.x509.GeneralName({rfc822: 'test@aaa.com'}); +3811 * gn = new KJUR.asn1.x509.GeneralName({dns: 'aaa.com'}); +3812 * gn = new KJUR.asn1.x509.GeneralName({uri: 'http://aaa.com/'}); +3813 * +3814 * gn = new KJUR.asn1.x509.GeneralName({ldapdn: 'O=Test,C=US'}); // DEPRECATED +3815 * gn = new KJUR.asn1.x509.GeneralName({certissuer: certPEM}); // DEPRECATED +3816 * gn = new KJUR.asn1.x509.GeneralName({certsubj: certPEM}); // DEPRECATED +3817 */ +3818 KJUR.asn1.x509.GeneralName = function(params) { +3819 KJUR.asn1.x509.GeneralName.superclass.constructor.call(this); +3820 var asn1Obj = null, +3821 type = null, +3822 pTag = {rfc822: '81', dns: '82', dn: 'a4', uri: '86', ip: '87'}, +3823 _KJUR = KJUR, +3824 _KJUR_asn1 = _KJUR.asn1, +3825 _DERSequence = _KJUR_asn1.DERSequence, +3826 _DEROctetString = _KJUR_asn1.DEROctetString, +3827 _DERIA5String = _KJUR_asn1.DERIA5String, +3828 _DERTaggedObject = _KJUR_asn1.DERTaggedObject, +3829 _ASN1Object = _KJUR_asn1.ASN1Object, +3830 _X500Name = _KJUR_asn1.x509.X500Name, +3831 _pemtohex = pemtohex; +3832 +3833 this.explicit = false; +3834 +3835 this.setByParam = function(params) { +3836 var str = null; +3837 var v = null; +3838 +3839 if (params === undefined) return; +3840 +3841 if (params.rfc822 !== undefined) { +3842 this.type = 'rfc822'; +3843 v = new _DERIA5String({str: params[this.type]}); +3844 } +3845 +3846 if (params.dns !== undefined) { +3847 this.type = 'dns'; +3848 v = new _DERIA5String({str: params[this.type]}); +3849 } +3850 +3851 if (params.uri !== undefined) { +3852 this.type = 'uri'; +3853 v = new _DERIA5String({str: params[this.type]}); +3854 } +3855 +3856 if (params.dn !== undefined) { +3857 this.type = 'dn'; +3858 this.explicit = true; +3859 if (typeof params.dn === "string") { +3860 v = new _X500Name({str: params.dn}); +3861 } else if (params.dn instanceof KJUR.asn1.x509.X500Name) { +3862 v = params.dn; +3863 } else { +3864 v = new _X500Name(params.dn); +3865 } +3866 } +3867 +3868 if (params.ldapdn !== undefined) { +3869 this.type = 'dn'; +3870 this.explicit = true; +3871 v = new _X500Name({ldapstr: params.ldapdn}); +3872 } +3873 +3874 if (params.certissuer !== undefined) { +3875 this.type = 'dn'; +3876 this.explicit = true; +3877 var certStr = params.certissuer; +3878 var certHex = null; +3879 +3880 if (certStr.match(/^[0-9A-Fa-f]+$/)) { +3881 certHex == certStr; +3882 } +3883 +3884 if (certStr.indexOf("-----BEGIN ") != -1) { +3885 certHex = _pemtohex(certStr); +3886 } +3887 +3888 if (certHex == null) throw "certissuer param not cert"; +3889 var x = new X509(); +3890 x.hex = certHex; +3891 var dnHex = x.getIssuerHex(); +3892 v = new _ASN1Object(); +3893 v.hTLV = dnHex; +3894 } +3895 +3896 if (params.certsubj !== undefined) { +3897 this.type = 'dn'; +3898 this.explicit = true; +3899 var certStr = params.certsubj; +3900 var certHex = null; +3901 if (certStr.match(/^[0-9A-Fa-f]+$/)) { +3902 certHex == certStr; +3903 } +3904 if (certStr.indexOf("-----BEGIN ") != -1) { +3905 certHex = _pemtohex(certStr); +3906 } +3907 if (certHex == null) throw "certsubj param not cert"; +3908 var x = new X509(); +3909 x.hex = certHex; +3910 var dnHex = x.getSubjectHex(); +3911 v = new _ASN1Object(); +3912 v.hTLV = dnHex; +3913 } +3914 +3915 if (params.ip !== undefined) { +3916 this.type = 'ip'; +3917 this.explicit = false; +3918 var ip = params.ip; +3919 var hIP; +3920 var malformedIPMsg = "malformed IP address"; +3921 if (ip.match(/^[0-9.]+[.][0-9.]+$/)) { // ipv4 +3922 hIP = intarystrtohex("[" + ip.split(".").join(",") + "]"); +3923 if (hIP.length !== 8) throw malformedIPMsg; +3924 } else if (ip.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)) { // ipv6 +3925 hIP = ipv6tohex(ip); +3926 } else if (ip.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)) { // hex +3927 hIP = ip; +3928 } else { +3929 throw malformedIPMsg; +3930 } +3931 v = new _DEROctetString({hex: hIP}); +3932 } +3933 +3934 if (this.type == null) +3935 throw "unsupported type in params=" + params; +3936 this.asn1Obj = new _DERTaggedObject({'explicit': this.explicit, +3937 'tag': pTag[this.type], +3938 'obj': v}); +3939 }; +3940 +3941 this.getEncodedHex = function() { +3942 return this.asn1Obj.getEncodedHex(); +3943 } +3944 +3945 if (params !== undefined) { +3946 this.setByParam(params); +3947 } +3948 +3949 }; +3950 extendClass(KJUR.asn1.x509.GeneralName, KJUR.asn1.ASN1Object); +3951 +3952 /** +3953 * GeneralNames ASN.1 structure class<br/> +3954 * @name KJUR.asn1.x509.GeneralNames +3955 * @class GeneralNames ASN.1 structure class +3956 * @description +3957 * <br/> +3958 * <h4>EXAMPLE AND ASN.1 SYNTAX</h4> +3959 * @example +3960 * gns = new KJUR.asn1.x509.GeneralNames([{'uri': 'http://aaa.com/'}, {'uri': 'http://bbb.com/'}]); +3961 * +3962 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName +3963 */ +3964 KJUR.asn1.x509.GeneralNames = function(paramsArray) { +3965 KJUR.asn1.x509.GeneralNames.superclass.constructor.call(this); +3966 var asn1Array = null, +3967 _KJUR = KJUR, +3968 _KJUR_asn1 = _KJUR.asn1; +3969 +3970 /** +3971 * set a array of {@link KJUR.asn1.x509.GeneralName} parameters<br/> +3972 * @name setByParamArray +3973 * @memberOf KJUR.asn1.x509.GeneralNames# +3974 * @function +3975 * @param {Array} paramsArray Array of {@link KJUR.asn1.x509.GeneralNames} +3976 * @description +3977 * <br/> +3978 * <h4>EXAMPLES</h4> +3979 * @example +3980 * gns = new KJUR.asn1.x509.GeneralNames(); +3981 * gns.setByParamArray([{uri: 'http://aaa.com/'}, {uri: 'http://bbb.com/'}]); +3982 */ +3983 this.setByParamArray = function(paramsArray) { +3984 for (var i = 0; i < paramsArray.length; i++) { +3985 var o = new _KJUR_asn1.x509.GeneralName(paramsArray[i]); +3986 this.asn1Array.push(o); +3987 } +3988 }; +3989 +3990 this.getEncodedHex = function() { +3991 var o = new _KJUR_asn1.DERSequence({'array': this.asn1Array}); +3992 return o.getEncodedHex(); +3993 }; +3994 +3995 this.asn1Array = new Array(); +3996 if (typeof paramsArray != "undefined") { +3997 this.setByParamArray(paramsArray); +3998 } +3999 }; +4000 extendClass(KJUR.asn1.x509.GeneralNames, KJUR.asn1.ASN1Object); +4001 +4002 /** +4003 * static object for OID +4004 * @name KJUR.asn1.x509.OID +4005 * @class static object for OID +4006 * @property {Assoc Array} atype2oidList for short attribute type name and oid (ex. 'C' and '2.5.4.6') +4007 * @property {Assoc Array} name2oidList for oid name and oid (ex. 'keyUsage' and '2.5.29.15') +4008 * @property {Assoc Array} objCache for caching name and DERObjectIdentifier object +4009 * @description +4010 * This class defines OID name and values. +4011 * AttributeType names registered in OID.atype2oidList are following: +4012 * <table style="border-width: thin; border-style: solid; witdh: 100%"> +4013 * <tr><th>short</th><th>long</th><th>OID</th></tr> +4014 * <tr><td>CN</td>commonName<td></td><td>2.5.4.3</td></tr> +4015 * <tr><td>L</td><td>localityName</td><td>2.5.4.7</td></tr> +4016 * <tr><td>ST</td><td>stateOrProvinceName</td><td>2.5.4.8</td></tr> +4017 * <tr><td>O</td><td>organizationName</td><td>2.5.4.10</td></tr> +4018 * <tr><td>OU</td><td>organizationalUnitName</td><td>2.5.4.11</td></tr> +4019 * <tr><td>C</td><td></td>countryName<td>2.5.4.6</td></tr> +4020 * <tr><td>STREET</td>streetAddress<td></td><td>2.5.4.6</td></tr> +4021 * <tr><td>DC</td><td>domainComponent</td><td>0.9.2342.19200300.100.1.25</td></tr> +4022 * <tr><td>UID</td><td>userId</td><td>0.9.2342.19200300.100.1.1</td></tr> +4023 * <tr><td>SN</td><td>surname</td><td>2.5.4.4</td></tr> +4024 * <tr><td>DN</td><td>distinguishedName</td><td>2.5.4.49</td></tr> +4025 * <tr><td>E</td><td>emailAddress</td><td>1.2.840.113549.1.9.1</td></tr> +4026 * <tr><td></td><td>businessCategory</td><td>2.5.4.15</td></tr> +4027 * <tr><td></td><td>postalCode</td><td>2.5.4.17</td></tr> +4028 * <tr><td></td><td>jurisdictionOfIncorporationL</td><td>1.3.6.1.4.1.311.60.2.1.1</td></tr> +4029 * <tr><td></td><td>jurisdictionOfIncorporationSP</td><td>1.3.6.1.4.1.311.60.2.1.2</td></tr> +4030 * <tr><td></td><td>jurisdictionOfIncorporationC</td><td>1.3.6.1.4.1.311.60.2.1.3</td></tr> +4031 * </table> +4032 * +4033 * @example +4034 */ +4035 KJUR.asn1.x509.OID = new function(params) { +4036 this.atype2oidList = { +4037 // RFC 4514 AttributeType name string (MUST recognized) +4038 'CN': '2.5.4.3', +4039 'L': '2.5.4.7', +4040 'ST': '2.5.4.8', +4041 'O': '2.5.4.10', +4042 'OU': '2.5.4.11', +4043 'C': '2.5.4.6', +4044 'STREET': '2.5.4.9', +4045 'DC': '0.9.2342.19200300.100.1.25', +4046 'UID': '0.9.2342.19200300.100.1.1', +4047 // other AttributeType name string +4048 // http://blog.livedoor.jp/k_urushima/archives/656114.html +4049 'SN': '2.5.4.4', // surname +4050 'T': '2.5.4.12', // title +4051 'DN': '2.5.4.49', // distinguishedName +4052 'E': '1.2.840.113549.1.9.1', // emailAddress in MS.NET or Bouncy +4053 // other AttributeType name string (no short name) +4054 'description': '2.5.4.13', +4055 'businessCategory': '2.5.4.15', +4056 'postalCode': '2.5.4.17', +4057 'serialNumber': '2.5.4.5', +4058 'uniqueIdentifier': '2.5.4.45', +4059 'organizationIdentifier': '2.5.4.97', +4060 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4061 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4062 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3' +4063 }; +4064 this.name2oidList = { +4065 'sha1': '1.3.14.3.2.26', +4066 'sha256': '2.16.840.1.101.3.4.2.1', +4067 'sha384': '2.16.840.1.101.3.4.2.2', +4068 'sha512': '2.16.840.1.101.3.4.2.3', +4069 'sha224': '2.16.840.1.101.3.4.2.4', +4070 'md5': '1.2.840.113549.2.5', +4071 'md2': '1.3.14.7.2.2.1', +4072 'ripemd160': '1.3.36.3.2.1', +4073 +4074 'MD2withRSA': '1.2.840.113549.1.1.2', +4075 'MD4withRSA': '1.2.840.113549.1.1.3', +4076 'MD5withRSA': '1.2.840.113549.1.1.4', +4077 'SHA1withRSA': '1.2.840.113549.1.1.5', +4078 'pkcs1-MGF': '1.2.840.113549.1.1.8', +4079 'rsaPSS': '1.2.840.113549.1.1.10', +4080 'SHA224withRSA': '1.2.840.113549.1.1.14', +4081 'SHA256withRSA': '1.2.840.113549.1.1.11', +4082 'SHA384withRSA': '1.2.840.113549.1.1.12', +4083 'SHA512withRSA': '1.2.840.113549.1.1.13', +4084 +4085 'SHA1withECDSA': '1.2.840.10045.4.1', +4086 'SHA224withECDSA': '1.2.840.10045.4.3.1', +4087 'SHA256withECDSA': '1.2.840.10045.4.3.2', +4088 'SHA384withECDSA': '1.2.840.10045.4.3.3', +4089 'SHA512withECDSA': '1.2.840.10045.4.3.4', +4090 +4091 'dsa': '1.2.840.10040.4.1', +4092 'SHA1withDSA': '1.2.840.10040.4.3', +4093 'SHA224withDSA': '2.16.840.1.101.3.4.3.1', +4094 'SHA256withDSA': '2.16.840.1.101.3.4.3.2', 4095 -4096 'dateOfBirth': '1.3.6.1.5.5.7.9.1', -4097 'placeOfBirth': '1.3.6.1.5.5.7.9.2', -4098 'gender': '1.3.6.1.5.5.7.9.3', -4099 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', -4100 'countryOfResidence': '1.3.6.1.5.5.7.9.5', -4101 -4102 'ecPublicKey': '1.2.840.10045.2.1', -4103 'P-256': '1.2.840.10045.3.1.7', -4104 'secp256r1': '1.2.840.10045.3.1.7', -4105 'secp256k1': '1.3.132.0.10', -4106 'secp384r1': '1.3.132.0.34', -4107 -4108 'pkcs5PBES2': '1.2.840.113549.1.5.13', -4109 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', -4110 -4111 'des-EDE3-CBC': '1.2.840.113549.3.7', -4112 -4113 'data': '1.2.840.113549.1.7.1', // CMS data -4114 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data -4115 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data -4116 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data -4117 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data -4118 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data -4119 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo -4120 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME -4121 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS -4122 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades -4123 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME -4124 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME -4125 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME -4126 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest -4127 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 -4128 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 -4129 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 -4130 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 -4131 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 -4132 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe -4133 'adobeTimeStamp': '1.2.840.113583.1.1.9.1' // Adobe -4134 }; -4135 -4136 this.objCache = {}; -4137 -4138 /** -4139 * get DERObjectIdentifier by registered OID name -4140 * @name name2obj -4141 * @memberOf KJUR.asn1.x509.OID -4142 * @function -4143 * @param {String} name OID -4144 * @description -4145 * @example -4146 * var asn1ObjOID = OID.name2obj('SHA1withRSA'); -4147 */ -4148 this.name2obj = function(name) { -4149 if (typeof this.objCache[name] != "undefined") -4150 return this.objCache[name]; -4151 if (typeof this.name2oidList[name] == "undefined") -4152 throw "Name of ObjectIdentifier not defined: " + name; -4153 var oid = this.name2oidList[name]; -4154 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); -4155 this.objCache[name] = obj; -4156 return obj; -4157 }; -4158 -4159 /** -4160 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> -4161 * @name atype2obj -4162 * @memberOf KJUR.asn1.x509.OID -4163 * @function -4164 * @param {String} atype short attribute type name such like 'C', 'CN' or OID -4165 * @return {@link KJUR.asn1.DERObjectIdentifier} instance -4166 * @description -4167 * @example -4168 * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 -4169 * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 -4170 * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 -4171 * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9 -4172 */ -4173 this.atype2obj = function(atype) { -4174 if (this.objCache[atype] !== undefined) -4175 return this.objCache[atype]; -4176 -4177 var oid; -4178 -4179 if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) { -4180 oid = atype; -4181 } else if (this.atype2oidList[atype] !== undefined) { -4182 oid = this.atype2oidList[atype]; -4183 } else if (this.name2oidList[atype] !== undefined) { -4184 oid = this.name2oidList[atype]; -4185 } else { -4186 throw "AttributeType name undefined: " + atype; -4187 } -4188 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); -4189 this.objCache[atype] = obj; -4190 return obj; -4191 }; -4192 }; +4096 'rsaEncryption': '1.2.840.113549.1.1.1', +4097 +4098 // X.500 AttributeType defined in RFC 4514 +4099 'commonName': '2.5.4.3', +4100 'countryName': '2.5.4.6', +4101 'localityName': '2.5.4.7', +4102 'stateOrProvinceName': '2.5.4.8', +4103 'streetAddress': '2.5.4.9', +4104 'organizationName': '2.5.4.10', +4105 'organizationalUnitName': '2.5.4.11', +4106 'domainComponent': '0.9.2342.19200300.100.1.25', +4107 'userId': '0.9.2342.19200300.100.1.1', +4108 // other AttributeType name string +4109 'surname': '2.5.4.4', +4110 'givenName': '2.5.4.42', +4111 'title': '2.5.4.12', +4112 'distinguishedName': '2.5.4.49', +4113 'emailAddress': '1.2.840.113549.1.9.1', +4114 // other AttributeType name string (no short name) +4115 'description': '2.5.4.13', +4116 'businessCategory': '2.5.4.15', +4117 'postalCode': '2.5.4.17', +4118 'uniqueIdentifier': '2.5.4.45', +4119 'organizationIdentifier': '2.5.4.97', +4120 'jurisdictionOfIncorporationL': '1.3.6.1.4.1.311.60.2.1.1', +4121 'jurisdictionOfIncorporationSP':'1.3.6.1.4.1.311.60.2.1.2', +4122 'jurisdictionOfIncorporationC': '1.3.6.1.4.1.311.60.2.1.3', +4123 +4124 'subjectDirectoryAttributes': '2.5.29.9', +4125 'subjectKeyIdentifier': '2.5.29.14', +4126 'keyUsage': '2.5.29.15', +4127 'subjectAltName': '2.5.29.17', +4128 'issuerAltName': '2.5.29.18', +4129 'basicConstraints': '2.5.29.19', +4130 'cRLNumber': '2.5.29.20', +4131 'cRLReason': '2.5.29.21', +4132 'nameConstraints': '2.5.29.30', +4133 'cRLDistributionPoints':'2.5.29.31', +4134 'certificatePolicies': '2.5.29.32', +4135 'anyPolicy': '2.5.29.32.0', +4136 'authorityKeyIdentifier':'2.5.29.35', +4137 'policyConstraints': '2.5.29.36', +4138 'extKeyUsage': '2.5.29.37', +4139 'authorityInfoAccess': '1.3.6.1.5.5.7.1.1', +4140 'ocsp': '1.3.6.1.5.5.7.48.1', +4141 'ocspBasic': '1.3.6.1.5.5.7.48.1.1', +4142 'ocspNonce': '1.3.6.1.5.5.7.48.1.2', +4143 'ocspNoCheck': '1.3.6.1.5.5.7.48.1.5', +4144 'caIssuers': '1.3.6.1.5.5.7.48.2', +4145 +4146 'anyExtendedKeyUsage': '2.5.29.37.0', +4147 'serverAuth': '1.3.6.1.5.5.7.3.1', +4148 'clientAuth': '1.3.6.1.5.5.7.3.2', +4149 'codeSigning': '1.3.6.1.5.5.7.3.3', +4150 'emailProtection': '1.3.6.1.5.5.7.3.4', +4151 'timeStamping': '1.3.6.1.5.5.7.3.8', +4152 'ocspSigning': '1.3.6.1.5.5.7.3.9', +4153 +4154 'dateOfBirth': '1.3.6.1.5.5.7.9.1', +4155 'placeOfBirth': '1.3.6.1.5.5.7.9.2', +4156 'gender': '1.3.6.1.5.5.7.9.3', +4157 'countryOfCitizenship': '1.3.6.1.5.5.7.9.4', +4158 'countryOfResidence': '1.3.6.1.5.5.7.9.5', +4159 +4160 'ecPublicKey': '1.2.840.10045.2.1', +4161 'P-256': '1.2.840.10045.3.1.7', +4162 'secp256r1': '1.2.840.10045.3.1.7', +4163 'secp256k1': '1.3.132.0.10', +4164 'secp384r1': '1.3.132.0.34', +4165 +4166 'pkcs5PBES2': '1.2.840.113549.1.5.13', +4167 'pkcs5PBKDF2': '1.2.840.113549.1.5.12', +4168 +4169 'des-EDE3-CBC': '1.2.840.113549.3.7', +4170 +4171 'data': '1.2.840.113549.1.7.1', // CMS data +4172 'signed-data': '1.2.840.113549.1.7.2', // CMS signed-data +4173 'enveloped-data': '1.2.840.113549.1.7.3', // CMS enveloped-data +4174 'digested-data': '1.2.840.113549.1.7.5', // CMS digested-data +4175 'encrypted-data': '1.2.840.113549.1.7.6', // CMS encrypted-data +4176 'authenticated-data': '1.2.840.113549.1.9.16.1.2', // CMS authenticated-data +4177 'tstinfo': '1.2.840.113549.1.9.16.1.4', // RFC3161 TSTInfo +4178 'signingCertificate': '1.2.840.113549.1.9.16.2.12',// SMIME +4179 'timeStampToken': '1.2.840.113549.1.9.16.2.14',// sigTS +4180 'signaturePolicyIdentifier': '1.2.840.113549.1.9.16.2.15',// cades +4181 'etsArchiveTimeStamp': '1.2.840.113549.1.9.16.2.27',// SMIME +4182 'signingCertificateV2': '1.2.840.113549.1.9.16.2.47',// SMIME +4183 'etsArchiveTimeStampV2':'1.2.840.113549.1.9.16.2.48',// SMIME +4184 'extensionRequest': '1.2.840.113549.1.9.14',// CSR extensionRequest +4185 'contentType': '1.2.840.113549.1.9.3',//PKCS#9 +4186 'messageDigest': '1.2.840.113549.1.9.4',//PKCS#9 +4187 'signingTime': '1.2.840.113549.1.9.5',//PKCS#9 +4188 'counterSignature': '1.2.840.113549.1.9.6',//PKCS#9 +4189 'archiveTimeStampV3': '0.4.0.1733.2.4',//ETSI EN29319122/TS101733 +4190 'pdfRevocationInfoArchival':'1.2.840.113583.1.1.8', //Adobe +4191 'adobeTimeStamp': '1.2.840.113583.1.1.9.1' // Adobe +4192 }; 4193 -4194 /** -4195 * convert OID to name<br/> -4196 * @name oid2name -4197 * @memberOf KJUR.asn1.x509.OID -4198 * @function -4199 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4200 * @return {String} OID name if registered otherwise empty string -4201 * @since asn1x509 1.0.9 -4202 * @description -4203 * This static method converts OID string to its name. -4204 * If OID is undefined then it returns empty string (i.e. ''). -4205 * @example -4206 * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess' -4207 */ -4208 KJUR.asn1.x509.OID.oid2name = function(oid) { -4209 var list = KJUR.asn1.x509.OID.name2oidList; -4210 for (var name in list) { -4211 if (list[name] == oid) return name; -4212 } -4213 return ''; -4214 }; -4215 -4216 /** -4217 * convert OID to AttributeType name<br/> -4218 * @name oid2atype -4219 * @memberOf KJUR.asn1.x509.OID -4220 * @function -4221 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) -4222 * @return {String} OID AttributeType name if registered otherwise oid -4223 * @since jsrsasign 6.2.2 asn1x509 1.0.18 -4224 * @description -4225 * This static method converts OID string to its AttributeType name. -4226 * If OID is not defined in OID.atype2oidList associative array then it returns OID -4227 * specified as argument. -4228 * @example -4229 * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN -4230 * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC -4231 * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID -4232 */ -4233 KJUR.asn1.x509.OID.oid2atype = function(oid) { -4234 var list = KJUR.asn1.x509.OID.atype2oidList; -4235 for (var atype in list) { -4236 if (list[atype] == oid) return atype; -4237 } -4238 return oid; -4239 }; -4240 -4241 /** -4242 * convert OID name to OID value<br/> -4243 * @name name2oid -4244 * @memberOf KJUR.asn1.x509.OID -4245 * @function -4246 * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4") -4247 * @return {String} dot noted Object Identifer string (ex. 1.2.3.4) -4248 * @since asn1x509 1.0.11 -4249 * @description -4250 * This static method converts from OID name to OID string. -4251 * If OID is undefined then it returns empty string (i.e. ''). -4252 * @example -4253 * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1" -4254 * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4" -4255 * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → "" -4256 */ -4257 KJUR.asn1.x509.OID.name2oid = function(name) { -4258 if (name.match(/^[0-9.]+$/)) return name; -4259 var list = KJUR.asn1.x509.OID.name2oidList; -4260 if (list[name] === undefined) return ''; -4261 return list[name]; -4262 }; -4263 -4264 /** -4265 * X.509 certificate and CRL utilities class<br/> -4266 * @name KJUR.asn1.x509.X509Util -4267 * @class X.509 certificate and CRL utilities class -4268 */ -4269 KJUR.asn1.x509.X509Util = {}; -4270 -4271 /** -4272 * issue a certificate in PEM format (DEPRECATED) -4273 * @name newCertPEM -4274 * @memberOf KJUR.asn1.x509.X509Util -4275 * @function -4276 * @param {Array} param JSON object of parameter to issue a certificate -4277 * @since asn1x509 1.0.6 -4278 * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor -4279 * @description -4280 * This method can issue a certificate by a simple -4281 * JSON object. -4282 * Signature value will be provided by signing with -4283 * private key using 'cakey' parameter or -4284 * hexadecimal signature value by 'sighex' parameter. -4285 * <br/> -4286 * NOTE: Algorithm parameter of AlgorithmIdentifier will -4287 * be set automatically by default. -4288 * (see {@link KJUR.asn1.x509.AlgorithmIdentifier}) -4289 * from jsrsasign 7.1.1 asn1x509 1.0.20. -4290 * <br/> -4291 * NOTE2: -4292 * RSA-PSS algorithm has been supported from jsrsasign 8.0.21. -4293 * As for RSA-PSS signature algorithm names and signing parameters -4294 * such as MGF function and salt length, please see -4295 * {@link KJUR.asn1.x509.AlgorithmIdentifier} class. -4296 * -4297 * @example -4298 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4299 * serial: {int: 4}, -4300 * sigalg: {name: 'SHA1withECDSA'}, -4301 * issuer: {str: '/C=US/O=a'}, -4302 * notbefore: {'str': '130504235959Z'}, -4303 * notafter: {'str': '140504235959Z'}, -4304 * subject: {str: '/C=US/O=b'}, -4305 * sbjpubkey: pubKeyObj, -4306 * ext: [ -4307 * {basicConstraints: {cA: true, critical: true}}, -4308 * {keyUsage: {bin: '11'}}, -4309 * ], -4310 * cakey: prvKeyObj -4311 * }); -4312 * // -- or -- -4313 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4314 * serial: {int: 4}, -4315 * sigalg: {name: 'SHA1withECDSA'}, -4316 * issuer: {str: '/C=US/O=a'}, -4317 * notbefore: {'str': '130504235959Z'}, -4318 * notafter: {'str': '140504235959Z'}, -4319 * subject: {str: '/C=US/O=b'}, -4320 * sbjpubkey: pubKeyPEM, -4321 * ext: [ -4322 * {basicConstraints: {cA: true, critical: true}}, -4323 * {keyUsage: {bin: '11'}}, -4324 * ], -4325 * cakey: [prvkey, pass]} -4326 * ); -4327 * // -- or -- -4328 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4329 * serial: {int: 1}, -4330 * sigalg: {name: 'SHA1withRSA'}, -4331 * issuer: {str: '/C=US/O=T1'}, -4332 * notbefore: {'str': '130504235959Z'}, -4333 * notafter: {'str': '140504235959Z'}, -4334 * subject: {str: '/C=US/O=T1'}, -4335 * sbjpubkey: pubKeyObj, -4336 * sighex: '0102030405..' -4337 * }); -4338 * // for the issuer and subject field, another -4339 * // representation is also available -4340 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ -4341 * serial: {int: 1}, -4342 * sigalg: {name: 'SHA256withRSA'}, -4343 * issuer: {C: "US", O: "T1"}, -4344 * notbefore: {'str': '130504235959Z'}, -4345 * notafter: {'str': '140504235959Z'}, -4346 * subject: {C: "US", O: "T1", CN: "http://example.com/"}, -4347 * sbjpubkey: pubKeyObj, -4348 * sighex: '0102030405..' -4349 * }); -4350 */ -4351 KJUR.asn1.x509.X509Util.newCertPEM = function(param) { -4352 var _KJUR_asn1_x509 = KJUR.asn1.x509, -4353 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, -4354 _Certificate = _KJUR_asn1_x509.Certificate; -4355 var cert = new _Certificate(param); -4356 return cert.getPEM(); -4357 }; -4358 -4359 \ No newline at end of file +4194 this.objCache = {}; +4195 +4196 /** +4197 * get DERObjectIdentifier by registered OID name +4198 * @name name2obj +4199 * @memberOf KJUR.asn1.x509.OID +4200 * @function +4201 * @param {String} name OID +4202 * @description +4203 * @example +4204 * var asn1ObjOID = OID.name2obj('SHA1withRSA'); +4205 */ +4206 this.name2obj = function(name) { +4207 if (typeof this.objCache[name] != "undefined") +4208 return this.objCache[name]; +4209 if (typeof this.name2oidList[name] == "undefined") +4210 throw "Name of ObjectIdentifier not defined: " + name; +4211 var oid = this.name2oidList[name]; +4212 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); +4213 this.objCache[name] = obj; +4214 return obj; +4215 }; +4216 +4217 /** +4218 * get DERObjectIdentifier by registered attribute type name such like 'C' or 'CN'<br/> +4219 * @name atype2obj +4220 * @memberOf KJUR.asn1.x509.OID +4221 * @function +4222 * @param {String} atype short attribute type name such like 'C', 'CN' or OID +4223 * @return {@link KJUR.asn1.DERObjectIdentifier} instance +4224 * @description +4225 * @example +4226 * KJUR.asn1.x509.OID.atype2obj('CN') → DERObjectIdentifier of 2.5.4.3 +4227 * KJUR.asn1.x509.OID.atype2obj('OU') → DERObjectIdentifier of 2.5.4.11 +4228 * KJUR.asn1.x509.OID.atype2obj('streetAddress') → DERObjectIdentifier of 2.5.4.9 +4229 * KJUR.asn1.x509.OID.atype2obj('2.5.4.9') → DERObjectIdentifier of 2.5.4.9 +4230 */ +4231 this.atype2obj = function(atype) { +4232 if (this.objCache[atype] !== undefined) +4233 return this.objCache[atype]; +4234 +4235 var oid; +4236 +4237 if (atype.match(/^\d+\.\d+\.[0-9.]+$/)) { +4238 oid = atype; +4239 } else if (this.atype2oidList[atype] !== undefined) { +4240 oid = this.atype2oidList[atype]; +4241 } else if (this.name2oidList[atype] !== undefined) { +4242 oid = this.name2oidList[atype]; +4243 } else { +4244 throw "AttributeType name undefined: " + atype; +4245 } +4246 var obj = new KJUR.asn1.DERObjectIdentifier({'oid': oid}); +4247 this.objCache[atype] = obj; +4248 return obj; +4249 }; +4250 }; +4251 +4252 /** +4253 * convert OID to name<br/> +4254 * @name oid2name +4255 * @memberOf KJUR.asn1.x509.OID +4256 * @function +4257 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) +4258 * @return {String} OID name if registered otherwise empty string +4259 * @since asn1x509 1.0.9 +4260 * @description +4261 * This static method converts OID string to its name. +4262 * If OID is undefined then it returns empty string (i.e. ''). +4263 * @example +4264 * KJUR.asn1.x509.OID.oid2name("1.3.6.1.5.5.7.1.1") → 'authorityInfoAccess' +4265 */ +4266 KJUR.asn1.x509.OID.oid2name = function(oid) { +4267 var list = KJUR.asn1.x509.OID.name2oidList; +4268 for (var name in list) { +4269 if (list[name] == oid) return name; +4270 } +4271 return ''; +4272 }; +4273 +4274 /** +4275 * convert OID to AttributeType name<br/> +4276 * @name oid2atype +4277 * @memberOf KJUR.asn1.x509.OID +4278 * @function +4279 * @param {String} oid dot noted Object Identifer string (ex. 1.2.3.4) +4280 * @return {String} OID AttributeType name if registered otherwise oid +4281 * @since jsrsasign 6.2.2 asn1x509 1.0.18 +4282 * @description +4283 * This static method converts OID string to its AttributeType name. +4284 * If OID is not defined in OID.atype2oidList associative array then it returns OID +4285 * specified as argument. +4286 * @example +4287 * KJUR.asn1.x509.OID.oid2atype("2.5.4.3") → CN +4288 * KJUR.asn1.x509.OID.oid2atype("1.3.6.1.4.1.311.60.2.1.3") → jurisdictionOfIncorporationC +4289 * KJUR.asn1.x509.OID.oid2atype("0.1.2.3.4") → 0.1.2.3.4 // unregistered OID +4290 */ +4291 KJUR.asn1.x509.OID.oid2atype = function(oid) { +4292 var list = KJUR.asn1.x509.OID.atype2oidList; +4293 for (var atype in list) { +4294 if (list[atype] == oid) return atype; +4295 } +4296 return oid; +4297 }; +4298 +4299 /** +4300 * convert OID name to OID value<br/> +4301 * @name name2oid +4302 * @memberOf KJUR.asn1.x509.OID +4303 * @function +4304 * @param {String} name OID name or OID (ex. "sha1" or "1.2.3.4") +4305 * @return {String} dot noted Object Identifer string (ex. 1.2.3.4) +4306 * @since asn1x509 1.0.11 +4307 * @description +4308 * This static method converts from OID name to OID string. +4309 * If OID is undefined then it returns empty string (i.e. ''). +4310 * @example +4311 * KJUR.asn1.x509.OID.name2oid("authorityInfoAccess") → "1.3.6.1.5.5.7.1.1" +4312 * KJUR.asn1.x509.OID.name2oid("1.2.3.4") → "1.2.3.4" +4313 * KJUR.asn1.x509.OID.name2oid("UNKNOWN NAME") → "" +4314 */ +4315 KJUR.asn1.x509.OID.name2oid = function(name) { +4316 if (name.match(/^[0-9.]+$/)) return name; +4317 var list = KJUR.asn1.x509.OID.name2oidList; +4318 if (list[name] === undefined) return ''; +4319 return list[name]; +4320 }; +4321 +4322 /** +4323 * X.509 certificate and CRL utilities class<br/> +4324 * @name KJUR.asn1.x509.X509Util +4325 * @class X.509 certificate and CRL utilities class +4326 */ +4327 KJUR.asn1.x509.X509Util = {}; +4328 +4329 /** +4330 * issue a certificate in PEM format (DEPRECATED) +4331 * @name newCertPEM +4332 * @memberOf KJUR.asn1.x509.X509Util +4333 * @function +4334 * @param {Array} param JSON object of parameter to issue a certificate +4335 * @since asn1x509 1.0.6 +4336 * @deprecated since jsrsasign 9.0.0 asn1x509 2.0.0. please move to {@link KJUR.asn1.x509.Certificate} constructor +4337 * @description +4338 * This method can issue a certificate by a simple +4339 * JSON object. +4340 * Signature value will be provided by signing with +4341 * private key using 'cakey' parameter or +4342 * hexadecimal signature value by 'sighex' parameter. +4343 * <br/> +4344 * NOTE: Algorithm parameter of AlgorithmIdentifier will +4345 * be set automatically by default. +4346 * (see {@link KJUR.asn1.x509.AlgorithmIdentifier}) +4347 * from jsrsasign 7.1.1 asn1x509 1.0.20. +4348 * <br/> +4349 * NOTE2: +4350 * RSA-PSS algorithm has been supported from jsrsasign 8.0.21. +4351 * As for RSA-PSS signature algorithm names and signing parameters +4352 * such as MGF function and salt length, please see +4353 * {@link KJUR.asn1.x509.AlgorithmIdentifier} class. +4354 * +4355 * @example +4356 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4357 * serial: {int: 4}, +4358 * sigalg: {name: 'SHA1withECDSA'}, +4359 * issuer: {str: '/C=US/O=a'}, +4360 * notbefore: {'str': '130504235959Z'}, +4361 * notafter: {'str': '140504235959Z'}, +4362 * subject: {str: '/C=US/O=b'}, +4363 * sbjpubkey: pubKeyObj, +4364 * ext: [ +4365 * {basicConstraints: {cA: true, critical: true}}, +4366 * {keyUsage: {bin: '11'}}, +4367 * ], +4368 * cakey: prvKeyObj +4369 * }); +4370 * // -- or -- +4371 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4372 * serial: {int: 4}, +4373 * sigalg: {name: 'SHA1withECDSA'}, +4374 * issuer: {str: '/C=US/O=a'}, +4375 * notbefore: {'str': '130504235959Z'}, +4376 * notafter: {'str': '140504235959Z'}, +4377 * subject: {str: '/C=US/O=b'}, +4378 * sbjpubkey: pubKeyPEM, +4379 * ext: [ +4380 * {basicConstraints: {cA: true, critical: true}}, +4381 * {keyUsage: {bin: '11'}}, +4382 * ], +4383 * cakey: [prvkey, pass]} +4384 * ); +4385 * // -- or -- +4386 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4387 * serial: {int: 1}, +4388 * sigalg: {name: 'SHA1withRSA'}, +4389 * issuer: {str: '/C=US/O=T1'}, +4390 * notbefore: {'str': '130504235959Z'}, +4391 * notafter: {'str': '140504235959Z'}, +4392 * subject: {str: '/C=US/O=T1'}, +4393 * sbjpubkey: pubKeyObj, +4394 * sighex: '0102030405..' +4395 * }); +4396 * // for the issuer and subject field, another +4397 * // representation is also available +4398 * var certPEM = KJUR.asn1.x509.X509Util.newCertPEM({ +4399 * serial: {int: 1}, +4400 * sigalg: {name: 'SHA256withRSA'}, +4401 * issuer: {C: "US", O: "T1"}, +4402 * notbefore: {'str': '130504235959Z'}, +4403 * notafter: {'str': '140504235959Z'}, +4404 * subject: {C: "US", O: "T1", CN: "http://example.com/"}, +4405 * sbjpubkey: pubKeyObj, +4406 * sighex: '0102030405..' +4407 * }); +4408 */ +4409 KJUR.asn1.x509.X509Util.newCertPEM = function(param) { +4410 var _KJUR_asn1_x509 = KJUR.asn1.x509, +4411 _TBSCertificate = _KJUR_asn1_x509.TBSCertificate, +4412 _Certificate = _KJUR_asn1_x509.Certificate; +4413 var cert = new _Certificate(param); +4414 return cert.getPEM(); +4415 }; +4416 +4417 \ No newline at end of file diff --git a/bower.json b/bower.json index a7a1f778..505e793e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kjur-jsrsasign", - "version": "10.4.0", + "version": "10.4.1", "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 6d3445ca..0055a5ad 100644 --- a/jsrsasign-all-min.js +++ b/jsrsasign-all-min.js @@ -1,5 +1,5 @@ /* - * jsrsasign(all) 10.4.0 (2021-08-17) (c) 2010-2021 Kenji Urushima | kjur.github.com/jsrsasign/license + * jsrsasign(all) 10.4.1 (2021-09-30) (c) 2010-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /*! CryptoJS v3.1.2 core-fix.js @@ -217,9 +217,9 @@ ECFieldElementFp.prototype.getByteLength=function(){return Math.floor((this.toBi /*! Mike Samuel (c) 2009 | code.google.com/p/json-sans-eval */ var jsonParse=(function(){var e="(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)";var j='(?:[^\\0-\\x08\\x0a-\\x1f"\\\\]|\\\\(?:["/\\\\bfnrt]|u[0-9A-Fa-f]{4}))';var i='(?:"'+j+'*")';var d=new RegExp("(?:false|true|null|[\\{\\}\\[\\]]|"+e+"|"+i+")","g");var k=new RegExp("\\\\(?:([^u])|u(.{4}))","g");var g={'"':'"',"/":"/","\\":"\\",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};function h(l,m,n){return m?g[m]:String.fromCharCode(parseInt(n,16))}var c=new String("");var a="\\";var f={"{":Object,"[":Array};var b=Object.hasOwnProperty;return function(u,q){var p=u.match(d);var x;var v=p[0];var l=false;if("{"===v){x={}}else{if("["===v){x=[]}else{x=[];l=true}}var t;var r=[x];for(var o=1-l,m=p.length;o=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=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.getEncodedHex()}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;u31){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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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;m=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=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.getEncodedHex()}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;u31){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;ef.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||70){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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;e=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=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.getEncodedHex()}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;u31){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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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;m=a.length){return null}}var e="";while(++f191)&&(h<224)){e+=String.fromCharCode(((h&31)<<6)|(a[f+1]&63));++f}else{e+=String.fromCharCode(((h&15)<<12)|((a[f+1]&63)<<6)|(a[f+2]&63));f+=2}}}return e}function oaep_mgf1_str(c,a,e){var b="",d=0;while(b.length>24,(d&16711680)>>16,(d&65280)>>8,d&255]));d+=1}return b}function oaep_unpad(o,b,g,p){var e=KJUR.crypto.MessageDigest;var r=KJUR.crypto.Util;var c=null;if(!g){g="sha1"}if(typeof g==="string"){c=e.getCanonicalAlgName(g);p=e.getHashLength(c);g=function(d){return hextorstr(r.hashHex(rstrtohex(d),c))}}o=o.toByteArray();var h;for(h=0;h0&&a.length>0){this.n=parseBigInt(c,16);this.e=parseInt(a,16);this.d=parseBigInt(b,16)}else{throw"Invalid RSA private key"}}}function RSASetPrivateEx(g,d,e,c,b,a,h,f){this.isPrivate=true;this.isPublic=false;if(g==null){throw"RSASetPrivateEx N == null"}if(d==null){throw"RSASetPrivateEx E == null"}if(g.length==0){throw"RSASetPrivateEx N.length == 0"}if(d.length==0){throw"RSASetPrivateEx E.length == 0"}if(g!=null&&d!=null&&g.length>0&&d.length>0){this.n=parseBigInt(g,16);this.e=parseInt(d,16);this.d=parseBigInt(e,16);this.p=parseBigInt(c,16);this.q=parseBigInt(b,16);this.dmp1=parseBigInt(a,16);this.dmq1=parseBigInt(h,16);this.coeff=parseBigInt(f,16)}else{throw"Invalid RSA private key in RSASetPrivateEx"}}function RSAGenerate(b,i){var a=new SecureRandom();var f=b>>1;this.e=parseInt(i,16);var c=new BigInteger(i,16);for(;;){for(;;){this.p=new BigInteger(b-f,1,a);if(this.p.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(f,1,a);if(this.q.subtract(BigInteger.ONE).gcd(c).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var h=this.p;this.p=this.q;this.q=h}var g=this.p.subtract(BigInteger.ONE);var d=this.q.subtract(BigInteger.ONE);var e=g.multiply(d);if(e.gcd(c).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);if(this.n.bitLength()==b){this.d=c.modInverse(e);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(d);this.coeff=this.q.modInverse(this.p);break}}}this.isPrivate=true}function RSADoPrivate(a){if(this.p==null||this.q==null){return a.modPow(this.d,this.n)}var c=a.mod(this.p).modPow(this.dmp1,this.p);var b=a.mod(this.q).modPow(this.dmq1,this.q);while(c.compareTo(b)<0){c=c.add(this.p)}return c.subtract(b).multiply(this.coeff).mod(this.p).multiply(this.q).add(b)}function RSADecrypt(b){if(b.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var d=parseBigInt(b,16);var a=this.doPrivate(d);if(a==null){return null}return pkcs1unpad2(a,(this.n.bitLength()+7)>>3)}function RSADecryptOAEP(e,d,b){if(e.length!=Math.ceil(this.n.bitLength()/4)){throw new Error("wrong ctext length")}var f=parseBigInt(e,16);var a=this.doPrivate(f);if(a==null){return null}return oaep_unpad(a,(this.n.bitLength()+7)>>3,d,b)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;RSAKey.prototype.decryptOAEP=RSADecryptOAEP; -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=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.getEncodedHex()}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;u31){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;ef.length){f=c[d]}}e=e.replace(f,"::");return e.slice(1,-1)}function hextoip(b){var d="malformed hex value";if(!b.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){throw d}if(b.length==8){var c;try{c=parseInt(b.substr(0,2),16)+"."+parseInt(b.substr(2,2),16)+"."+parseInt(b.substr(4,2),16)+"."+parseInt(b.substr(6,2),16);return c}catch(a){throw d}}else{if(b.length==32){return hextoipv6(b)}else{return b}}}function iptohex(f){var j="malformed IP address";f=f.toLowerCase(f);if(f.match(/^[0-9.]+$/)){var b=f.split(".");if(b.length!==4){throw j}var g="";try{for(var e=0;e<4;e++){var h=parseInt(b[e]);g+=("0"+h.toString(16)).slice(-2)}return g}catch(c){throw j}}else{if(f.match(/^[0-9a-f:]+$/)&&f.indexOf(":")!==-1){return ipv6tohex(f)}else{throw j}}}function ucs2hextoutf8(d){function e(f){var h=parseInt(f.substr(0,2),16);var a=parseInt(f.substr(2),16);if(h==0&a<128){return String.fromCharCode(a)}if(h<8){var j=192|((h&7)<<3)|((a&192)>>6);var i=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16))}var j=224|((h&240)>>4);var i=128|((h&15)<<2)|((a&192)>>6);var g=128|(a&63);return hextoutf8(j.toString(16)+i.toString(16)+g.toString(16))}var c=d.match(/.{4}/g);var b=c.map(e);return b.join("")}function encodeURIComponentAll(a){var d=encodeURIComponent(a);var b="";for(var c=0;c"7"){return"00"+a}return a}function intarystrtohex(b){b=b.replace(/^\s*\[\s*/,"");b=b.replace(/\s*\]\s*$/,"");b=b.replace(/\s*/g,"");try{var c=b.split(/,/).map(function(g,e,h){var f=parseInt(g);if(f<0||255a.length){d=a.length}for(var b=0;b0){o=o+"."+k.join(".")}return o}catch(j){return null}}var strpad=function(c,b,a){if(a==undefined){a="0"}if(c.length>=b){return c}return new Array(b-c.length+1).join(a)+c};function bitstrtoint(e){try{var a=e.substr(0,2);if(a=="00"){return parseInt(e.substr(2),16)}var b=parseInt(a,16);var f=e.substr(2);var d=parseInt(f,16).toString(2);if(d=="0"){d="00000000"}d=d.slice(0,0-b);return parseInt(d,2)}catch(c){return -1}}function inttobitstr(e){var c=Number(e).toString(2);var b=8-c.length%8;if(b==8){b=0}c=c+strpad("",b,"0");var d=parseInt(c,2).toString(16);if(d.length%2==1){d="0"+d}var a="0"+b;return a+d}function extendClass(c,a){var b=function(){};b.prototype=a.prototype;c.prototype=new b();c.prototype.constructor=c;c.superclass=a.prototype;if(a.prototype.constructor==Object.prototype.constructor){a.prototype.constructor=a}}; if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.crypto=="undefined"||!KJUR.crypto){KJUR.crypto={}}KJUR.crypto.Util=new function(){this.DIGESTINFOHEAD={sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",ripemd160:"3021300906052b2403020105000414",};this.DEFAULTPROVIDER={md5:"cryptojs",sha1:"cryptojs",sha224:"cryptojs",sha256:"cryptojs",sha384:"cryptojs",sha512:"cryptojs",ripemd160:"cryptojs",hmacmd5:"cryptojs",hmacsha1:"cryptojs",hmacsha224:"cryptojs",hmacsha256:"cryptojs",hmacsha384:"cryptojs",hmacsha512:"cryptojs",hmacripemd160:"cryptojs",MD5withRSA:"cryptojs/jsrsa",SHA1withRSA:"cryptojs/jsrsa",SHA224withRSA:"cryptojs/jsrsa",SHA256withRSA:"cryptojs/jsrsa",SHA384withRSA:"cryptojs/jsrsa",SHA512withRSA:"cryptojs/jsrsa",RIPEMD160withRSA:"cryptojs/jsrsa",MD5withECDSA:"cryptojs/jsrsa",SHA1withECDSA:"cryptojs/jsrsa",SHA224withECDSA:"cryptojs/jsrsa",SHA256withECDSA:"cryptojs/jsrsa",SHA384withECDSA:"cryptojs/jsrsa",SHA512withECDSA:"cryptojs/jsrsa",RIPEMD160withECDSA:"cryptojs/jsrsa",SHA1withDSA:"cryptojs/jsrsa",SHA224withDSA:"cryptojs/jsrsa",SHA256withDSA:"cryptojs/jsrsa",MD5withRSAandMGF1:"cryptojs/jsrsa",SHAwithRSAandMGF1:"cryptojs/jsrsa",SHA1withRSAandMGF1:"cryptojs/jsrsa",SHA224withRSAandMGF1:"cryptojs/jsrsa",SHA256withRSAandMGF1:"cryptojs/jsrsa",SHA384withRSAandMGF1:"cryptojs/jsrsa",SHA512withRSAandMGF1:"cryptojs/jsrsa",RIPEMD160withRSAandMGF1:"cryptojs/jsrsa",};this.CRYPTOJSMESSAGEDIGESTNAME={md5:CryptoJS.algo.MD5,sha1:CryptoJS.algo.SHA1,sha224:CryptoJS.algo.SHA224,sha256:CryptoJS.algo.SHA256,sha384:CryptoJS.algo.SHA384,sha512:CryptoJS.algo.SHA512,ripemd160:CryptoJS.algo.RIPEMD160};this.getDigestInfoHex=function(a,b){if(typeof this.DIGESTINFOHEAD[b]=="undefined"){throw"alg not supported in Util.DIGESTINFOHEAD: "+b}return this.DIGESTINFOHEAD[b]+a};this.getPaddedDigestInfoHex=function(h,a,j){var c=this.getDigestInfoHex(h,a);var d=j/4;if(c.length+22>d){throw"key is too short for SigAlg: keylen="+j+","+a}var b="0001";var k="00"+c;var g="";var l=d-b.length-k.length;for(var f=0;f=0;){delete D[n[A]]}}}return q.call(C,B,D)};x=s({"":x},"")}return x}})(); -if(typeof KJUR=="undefined"||!KJUR){KJUR={}}if(typeof KJUR.asn1=="undefined"||!KJUR.asn1){KJUR.asn1={}}KJUR.asn1.ASN1Util=new function(){this.integerToByteHex=function(a){var b=a.toString(16);if((b.length%2)==1){b="0"+b}return b};this.bigIntToMinTwosComplementsHex=function(j){var f=j.toString(16);if(f.substr(0,1)!="-"){if(f.length%2==1){f="0"+f}else{if(!f.match(/^[0-7]/)){f="00"+f}}}else{var a=f.substr(1);var e=a.length;if(e%2==1){e+=1}else{if(!f.match(/^[0-7]/)){e+=2}}var g="";for(var d=0;d15){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=stohex(d)};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||715){throw"ASN.1 length too long to represent by 8x: n = "+j.toString(16)}var g=128+h;return g.toString(16)+i}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""};this.setByParam=function(g){this.params=g};if(e!=undefined){if(e.tlv!=undefined){this.hTLV=e.tlv;this.isModified=false}}};KJUR.asn1.DERAbstractString=function(c){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var b=null;var a=null;this.getString=function(){return this.s};this.setString=function(d){this.hTLV=null;this.isModified=true;this.s=d;this.hV=utf8tohex(this.s).toLowerCase()};this.setStringHex=function(d){this.hTLV=null;this.isModified=true;this.s=null;this.hV=d};this.getFreshValueHex=function(){return this.hV};if(typeof c!="undefined"){if(typeof c=="string"){this.setString(c)}else{if(typeof c.str!="undefined"){this.setString(c.str)}else{if(typeof c.hex!="undefined"){this.setStringHex(c.hex)}}}}};extendClass(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(c){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);var b=null;var a=null;this.localDateToUTC=function(g){var e=g.getTime()+(g.getTimezoneOffset()*60000);var f=new Date(e);return f};this.formatDate=function(m,o,e){var g=this.zeroPadding;var n=this.localDateToUTC(m);var p=String(n.getFullYear());if(o=="utc"){p=p.substr(2,2)}var l=g(String(n.getMonth()+1),2);var q=g(String(n.getDate()),2);var h=g(String(n.getHours()),2);var i=g(String(n.getMinutes()),2);var j=g(String(n.getSeconds()),2);var r=p+l+q+h+i+j;if(e===true){var f=n.getMilliseconds();if(f!=0){var k=g(String(f),3);k=k.replace(/[0]+$/,"");r=r+"."+k}}return r+"Z"};this.zeroPadding=function(e,d){if(e.length>=d){return e}return new Array(d-e.length+1).join("0")+e};this.setByParam=function(d){this.hV=null;this.hTLV=null;this.params=d};this.getString=function(){return undefined};this.setString=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.str=d};this.setByDate=function(d){this.hTLV=null;this.isModified=true;if(this.params==undefined){this.params={}}this.params.date=d};this.setByDateValue=function(h,j,e,d,f,g){var i=new Date(Date.UTC(h,j-1,e,d,f,g,0));this.setByDate(i)};this.getFreshValueHex=function(){return this.hV}};extendClass(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(b){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);var a=null;this.setByASN1ObjectArray=function(c){this.hTLV=null;this.isModified=true;this.asn1Array=c};this.appendASN1Object=function(c){this.hTLV=null;this.isModified=true;this.asn1Array.push(c)};this.asn1Array=new Array();if(typeof b!="undefined"){if(typeof b.array!="undefined"){this.asn1Array=b.array}}};extendClass(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(a){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";if(a==false){this.hTLV="010100"}else{this.hTLV="0101ff"}};extendClass(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(a){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(b){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(b)};this.setByInteger=function(c){var b=new BigInteger(String(c),10);this.setByBigInteger(b)};this.setValueHex=function(b){this.hV=b};this.getFreshValueHex=function(){return this.hV};if(typeof a!="undefined"){if(typeof a.bigint!="undefined"){this.setByBigInteger(a.bigint)}else{if(typeof a["int"]!="undefined"){this.setByInteger(a["int"])}else{if(typeof a=="number"){this.setByInteger(a)}else{if(typeof a.hex!="undefined"){this.setValueHex(a.hex)}}}}}};extendClass(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(b){if(b!==undefined&&typeof b.obj!=="undefined"){var a=KJUR.asn1.ASN1Util.newObject(b.obj);b.hex="00"+a.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(c){this.hTLV=null;this.isModified=true;this.hV=c};this.setUnusedBitsAndHexValue=function(c,e){if(c<0||7=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.getEncodedHex()}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;u31){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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.setTimeParams=function(h){this.timeParams=h};this.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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){n.push(new c({tag:"a3",obj:new j(q.ext)}))}var o=new KJUR.asn1.DERSequence({array:n});return o.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex()}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.getEncodedHex()}};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.getEncodedHex=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.getEncodedHex()};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.getEncodedHex=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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=function(){var p=this.getASN1Object();this.hTLV=p.getEncodedHex();return this.hTLV};this.setPubKey=function(q){try{if(q instanceof RSAKey){var u=h({seq:[{"int":{bigint:q.n}},{"int":{"int":q.e}}]});var s=u.getEncodedHex();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.getEncodedHex()})}}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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.TLV};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.getEncodedHex=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.getEncodedHex();return this.hTLV};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(e){KJUR.asn1.x509.GeneralName.superclass.constructor.call(this);var m=null,i=null,k={rfc822:"81",dns:"82",dn:"a4",uri:"86",ip:"87"},b=KJUR,g=b.asn1,f=g.DERSequence,j=g.DEROctetString,d=g.DERIA5String,c=g.DERTaggedObject,l=g.ASN1Object,a=g.x509.X500Name,h=pemtohex;this.explicit=false;this.setByParam=function(p){var r=null;var u=null;if(p===undefined){return}if(p.rfc822!==undefined){this.type="rfc822";u=new d({str:p[this.type]})}if(p.dns!==undefined){this.type="dns";u=new d({str:p[this.type]})}if(p.uri!==undefined){this.type="uri";u=new d({str:p[this.type]})}if(p.dn!==undefined){this.type="dn";this.explicit=true;if(typeof p.dn==="string"){u=new a({str:p.dn})}else{if(p.dn instanceof KJUR.asn1.x509.X500Name){u=p.dn}else{u=new a(p.dn)}}}if(p.ldapdn!==undefined){this.type="dn";this.explicit=true;u=new a({ldapstr:p.ldapdn})}if(p.certissuer!==undefined){this.type="dn";this.explicit=true;var o=p.certissuer;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certissuer param not cert"}var t=new X509();t.hex=w;var y=t.getIssuerHex();u=new l();u.hTLV=y}if(p.certsubj!==undefined){this.type="dn";this.explicit=true;var o=p.certsubj;var w=null;if(o.match(/^[0-9A-Fa-f]+$/)){w==o}if(o.indexOf("-----BEGIN ")!=-1){w=h(o)}if(w==null){throw"certsubj param not cert"}var t=new X509();t.hex=w;var y=t.getSubjectHex();u=new l();u.hTLV=y}if(p.ip!==undefined){this.type="ip";this.explicit=false;var q=p.ip;var s;var n="malformed IP address";if(q.match(/^[0-9.]+[.][0-9.]+$/)){s=intarystrtohex("["+q.split(".").join(",")+"]");if(s.length!==8){throw n}}else{if(q.match(/^[0-9A-Fa-f:]+:[0-9A-Fa-f:]+$/)){s=ipv6tohex(q)}else{if(q.match(/^([0-9A-Fa-f][0-9A-Fa-f]){1,}$/)){s=q}else{throw n}}}u=new j({hex:s})}if(this.type==null){throw"unsupported type in params="+p}this.asn1Obj=new c({explicit:this.explicit,tag:k[this.type],obj:u})};this.getEncodedHex=function(){return this.asn1Obj.getEncodedHex()};if(e!==undefined){this.setByParam(e)}};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;mMIT License */ @@ -632,6 +632,9 @@ extendClass(KJUR.asn1.DERAbstractString, KJUR.asn1.ASN1Object); * @extends KJUR.asn1.ASN1Object * @description * @see KJUR.asn1.ASN1Object - superclass + * @see KJUR.asn1.DERGeneralizedTime + * @see KJUR.asn1.DERUTCTime + * @see KJUR.asn1.x509.Time */ KJUR.asn1.DERAbstractTime = function(params) { KJUR.asn1.DERAbstractTime.superclass.constructor.call(this); @@ -683,29 +686,82 @@ KJUR.asn1.DERAbstractTime = function(params) { }; // --- PUBLIC METHODS -------------------- + /** - * get string value of this string object + * set parameter of time + * @name setByParam + * @memberOf KJUR.asn1.DERAbstractTime# + * @function + * @param {Object} params JSON object, Date object or string of time + * @since jsrsasign 10.4.1 asn1 1.0.22 + * + * NOTE: If a member "millis" has a value "true", + * a fraction of second will be specified for this object. + * This default is "false". + * + * @example + * d1 = new KJUR.asn1.DERGeneralizedTime(); + * d1.setByParam("20210930235959.123Z"); + * d1.setByParam({str: "20210930235959.123Z"}); + * + * d1.setByParam(new Date("2013/12/31 23:59:59.12")); + * date1 = new Date(Date.UTC(2021,8,31,23,59,59,123)); + * d1.setByParam(date1); + * d1.setByParam({date: date1}); + * d1.setByParam({date: date1, millis: true}); + */ + this.setByParam = function(params) { + this.hV = null; + this.hTLV = null; + this.params = params; + }; + + /** + * get string value of this string object (DEPRECATED) * @name getString * @memberOf KJUR.asn1.DERAbstractTime# * @function * @return {String} string value of this time object + * @deprecated from jsrsasign 10.4.1 asn1 1.0.22. */ this.getString = function() { - return this.s; + return undefined; }; /** - * set value by a string + * set value by a string (DEPRECATED) * @name setString * @memberOf KJUR.asn1.DERAbstractTime# * @function * @param {String} newS value by a string to set such like "130430235959Z" + * @deprecated from jsrsasign 10.4.1 asn1 1.0.22. */ this.setString = function(newS) { this.hTLV = null; this.isModified = true; - this.s = newS; - this.hV = stohex(newS); + if (this.params == undefined) this.params = {}; + this.params.str = newS; + }; + + /** + * set value by a Date object
+ * @name setByDate + * @memberOf KJUR.asn1.DERAbstractTime# + * @function + * @param {Date} dateObject Date object to set ASN.1 value(V) + * @since jsrsasign 10.4.1 asn1 1.0.22 + * + * @example + * o = new KJUR.asn1.DERUTCTime(); + * o.setByDate(new Date("2016/12/31 23:59:59.12")); + * // 2015-Jan-31 23:59:59.12 + * o.setByDate(new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0))); + */ + this.setByDate = function(dateObject) { + this.hTLV = null; + this.isModified = true; + if (this.params == undefined) this.params = {}; + this.params.date = dateObject; }; /** @@ -721,7 +777,8 @@ KJUR.asn1.DERAbstractTime = function(params) { * @param {Integer} sec seconds of date */ this.setByDateValue = function(year, month, day, hour, min, sec) { - var dateObject = new Date(Date.UTC(year, month - 1, day, hour, min, sec, 0)); + var dateObject = new Date(Date.UTC(year, month - 1, day, + hour, min, sec, 0)); this.setByDate(dateObject); }; @@ -1445,67 +1502,69 @@ extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); * @class class for ASN.1 DER UTCTime * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) * @extends KJUR.asn1.DERAbstractTime + * @see KJUR.asn1.DERGeneralizedTime + * @see KJUR.asn1.x509.Time + * * @description *
* As for argument 'params' for constructor, you can specify one of * following properties: *
    *
  • str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')
  • - *
  • hex - specify initial ASN.1 value(V) by a hexadecimal string
  • *
  • date - specify Date object.
  • + *
  • millis - specify flag to show milliseconds (from 1.0.6)
  • *
- * NOTE: 'params' can be omitted. + * NOTE1: 'params' can be omitted. + * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22. + * *

EXAMPLES

* @example - * d1 = new KJUR.asn1.DERUTCTime(); - * d1.setString('130430125959Z'); - * - * d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'}); - * d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))}); - * d4 = new KJUR.asn1.DERUTCTime('130430125959Z'); + * new DERUTCTime("20151231235959Z") + * new DERUTCTime("20151231235959.123Z") + * new DERUTCTime(new Date()) + * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) + * new DERUTCTime({str: "20151231235959.123Z"}) + * new DERUTCTime({date: new Date()}) + * new DERUTCTime({date: new Date(), millis: true}) + * new DERUTCTime({millis: true}) */ KJUR.asn1.DERUTCTime = function(params) { KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); this.hT = "17"; - - /** - * set value by a Date object
- * @name setByDate - * @memberOf KJUR.asn1.DERUTCTime# - * @function - * @param {Date} dateObject Date object to set ASN.1 value(V) - * @example - * o = new KJUR.asn1.DERUTCTime(); - * o.setByDate(new Date("2016/12/31")); - */ - this.setByDate = function(dateObject) { - this.hTLV = null; - this.isModified = true; - this.date = dateObject; - this.s = this.formatDate(this.date, 'utc'); - this.hV = stohex(this.s); - }; + this.params = undefined; this.getFreshValueHex = function() { - if (typeof this.date == "undefined" && typeof this.s == "undefined") { - this.date = new Date(); - this.s = this.formatDate(this.date, 'utc'); - this.hV = stohex(this.s); - } - return this.hV; + var params = this.params; + + if (this.params == undefined) params = { date: new Date() }; + + if (typeof params == "string") { + if (params.match(/^[0-9]{12}Z$/) || + params.match(/^[0-9]{12}\.[0-9]+Z$/)) { + this.hV = stohex(params); + } else { + throw new Error("malformed string for GeneralizedTime: " + params); + } + } else if (params.str != undefined) { + this.hV = stohex(params.str); + } else if (params.date == undefined && params.millis == true) { + var date = new Date(); + this.hV = stohex(this.formatDate(date, 'utc', true)); + } else if (params.date != undefined && + params.date instanceof Date) { + var withMillis = (params.millis === true); + this.hV = stohex(this.formatDate(params.date, 'utc', withMillis)); + } else if (params instanceof Date) { + this.hV = stohex(this.formatDate(params, 'utc')); + } + + if (this.hV == undefined) { + throw new Error("parameter not specified properly for UTCTime"); + } + return this.hV; }; - if (params !== undefined) { - if (params.str !== undefined) { - this.setString(params.str); - } else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) { - this.setString(params); - } else if (params.hex !== undefined) { - this.setStringHex(params.hex); - } else if (params.date !== undefined) { - this.setByDate(params.date); - } - } + if (params != undefined) this.setByParam(params); }; extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); @@ -1517,68 +1576,69 @@ extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) * @property {Boolean} withMillis flag to show milliseconds or not * @extends KJUR.asn1.DERAbstractTime + * @see KJUR.asn1.DERUTCTime + * @see KJUR.asn1.x509.Time + * * @description *
* As for argument 'params' for constructor, you can specify one of * following properties: *
    *
  • str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')
  • - *
  • hex - specify initial ASN.1 value(V) by a hexadecimal string
  • *
  • date - specify Date object.
  • *
  • millis - specify flag to show milliseconds (from 1.0.6)
  • *
* NOTE1: 'params' can be omitted. - * NOTE2: 'withMillis' property is supported from asn1 1.0.6. + * NOTE2: 'millis' property is supported from asn1 1.0.6. + * + *

EXAMPLES

+ * @example + * new DERGeneralizedTime("20151231235959Z") + * new DERGeneralizedTime("20151231235959.123Z") + * new DERGeneralizedTime(new Date()) + * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) + * new DERGeneralizedTime({str: "20151231235959.123Z"}) + * new DERGeneralizedTime({date: new Date()}) + * new DERGeneralizedTime({date: new Date(), millis: true}) + * new DERGeneralizedTime({millis: true}) */ KJUR.asn1.DERGeneralizedTime = function(params) { KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); this.hT = "18"; - this.withMillis = false; - - /** - * set value by a Date object - * @name setByDate - * @memberOf KJUR.asn1.DERGeneralizedTime# - * @function - * @param {Date} dateObject Date object to set ASN.1 value(V) - * @example - * When you specify UTC time, use 'Date.UTC' method like this:
- * o1 = new DERUTCTime(); - * o1.setByDate(date); - * - * date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59 - */ - this.setByDate = function(dateObject) { - this.hTLV = null; - this.isModified = true; - this.date = dateObject; - this.s = this.formatDate(this.date, 'gen', this.withMillis); - this.hV = stohex(this.s); - }; + this.params = params; this.getFreshValueHex = function() { - if (this.date === undefined && this.s === undefined) { - this.date = new Date(); - this.s = this.formatDate(this.date, 'gen', this.withMillis); - this.hV = stohex(this.s); - } - return this.hV; + var params = this.params; + + if (this.params == undefined) params = { date: new Date() }; + + if (typeof params == "string") { + if (params.match(/^[0-9]{14}Z$/) || + params.match(/^[0-9]{14}\.[0-9]+Z$/)) { + this.hV = stohex(params); + } else { + throw new Error("malformed string for GeneralizedTime: " + params); + } + } else if (params.str != undefined) { + this.hV = stohex(params.str); + } else if (params.date == undefined && params.millis == true) { + var date = new Date(); + this.hV = stohex(this.formatDate(date, 'gen', true)); + } else if (params.date != undefined && + params.date instanceof Date) { + var withMillis = (params.millis === true); + this.hV = stohex(this.formatDate(params.date, 'gen', withMillis)); + } else if (params instanceof Date) { + this.hV = stohex(this.formatDate(params, 'gen')); + } + + if (this.hV == undefined) { + throw new Error("parameter not specified properly for GeneralizedTime"); + } + return this.hV; }; - if (params !== undefined) { - if (params.str !== undefined) { - this.setString(params.str); - } else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) { - this.setString(params); - } else if (params.hex !== undefined) { - this.setStringHex(params.hex); - } else if (params.date !== undefined) { - this.setByDate(params.date); - } - if (params.millis === true) { - this.withMillis = true; - } - } + if (params != undefined) this.setByParam(params); }; extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); diff --git a/src/asn1x509-1.0.js b/src/asn1x509-1.0.js index b8307dfe..837e7a4c 100644 --- a/src/asn1x509-1.0.js +++ b/src/asn1x509-1.0.js @@ -1,4 +1,4 @@ -/* asn1x509-2.1.8.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license +/* asn1x509-2.1.9.js (c) 2013-2021 Kenji Urushima | kjur.github.io/jsrsasign/license */ /* * asn1x509.js - ASN.1 DER encoder classes for X.509 certificate @@ -16,7 +16,7 @@ * @fileOverview * @name asn1x509-1.0.js * @author Kenji Urushima kenji.urushima@gmail.com - * @version jsrsasign 10.1.10 asn1x509 2.1.8 (2021-Feb-14) + * @version jsrsasign 10.4.1 asn1x509 2.1.9 (2021-Sep-30) * @since jsrsasign 2.1 * @license MIT License */ @@ -3508,6 +3508,64 @@ extendClass(KJUR.asn1.x509.SubjectPublicKeyInfo, KJUR.asn1.ASN1Object); */ KJUR.asn1.x509.Time = function(params) { KJUR.asn1.x509.Time.superclass.constructor.call(this); + var type = null, + timeParams = null, + _KJUR = KJUR, + _KJUR_asn1 = _KJUR.asn1, + _DERUTCTime = _KJUR_asn1.DERUTCTime, + _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime; + this.params = null; + this.type = null; + + // deprecated + this.setTimeParams = function(timeParams) { + this.timeParams = timeParams; + } + + this.setByParam = function(params) { + this.params = params; + }; + + this.getType = function(s) { + if (s.match(/^[0-9]{12}Z$/)) return "utc"; + if (s.match(/^[0-9]{14}Z$/)) return "gen"; + if (s.match(/^[0-9]{12}\.[0-9]+Z$/)) return "utc"; + if (s.match(/^[0-9]{14}\.[0-9]+Z$/)) return "gen"; + return null; + }; + + this.getEncodedHex = function() { + var params = this.params; + var o = null; + + if (typeof params == "string") params = {str: params}; + if (params != null && + params.str && + (params.type == null || params.type == undefined)) { + params.type = this.getType(params.str); + } + + if (params != null && params.str) { + if (params.type == "utc") o = new _DERUTCTime(params.str); + if (params.type == "gen") o = new _DERGeneralizedTime(params.str); + } else { + if (this.type == "gen") { + o = new _DERGeneralizedTime(); + } else { + o = new _DERUTCTime(); + } + } + + if (o == null) throw new Error("wrong setting for Time"); + this.TLV = o.getEncodedHex(); + return this.TLV; + }; + + if (params != undefined) this.setByParam(params); +}; + +KJUR.asn1.x509.Time_bak = function(params) { + KJUR.asn1.x509.Time_bak.superclass.constructor.call(this); var type = null, timeParams = null, _KJUR = KJUR, diff --git a/test/qunit-do-asn1.html b/test/qunit-do-asn1.html index 9de69b15..49f11b90 100755 --- a/test/qunit-do-asn1.html +++ b/test/qunit-do-asn1.html @@ -14,6 +14,7 @@ + @@ -200,56 +201,182 @@ }); test("UTCTime Test", function() { - expect(5); - - var d1 = new KJUR.asn1.DERUTCTime(); - d1.setString('130430125959Z'); - equal(d1.getEncodedHex(), "170d3133303433303132353935395a", "setString 130430125959Z"); - - var d2 = new KJUR.asn1.DERUTCTime(); - d2.setByDate(new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))); - equal(d2.s, "150131000000Z", "setByDate Date.UTC"); - - var d3 = new KJUR.asn1.DERUTCTime(); - d3.setByDateValue(2015, 1, 31, 0, 0, 0); - equal(d3.s, "150131000000Z", "setByDateValue"); +var _DERUTCTime = KJUR.asn1.DERUTCTime; +var d; + +d = new _DERUTCTime(); +d.setString('130430125959Z'); +equal(d.getEncodedHex(), + "170d3133303433303132353935395a", + "d.setString(130430125959Z)"); + +d = new _DERUTCTime(); +d.setByDate(new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "d.setByDate(new Date(?2015/01/31 00:00:00?))"); + +d = new _DERUTCTime(); +d.setByDateValue(2015, 1, 31, 0, 0, 0); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "d.setByDateValue(2015,1,31,0,0,0)"); + +// -- implicit constructor test -- +d = new _DERUTCTime({'date':new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))}); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "new DERUTCTime({date: new Date(?2015/01/31 00:00:00?)})"); + +d = new _DERUTCTime("150131000000Z"); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "new DERUTCTime(20150131000000Z)"); + +d = new _DERUTCTime("150131000000.123Z"); +equal(d.getEncodedHex(), + "17113135303133313030303030302e3132335a", + "new DERUTCTime(20150131000000.123Z)"); + +// -- JSON constructor test -- +d = new _DERUTCTime({ + 'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0)) +}); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "new DERUTCTime({date: new Date(?2015/01/31 00:00:00?)})"); - var d4 = new KJUR.asn1.DERUTCTime({'date':new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))}); - equal(d4.s, "150131000000Z", "constructor date argument"); +d = new _DERUTCTime({ + 'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 120)), + millis: true +}); +equal(d.getEncodedHex(), + "17103135303133313030303030302e31325a", + "new UTCTime({date: new Date(?2015/01/31 00:00:00.12?)})"); + +d = new _DERUTCTime({str: "150131000000Z"}); +equal(d.getEncodedHex(), + "170d3135303133313030303030305a", + "new DERUTCTime({str: 150131000000Z})"); + +d = new _DERUTCTime({str: "150131000000.12Z"}); +equal(d.getEncodedHex(), + "17103135303133313030303030302e31325a", + "new DERUTCTime({str: 150131000000.123Z})"); + +d = new _DERUTCTime(); +var d5hex = d.getEncodedHex() +equal(d5hex.substr(0, 4), "170d", "new DERUTCTime() -> 170d..."); + +// now + millis test +// - fraction of second may not include with one in a hundred chance +// - so any of three times is fine, it will be fine. +var d6flag = false; +var s1 = ""; +for (var i = 0; i < 3; i++) { + var startMsec = new Date(); + while (new Date() - startMsec < 258); + d = new _DERUTCTime({millis: true}); + var d6hex = d.getEncodedHex(); + if (d6hex.substr(0, 2) != "17") continue; + var hS = ASN1HEX.getV(d6hex, 0); + var s = hextoutf8(hS); + s1 += s + "/"; + if (s.indexOf(".") == -1) continue; + d6flag = true; +} +equal(d6flag, true, "new DERUTCTime({millis: true}): " + s1); - var d5 = new KJUR.asn1.DERUTCTime(); - var d5hex = d5.getEncodedHex() - equal(d5hex.substr(0, 4), "170d", "now[0,4]=170d"); }); test("GeneralizedTime Test", function() { - expect(7); - var d1 = new KJUR.asn1.DERGeneralizedTime(); - d1.setString('20130430125959Z'); - equal(d1.getEncodedHex(), "180f32303133303433303132353935395a", - "GeneralizedTime 20130430125959Z"); - - var d2 = new KJUR.asn1.DERGeneralizedTime(); - d2.setByDate(new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))); - equal(d2.s, "20150131000000Z", "setByDate Date.UTC"); - - var d3 = new KJUR.asn1.DERGeneralizedTime(); - d3.setByDateValue(2015, 1, 31, 0, 0, 0); - equal(d3.s, "20150131000000Z", "setByDateValue"); - - var date4 = new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0)); - var d4 = new KJUR.asn1.DERGeneralizedTime({'date': date4}); - equal(d4.s, "20150131000000Z", "constructor date argument"); - - var d5 = new KJUR.asn1.DERGeneralizedTime(); - var d5hex = d5.getEncodedHex() - equal(d5hex.substr(0, 4), "180f", "now[0,4]=180f"); - equal(d5.s.length, 15, "now length=15"); - - var d6 = new KJUR.asn1.DERGeneralizedTime({millis: true}); - var d6hex = d6.getEncodedHex() - equal(d6.s.match(/^[0-9]+[.]?[0-9]*Z$/) != null, true, "now ({millis: true}) match/^d+.?d*Z$/"); +var _DERGeneralizedTime = KJUR.asn1.DERGeneralizedTime; +var d; + +// setter method test +d = new _DERGeneralizedTime(); +d.setString('20130430125959Z'); +equal(d.getEncodedHex(), + "180f32303133303433303132353935395a", + "d.setString(20130430125959Z)"); + +d = new _DERGeneralizedTime(); +d.setByDate(new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "d.setByDate(new Date(?2015/01/31 00:00:00?))"); + +d = new _DERGeneralizedTime(); +d.setByDateValue(2015, 1, 31, 0, 0, 0); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "d.setByDateValue(2015,1,31,0,0,0)"); + +// -- implicit constructor test -- +d = new _DERGeneralizedTime(new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "new GeneralizedTime(new Date(?2015/01/31 00:00:00?))"); + +d = new _DERGeneralizedTime("20150131000000Z"); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "new GeneralizedTime(20150131000000Z)"); + +d = new _DERGeneralizedTime("20150131000000.123Z"); +equal(d.getEncodedHex(), + "181332303135303133313030303030302e3132335a", + "new GeneralizedTime(20150131000000.123Z)"); + +// -- JSON constructor test -- +d = new _DERGeneralizedTime({ + 'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0)) +}); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "new GeneralizedTime({date: new Date(?2015/01/31 00:00:00?)})"); +d = new _DERGeneralizedTime({ + 'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 120)), + millis: true +}); +equal(d.getEncodedHex(), + "181232303135303133313030303030302e31325a", + "new GeneralizedTime({date: new Date(?2015/01/31 00:00:00.12?)})"); + +d = new _DERGeneralizedTime({str: "20150131000000Z"}); +equal(d.getEncodedHex(), + "180f32303135303133313030303030305a", + "new DERGeneralizedTime({str: 20150131000000Z})"); + +d = new _DERGeneralizedTime({str: "20150131000000.123Z"}); +equal(d.getEncodedHex(), + "181332303135303133313030303030302e3132335a", + "new DERGeneralizedTime({str: 20150131000000.123Z})"); + +d = new _DERGeneralizedTime(); +var d5hex = d.getEncodedHex() +equal(d5hex.substr(0, 4), "180f", "new GeneralizedTime() -> 180f..."); +equal(d5hex.length, 34, "new GeneralizedTime().getEncodedHex().length()=34"); + +// now + millis test +// - fraction of second may not include with one in a hundred chance +// - so any of three times is fine, it will be fine. +var d6flag = false; +var s1 = ""; +for (var i = 0; i < 3; i++) { + var startMsec = new Date(); + while (new Date() - startMsec < 258); + d = new _DERGeneralizedTime({millis: true}); + var d6hex = d.getEncodedHex(); + if (d6hex.substr(0, 2) != "18") continue; + var hS = ASN1HEX.getV(d6hex, 0); + var s = hextoutf8(hS); + s1 += s + "/"; + if (s.indexOf(".") == -1) continue; + d6flag = true; +} +equal(d6flag, true, "new GeneralizedTime({millis: true}): " + s1); }); test("Sequence Test", function() { diff --git a/test/qunit-do-asn1tsp.html b/test/qunit-do-asn1tsp.html index 60237f60..f3b89816 100755 --- a/test/qunit-do-asn1tsp.html +++ b/test/qunit-do-asn1tsp.html @@ -1,4 +1,4 @@ -s @@ -24,7 +24,6 @@ - diff --git a/test/qunit-do-asn1x509.html b/test/qunit-do-asn1x509.html index b01226cc..dfe0fcdb 100755 --- a/test/qunit-do-asn1x509.html +++ b/test/qunit-do-asn1x509.html @@ -469,19 +469,43 @@ // ===== END Name related class test ============== test("Time class test", function() { - expect(4); +var _Time = KJUR.asn1.x509.Time; +var o; - var o1 = new KJUR.asn1.x509.Time({'str':'130430235959Z'}); // UTC - equal(o1.getEncodedHex(), "170d3133303433303233353935395a", "constructor default timestr"); +o = new _Time({'str':'130430235959Z'}); // UTC +equal(o.getEncodedHex(), "170d3133303433303233353935395a", "param={str: utcstr}"); - var o2 = new KJUR.asn1.x509.Time({'str':'20130430235959Z', 'type': 'gen'}); // Gen - equal(o2.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr"); +o = new _Time({'str':'20130430235959Z', 'type': 'gen'}); // Gen +equal(o.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr"); - var o3 = new KJUR.asn1.x509.Time({'str':'20130430235959Z'}); // Gen - equal(o3.getEncodedHex(), "180f32303133303433303233353935395a", "constructor default timestr (auto gen)"); +o = new _Time({'str':'20130430235959Z'}); // Gen +equal(o.getEncodedHex(), "180f32303133303433303233353935395a", "param={str: genstr}"); - var o4 = new KJUR.asn1.x509.Time(); // auto UTC - equal(o4.getEncodedHex().substr(0, 4), "170d", "constructor default timestr (empty)=170d..."); +o = new _Time(); // auto UTC +equal(o.getEncodedHex().substr(0, 4), "170d", "no param"); + +o = new _Time('130430235959Z'); // UTC +equal(o.getEncodedHex(), "170d3133303433303233353935395a", "param=utcstr"); + +o = new _Time('130430235959.12Z'); // UTC +equal(o.getEncodedHex(), + "17103133303433303233353935392e31325a", + "new Time(130430235959.12Z) - UTC"); + +o = new _Time('20130430235959Z'); // Gen +equal(o.getEncodedHex(), + "180f32303133303433303233353935395a", + "new Time(20130430235959Z) - Gen"); + +o = new _Time('20130430235959.12Z'); // Gen +equal(o.getEncodedHex(), + "181232303133303433303233353935392e31325a", + "new Time(20130430235959.12Z) - Gen"); + +o = new _Time({type: "utc", str: '130430235959.12Z'}); // UTC +equal(o.getEncodedHex(), + "17103133303433303233353935392e31325a", + "new Time({type:utc, str:130430235959.12Z})"); }); test("SubjectPublicKeyInfo class test", function() {