diff --git a/ChangeLog.txt b/ChangeLog.txt index 9dc18873..30718283 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,8 +1,21 @@ ChangeLog for jsrsasign +DERBitString, KeyUsage and tsp PKIFailureInfo critical bug fix +* Changes from 10.5.21 to 10.5.22 (2022-May-24) + - src/asn1.js + - DERBitString critical bugfix + - src/asn1tsp.js + - PKIFailureInfo critical bugfix + - src/asn1x509.js + - KeyUsage critical bugfix + - src/base64.x + - namearraytobinstr critical bugfix + - test/qunit-do-{asn1,asn1tsp,asn1x509,base64x}.html + - add and fix some test cases for above + DERBitString, KeyUsage and tsp PKIFailureInfo fix -* Changes from 10.5.20 to 10.5.21 (2022-May-23) +* Changes from 10.5.20 to 10.5.21 (2022-May-23) *RELEASE RESIGNED* - src/asn1x509.js - KeyUsage bugfix, refactoring - src/asn1tsp.js diff --git a/api/files.html b/api/files.html index ad064e34..c2bc008e 100644 --- a/api/files.html +++ b/api/files.html @@ -529,7 +529,7 @@
db = { a: 0, b: 3, c: 8, d: 9, e: 17, f: 19 }; -namearraytobinstr(['a', 'c', 'd'], db) &rarr: '1100000001' -namearraytobinstr(['c', 'b'], db) &rarr: '100001000'+namearraytobinstr(['a', 'c', 'd'], db) &rarr: '1000000011' +namearraytobinstr(['c', 'b'], db) &rarr: '000100001' diff --git a/api/symbols/src/asn1-1.0.js.html b/api/symbols/src/asn1-1.0.js.html index 8b82600e..b3a9cb62 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.25.js (c) 2013-2022 Kenji Urushima | kjur.github.io/jsrsasign/license +1 /* asn1-1.0.26.js (c) 2013-2022 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.21 asn1 1.0.25 (2022-May-23) + 19 * @version jsrsasign 10.5.22 asn1 1.0.26 (2022-May-24) 20 * @since jsrsasign 2.1 21 * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a> 22 */ @@ -981,867 +981,868 @@ 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 * @example -978 * // default constructor -979 * o = new KJUR.asn1.DERBitString(); -980 * // initialize with binary string -981 * o = new KJUR.asn1.DERBitString({bin: "1011"}); -982 * // initialize with boolean array -983 * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]}); -984 * // initialize with hexadecimal string (04 is unused bits) -985 * o = new KJUR.asn1.DERBitString({hex: "04bac0"}); -986 * // initialize with ASN1Util.newObject argument for encapsulated -987 * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -988 * // above generates a ASN.1 data like this: -989 * // BIT STRING, encapsulates { -990 * // SEQUENCE { -991 * // INTEGER 3 -992 * // PrintableString 'aaa' -993 * // } -994 * // } -995 */ -996 KJUR.asn1.DERBitString = function(params) { -997 if (params !== undefined && typeof params.obj !== "undefined") { -998 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -999 params.hex = "00" + o.tohex(); -1000 } -1001 KJUR.asn1.DERBitString.superclass.constructor.call(this); -1002 this.hT = "03"; -1003 -1004 /** -1005 * set ASN.1 value(V) by a hexadecimal string including unused bits -1006 * @name setHexValueIncludingUnusedBits -1007 * @memberOf KJUR.asn1.DERBitString# -1008 * @function -1009 * @param {String} newHexStringIncludingUnusedBits -1010 */ -1011 this.setHexValueIncludingUnusedBits = function(newHexStringIncludingUnusedBits) { -1012 this.hTLV = null; -1013 this.isModified = true; -1014 this.hV = newHexStringIncludingUnusedBits; -1015 }; -1016 -1017 /** -1018 * set ASN.1 value(V) by unused bit and hexadecimal string of value -1019 * @name setUnusedBitsAndHexValue -1020 * @memberOf KJUR.asn1.DERBitString# -1021 * @function -1022 * @param {Integer} unusedBits -1023 * @param {String} hValue -1024 */ -1025 this.setUnusedBitsAndHexValue = function(unusedBits, hValue) { -1026 if (unusedBits < 0 || 7 < unusedBits) { -1027 throw "unused bits shall be from 0 to 7: u = " + unusedBits; -1028 } -1029 var hUnusedBits = "0" + unusedBits; -1030 this.hTLV = null; -1031 this.isModified = true; -1032 this.hV = hUnusedBits + hValue; -1033 }; -1034 -1035 /** -1036 * set ASN.1 DER BitString by binary string<br/> -1037 * @name setByBinaryString -1038 * @memberOf KJUR.asn1.DERBitString# -1039 * @function -1040 * @param {String} binaryString binary value string (i.e. '10111') -1041 * @description -1042 * Its unused bits will be calculated automatically by length of -1043 * 'binaryValue'. <br/> -1044 * NOTE: Leading zeros '0' will be ignored. -1045 * @example -1046 * o = new KJUR.asn1.DERBitString(); -1047 * o.setByBinaryString("1011"); -1048 * o.setByBinaryString("001"); // leading zeros ignored -1049 */ -1050 this.setByBinaryString = function(binaryString) { -1051 binaryString = binaryString.replace(/^0+/, ''); -1052 var unusedBits = 8 - binaryString.length % 8; -1053 if (unusedBits == 8) unusedBits = 0; -1054 -1055 binaryString += "0000000".substr(0, unusedBits); -1056 -1057 var h = ''; -1058 for (var i = 0; i < binaryString.length - 1; i += 8) { -1059 var b = binaryString.substr(i, 8); -1060 var x = parseInt(b, 2).toString(16); -1061 if (x.length == 1) x = '0' + x; -1062 h += x; -1063 } -1064 this.hTLV = null; -1065 this.isModified = true; -1066 this.hV = '0' + unusedBits + h; -1067 }; -1068 -1069 /** -1070 * set ASN.1 TLV value(V) by an array of boolean<br/> -1071 * @name setByBooleanArray -1072 * @memberOf KJUR.asn1.DERBitString# -1073 * @function -1074 * @param {array} booleanArray array of boolean (ex. [true, false, true]) -1075 * @description -1076 * NOTE: Trailing falses will be ignored in the ASN.1 DER Object. -1077 * @example -1078 * o = new KJUR.asn1.DERBitString(); -1079 * o.setByBooleanArray([false, true, false, true, true]); -1080 */ -1081 this.setByBooleanArray = function(booleanArray) { -1082 var s = ''; -1083 for (var i = 0; i < booleanArray.length; i++) { -1084 if (booleanArray[i] == true) { -1085 s += '1'; -1086 } else { -1087 s += '0'; -1088 } -1089 } -1090 this.setByBinaryString(s); -1091 }; -1092 -1093 /** -1094 * generate an array of falses with specified length<br/> -1095 * @name newFalseArray -1096 * @memberOf KJUR.asn1.DERBitString -1097 * @function -1098 * @param {Integer} nLength length of array to generate -1099 * @return {array} array of boolean falses -1100 * @description -1101 * This static method may be useful to initialize boolean array. -1102 * @example -1103 * o = new KJUR.asn1.DERBitString(); -1104 * o.newFalseArray(3) → [false, false, false] -1105 */ -1106 this.newFalseArray = function(nLength) { -1107 var a = new Array(nLength); -1108 for (var i = 0; i < nLength; i++) { -1109 a[i] = false; -1110 } -1111 return a; -1112 }; -1113 -1114 this.getFreshValueHex = function() { -1115 return this.hV; -1116 }; -1117 -1118 if (typeof params != "undefined") { -1119 if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) { -1120 this.setHexValueIncludingUnusedBits(params); -1121 } else if (typeof params['hex'] != "undefined") { -1122 this.setHexValueIncludingUnusedBits(params['hex']); -1123 } else if (typeof params['bin'] != "undefined") { -1124 this.setByBinaryString(params['bin']); -1125 } else if (typeof params['array'] != "undefined") { -1126 this.setByBooleanArray(params['array']); -1127 } -1128 } -1129 }; -1130 extendClass(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object); -1131 -1132 // ******************************************************************** -1133 /** -1134 * class for ASN.1 DER OctetString<br/> -1135 * @name KJUR.asn1.DEROctetString -1136 * @class class for ASN.1 DER OctetString -1137 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1138 * @extends KJUR.asn1.DERAbstractString -1139 * @description -1140 * This class provides ASN.1 OctetString simple type.<br/> -1141 * Supported "params" attributes are: -1142 * <ul> -1143 * <li>str - to set a string as a value</li> -1144 * <li>hex - to set a hexadecimal string as a value</li> -1145 * <li>obj - to set a encapsulated ASN.1 value by JSON object -1146 * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li> -1147 * </ul> -1148 * NOTE: A parameter 'obj' have been supported -1149 * for "OCTET STRING, encapsulates" structure. -1150 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25). -1151 * @see KJUR.asn1.DERAbstractString - superclass -1152 * @example -1153 * // default constructor -1154 * o = new KJUR.asn1.DEROctetString(); -1155 * // initialize with string -1156 * o = new KJUR.asn1.DEROctetString({str: "aaa"}); -1157 * // initialize with hexadecimal string -1158 * o = new KJUR.asn1.DEROctetString({hex: "616161"}); -1159 * // initialize with ASN1Util.newObject argument -1160 * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}}); -1161 * // above generates a ASN.1 data like this: -1162 * // OCTET STRING, encapsulates { -1163 * // SEQUENCE { -1164 * // INTEGER 3 -1165 * // PrintableString 'aaa' -1166 * // } -1167 * // } -1168 */ -1169 KJUR.asn1.DEROctetString = function(params) { -1170 if (params !== undefined && typeof params.obj !== "undefined") { -1171 var o = KJUR.asn1.ASN1Util.newObject(params.obj); -1172 params.hex = o.tohex(); -1173 } -1174 KJUR.asn1.DEROctetString.superclass.constructor.call(this, params); -1175 this.hT = "04"; -1176 }; -1177 extendClass(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString); -1178 -1179 // ******************************************************************** -1180 /** -1181 * class for ASN.1 DER Null -1182 * @name KJUR.asn1.DERNull -1183 * @class class for ASN.1 DER Null -1184 * @extends KJUR.asn1.ASN1Object -1185 * @description -1186 * @see KJUR.asn1.ASN1Object - superclass -1187 */ -1188 KJUR.asn1.DERNull = function() { -1189 KJUR.asn1.DERNull.superclass.constructor.call(this); -1190 this.hT = "05"; -1191 this.hTLV = "0500"; -1192 }; -1193 extendClass(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object); -1194 -1195 // ******************************************************************** -1196 /** -1197 * class for ASN.1 DER ObjectIdentifier -1198 * @name KJUR.asn1.DERObjectIdentifier -1199 * @class class for ASN.1 DER ObjectIdentifier -1200 * @param {Object} JSON object or string of parameters (ex. {'oid': '2.5.4.5'}) -1201 * @extends KJUR.asn1.ASN1Object -1202 * @see oidtohex -1203 * -1204 * @description -1205 * <br/> -1206 * As for argument 'params' for constructor, you can specify one of -1207 * following properties: -1208 * <ul> -1209 * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li> -1210 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1211 * </ul> -1212 * NOTE: 'params' can be omitted. -1213 * @example -1214 * new DERObjectIdentifier({"name": "sha1"}) -1215 * new DERObjectIdentifier({"oid": "1.2.3.4"}) -1216 * new DERObjectIdentifier({"hex": "2d..."}) -1217 * new DERObjectIdentifier("1.2.3.4") -1218 * new DERObjectIdentifier("SHA1withRSA") -1219 */ -1220 KJUR.asn1.DERObjectIdentifier = function(params) { -1221 KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this); -1222 this.hT = "06"; -1223 -1224 /** -1225 * set value by a hexadecimal string -1226 * @name setValueHex -1227 * @memberOf KJUR.asn1.DERObjectIdentifier# -1228 * @function -1229 * @param {String} newHexString hexadecimal value of OID bytes -1230 */ -1231 this.setValueHex = function(newHexString) { -1232 this.hTLV = null; -1233 this.isModified = true; -1234 this.s = null; -1235 this.hV = newHexString; -1236 }; -1237 -1238 /** -1239 * set value by a OID string<br/> -1240 * @name setValueOidString -1241 * @memberOf KJUR.asn1.DERObjectIdentifier# -1242 * @function -1243 * @param {String} oidString OID string (ex. 2.5.4.13) -1244 * @example -1245 * o = new KJUR.asn1.DERObjectIdentifier(); -1246 * o.setValueOidString("2.5.4.13"); -1247 */ -1248 this.setValueOidString = function(oidString) { -1249 var h = oidtohex(oidString); -1250 if (h == null) -1251 throw new Error("malformed oid string: " + oidString); -1252 this.hTLV = null; -1253 this.isModified = true; -1254 this.s = null; -1255 this.hV = h; -1256 }; -1257 -1258 /** -1259 * set value by a OID name -1260 * @name setValueName -1261 * @memberOf KJUR.asn1.DERObjectIdentifier# -1262 * @function -1263 * @param {String} oidName OID name (ex. 'serverAuth') -1264 * @since 1.0.1 -1265 * @description -1266 * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'. -1267 * Otherwise raise error. -1268 * @example -1269 * o = new KJUR.asn1.DERObjectIdentifier(); -1270 * o.setValueName("serverAuth"); -1271 */ -1272 this.setValueName = function(oidName) { -1273 var oid = KJUR.asn1.x509.OID.name2oid(oidName); -1274 if (oid !== '') { -1275 this.setValueOidString(oid); -1276 } else { -1277 throw new Error("DERObjectIdentifier oidName undefined: " + oidName); -1278 } -1279 }; -1280 -1281 this.setValueNameOrOid = function(nameOrOid) { -1282 if (nameOrOid.match(/^[0-2].[0-9.]+$/)) { -1283 this.setValueOidString(nameOrOid); -1284 } else { -1285 this.setValueName(nameOrOid); -1286 } -1287 } -1288 -1289 this.getFreshValueHex = function() { -1290 return this.hV; -1291 }; -1292 -1293 this.setByParam = function(params) { -1294 if (typeof params === "string") { -1295 this.setValueNameOrOid(params); -1296 } else if (params.oid !== undefined) { -1297 this.setValueNameOrOid(params.oid); -1298 } else if (params.name !== undefined) { -1299 this.setValueNameOrOid(params.name); -1300 } else if (params.hex !== undefined) { -1301 this.setValueHex(params.hex); -1302 } -1303 }; -1304 -1305 if (params !== undefined) this.setByParam(params); -1306 }; -1307 extendClass(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object); -1308 -1309 // ******************************************************************** -1310 /** -1311 * class for ASN.1 DER Enumerated -1312 * @name KJUR.asn1.DEREnumerated -1313 * @class class for ASN.1 DER Enumerated -1314 * @extends KJUR.asn1.ASN1Object -1315 * @description -1316 * <br/> -1317 * As for argument 'params' for constructor, you can specify one of -1318 * following properties: -1319 * <ul> -1320 * <li>int - specify initial ASN.1 value(V) by integer value</li> -1321 * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li> -1322 * </ul> -1323 * NOTE: 'params' can be omitted. -1324 * @example -1325 * new KJUR.asn1.DEREnumerated(123); -1326 * new KJUR.asn1.DEREnumerated({int: 123}); -1327 * new KJUR.asn1.DEREnumerated({hex: '1fad'}); -1328 */ -1329 KJUR.asn1.DEREnumerated = function(params) { -1330 KJUR.asn1.DEREnumerated.superclass.constructor.call(this); -1331 this.hT = "0a"; -1332 -1333 /** -1334 * set value by Tom Wu's BigInteger object -1335 * @name setByBigInteger -1336 * @memberOf KJUR.asn1.DEREnumerated# -1337 * @function -1338 * @param {BigInteger} bigIntegerValue to set -1339 */ -1340 this.setByBigInteger = function(bigIntegerValue) { -1341 this.hTLV = null; -1342 this.isModified = true; -1343 this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue); -1344 }; -1345 -1346 /** -1347 * set value by integer value -1348 * @name setByInteger -1349 * @memberOf KJUR.asn1.DEREnumerated# -1350 * @function -1351 * @param {Integer} integer value to set -1352 */ -1353 this.setByInteger = function(intValue) { -1354 var bi = new BigInteger(String(intValue), 10); -1355 this.setByBigInteger(bi); -1356 }; -1357 -1358 /** -1359 * set value by integer value -1360 * @name setValueHex -1361 * @memberOf KJUR.asn1.DEREnumerated# -1362 * @function -1363 * @param {String} hexadecimal string of integer value -1364 * @description -1365 * <br/> -1366 * NOTE: Value shall be represented by minimum octet length of -1367 * two's complement representation. -1368 */ -1369 this.setValueHex = function(newHexString) { -1370 this.hV = newHexString; -1371 }; -1372 -1373 this.getFreshValueHex = function() { -1374 return this.hV; -1375 }; -1376 -1377 if (typeof params != "undefined") { -1378 if (typeof params['int'] != "undefined") { -1379 this.setByInteger(params['int']); -1380 } else if (typeof params == "number") { -1381 this.setByInteger(params); -1382 } else if (typeof params['hex'] != "undefined") { -1383 this.setValueHex(params['hex']); -1384 } -1385 } -1386 }; -1387 extendClass(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object); -1388 -1389 // ******************************************************************** -1390 /** -1391 * class for ASN.1 DER UTF8String -1392 * @name KJUR.asn1.DERUTF8String -1393 * @class class for ASN.1 DER UTF8String -1394 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1395 * @extends KJUR.asn1.DERAbstractString -1396 * @description -1397 * @see KJUR.asn1.DERAbstractString - superclass -1398 */ -1399 KJUR.asn1.DERUTF8String = function(params) { -1400 KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params); -1401 this.hT = "0c"; -1402 }; -1403 extendClass(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString); -1404 -1405 // ******************************************************************** -1406 /** -1407 * class for ASN.1 DER NumericString -1408 * @name KJUR.asn1.DERNumericString -1409 * @class class for ASN.1 DER NumericString -1410 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1411 * @extends KJUR.asn1.DERAbstractString -1412 * @description -1413 * @see KJUR.asn1.DERAbstractString - superclass -1414 */ -1415 KJUR.asn1.DERNumericString = function(params) { -1416 KJUR.asn1.DERNumericString.superclass.constructor.call(this, params); -1417 this.hT = "12"; -1418 }; -1419 extendClass(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString); -1420 -1421 // ******************************************************************** -1422 /** -1423 * class for ASN.1 DER PrintableString -1424 * @name KJUR.asn1.DERPrintableString -1425 * @class class for ASN.1 DER PrintableString -1426 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1427 * @extends KJUR.asn1.DERAbstractString -1428 * @description -1429 * @see KJUR.asn1.DERAbstractString - superclass -1430 */ -1431 KJUR.asn1.DERPrintableString = function(params) { -1432 KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params); -1433 this.hT = "13"; -1434 }; -1435 extendClass(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString); -1436 -1437 // ******************************************************************** -1438 /** -1439 * class for ASN.1 DER TeletexString -1440 * @name KJUR.asn1.DERTeletexString -1441 * @class class for ASN.1 DER TeletexString -1442 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1443 * @extends KJUR.asn1.DERAbstractString -1444 * @description -1445 * @see KJUR.asn1.DERAbstractString - superclass -1446 */ -1447 KJUR.asn1.DERTeletexString = function(params) { -1448 KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params); -1449 this.hT = "14"; -1450 }; -1451 extendClass(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString); -1452 -1453 // ******************************************************************** -1454 /** -1455 * class for ASN.1 DER IA5String -1456 * @name KJUR.asn1.DERIA5String -1457 * @class class for ASN.1 DER IA5String -1458 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1459 * @extends KJUR.asn1.DERAbstractString -1460 * @description -1461 * @see KJUR.asn1.DERAbstractString - superclass -1462 */ -1463 KJUR.asn1.DERIA5String = function(params) { -1464 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1465 this.hT = "16"; -1466 }; -1467 extendClass(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString); -1468 -1469 // ******************************************************************** -1470 /** -1471 * class for ASN.1 DER VisibleString -1472 * @name KJUR.asn1.DERVisibleString -1473 * @class class for ASN.1 DER VisibleString -1474 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1475 * @extends KJUR.asn1.DERAbstractString -1476 * @since jsrsasign 8.0.23 asn1 1.0.15 -1477 * @description -1478 * @see KJUR.asn1.DERAbstractString - superclass -1479 */ -1480 KJUR.asn1.DERVisibleString = function(params) { -1481 KJUR.asn1.DERIA5String.superclass.constructor.call(this, params); -1482 this.hT = "1a"; -1483 }; -1484 extendClass(KJUR.asn1.DERVisibleString, KJUR.asn1.DERAbstractString); -1485 -1486 // ******************************************************************** -1487 /** -1488 * class for ASN.1 DER BMPString -1489 * @name KJUR.asn1.DERBMPString -1490 * @class class for ASN.1 DER BMPString -1491 * @param {Array} params associative array of parameters (ex. {'str': 'aaa'}) -1492 * @extends KJUR.asn1.DERAbstractString -1493 * @since jsrsasign 8.0.23 asn1 1.0.15 -1494 * @description -1495 * @see KJUR.asn1.DERAbstractString - superclass -1496 */ -1497 KJUR.asn1.DERBMPString = function(params) { -1498 KJUR.asn1.DERBMPString.superclass.constructor.call(this, params); -1499 this.hT = "1e"; -1500 }; -1501 extendClass(KJUR.asn1.DERBMPString, KJUR.asn1.DERAbstractString); -1502 -1503 // ******************************************************************** -1504 /** -1505 * class for ASN.1 DER UTCTime -1506 * @name KJUR.asn1.DERUTCTime -1507 * @class class for ASN.1 DER UTCTime -1508 * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'}) -1509 * @extends KJUR.asn1.DERAbstractTime -1510 * @see KJUR.asn1.DERGeneralizedTime -1511 * @see KJUR.asn1.x509.Time -1512 * -1513 * @description -1514 * <br/> -1515 * As for argument 'params' for constructor, you can specify one of -1516 * following properties: -1517 * <ul> -1518 * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li> -1519 * <li>date - specify Date object.</li> -1520 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> -1521 * </ul> -1522 * NOTE1: 'params' can be omitted. -1523 * NOTE2: 'millis' property is supported from jsrsasign 10.4.1 asn1 1.0.22. -1524 * -1525 * <h4>EXAMPLES</h4> -1526 * @example -1527 * new DERUTCTime("20151231235959Z") -1528 * new DERUTCTime("20151231235959.123Z") -1529 * new DERUTCTime(new Date()) -1530 * new DERUTCTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) -1531 * new DERUTCTime({str: "20151231235959.123Z"}) -1532 * new DERUTCTime({date: new Date()}) -1533 * new DERUTCTime({date: new Date(), millis: true}) -1534 * new DERUTCTime({millis: true}) -1535 */ -1536 KJUR.asn1.DERUTCTime = function(params) { -1537 KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params); -1538 this.hT = "17"; -1539 this.params = undefined; -1540 -1541 this.getFreshValueHex = function() { -1542 var params = this.params; -1543 -1544 if (this.params == undefined) params = { date: new Date() }; -1545 -1546 if (typeof params == "string") { -1547 if (params.match(/^[0-9]{12}Z$/) || -1548 params.match(/^[0-9]{12}\.[0-9]+Z$/)) { -1549 this.hV = stohex(params); -1550 } else { -1551 throw new Error("malformed string for UTCTime: " + params); -1552 } -1553 } else if (params.str != undefined) { -1554 this.hV = stohex(params.str); -1555 } else if (params.date == undefined && params.millis == true) { -1556 var date = new Date(); -1557 this.hV = stohex(this.formatDate(date, 'utc', true)); -1558 } else if (params.date != undefined && -1559 params.date instanceof Date) { -1560 var withMillis = (params.millis === true); -1561 this.hV = stohex(this.formatDate(params.date, 'utc', withMillis)); -1562 } else if (params instanceof Date) { -1563 this.hV = stohex(this.formatDate(params, 'utc')); -1564 } -1565 -1566 if (this.hV == undefined) { -1567 throw new Error("parameter not specified properly for UTCTime"); -1568 } -1569 return this.hV; -1570 }; -1571 -1572 if (params != undefined) this.setByParam(params); -1573 }; -1574 extendClass(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime); -1575 -1576 // ******************************************************************** -1577 /** -1578 * class for ASN.1 DER GeneralizedTime -1579 * @name KJUR.asn1.DERGeneralizedTime -1580 * @class class for ASN.1 DER GeneralizedTime -1581 * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'}) -1582 * @property {Boolean} withMillis flag to show milliseconds or not -1583 * @extends KJUR.asn1.DERAbstractTime -1584 * @see KJUR.asn1.DERUTCTime -1585 * @see KJUR.asn1.x509.Time -1586 * -1587 * @description -1588 * <br/> -1589 * As for argument 'params' for constructor, you can specify one of -1590 * following properties: -1591 * <ul> -1592 * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li> -1593 * <li>date - specify Date object.</li> -1594 * <li>millis - specify flag to show milliseconds (from 1.0.6)</li> -1595 * </ul> -1596 * NOTE1: 'params' can be omitted. -1597 * NOTE2: 'millis' property is supported from asn1 1.0.6. -1598 * -1599 * <h4>EXAMPLES</h4> -1600 * @example -1601 * new DERGeneralizedTime("20151231235959Z") -1602 * new DERGeneralizedTime("20151231235959.123Z") -1603 * new DERGeneralizedTime(new Date()) -1604 * new DERGeneralizedTime(new Date(Date.UTC(2015,11,31,23,59,59,123))) -1605 * new DERGeneralizedTime({str: "20151231235959.123Z"}) -1606 * new DERGeneralizedTime({date: new Date()}) -1607 * new DERGeneralizedTime({date: new Date(), millis: true}) -1608 * new DERGeneralizedTime({millis: true}) -1609 */ -1610 KJUR.asn1.DERGeneralizedTime = function(params) { -1611 KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params); -1612 this.hT = "18"; -1613 this.params = params; -1614 -1615 this.getFreshValueHex = function() { -1616 var params = this.params; -1617 -1618 if (this.params == undefined) params = { date: new Date() }; -1619 -1620 if (typeof params == "string") { -1621 if (params.match(/^[0-9]{14}Z$/) || -1622 params.match(/^[0-9]{14}\.[0-9]+Z$/)) { -1623 this.hV = stohex(params); -1624 } else { -1625 throw new Error("malformed string for GeneralizedTime: " + params); -1626 } -1627 } else if (params.str != undefined) { -1628 this.hV = stohex(params.str); -1629 } else if (params.date == undefined && params.millis == true) { -1630 var date = new Date(); -1631 this.hV = stohex(this.formatDate(date, 'gen', true)); -1632 } else if (params.date != undefined && -1633 params.date instanceof Date) { -1634 var withMillis = (params.millis === true); -1635 this.hV = stohex(this.formatDate(params.date, 'gen', withMillis)); -1636 } else if (params instanceof Date) { -1637 this.hV = stohex(this.formatDate(params, 'gen')); -1638 } -1639 -1640 if (this.hV == undefined) { -1641 throw new Error("parameter not specified properly for GeneralizedTime"); -1642 } -1643 return this.hV; -1644 }; -1645 -1646 if (params != undefined) this.setByParam(params); -1647 }; -1648 extendClass(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime); -1649 -1650 // ******************************************************************** -1651 /** -1652 * class for ASN.1 DER Sequence -1653 * @name KJUR.asn1.DERSequence -1654 * @class class for ASN.1 DER Sequence -1655 * @extends KJUR.asn1.DERAbstractStructured -1656 * @description -1657 * <br/> -1658 * As for argument 'params' for constructor, you can specify one of -1659 * following properties: -1660 * <ul> -1661 * <li>array - specify array of ASN1Object to set elements of content</li> -1662 * </ul> -1663 * NOTE: 'params' can be omitted. -1664 */ -1665 KJUR.asn1.DERSequence = function(params) { -1666 KJUR.asn1.DERSequence.superclass.constructor.call(this, params); -1667 this.hT = "30"; -1668 this.getFreshValueHex = function() { -1669 var h = ''; -1670 for (var i = 0; i < this.asn1Array.length; i++) { -1671 var asn1Obj = this.asn1Array[i]; -1672 h += asn1Obj.tohex(); -1673 } -1674 this.hV = h; -1675 return this.hV; -1676 }; -1677 }; -1678 extendClass(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured); -1679 -1680 // ******************************************************************** -1681 /** -1682 * class for ASN.1 DER Set -1683 * @name KJUR.asn1.DERSet -1684 * @class class for ASN.1 DER Set -1685 * @extends KJUR.asn1.DERAbstractStructured -1686 * @description -1687 * <br/> -1688 * As for argument 'params' for constructor, you can specify one of -1689 * following properties: -1690 * <ul> -1691 * <li>array - specify array of ASN1Object to set elements of content</li> -1692 * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li> -1693 * </ul> -1694 * NOTE1: 'params' can be omitted.<br/> -1695 * NOTE2: sortflag is supported since 1.0.5. -1696 */ -1697 KJUR.asn1.DERSet = function(params) { -1698 KJUR.asn1.DERSet.superclass.constructor.call(this, params); -1699 this.hT = "31"; -1700 this.sortFlag = true; // item shall be sorted only in ASN.1 DER -1701 this.getFreshValueHex = function() { -1702 var a = new Array(); -1703 for (var i = 0; i < this.asn1Array.length; i++) { -1704 var asn1Obj = this.asn1Array[i]; -1705 a.push(asn1Obj.tohex()); -1706 } -1707 if (this.sortFlag == true) a.sort(); -1708 this.hV = a.join(''); -1709 return this.hV; -1710 }; -1711 -1712 if (typeof params != "undefined") { -1713 if (typeof params.sortflag != "undefined" && -1714 params.sortflag == false) -1715 this.sortFlag = false; -1716 } -1717 }; -1718 extendClass(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured); -1719 -1720 // ******************************************************************** -1721 /** -1722 * class for ASN.1 DER TaggedObject -1723 * @name KJUR.asn1.DERTaggedObject -1724 * @class class for ASN.1 DER TaggedObject -1725 * @extends KJUR.asn1.ASN1Object -1726 * -1727 * @description -1728 * <br/> -1729 * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object. -1730 * For example, if you find '[1]' tag in a ASN.1 dump, -1731 * 'tagNoHex' will be 'a1'. -1732 * <br/> -1733 * As for optional argument 'params' for constructor, you can specify *ANY* of -1734 * following properties: -1735 * <ul> -1736 * <li>tag - specify tag (default is 'a0' which means [0])</li> -1737 * <li>explicit - specify true if this is explicit tag otherwise false -1738 * (default is 'true').</li> -1739 * <li>obj - specify ASN1Object which is tagged</li> -1740 * <li>tage - specify tag with explicit</li> -1741 * <li>tagi - specify tag with implicit</li> -1742 * </ul> -1743 * -1744 * @example -1745 * new KJUR.asn1.DERTaggedObject({ -1746 * tage:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1747 * }) -1748 * new KJUR.asn1.DERTaggedObject({ -1749 * tagi:'a0', obj: new KJUR.asn1.DERInteger({int: 3}) // implicit -1750 * }) -1751 * new KJUR.asn1.DERTaggedObject({ -1752 * tag:'a0', explicit: true, obj: new KJUR.asn1.DERInteger({int: 3}) // explicit -1753 * }) -1754 * -1755 * // to hexadecimal -1756 * d1 = new KJUR.asn1.DERUTF8String({str':'a'}) -1757 * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1}); -1758 * hex = d2.tohex(); -1759 */ -1760 KJUR.asn1.DERTaggedObject = function(params) { -1761 KJUR.asn1.DERTaggedObject.superclass.constructor.call(this); -1762 -1763 var _KJUR_asn1 = KJUR.asn1, -1764 _ASN1HEX = ASN1HEX, -1765 _getV = _ASN1HEX.getV, -1766 _isASN1HEX = _ASN1HEX.isASN1HEX, -1767 _newObject = _KJUR_asn1.ASN1Util.newObject; -1768 -1769 this.hT = "a0"; -1770 this.hV = ''; -1771 this.isExplicit = true; -1772 this.asn1Object = null; -1773 this.params = {tag: "a0", explicit: true}; //"tag": "a0, "explicit": true}; -1774 -1775 /** -1776 * set value by an ASN1Object -1777 * @name setString -1778 * @memberOf KJUR.asn1.DERTaggedObject# -1779 * @function -1780 * @param {Boolean} isExplicitFlag flag for explicit/implicit tag -1781 * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag -1782 * @param {ASN1Object} asn1Object ASN.1 to encapsulate -1783 * @deprecated since jsrsasign 10.5.4 please use setByParam instead -1784 */ -1785 this.setASN1Object = function(isExplicitFlag, tagNoHex, asn1Object) { -1786 this.params = {tag: tagNoHex, -1787 explicit: isExplicitFlag, -1788 obj: asn1Object}; -1789 }; -1790 -1791 this.getFreshValueHex = function() { -1792 var params = this.params; -1793 -1794 if (params.explicit == undefined) params.explicit = true; -1795 -1796 if (params.tage != undefined) { -1797 params.tag = params.tage; -1798 params.explicit = true; -1799 } -1800 if (params.tagi != undefined) { -1801 params.tag = params.tagi; -1802 params.explicit = false; -1803 } -1804 -1805 if (params.str != undefined) { -1806 this.hV = utf8tohex(params.str); -1807 } else if (params.hex != undefined) { -1808 this.hV = params.hex; -1809 } else if (params.obj != undefined) { -1810 var hV1; -1811 if (params.obj instanceof _KJUR_asn1.ASN1Object) { -1812 hV1 = params.obj.tohex(); -1813 } else if (typeof params.obj == "object") { -1814 hV1 = _newObject(params.obj).tohex(); -1815 } -1816 if (params.explicit) { -1817 this.hV = hV1; -1818 } else { -1819 this.hV = _getV(hV1, 0); -1820 } -1821 } else { -1822 throw new Error("str, hex nor obj not specified"); -1823 } -1824 -1825 if (params.tag == undefined) params.tag = "a0"; -1826 this.hT = params.tag; -1827 this.hTLV = null; -1828 this.isModified = true; -1829 -1830 return this.hV; -1831 }; -1832 -1833 this.setByParam = function(params) { -1834 this.params = params; -1835 }; -1836 -1837 if (params !== undefined) this.setByParam(params); -1838 }; -1839 extendClass(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object); -1840