diff --git a/ChangeLog.txt b/ChangeLog.txt index 6de0f6e4..c6d94ab7 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,19 @@ ChangeLog for jsrsasign +UserNotice of CertificatePolicies support and more +* Changes from 10.7.0 to 10.8.0 (2023-Apr-8) + - x509.js + - X509.getUserNotice supports NoticeReference + - add asn1ToDisplayText method + - base64x.js + - add function msectozulu + - add aryval for nested JSON value access + - asn1.js + - DERInteger refactoring + - test/qunit-do-{asn1,asn1x509,base64x,x509-ext}.html + - update and add some test cases for above + custom X.509 extension support and utility functions * Changes from 10.6.1 to 10.7.0 (2023-Mar-12) - x509.js diff --git a/README.md b/README.md index 07204e19..f4d8c6ae 100755 --- a/README.md +++ b/README.md @@ -18,8 +18,22 @@ Public page is https://kjur.github.io/jsrsasign . Your bugfix and pull request contribution are always welcomed :) +NOTICE FOR COMMING 11.0.0 RELEASE +--------------------------------- +The "jsrsasign" library is a long lived JavaScript library from 2010 developed with old JavaScript style and backword compatibility. From coming release 11.0.0, following are planed and suport them gradually: +- Stop to support Internet Explorer. +- Stop to support bower. +- Modern ECMA functions will be introduced such as Promise, let, Array methods or class. +- API document generator will be changed from Jsdoc Toolkit to JSDoc3. +- Module bandler will be used such as browserify or webpack. +- Not to use YUI compressor. +- Unit test framework will be changed from QUnit and mocha to jest. +- W3C Web Crypto API support. +- split into some modules besides jsrsasign have been all in package before 11.0.0. + NEWS ---- +- 2023-Mar-12: [10.7.0 Release](https://github.com/kjur/jsrsasign/releases/tag/10.7.0). Now supports custom X.509 extension and custom OIDs by new "Add-on" architecture. ([See here in detail](https://github.com/kjur/jsrsasign/wiki/jsrsasign-Add-On2)) - 2021-Nov-21: [10.5.0 Release](https://github.com/kjur/jsrsasign/releases/tag/10.5.0). Now supports secp521r1(P-521) ECDSA. - 2021-Apr-14: [Security advisory](https://github.com/kjur/jsrsasign/security/advisories/GHSA-27fj-mc8w-j9wg) and [update](https://github.com/kjur/jsrsasign/releases/tag/10.2.0) for CVE-2021-30246 RSA signature validation vulnerability published - 2020-Oct-05: jsrsasign won [Google Open Source Peer Bonus Award](https://opensource.googleblog.com/2020/10/announcing-latest-google-open-source.html). Thank you Google. @@ -39,7 +53,8 @@ HIGHLIGHTS - no dependency to other library - no dependency to [W3C Web Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) nor [OpenSSL](https://www.openssl.org/) - no dependency on newer ECMAScirpt function. So old browsers also supported. -- very popular crypto library with [1M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2022-11-18) +- very popular crypto library with [1M+ npm downloads/month](https://npm-stat.com/charts.html?package=jsrsasign&from=2016-05-01&to=2023-04-05) +- supports "Add-on" architecture INSTALL ------- diff --git a/api/files.html b/api/files.html index b599d029..d065bc70 100644 --- a/api/files.html +++ b/api/files.html @@ -535,7 +535,7 @@
new KJUR.asn1.DERInteger(123); new KJUR.asn1.DERInteger({'int': 123}); -new KJUR.asn1.DERInteger({'hex': '1fad'});+new KJUR.asn1.DERInteger({'hex': '1fad'}); +new KJUR.asn1.DERInteger({'bigint': new BigInteger("1234", 10)}); diff --git a/api/symbols/X509.html b/api/symbols/X509.html index 4c3698c8..366752d2 100644 --- a/api/symbols/X509.html +++ b/api/symbols/X509.html @@ -659,6 +659,19 @@
+DisplayText ::= CHOICE { + ia5String IA5String (SIZE (1..200)), + visibleString VisibleString (SIZE (1..200)), + bmpString BMPString (SIZE (1..200)), + utf8String UTF8String (SIZE (1..200)) } ++Result of this method can be passed to +KJUR.asn1.x509.DisplayText constructor. + + +
x = new X509(); +x.asn1ToDisplayText({utf8str: {str: "aaa"}}) &rarr {type: 'utf8', str: 'aaa'} +x.asn1ToDisplayText({bmpstr: {str: "aaa"}}) &rarr {type: 'bmp', str: 'aaa'}+ + + + +
x = new X509(); -x.getUserNotice("30...") → {exptext: {type: 'utf8', str: 'aaa'}}+x.getUserNotice("30...") → { + noticeref: { + org: {type: 'utf8', str: 'test org'}, + noticenum: [1] + }, + exptext: {type: 'utf8', str: 'test text'} +} @@ -6505,6 +6605,8 @@
let p = { + fruit: apple, + info: [ + { toy: 4 }, + { pen: 6 } + ] +}; +aryval(p, 'fruit') &rarr "apple" +aryval(p, 'info') &rarr [{toy: 4},{pen: 6}] +aryval(p, 'info.1') &rarr {pen: 6} +aryval(p, 'info.1.pen') &rarr 6 +aryval(p, 'money.amount') &rarr undefined +aryval(p, 'money.amount', null) &rarr null+ + + + +
msectozulu(1199145599000) → "20071231235959Z" #Mon, 31 Dec 2007 23:59:59 GMT +msectozulu(1199145599100) → "20071231235959.1Z" #Mon, 31 Dec 2007 23:59:59.1 GMT +msectozulu(1199145599123) → "20071231235959.123Z" #Mon, 31 Dec 2007 23:59:59.123 GMT+ + + + +
1 /* asn1-1.0.26.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1-1.0.27.js (c) 2013-2023 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.5.22 asn1 1.0.26 (2022-May-24) + 19 * @version jsrsasign 10.8.0 asn1 1.0.27 (2023-Apr-08) 20 * @since jsrsasign 2.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -898,960 +898,974 @@ 891 KJUR.asn1.DERInteger = function(params) { 892 KJUR.asn1.DERInteger.superclass.constructor.call(this); 893 this.hT = "02"; -894 -895 /** -896 * set value by Tom Wu's BigInteger object -897 * @name setByBigInteger -898 * @memberOf KJUR.asn1.DERInteger# -899 * @function -900 * @param {BigInteger} bigIntegerValue to set -901 */ -902 this.setByBigInteger = function(bigIntegerValue) { -903 this.hTLV = null; -904 this.isModified = true; -905 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); -906 }; -907 -908 /** -909 * set value by integer value -910 * @name setByInteger -911 * @memberOf KJUR.asn1.DERInteger -912 * @function -913 * @param {Integer} integer value to set -914 */ -915 this.setByInteger = function(intValue) { -916 var bi = new BigInteger(String(intValue), 10); -917 this.setByBigInteger(bi); -918 }; -919 -920 /** -921 * set value by integer value -922 * @name setValueHex -923 * @memberOf KJUR.asn1.DERInteger# -924 * @function -925 * @param {String} hexadecimal string of integer value -926 * @description -927 * <br/> -928 * NOTE: Value shall be represented by minimum octet length of -929 * two's complement representation. -930 * @example -931 * new KJUR.asn1.DERInteger(123); -932 * new KJUR.asn1.DERInteger({'int': 123}); -933 * new KJUR.asn1.DERInteger({'hex': '1fad'}); -934 */ -935 this.setValueHex = function(newHexString) { -936 this.hV = newHexString; -937 }; -938 -939 this.getFreshValueHex = function() { -940 return this.hV; -941 }; -942 -943 if (typeof params != "undefined") { -944 if (typeof params['bigint'] != "undefined") { -945 this.setByBigInteger(params['bigint']); -946 } else if (typeof params['int'] != "undefined") { -947 this.setByInteger(params['int']); -948 } else if (typeof params == "number") { -949 this.setByInteger(params); -950 } else if (typeof params['hex'] != "undefined") { -951 this.setValueHex(params['hex']); -952 } -953 } -954 }; -955 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object); -956 -957 // ******************************************************************** -958 /** -959 * class for ASN.1 DER encoded BitString primitive -960 * @name KJUR.asn1.DERBitString -961 * @class class for ASN.1 DER encoded BitString primitive -962 * @extends KJUR.asn1.ASN1Object -963 * @description -964 * <br/> -965 * As for argument 'params' for constructor, you can specify one of -966 * following properties: -967 * <ul> -968 * <li>bin - specify binary string (ex. '10111')</li> -969 * <li>array - specify array of boolean (ex. [true,false,true,true])</li> -970 * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li> -971 * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} -972 * argument for "BitString encapsulates" structure.</li> -973 * </ul> -974 * NOTE1: 'params' can be omitted.<br/> -975 * NOTE2: 'obj' parameter have been supported since -976 * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/> -977 * -978 * @example -979 * // default constructor -980 * o = new KJUR.asn1.DERBitString(); -981 * // initialize with binary string -982 * o = new KJUR.asn1.DERBitString({bin: "1011"}); -983 * // initialize with boolean array -984 * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]}); -985 * // initialize with hexadecimal string (04 is unused bits) -986 * o = new KJUR.asn1.DERBitString({hex: "04bac0"}); -987 * // initialize with ASN1Util.newObject argument for encapsulated -988 * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -989 * // above generates a ASN.1 data like this: -990 * // BIT STRING, encapsulates { -991 * // SEQUENCE { -992 * // INTEGER 3 -993 * // PrintableString 'aaa' -994 * // } -995 * // } -996 */ -997 KJUR.asn1.DERBitString = function(params) { -998 if (params !== undefined && typeof params.obj !== "undefined") { -999 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -1000 params.hex = "00" + o.tohex(); -1001 } -1002 KJUR.asn1.DERBitString.superclass.constructor.call(this); -1003 this.hT = "03"; -1004 -1005 /** -1006 * set ASN.1 value(V) by a hexadecimal string including unused bits -1007 * @name setHexValueIncludingUnusedBits -1008 * @memberOf KJUR.asn1.DERBitString# -1009 * @function -1010 * @param {String} newHexStringIncludingUnusedBits -1011 */ -1012 this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) { -1013 this.hTLV = null; -1014 this.isModified = true; -1015 this.hV = newHexStringIncludingUnusedBits; -1016 }; -1017 -1018 /** -1019 * set ASN.1 value(V) by unused bit and hexadecimal string of value -1020 * @name setUnusedBitsAndHexValue -1021 * @memberOf KJUR.asn1.DERBitString# -1022 * @function -1023 * @param {Integer} unusedBits -1024 * @param {String} hValue +894 this.params = null; +895 var _biToTwoCompl = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex; +896 +897 /** +898 * set value by Tom Wu's BigInteger object +899 * @name setByBigInteger +900 * @memberOf KJUR.asn1.DERInteger# +901 * @function +902 * @param {BigInteger} bigIntegerValue to set +903 */ +904 this.setByBigInteger = function(bigIntegerValue) { +905 this.isModified = true; +906 this.params = { bigint: bigIntegerValue }; +907 }; +908 +909 /** +910 * set value by integer value +911 * @name setByInteger +912 * @memberOf KJUR.asn1.DERInteger +913 * @function +914 * @param {Integer} integer value to set +915 */ +916 this.setByInteger = function(intValue) { +917 this.isModified = true; +918 this.params = intValue; +919 }; +920 +921 /** +922 * set value by integer value +923 * @name setValueHex +924 * @memberOf KJUR.asn1.DERInteger# +925 * @function +926 * @param {String} hexadecimal string of integer value +927 * @description +928 * <br/> +929 * NOTE: Value shall be represented by minimum octet length of +930 * two's complement representation. +931 * @example +932 * new KJUR.asn1.DERInteger(123); +933 * new KJUR.asn1.DERInteger({'int': 123}); +934 * new KJUR.asn1.DERInteger({'hex': '1fad'}); +935 * new KJUR.asn1.DERInteger({'bigint': new BigInteger("1234", 10)}); +936 */ +937 this.setValueHex = function(newHexString) { +938 this.isModified = true; +939 this.params = { hex: newHexString }; +940 }; +941 +942 this.getFreshValueHex = function() { +943 var params = this.params; +944 var bi = null; +945 if (params == null) throw new Error("value not set"); +946 +947 if (typeof params == "object" && params.hex != undefined) { +948 this.hV = params.hex; +949 return this.hV; +950 } +951 +952 if (typeof params == "number") { +953 bi = new BigInteger(String(params), 10); +954 } else if (params["int"] != undefined) { +955 bi = new BigInteger(String(params["int"]), 10); +956 } else if (params.bigint != undefined) { +957 bi = params.bigint; +958 } else { +959 throw new Error("wrong parameter"); +960 } +961 this.hV = _biToTwoCompl(bi); +962 return this.hV; +963 }; +964 +965 if (params != undefined) { +966 this.params = params; +967 } +968 }; +969 extendClass(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object); +970 +971 // ******************************************************************** +972 /** +973 * class for ASN.1 DER encoded BitString primitive +974 * @name KJUR.asn1.DERBitString +975 * @class class for ASN.1 DER encoded BitString primitive +976 * @extends KJUR.asn1.ASN1Object +977 * @description +978 * <br/> +979 * As for argument 'params' for constructor, you can specify one of +980 * following properties: +981 * <ul> +982 * <li>bin - specify binary string (ex. '10111')</li> +983 * <li>array - specify array of boolean (ex. [true,false,true,true])</li> +984 * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li> +985 * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject} +986 * argument for "BitString encapsulates" structure.</li> +987 * </ul> +988 * NOTE1: 'params' can be omitted.<br/> +989 * NOTE2: 'obj' parameter have been supported since +990 * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/> +991 * +992 * @example +993 * // default constructor +994 * o = new KJUR.asn1.DERBitString(); +995 * // initialize with binary string +996 * o = new KJUR.asn1.DERBitString({bin: "1011"}); +997 * // initialize with boolean array +998 * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]}); +999 * // initialize with hexadecimal string (04 is unused bits) +1000 * o = new KJUR.asn1.DERBitString({hex: "04bac0"}); +1001 * // initialize with ASN1Util.newObject argument for encapsulated +1002 * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); +1003 * // above generates a ASN.1 data like this: +1004 * // BIT STRING, encapsulates { +1005 * // SEQUENCE { +1006 * // INTEGER 3 +1007 * // PrintableString 'aaa' +1008 * // } +1009 * // } +1010 */ +1011 KJUR.asn1.DERBitString = function(params) { +1012 if (params !== undefined && typeof params.obj !== "undefined") { +1013 var o = KJUR.asn1.ASN1Util.newObject(params.obj); +1014 params.hex = "00" + o.tohex(); +1015 } +1016 KJUR.asn1.DERBitString.superclass.constructor.call(this); +1017 this.hT = "03"; +1018 +1019 /** +1020 * set ASN.1 value(V) by a hexadecimal string including unused bits +1021 * @name setHexValueIncludingUnusedBits +1022 * @memberOf KJUR.asn1.DERBitString# +1023 * @function +1024 * @param {String} newHexStringIncludingUnusedBits 1025 */ -1026 this.setUnusedBitsAndHexValue = function(unusedBits, hValue) { -1027 if (unusedBits < 0 || 7 < unusedBits) { -1028 throw "unused bits shall be from 0 to 7: u = " + unusedBits; -1029 } -1030 var hUnusedBits = "0" + unusedBits; -1031 this.hTLV = null; -1032 this.isModified = true; -1033 this.hV = hUnusedBits + hValue; -1034 }; -1035 -1036 /** -1037 * set ASN.1 DER BitString by binary string<br/> -1038 * @name setByBinaryString -1039 * @memberOf KJUR.asn1.DERBitString# -1040 * @function -1041 * @param {String} binaryString binary value string (i.e. '10111') -1042 * @description -1043 * Its unused bits will be calculated automatically by length of -1044 * 'binaryValue'. <br/> -1045 * NOTE: Leading zeros '0' will be ignored. -1046 * @example -1047 * o = new KJUR.asn1.DERBitString(); -1048 * o.setByBinaryString("1011"); -1049 * o.setByBinaryString("001"); // leading zeros ignored -1050 */ -1051 this.setByBinaryString = function(binaryString) { -1052 binaryString = binaryString.replace(/0+$/, ''); -1053 var unusedBits = 8 - binaryString.length % 8; -1054 if (unusedBits == 8) unusedBits = 0; -1055 -1056 binaryString += "0000000".substr(0, unusedBits); -1057 -1058 var h = ''; -1059 for (var i = 0; i < binaryString.length - 1; i += 8) { -1060 var b = binaryString.substr(i, 8); -1061 var x = parseInt(b, 2).toString(16); -1062 if (x.length == 1) x = '0' + x; -1063 h += x; -1064 } -1065 this.hTLV = null; -1066 this.isModified = true; -1067 this.hV = '0' + unusedBits + h; -1068 }; -1069 -1070 /** -1071 * set ASN.1 TLV value(V) by an array of boolean<br/> -1072 * @name setByBooleanArray -1073 * @memberOf KJUR.asn1.DERBitString# -1074 * @function -1075 * @param {array} booleanArray array of boolean (ex. [true, false, true]) -1076 * @description -1077 * NOTE: Trailing falses will be ignored in the ASN.1 DER Object. -1078 * @example -1079 * o = new KJUR.asn1.DERBitString(); -1080 * o.setByBooleanArray([false, true, false, true, true]); -1081 */ -1082 this.setByBooleanArray = function(booleanArray) { -1083 var s = ''; -1084 for (var i = 0; i < booleanArray.length; i++) { -1085 if (booleanArray[i] == true) { -1086 s += '1'; -1087 } else { -1088 s += '0'; -1089 } -1090 } -1091 this.setByBinaryString(s); -1092 }; -1093 -1094 /** -1095 * generate an array of falses with specified length<br/> -1096 * @name newFalseArray -1097 * @memberOf KJUR.asn1.DERBitString -1098 * @function -1099 * @param {Integer} nLength length of array to generate -1100 * @return {array} array of boolean falses -1101 * @description -1102 * This static method may be useful to initialize boolean array. -1103 * @example -1104 * o = new KJUR.asn1.DERBitString(); -1105 * o.newFalseArray(3) → [false, false, false] -1106 */ -1107 this.newFalseArray = function(nLength) { -1108 var a = new Array(nLength); -1109 for (var i = 0; i < nLength; i++) { -1110 a[i] = false; -1111 } -1112 return a; -1113 }; -1114 -1115 this.getFreshValueHex = function() { -1116 return this.hV; -1117 }; -1118 -1119 if (typeof params != "undefined") { -1120 if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) { -1121 this.setHexValueIncludingUnusedBits(params); -1122 } else if (typeof params['hex'] != "undefined") { -1123 this.setHexValueIncludingUnusedBits(params['hex']); -1124 } else if (typeof params['bin'] != "undefined") { -1125 this.setByBinaryString(params['bin']); -1126 } else if (typeof params['array'] != "undefined") { -1127 this.setByBooleanArray(params['array']); -1128 } -1129 } -1130 }; -1131 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object); +1026 this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) { +1027 this.hTLV = null; +1028 this.isModified = true; +1029 this.hV = newHexStringIncludingUnusedBits; +1030 }; +1031 +1032 /** +1033 * set ASN.1 value(V) by unused bit and hexadecimal string of value +1034 * @name setUnusedBitsAndHexValue +1035 * @memberOf KJUR.asn1.DERBitString# +1036 * @function +1037 * @param {Integer} unusedBits +1038 * @param {String} hValue +1039 */ +1040 this.setUnusedBitsAndHexValue = function(unusedBits, hValue) { +1041 if (unusedBits < 0 || 7 < unusedBits) { +1042 throw "unused bits shall be from 0 to 7: u = " + unusedBits; +1043 } +1044 var hUnusedBits = "0" + unusedBits; +1045 this.hTLV = null; +1046 this.isModified = true; +1047 this.hV = hUnusedBits + hValue; +1048 }; +1049 +1050 /** +1051 * set ASN.1 DER BitString by binary string<br/> +1052 * @name setByBinaryString +1053 * @memberOf KJUR.asn1.DERBitString# +1054 * @function +1055 * @param {String} binaryString binary value string (i.e. '10111') +1056 * @description +1057 * Its unused bits will be calculated automatically by length of +1058 * 'binaryValue'. <br/> +1059 * NOTE: Leading zeros '0' will be ignored. +1060 * @example +1061 * o = new KJUR.asn1.DERBitString(); +1062 * o.setByBinaryString("1011"); +1063 * o.setByBinaryString("001"); // leading zeros ignored +1064 */ +1065 this.setByBinaryString = function(binaryString) { +1066 binaryString = binaryString.replace(/0+$/, ''); +1067 var unusedBits = 8 - binaryString.length % 8; +1068 if (unusedBits == 8) unusedBits = 0; +1069 +1070 binaryString += "0000000".substr(0, unusedBits); +1071 +1072 var h = ''; +1073 for (var i = 0; i < binaryString.length - 1; i += 8) { +1074 var b = binaryString.substr(i, 8); +1075 var x = parseInt(b, 2).toString(16); +1076 if (x.length == 1) x = '0' + x; +1077 h += x; +1078 } +1079 this.hTLV = null; +1080 this.isModified = true; +1081 this.hV = '0' + unusedBits + h; +1082 }; +1083 +1084 /** +1085 * set ASN.1 TLV value(V) by an array of boolean<br/> +1086 * @name setByBooleanArray +1087 * @memberOf KJUR.asn1.DERBitString# +1088 * @function +1089 * @param {array} booleanArray array of boolean (ex. [true, false, true]) +1090 * @description +1091 * NOTE: Trailing falses will be ignored in the ASN.1 DER Object. +1092 * @example +1093 * o = new KJUR.asn1.DERBitString(); +1094 * o.setByBooleanArray([false, true, false, true, true]); +1095 */ +1096 this.setByBooleanArray = function(booleanArray) { +1097 var s = ''; +1098 for (var i = 0; i < booleanArray.length; i++) { +1099 if (booleanArray[i] == true) { +1100 s += '1'; +1101 } else { +1102 s += '0'; +1103 } +1104 } +1105 this.setByBinaryString(s); +1106 }; +1107 +1108 /** +1109 * generate an array of falses with specified length<br/> +1110 * @name newFalseArray +1111 * @memberOf KJUR.asn1.DERBitString +1112 * @function +1113 * @param {Integer} nLength length of array to generate +1114 * @return {array} array of boolean falses +1115 * @description +1116 * This static method may be useful to initialize boolean array. +1117 * @example +1118 * o = new KJUR.asn1.DERBitString(); +1119 * o.newFalseArray(3) → [false, false, false] +1120 */ +1121 this.newFalseArray = function(nLength) { +1122 var a = new Array(nLength); +1123 for (var i = 0; i < nLength; i++) { +1124 a[i] = false; +1125 } +1126 return a; +1127 }; +1128 +1129 this.getFreshValueHex = function() { +1130 return this.hV; +1131 }; 1132 -1133 // ******************************************************************** -1134 /** -1135 * class for ASN.1 DER OctetString<br/> -1136 * @name KJUR.asn1.DEROctetString -1137 * @class class for ASN.1 DER OctetString -1138 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1139 * @extends KJUR.asn1.DERAbstractString -1140 * @description -1141 * This class provides ASN.1 OctetString simple type.<br/> -1142 * Supported "params" attributes are: -1143 * <ul> -1144 * <li>str - to set a string as a value</li> -1145 * <li>hex - to set a hexadecimal string as a value</li> -1146 * <li>obj - to set a encapsulated ASN.1 value by JSON object -1147 * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li> -1148 * </ul> -1149 * NOTE: A parameter 'obj' have been supported -1150 * for "OCTET STRING, encapsulates" structure. -1151 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25). -1152 * @see KJUR.asn1.DERAbstractString - superclass -1153 * @example -1154 * // default constructor -1155 * o = new KJUR.asn1.DEROctetString(); -1156 * // initialize with string -1157 * o = new KJUR.asn1.DEROctetString({str: "aaa"}); -1158 * // initialize with hexadecimal string -1159 * o = new KJUR.asn1.DEROctetString({hex: "616161"}); -1160 * // initialize with ASN1Util.newObject argument -1161 * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -1162 * // above generates a ASN.1 data like this: -1163 * // OCTET STRING, encapsulates { -1164 * // SEQUENCE { -1165 * // INTEGER 3 -1166 * // PrintableString 'aaa' -1167 * // } -1168 * // } -1169 */ -1170 KJUR.asn1.DEROctetString = function(params) { -1171 if (params !== undefined && typeof params.obj !== "undefined") { -1172 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -1173 params.hex = o.tohex(); -1174 } -1175 KJUR.asn1.DEROctetString.superclass.constructor.call(this, params); -1176 this.hT = "04"; -1177 }; -1178 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString); -1179 -1180 // ******************************************************************** -1181 /** -1182 * class for ASN.1 DER Null -1183 * @name KJUR.asn1.DERNull -1184 * @class class for ASN.1 DER Null -1185 * @extends KJUR.asn1.ASN1Object -1186 * @description -1187 * @see KJUR.asn1.ASN1Object - superclass -1188 */ -1189 KJUR.asn1.DERNull = function() { -1190 KJUR.asn1.DERNull.superclass.constructor.call(this); -1191 this.hT = "05"; -1192 this.hTLV = "0500"; -1193 }; -1194 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object); -1195 -1196 // ******************************************************************** -1197 /** -1198 * class for ASN.1 DER ObjectIdentifier -1199 * @name KJUR.asn1.DERObjectIdentifier -1200 * @class class for ASN.1 DER ObjectIdentifier -1201 * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'}) -1202 * @extends KJUR.asn1.ASN1Object -1203 * @see oidtohex -1204 * -1205 * @description -1206 * <br/> -1207 * As for argument 'params' for constructor, you can specify one of -1208 * following properties: -1209 * <ul> -1210 * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li> -1211 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1212 * </ul> -1213 * NOTE: 'params' can be omitted. -1214 * @example -1215 * new DERObjectIdentifier({"name": "sha1"}) -1216 * new DERObjectIdentifier({"oid": "1.2.3.4"}) -1217 * new DERObjectIdentifier({"hex": "2d..."}) -1218 * new DERObjectIdentifier("1.2.3.4") -1219 * new DERObjectIdentifier("SHA1withRSA") -1220 */ -1221 KJUR.asn1.DERObjectIdentifier = function(params) { -1222 KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this); -1223 this.hT = "06"; -1224 -1225 /** -1226 * set value by a hexadecimal string -1227 * @name setValueHex -1228 * @memberOf KJUR.asn1.DERObjectIdentifier# -1229 * @function -1230 * @param {String} newHexString hexadecimal value of OID bytes -1231 */ -1232 this.setValueHex = function(newHexString) { -1233 this.hTLV = null; -1234 this.isModified = true; -1235 this.s = null; -1236 this.hV = newHexString; -1237 }; +1133 if (typeof params != "undefined") { +1134 if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) { +1135 this.setHexValueIncludingUnusedBits(params); +1136 } else if (typeof params['hex'] != "undefined") { +1137 this.setHexValueIncludingUnusedBits(params['hex']); +1138 } else if (typeof params['bin'] != "undefined") { +1139 this.setByBinaryString(params['bin']); +1140 } else if (typeof params['array'] != "undefined") { +1141 this.setByBooleanArray(params['array']); +1142 } +1143 } +1144 }; +1145 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object); +1146 +1147 // ******************************************************************** +1148 /** +1149 * class for ASN.1 DER OctetString<br/> +1150 * @name KJUR.asn1.DEROctetString +1151 * @class class for ASN.1 DER OctetString +1152 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1153 * @extends KJUR.asn1.DERAbstractString +1154 * @description +1155 * This class provides ASN.1 OctetString simple type.<br/> +1156 * Supported "params" attributes are: +1157 * <ul> +1158 * <li>str - to set a string as a value</li> +1159 * <li>hex - to set a hexadecimal string as a value</li> +1160 * <li>obj - to set a encapsulated ASN.1 value by JSON object +1161 * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li> +1162 * </ul> +1163 * NOTE: A parameter 'obj' have been supported +1164 * for "OCTET STRING, encapsulates" structure. +1165 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25). +1166 * @see KJUR.asn1.DERAbstractString - superclass +1167 * @example +1168 * // default constructor +1169 * o = new KJUR.asn1.DEROctetString(); +1170 * // initialize with string +1171 * o = new KJUR.asn1.DEROctetString({str: "aaa"}); +1172 * // initialize with hexadecimal string +1173 * o = new KJUR.asn1.DEROctetString({hex: "616161"}); +1174 * // initialize with ASN1Util.newObject argument +1175 * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); +1176 * // above generates a ASN.1 data like this: +1177 * // OCTET STRING, encapsulates { +1178 * // SEQUENCE { +1179 * // INTEGER 3 +1180 * // PrintableString 'aaa' +1181 * // } +1182 * // } +1183 */ +1184 KJUR.asn1.DEROctetString = function(params) { +1185 if (params !== undefined && typeof params.obj !== "undefined") { +1186 var o = KJUR.asn1.ASN1Util.newObject(params.obj); +1187 params.hex = o.tohex(); +1188 } +1189 KJUR.asn1.DEROctetString.superclass.constructor.call(this, params); +1190 this.hT = "04"; +1191 }; +1192 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString); +1193 +1194 // ******************************************************************** +1195 /** +1196 * class for ASN.1 DER Null +1197 * @name KJUR.asn1.DERNull +1198 * @class class for ASN.1 DER Null +1199 * @extends KJUR.asn1.ASN1Object +1200 * @description +1201 * @see KJUR.asn1.ASN1Object - superclass +1202 */ +1203 KJUR.asn1.DERNull = function() { +1204 KJUR.asn1.DERNull.superclass.constructor.call(this); +1205 this.hT = "05"; +1206 this.hTLV = "0500"; +1207 }; +1208 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object); +1209 +1210 // ******************************************************************** +1211 /** +1212 * class for ASN.1 DER ObjectIdentifier +1213 * @name KJUR.asn1.DERObjectIdentifier +1214 * @class class for ASN.1 DER ObjectIdentifier +1215 * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'}) +1216 * @extends KJUR.asn1.ASN1Object +1217 * @see oidtohex +1218 * +1219 * @description +1220 * <br/> +1221 * As for argument 'params' for constructor, you can specify one of +1222 * following properties: +1223 * <ul> +1224 * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li> +1225 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1226 * </ul> +1227 * NOTE: 'params' can be omitted. +1228 * @example +1229 * new DERObjectIdentifier({"name": "sha1"}) +1230 * new DERObjectIdentifier({"oid": "1.2.3.4"}) +1231 * new DERObjectIdentifier({"hex": "2d..."}) +1232 * new DERObjectIdentifier("1.2.3.4") +1233 * new DERObjectIdentifier("SHA1withRSA") +1234 */ +1235 KJUR.asn1.DERObjectIdentifier = function(params) { +1236 KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this); +1237 this.hT = "06"; 1238 1239 /** -1240 * set value by a OID string<br/> -1241 * @name setValueOidString +1240 * set value by a hexadecimal string +1241 * @name setValueHex 1242 * @memberOf KJUR.asn1.DERObjectIdentifier# 1243 * @function -1244 * @param {String} oidString OID string (ex. 2.5.4.13) -1245 * @example -1246 * o = new KJUR.asn1.DERObjectIdentifier(); -1247 * o.setValueOidString("2.5.4.13"); -1248 */ -1249 this.setValueOidString = function(oidString) { -1250 var h = oidtohex(oidString); -1251 if (h == null) -1252 throw new Error("malformed oid string: " + oidString); -1253 this.hTLV = null; -1254 this.isModified = true; -1255 this.s = null; -1256 this.hV = h; -1257 }; -1258 -1259 /** -1260 * set value by a OID name -1261 * @name setValueName -1262 * @memberOf KJUR.asn1.DERObjectIdentifier# -1263 * @function -1264 * @param {String} oidName OID name (ex. 'serverAuth') -1265 * @since 1.0.1 -1266 * @description -1267 * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'. -1268 * Otherwise raise error. -1269 * @example -1270 * o = new KJUR.asn1.DERObjectIdentifier(); -1271 * o.setValueName("serverAuth"); -1272 */ -1273 this.setValueName = function(oidName) { -1274 var oid = KJUR.asn1.x509.OID.name2oid(oidName); -1275 if (oid !== '') { -1276 this.setValueOidString(oid); -1277 } else { -1278 throw new Error("DERObjectIdentifier oidName undefined: " + oidName); -1279 } -1280 }; -1281 -1282 this.setValueNameOrOid = function(nameOrOid) { -1283 if (nameOrOid.match(/^[0-2].[0-9.]+$/)) { -1284 this.setValueOidString(nameOrOid); -1285 } else { -1286 this.setValueName(nameOrOid); -1287 } -1288 } -1289 -1290 this.getFreshValueHex = function() { -1291 return this.hV; -1292 }; -1293 -1294 this.setByParam = function(params) { -1295 if (typeof params === "string") { -1296 this.setValueNameOrOid(params); -1297 } else if (params.oid !== undefined) { -1298 this.setValueNameOrOid(params.oid); -1299 } else if (params.name !== undefined) { -1300 this.setValueNameOrOid(params.name); -1301 } else if (params.hex !== undefined) { -1302 this.setValueHex(params.hex); -1303 } -1304 }; -1305 -1306 if (params !== undefined) this.setByParam(params); -1307 }; -1308 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object); -1309 -1310 // ******************************************************************** -1311 /** -1312 * class for ASN.1 DER Enumerated -1313 * @name KJUR.asn1.DEREnumerated -1314 * @class class for ASN.1 DER Enumerated -1315 * @extends KJUR.asn1.ASN1Object -1316 * @description -1317 * <br/> -1318 * As for argument 'params' for constructor, you can specify one of -1319 * following properties: -1320 * <ul> -1321 * <li>int - specify initial ASN.1 value(V) by integer value</li> -1322 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1323 * </ul> -1324 * NOTE: 'params' can be omitted. -1325 * @example -1326 * new KJUR.asn1.DEREnumerated(123); -1327 * new KJUR.asn1.DEREnumerated({int: 123}); -1328 * new KJUR.asn1.DEREnumerated({hex: '1fad'}); -1329 */ -1330 KJUR.asn1.DEREnumerated = function(params) { -1331 KJUR.asn1.DEREnumerated.superclass.constructor.call(this); -1332 this.hT = "0a"; -1333 -1334 /** -1335 * set value by Tom Wu's BigInteger object -1336 * @name setByBigInteger -1337 * @memberOf KJUR.asn1.DEREnumerated# -1338 * @function -1339 * @param {BigInteger} bigIntegerValue to set -1340 */ -1341 this.setByBigInteger = function(bigIntegerValue) { -1342 this.hTLV = null; -1343 this.isModified = true; -1344 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); -1345 }; -1346 -1347 /** -1348 * set value by integer value -1349 * @name setByInteger -1350 * @memberOf KJUR.asn1.DEREnumerated# -1351 * @function -1352 * @param {Integer} integer value to set -1353 */ -1354 this.setByInteger = function(intValue) { -1355 var bi = new BigInteger(String(intValue), 10); -1356 this.setByBigInteger(bi); -1357 }; -1358 -1359 /** -1360 * set value by integer value -1361 * @name setValueHex -1362 * @memberOf KJUR.asn1.DEREnumerated# -1363 * @function -1364 * @param {String} hexadecimal string of integer value -1365 * @description -1366 * <br/> -1367 * NOTE: Value shall be represented by minimum octet length of -1368 * two's complement representation. -1369 */ -1370 this.setValueHex = function(newHexString) { -1371 this.hV = newHexString; -1372 }; -1373 -1374 this.getFreshValueHex = function() { -1375 return this.hV; -1376 }; -1377 -1378 if (typeof params != "undefined") { -1379 if (typeof params['int'] != "undefined") { -1380 this.setByInteger(params['int']); -1381 } else if (typeof params == "number") { -1382 this.setByInteger(params); -1383 } else if (typeof params['hex'] != "undefined") { -1384 this.setValueHex(params['hex']); -1385 } -1386 } -1387 }; -1388 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object); -1389 -1390 // ******************************************************************** -1391 /** -1392 * class for ASN.1 DER UTF8String -1393 * @name KJUR.asn1.DERUTF8String -1394 * @class class for ASN.1 DER UTF8String -1395 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1396 * @extends KJUR.asn1.DERAbstractString -1397 * @description -1398 * @see KJUR.asn1.DERAbstractString - superclass -1399 */ -1400 KJUR.asn1.DERUTF8String = function(params) { -1401 KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params); -1402 this.hT = "0c"; -1403 }; -1404 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString); -1405 -1406 // ******************************************************************** -1407 /** -1408 * class for ASN.1 DER NumericString -1409 * @name KJUR.asn1.DERNumericString -1410 * @class class for ASN.1 DER NumericString -1411 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1412 * @extends KJUR.asn1.DERAbstractString -1413 * @description -1414 * @see KJUR.asn1.DERAbstractString - superclass -1415 */ -1416 KJUR.asn1.DERNumericString = function(params) { -1417 KJUR.asn1.DERNumericString.superclass.constructor.call(this, params); -1418 this.hT = "12"; -1419 }; -1420 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString); -1421 -1422 // ******************************************************************** -1423 /** -1424 * class for ASN.1 DER PrintableString -1425 * @name KJUR.asn1.DERPrintableString -1426 * @class class for ASN.1 DER PrintableString -1427 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1428 * @extends KJUR.asn1.DERAbstractString -1429 * @description -1430 * @see KJUR.asn1.DERAbstractString - superclass -1431 */ -1432 KJUR.asn1.DERPrintableString = function(params) { -1433 KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params); -1434 this.hT = "13"; -1435 }; -1436 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString); -1437 -1438 // ******************************************************************** -1439 /** -1440 * class for ASN.1 DER TeletexString -1441 * @name KJUR.asn1.DERTeletexString -1442 * @class class for ASN.1 DER TeletexString -1443 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1444 * @extends KJUR.asn1.DERAbstractString -1445 * @description -1446 * @see KJUR.asn1.DERAbstractString - superclass -1447 */ -1448 KJUR.asn1.DERTeletexString = function(params) { -1449 KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params); -1450 this.hT = "14"; -1451 }; -1452 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString); -1453 -1454 // ******************************************************************** -1455 /** -1456 * class for ASN.1 DER IA5String -1457 * @name KJUR.asn1.DERIA5String -1458 * @class class for ASN.1 DER IA5String -1459 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1460 * @extends KJUR.asn1.DERAbstractString -1461 * @description -1462 * @see KJUR.asn1.DERAbstractString - superclass -1463 */ -1464 KJUR.asn1.DERIA5String = function(params) { -1465 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1466 this.hT = "16"; -1467 }; -1468 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString); -1469 -1470 // ******************************************************************** -1471 /** -1472 * class for ASN.1 DER VisibleString -1473 * @name KJUR.asn1.DERVisibleString -1474 * @class class for ASN.1 DER VisibleString -1475 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1476 * @extends KJUR.asn1.DERAbstractString -1477 * @since jsrsasign 8.0.23 asn1 1.0.15 -1478 * @description -1479 * @see KJUR.asn1.DERAbstractString - superclass -1480 */ -1481 KJUR.asn1.DERVisibleString = function(params) { -1482 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1483 this.hT = "1a"; -1484 }; -1485 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString); -1486 -1487 // ******************************************************************** -1488 /** -1489 * class for ASN.1 DER BMPString -1490 * @name KJUR.asn1.DERBMPString -1491 * @class class for ASN.1 DER BMPString -1492 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1493 * @extends KJUR.asn1.DERAbstractString -1494 * @since jsrsasign 8.0.23 asn1 1.0.15 -1495 * @description -1496 * @see KJUR.asn1.DERAbstractString - superclass -1497 */ -1498 KJUR.asn1.DERBMPString = function(params) { -1499 KJUR.asn1.DERBMPString.superclass.constructor.call(this, params); -1500 this.hT = "1e"; -1501 }; -1502 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); -1503 -1504 // ******************************************************************** -1505 /** -1506 * class for ASN.1 DER UTCTime -1507 * @name KJUR.asn1.DERUTCTime -1508 * @class class for ASN.1 DER UTCTime -1509 * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) -1510 * @extends KJUR.asn1.DERAbstractTime -1511 * @see KJUR.asn1.DERGeneralizedTime -1512 * @see KJUR.asn1.x509.Time -1513 * -1514 * @description -1515 * <br/> -1516 * As for argument 'params' for constructor, you can specify one of -1517 * following properties: -1518 * <ul> -1519 * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li> -1520 * <li>date - specify Date object.</li> -1521 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> -1522 * </ul> -1523 * NOTE1: 'params' can be omitted. -1524 * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22. -1525 * -1526 * <h4>EXAMPLES</h4> -1527 * @example -1528 * new DERUTCTime("20151231235959Z") -1529 * new DERUTCTime("20151231235959.123Z") -1530 * new DERUTCTime(new Date()) -1531 * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) -1532 * new DERUTCTime({str: "20151231235959.123Z"}) -1533 * new DERUTCTime({date: new Date()}) -1534 * new DERUTCTime({date: new Date(), millis: true}) -1535 * new DERUTCTime({millis: true}) -1536 */ -1537 KJUR.asn1.DERUTCTime = function(params) { -1538 KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); -1539 this.hT = "17"; -1540 this.params = undefined; -1541 -1542 this.getFreshValueHex = function() { -1543 var params = this.params; -1544 -1545 if (this.params == undefined) params = { date: new Date() }; -1546 -1547 if (typeof params == "string") { -1548 if (params.match(/^[0-9]{12}Z$/) || -1549 params.match(/^[0-9]{12}\.[0-9]+Z$/)) { -1550 this.hV = stohex(params); -1551 } else { -1552 throw new Error("malformed string for UTCTime: " + params); -1553 } -1554 } else if (params.str != undefined) { -1555 this.hV = stohex(params.str); -1556 } else if (params.date == undefined && params.millis == true) { -1557 var date = new Date(); -1558 this.hV = stohex(this.formatDate(date, 'utc', true)); -1559 } else if (params.date != undefined && -1560 params.date instanceof Date) { -1561 var withMillis = (params.millis === true); -1562 this.hV = stohex(this.formatDate(params.date, 'utc', withMillis)); -1563 } else if (params instanceof Date) { -1564 this.hV = stohex(this.formatDate(params, 'utc')); -1565 } -1566 -1567 if (this.hV == undefined) { -1568 throw new Error("parameter not specified properly for UTCTime"); -1569 } -1570 return this.hV; -1571 }; -1572 -1573 if (params != undefined) this.setByParam(params); -1574 }; -1575 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); -1576 -1577 // ******************************************************************** -1578 /** -1579 * class for ASN.1 DER GeneralizedTime -1580 * @name KJUR.asn1.DERGeneralizedTime -1581 * @class class for ASN.1 DER GeneralizedTime -1582 * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) -1583 * @property {Boolean} withMillis flag to show milliseconds or not -1584 * @extends KJUR.asn1.DERAbstractTime -1585 * @see KJUR.asn1.DERUTCTime -1586 * @see KJUR.asn1.x509.Time -1587 * -1588 * @description -1589 * <br/> -1590 * As for argument 'params' for constructor, you can specify one of -1591 * following properties: -1592 * <ul> -1593 * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li> -1594 * <li>date - specify Date object.</li> -1595 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> -1596 * </ul> -1597 * NOTE1: 'params' can be omitted. -1598 * NOTE2: 'millis' property is supported from asn1 1.0.6. -1599 * -1600 * <h4>EXAMPLES</h4> -1601 * @example -1602 * new DERGeneralizedTime("20151231235959Z") -1603 * new DERGeneralizedTime("20151231235959.123Z") -1604 * new DERGeneralizedTime(new Date()) -1605 * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) -1606 * new DERGeneralizedTime({str: "20151231235959.123Z"}) -1607 * new DERGeneralizedTime({date: new Date()}) -1608 * new DERGeneralizedTime({date: new Date(), millis: true}) -1609 * new DERGeneralizedTime({millis: true}) -1610 */ -1611 KJUR.asn1.DERGeneralizedTime = function(params) { -1612 KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); -1613 this.hT = "18"; -1614 this.params = params; -1615 -1616 this.getFreshValueHex = function() { -1617 var params = this.params; -1618 -1619 if (this.params == undefined) params = { date: new Date() }; -1620 -1621 if (typeof params == "string") { -1622 if (params.match(/^[0-9]{14}Z$/) || -1623 params.match(/^[0-9]{14}\.[0-9]+Z$/)) { -1624 this.hV = stohex(params); -1625 } else { -1626 throw new Error("malformed string for GeneralizedTime: " + params); -1627 } -1628 } else if (params.str != undefined) { -1629 this.hV = stohex(params.str); -1630 } else if (params.date == undefined && params.millis == true) { -1631 var date = new Date(); -1632 this.hV = stohex(this.formatDate(date, 'gen', true)); -1633 } else if (params.date != undefined && -1634 params.date instanceof Date) { -1635 var withMillis = (params.millis === true); -1636 this.hV = stohex(this.formatDate(params.date, 'gen', withMillis)); -1637 } else if (params instanceof Date) { -1638 this.hV = stohex(this.formatDate(params, 'gen')); -1639 } -1640 -1641 if (this.hV == undefined) { -1642 throw new Error("parameter not specified properly for GeneralizedTime"); -1643 } -1644 return this.hV; -1645 }; -1646 -1647 if (params != undefined) this.setByParam(params); -1648 }; -1649 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); -1650 -1651 // ******************************************************************** -1652 /** -1653 * class for ASN.1 DER Sequence -1654 * @name KJUR.asn1.DERSequence -1655 * @class class for ASN.1 DER Sequence -1656 * @extends KJUR.asn1.DERAbstractStructured -1657 * @description -1658 * <br/> -1659 * As for argument 'params' for constructor, you can specify one of -1660 * following properties: -1661 * <ul> -1662 * <li>array - specify array of ASN1Object to set elements of content</li> -1663 * </ul> -1664 * NOTE: 'params' can be omitted. -1665 */ -1666 KJUR.asn1.DERSequence = function(params) { -1667 KJUR.asn1.DERSequence.superclass.constructor.call(this, params); -1668 this.hT = "30"; -1669 this.getFreshValueHex = function() { -1670 var h = ''; -1671 for (var i = 0; i < this.asn1Array.length; i++) { -1672 var asn1Obj = this.asn1Array[i]; -1673 h += asn1Obj.tohex(); -1674 } -1675 this.hV = h; -1676 return this.hV; -1677 }; -1678 }; -1679 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured); -1680 -1681 // ******************************************************************** -1682 /** -1683 * class for ASN.1 DER Set -1684 * @name KJUR.asn1.DERSet -1685 * @class class for ASN.1 DER Set -1686 * @extends KJUR.asn1.DERAbstractStructured -1687 * @description -1688 * <br/> -1689 * As for argument 'params' for constructor, you can specify one of -1690 * following properties: -1691 * <ul> -1692 * <li>array - specify array of ASN1Object to set elements of content</li> -1693 * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li> -1694 * </ul> -1695 * NOTE1: 'params' can be omitted.<br/> -1696 * NOTE2: sortflag is supported since 1.0.5. -1697 */ -1698 KJUR.asn1.DERSet = function(params) { -1699 KJUR.asn1.DERSet.superclass.constructor.call(this, params); -1700 this.hT = "31"; -1701 this.sortFlag = true; // item shall be sorted only in ASN.1 DER -1702 this.getFreshValueHex = function() { -1703 var a = new Array(); -1704 for (var i = 0; i < this.asn1Array.length; i++) { -1705 var asn1Obj = this.asn1Array[i]; -1706 a.push(asn1Obj.tohex()); -1707 } -1708 if (this.sortFlag == true) a.sort(); -1709 this.hV = a.join(''); -1710 return this.hV; -1711 }; -1712 -1713 if (typeof params != "undefined") { -1714 if (typeof params.sortflag != "undefined" && -1715 params.sortflag == false) -1716 this.sortFlag = false; -1717 } -1718 }; -1719 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured); -1720 -1721 // ******************************************************************** -1722 /** -1723 * class for ASN.1 DER TaggedObject -1724 * @name KJUR.asn1.DERTaggedObject -1725 * @class class for ASN.1 DER TaggedObject -1726 * @extends KJUR.asn1.ASN1Object -1727 * @see KJUR_asn1.ASN1Util.newObject -1728 * -1729 * @description -1730 * <br/> -1731 * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object. -1732 * For example, if you find '[1]' tag in a ASN.1 dump, -1733 * 'tagNoHex' will be 'a1'. -1734 * <br/> -1735 * As for optional argument 'params' for constructor, you can specify *ANY* of -1736 * following properties: -1737 * <ul> -1738 * <li>tag - specify tag (default is 'a0' which means [0])</li> -1739 * <li>explicit - specify true if this is explicit tag otherwise false -1740 * (default is 'true').</li> -1741 * <li>obj - specify ASN1Object or JSON object which will be tagged</li> -1742 * <li>tage - specify tag with explicit</li> -1743 * <li>tagi - specify tag with implicit</li> -1744 * </ul> -1745 * As for the member "obj" value of JSON object, -1746 * {@link KJUR_asn1.ASN1Util.newObject} is used to generate. -1747 * -1748 * @example -1749 * // by JSON -1750 * new KJUR.asn1.DERTaggedObject({ -1751 * tag:'a0', explicit: true, obj: { "prnstr": { "str": "aaa" } } -1752 * }).tohex() -1753 * -1754 * // by ASN1Object object -1755 * new KJUR.asn1.DERTaggedObject({ -1756 * tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1757 * }) -1758 * new KJUR.asn1.DERTaggedObject({ -1759 * tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit -1760 * }) -1761 * new KJUR.asn1.DERTaggedObject({ -1762 * tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1763 * }) -1764 * -1765 * // to hexadecimal -1766 * d1 = new KJUR.asn1.DERUTF8String({str':'a'}) -1767 * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1}); -1768 * hex = d2.tohex(); -1769 */ -1770 KJUR.asn1.DERTaggedObject = function(params) { -1771 KJUR.asn1.DERTaggedObject.superclass.constructor.call(this); -1772 -1773 var _KJUR_asn1 = KJUR.asn1, -1774 _ASN1HEX = ASN1HEX, -1775 _getV = _ASN1HEX.getV, -1776 _isASN1HEX = _ASN1HEX.isASN1HEX, -1777 _newObject = _KJUR_asn1.ASN1Util.newObject; -1778 -1779 this.hT = "a0"; -1780 this.hV = ''; -1781 this.isExplicit = true; -1782 this.asn1Object = null; -1783 this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true}; -1784 -1785 /** -1786 * set value by an ASN1Object -1787 * @name setString -1788 * @memberOf KJUR.asn1.DERTaggedObject# -1789 * @function -1790 * @param {Boolean} isExplicitFlag flag for explicit/implicit tag -1791 * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag -1792 * @param {ASN1Object} asn1Object ASN.1 to encapsulate -1793 * @deprecated since jsrsasign 10.5.4 please use setByParam instead -1794 */ -1795 this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { -1796 this.params = {tag: tagNoHex, -1797 explicit: isExplicitFlag, -1798 obj: asn1Object}; -1799 }; -1800 -1801 this.getFreshValueHex = function() { -1802 var params = this.params; -1803 -1804 if (params.explicit == undefined) params.explicit = true; -1805 -1806 if (params.tage != undefined) { -1807 params.tag = params.tage; -1808 params.explicit = true; -1809 } -1810 if (params.tagi != undefined) { -1811 params.tag = params.tagi; -1812 params.explicit = false; -1813 } +1244 * @param {String} newHexString hexadecimal value of OID bytes +1245 */ +1246 this.setValueHex = function(newHexString) { +1247 this.hTLV = null; +1248 this.isModified = true; +1249 this.s = null; +1250 this.hV = newHexString; +1251 }; +1252 +1253 /** +1254 * set value by a OID string<br/> +1255 * @name setValueOidString +1256 * @memberOf KJUR.asn1.DERObjectIdentifier# +1257 * @function +1258 * @param {String} oidString OID string (ex. 2.5.4.13) +1259 * @example +1260 * o = new KJUR.asn1.DERObjectIdentifier(); +1261 * o.setValueOidString("2.5.4.13"); +1262 */ +1263 this.setValueOidString = function(oidString) { +1264 var h = oidtohex(oidString); +1265 if (h == null) +1266 throw new Error("malformed oid string: " + oidString); +1267 this.hTLV = null; +1268 this.isModified = true; +1269 this.s = null; +1270 this.hV = h; +1271 }; +1272 +1273 /** +1274 * set value by a OID name +1275 * @name setValueName +1276 * @memberOf KJUR.asn1.DERObjectIdentifier# +1277 * @function +1278 * @param {String} oidName OID name (ex. 'serverAuth') +1279 * @since 1.0.1 +1280 * @description +1281 * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'. +1282 * Otherwise raise error. +1283 * @example +1284 * o = new KJUR.asn1.DERObjectIdentifier(); +1285 * o.setValueName("serverAuth"); +1286 */ +1287 this.setValueName = function(oidName) { +1288 var oid = KJUR.asn1.x509.OID.name2oid(oidName); +1289 if (oid !== '') { +1290 this.setValueOidString(oid); +1291 } else { +1292 throw new Error("DERObjectIdentifier oidName undefined: " + oidName); +1293 } +1294 }; +1295 +1296 this.setValueNameOrOid = function(nameOrOid) { +1297 if (nameOrOid.match(/^[0-2].[0-9.]+$/)) { +1298 this.setValueOidString(nameOrOid); +1299 } else { +1300 this.setValueName(nameOrOid); +1301 } +1302 } +1303 +1304 this.getFreshValueHex = function() { +1305 return this.hV; +1306 }; +1307 +1308 this.setByParam = function(params) { +1309 if (typeof params === "string") { +1310 this.setValueNameOrOid(params); +1311 } else if (params.oid !== undefined) { +1312 this.setValueNameOrOid(params.oid); +1313 } else if (params.name !== undefined) { +1314 this.setValueNameOrOid(params.name); +1315 } else if (params.hex !== undefined) { +1316 this.setValueHex(params.hex); +1317 } +1318 }; +1319 +1320 if (params !== undefined) this.setByParam(params); +1321 }; +1322 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object); +1323 +1324 // ******************************************************************** +1325 /** +1326 * class for ASN.1 DER Enumerated +1327 * @name KJUR.asn1.DEREnumerated +1328 * @class class for ASN.1 DER Enumerated +1329 * @extends KJUR.asn1.ASN1Object +1330 * @description +1331 * <br/> +1332 * As for argument 'params' for constructor, you can specify one of +1333 * following properties: +1334 * <ul> +1335 * <li>int - specify initial ASN.1 value(V) by integer value</li> +1336 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> +1337 * </ul> +1338 * NOTE: 'params' can be omitted. +1339 * @example +1340 * new KJUR.asn1.DEREnumerated(123); +1341 * new KJUR.asn1.DEREnumerated({int: 123}); +1342 * new KJUR.asn1.DEREnumerated({hex: '1fad'}); +1343 */ +1344 KJUR.asn1.DEREnumerated = function(params) { +1345 KJUR.asn1.DEREnumerated.superclass.constructor.call(this); +1346 this.hT = "0a"; +1347 +1348 /** +1349 * set value by Tom Wu's BigInteger object +1350 * @name setByBigInteger +1351 * @memberOf KJUR.asn1.DEREnumerated# +1352 * @function +1353 * @param {BigInteger} bigIntegerValue to set +1354 */ +1355 this.setByBigInteger = function(bigIntegerValue) { +1356 this.hTLV = null; +1357 this.isModified = true; +1358 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); +1359 }; +1360 +1361 /** +1362 * set value by integer value +1363 * @name setByInteger +1364 * @memberOf KJUR.asn1.DEREnumerated# +1365 * @function +1366 * @param {Integer} integer value to set +1367 */ +1368 this.setByInteger = function(intValue) { +1369 var bi = new BigInteger(String(intValue), 10); +1370 this.setByBigInteger(bi); +1371 }; +1372 +1373 /** +1374 * set value by integer value +1375 * @name setValueHex +1376 * @memberOf KJUR.asn1.DEREnumerated# +1377 * @function +1378 * @param {String} hexadecimal string of integer value +1379 * @description +1380 * <br/> +1381 * NOTE: Value shall be represented by minimum octet length of +1382 * two's complement representation. +1383 */ +1384 this.setValueHex = function(newHexString) { +1385 this.hV = newHexString; +1386 }; +1387 +1388 this.getFreshValueHex = function() { +1389 return this.hV; +1390 }; +1391 +1392 if (typeof params != "undefined") { +1393 if (typeof params['int'] != "undefined") { +1394 this.setByInteger(params['int']); +1395 } else if (typeof params == "number") { +1396 this.setByInteger(params); +1397 } else if (typeof params['hex'] != "undefined") { +1398 this.setValueHex(params['hex']); +1399 } +1400 } +1401 }; +1402 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object); +1403 +1404 // ******************************************************************** +1405 /** +1406 * class for ASN.1 DER UTF8String +1407 * @name KJUR.asn1.DERUTF8String +1408 * @class class for ASN.1 DER UTF8String +1409 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1410 * @extends KJUR.asn1.DERAbstractString +1411 * @description +1412 * @see KJUR.asn1.DERAbstractString - superclass +1413 */ +1414 KJUR.asn1.DERUTF8String = function(params) { +1415 KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params); +1416 this.hT = "0c"; +1417 }; +1418 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString); +1419 +1420 // ******************************************************************** +1421 /** +1422 * class for ASN.1 DER NumericString +1423 * @name KJUR.asn1.DERNumericString +1424 * @class class for ASN.1 DER NumericString +1425 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1426 * @extends KJUR.asn1.DERAbstractString +1427 * @description +1428 * @see KJUR.asn1.DERAbstractString - superclass +1429 */ +1430 KJUR.asn1.DERNumericString = function(params) { +1431 KJUR.asn1.DERNumericString.superclass.constructor.call(this, params); +1432 this.hT = "12"; +1433 }; +1434 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString); +1435 +1436 // ******************************************************************** +1437 /** +1438 * class for ASN.1 DER PrintableString +1439 * @name KJUR.asn1.DERPrintableString +1440 * @class class for ASN.1 DER PrintableString +1441 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1442 * @extends KJUR.asn1.DERAbstractString +1443 * @description +1444 * @see KJUR.asn1.DERAbstractString - superclass +1445 */ +1446 KJUR.asn1.DERPrintableString = function(params) { +1447 KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params); +1448 this.hT = "13"; +1449 }; +1450 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString); +1451 +1452 // ******************************************************************** +1453 /** +1454 * class for ASN.1 DER TeletexString +1455 * @name KJUR.asn1.DERTeletexString +1456 * @class class for ASN.1 DER TeletexString +1457 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1458 * @extends KJUR.asn1.DERAbstractString +1459 * @description +1460 * @see KJUR.asn1.DERAbstractString - superclass +1461 */ +1462 KJUR.asn1.DERTeletexString = function(params) { +1463 KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params); +1464 this.hT = "14"; +1465 }; +1466 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString); +1467 +1468 // ******************************************************************** +1469 /** +1470 * class for ASN.1 DER IA5String +1471 * @name KJUR.asn1.DERIA5String +1472 * @class class for ASN.1 DER IA5String +1473 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1474 * @extends KJUR.asn1.DERAbstractString +1475 * @description +1476 * @see KJUR.asn1.DERAbstractString - superclass +1477 */ +1478 KJUR.asn1.DERIA5String = function(params) { +1479 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); +1480 this.hT = "16"; +1481 }; +1482 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString); +1483 +1484 // ******************************************************************** +1485 /** +1486 * class for ASN.1 DER VisibleString +1487 * @name KJUR.asn1.DERVisibleString +1488 * @class class for ASN.1 DER VisibleString +1489 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1490 * @extends KJUR.asn1.DERAbstractString +1491 * @since jsrsasign 8.0.23 asn1 1.0.15 +1492 * @description +1493 * @see KJUR.asn1.DERAbstractString - superclass +1494 */ +1495 KJUR.asn1.DERVisibleString = function(params) { +1496 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); +1497 this.hT = "1a"; +1498 }; +1499 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString); +1500 +1501 // ******************************************************************** +1502 /** +1503 * class for ASN.1 DER BMPString +1504 * @name KJUR.asn1.DERBMPString +1505 * @class class for ASN.1 DER BMPString +1506 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) +1507 * @extends KJUR.asn1.DERAbstractString +1508 * @since jsrsasign 8.0.23 asn1 1.0.15 +1509 * @description +1510 * @see KJUR.asn1.DERAbstractString - superclass +1511 */ +1512 KJUR.asn1.DERBMPString = function(params) { +1513 KJUR.asn1.DERBMPString.superclass.constructor.call(this, params); +1514 this.hT = "1e"; +1515 }; +1516 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); +1517 +1518 // ******************************************************************** +1519 /** +1520 * class for ASN.1 DER UTCTime +1521 * @name KJUR.asn1.DERUTCTime +1522 * @class class for ASN.1 DER UTCTime +1523 * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) +1524 * @extends KJUR.asn1.DERAbstractTime +1525 * @see KJUR.asn1.DERGeneralizedTime +1526 * @see KJUR.asn1.x509.Time +1527 * +1528 * @description +1529 * <br/> +1530 * As for argument 'params' for constructor, you can specify one of +1531 * following properties: +1532 * <ul> +1533 * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li> +1534 * <li>date - specify Date object.</li> +1535 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> +1536 * </ul> +1537 * NOTE1: 'params' can be omitted. +1538 * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22. +1539 * +1540 * <h4>EXAMPLES</h4> +1541 * @example +1542 * new DERUTCTime("20151231235959Z") +1543 * new DERUTCTime("20151231235959.123Z") +1544 * new DERUTCTime(new Date()) +1545 * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) +1546 * new DERUTCTime({str: "20151231235959.123Z"}) +1547 * new DERUTCTime({date: new Date()}) +1548 * new DERUTCTime({date: new Date(), millis: true}) +1549 * new DERUTCTime({millis: true}) +1550 */ +1551 KJUR.asn1.DERUTCTime = function(params) { +1552 KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); +1553 this.hT = "17"; +1554 this.params = undefined; +1555 +1556 this.getFreshValueHex = function() { +1557 var params = this.params; +1558 +1559 if (this.params == undefined) params = { date: new Date() }; +1560 +1561 if (typeof params == "string") { +1562 if (params.match(/^[0-9]{12}Z$/) || +1563 params.match(/^[0-9]{12}\.[0-9]+Z$/)) { +1564 this.hV = stohex(params); +1565 } else { +1566 throw new Error("malformed string for UTCTime: " + params); +1567 } +1568 } else if (params.str != undefined) { +1569 this.hV = stohex(params.str); +1570 } else if (params.date == undefined && params.millis == true) { +1571 var date = new Date(); +1572 this.hV = stohex(this.formatDate(date, 'utc', true)); +1573 } else if (params.date != undefined && +1574 params.date instanceof Date) { +1575 var withMillis = (params.millis === true); +1576 this.hV = stohex(this.formatDate(params.date, 'utc', withMillis)); +1577 } else if (params instanceof Date) { +1578 this.hV = stohex(this.formatDate(params, 'utc')); +1579 } +1580 +1581 if (this.hV == undefined) { +1582 throw new Error("parameter not specified properly for UTCTime"); +1583 } +1584 return this.hV; +1585 }; +1586 +1587 if (params != undefined) this.setByParam(params); +1588 }; +1589 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); +1590 +1591 // ******************************************************************** +1592 /** +1593 * class for ASN.1 DER GeneralizedTime +1594 * @name KJUR.asn1.DERGeneralizedTime +1595 * @class class for ASN.1 DER GeneralizedTime +1596 * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) +1597 * @property {Boolean} withMillis flag to show milliseconds or not +1598 * @extends KJUR.asn1.DERAbstractTime +1599 * @see KJUR.asn1.DERUTCTime +1600 * @see KJUR.asn1.x509.Time +1601 * +1602 * @description +1603 * <br/> +1604 * As for argument 'params' for constructor, you can specify one of +1605 * following properties: +1606 * <ul> +1607 * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li> +1608 * <li>date - specify Date object.</li> +1609 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> +1610 * </ul> +1611 * NOTE1: 'params' can be omitted. +1612 * NOTE2: 'millis' property is supported from asn1 1.0.6. +1613 * +1614 * <h4>EXAMPLES</h4> +1615 * @example +1616 * new DERGeneralizedTime("20151231235959Z") +1617 * new DERGeneralizedTime("20151231235959.123Z") +1618 * new DERGeneralizedTime(new Date()) +1619 * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) +1620 * new DERGeneralizedTime({str: "20151231235959.123Z"}) +1621 * new DERGeneralizedTime({date: new Date()}) +1622 * new DERGeneralizedTime({date: new Date(), millis: true}) +1623 * new DERGeneralizedTime({millis: true}) +1624 */ +1625 KJUR.asn1.DERGeneralizedTime = function(params) { +1626 KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); +1627 this.hT = "18"; +1628 this.params = params; +1629 +1630 this.getFreshValueHex = function() { +1631 var params = this.params; +1632 +1633 if (this.params == undefined) params = { date: new Date() }; +1634 +1635 if (typeof params == "string") { +1636 if (params.match(/^[0-9]{14}Z$/) || +1637 params.match(/^[0-9]{14}\.[0-9]+Z$/)) { +1638 this.hV = stohex(params); +1639 } else { +1640 throw new Error("malformed string for GeneralizedTime: " + params); +1641 } +1642 } else if (params.str != undefined) { +1643 this.hV = stohex(params.str); +1644 } else if (params.date == undefined && params.millis == true) { +1645 var date = new Date(); +1646 this.hV = stohex(this.formatDate(date, 'gen', true)); +1647 } else if (params.date != undefined && +1648 params.date instanceof Date) { +1649 var withMillis = (params.millis === true); +1650 this.hV = stohex(this.formatDate(params.date, 'gen', withMillis)); +1651 } else if (params instanceof Date) { +1652 this.hV = stohex(this.formatDate(params, 'gen')); +1653 } +1654 +1655 if (this.hV == undefined) { +1656 throw new Error("parameter not specified properly for GeneralizedTime"); +1657 } +1658 return this.hV; +1659 }; +1660 +1661 if (params != undefined) this.setByParam(params); +1662 }; +1663 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); +1664 +1665 // ******************************************************************** +1666 /** +1667 * class for ASN.1 DER Sequence +1668 * @name KJUR.asn1.DERSequence +1669 * @class class for ASN.1 DER Sequence +1670 * @extends KJUR.asn1.DERAbstractStructured +1671 * @description +1672 * <br/> +1673 * As for argument 'params' for constructor, you can specify one of +1674 * following properties: +1675 * <ul> +1676 * <li>array - specify array of ASN1Object to set elements of content</li> +1677 * </ul> +1678 * NOTE: 'params' can be omitted. +1679 */ +1680 KJUR.asn1.DERSequence = function(params) { +1681 KJUR.asn1.DERSequence.superclass.constructor.call(this, params); +1682 this.hT = "30"; +1683 this.getFreshValueHex = function() { +1684 var h = ''; +1685 for (var i = 0; i < this.asn1Array.length; i++) { +1686 var asn1Obj = this.asn1Array[i]; +1687 h += asn1Obj.tohex(); +1688 } +1689 this.hV = h; +1690 return this.hV; +1691 }; +1692 }; +1693 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured); +1694 +1695 // ******************************************************************** +1696 /** +1697 * class for ASN.1 DER Set +1698 * @name KJUR.asn1.DERSet +1699 * @class class for ASN.1 DER Set +1700 * @extends KJUR.asn1.DERAbstractStructured +1701 * @description +1702 * <br/> +1703 * As for argument 'params' for constructor, you can specify one of +1704 * following properties: +1705 * <ul> +1706 * <li>array - specify array of ASN1Object to set elements of content</li> +1707 * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li> +1708 * </ul> +1709 * NOTE1: 'params' can be omitted.<br/> +1710 * NOTE2: sortflag is supported since 1.0.5. +1711 */ +1712 KJUR.asn1.DERSet = function(params) { +1713 KJUR.asn1.DERSet.superclass.constructor.call(this, params); +1714 this.hT = "31"; +1715 this.sortFlag = true; // item shall be sorted only in ASN.1 DER +1716 this.getFreshValueHex = function() { +1717 var a = new Array(); +1718 for (var i = 0; i < this.asn1Array.length; i++) { +1719 var asn1Obj = this.asn1Array[i]; +1720 a.push(asn1Obj.tohex()); +1721 } +1722 if (this.sortFlag == true) a.sort(); +1723 this.hV = a.join(''); +1724 return this.hV; +1725 }; +1726 +1727 if (typeof params != "undefined") { +1728 if (typeof params.sortflag != "undefined" && +1729 params.sortflag == false) +1730 this.sortFlag = false; +1731 } +1732 }; +1733 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured); +1734 +1735 // ******************************************************************** +1736 /** +1737 * class for ASN.1 DER TaggedObject +1738 * @name KJUR.asn1.DERTaggedObject +1739 * @class class for ASN.1 DER TaggedObject +1740 * @extends KJUR.asn1.ASN1Object +1741 * @see KJUR_asn1.ASN1Util.newObject +1742 * +1743 * @description +1744 * <br/> +1745 * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object. +1746 * For example, if you find '[1]' tag in a ASN.1 dump, +1747 * 'tagNoHex' will be 'a1'. +1748 * <br/> +1749 * As for optional argument 'params' for constructor, you can specify *ANY* of +1750 * following properties: +1751 * <ul> +1752 * <li>tag - specify tag (default is 'a0' which means [0])</li> +1753 * <li>explicit - specify true if this is explicit tag otherwise false +1754 * (default is 'true').</li> +1755 * <li>obj - specify ASN1Object or JSON object which will be tagged</li> +1756 * <li>tage - specify tag with explicit</li> +1757 * <li>tagi - specify tag with implicit</li> +1758 * </ul> +1759 * As for the member "obj" value of JSON object, +1760 * {@link KJUR_asn1.ASN1Util.newObject} is used to generate. +1761 * +1762 * @example +1763 * // by JSON +1764 * new KJUR.asn1.DERTaggedObject({ +1765 * tag:'a0', explicit: true, obj: { "prnstr": { "str": "aaa" } } +1766 * }).tohex() +1767 * +1768 * // by ASN1Object object +1769 * new KJUR.asn1.DERTaggedObject({ +1770 * tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit +1771 * }) +1772 * new KJUR.asn1.DERTaggedObject({ +1773 * tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit +1774 * }) +1775 * new KJUR.asn1.DERTaggedObject({ +1776 * tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit +1777 * }) +1778 * +1779 * // to hexadecimal +1780 * d1 = new KJUR.asn1.DERUTF8String({str':'a'}) +1781 * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1}); +1782 * hex = d2.tohex(); +1783 */ +1784 KJUR.asn1.DERTaggedObject = function(params) { +1785 KJUR.asn1.DERTaggedObject.superclass.constructor.call(this); +1786 +1787 var _KJUR_asn1 = KJUR.asn1, +1788 _ASN1HEX = ASN1HEX, +1789 _getV = _ASN1HEX.getV, +1790 _isASN1HEX = _ASN1HEX.isASN1HEX, +1791 _newObject = _KJUR_asn1.ASN1Util.newObject; +1792 +1793 this.hT = "a0"; +1794 this.hV = ''; +1795 this.isExplicit = true; +1796 this.asn1Object = null; +1797 this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true}; +1798 +1799 /** +1800 * set value by an ASN1Object +1801 * @name setString +1802 * @memberOf KJUR.asn1.DERTaggedObject# +1803 * @function +1804 * @param {Boolean} isExplicitFlag flag for explicit/implicit tag +1805 * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag +1806 * @param {ASN1Object} asn1Object ASN.1 to encapsulate +1807 * @deprecated since jsrsasign 10.5.4 please use setByParam instead +1808 */ +1809 this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { +1810 this.params = {tag: tagNoHex, +1811 explicit: isExplicitFlag, +1812 obj: asn1Object}; +1813 }; 1814 -1815 if (params.str != undefined) { -1816 this.hV = utf8tohex(params.str); -1817 } else if (params.hex != undefined) { -1818 this.hV = params.hex; -1819 } else if (params.obj != undefined) { -1820 var hV1; -1821 if (params.obj instanceof _KJUR_asn1.ASN1Object) { -1822 hV1 = params.obj.tohex(); -1823 } else if (typeof params.obj == "object") { -1824 hV1 = _newObject(params.obj).tohex(); -1825 } -1826 if (params.explicit) { -1827 this.hV = hV1; -1828 } else { -1829 this.hV = _getV(hV1, 0); -1830 } -1831 } else { -1832 throw new Error("str, hex nor obj not specified"); -1833 } -1834 -1835 if (params.tag == undefined) params.tag = "a0"; -1836 this.hT = params.tag; -1837 this.hTLV = null; -1838 this.isModified = true; -1839 -1840 return this.hV; -1841 }; -1842 -1843 this.setByParam = function(params) { -1844 this.params = params; -1845 }; -1846 -1847 if (params !== undefined) this.setByParam(params); -1848 }; -1849 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); -1850