node-forge 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/dist/forge.all.min.js +1 -1
- package/dist/forge.min.js +1 -1
- package/lib/asn1.js +29 -3
- package/lib/log.js +5 -8
- package/lib/oids.js +4 -0
- package/lib/rsa.js +94 -3
- package/package.json +1 -1
package/lib/asn1.js
CHANGED
|
@@ -411,6 +411,8 @@ var _getValueLength = function(bytes, remaining) {
|
|
|
411
411
|
* @param [options] object with options or boolean strict flag
|
|
412
412
|
* [strict] true to be strict when checking value lengths, false to
|
|
413
413
|
* allow truncated values (default: true).
|
|
414
|
+
* [parseAllBytes] true to ensure all bytes are parsed
|
|
415
|
+
* (default: true)
|
|
414
416
|
* [decodeBitStrings] true to attempt to decode the content of
|
|
415
417
|
* BIT STRINGs (not OCTET STRINGs) using strict mode. Note that
|
|
416
418
|
* without schema support to understand the data context this can
|
|
@@ -418,24 +420,31 @@ var _getValueLength = function(bytes, remaining) {
|
|
|
418
420
|
* flag will be deprecated or removed as soon as schema support is
|
|
419
421
|
* available. (default: true)
|
|
420
422
|
*
|
|
423
|
+
* @throws Will throw an error for various malformed input conditions.
|
|
424
|
+
*
|
|
421
425
|
* @return the parsed asn1 object.
|
|
422
426
|
*/
|
|
423
427
|
asn1.fromDer = function(bytes, options) {
|
|
424
428
|
if(options === undefined) {
|
|
425
429
|
options = {
|
|
426
430
|
strict: true,
|
|
431
|
+
parseAllBytes: true,
|
|
427
432
|
decodeBitStrings: true
|
|
428
433
|
};
|
|
429
434
|
}
|
|
430
435
|
if(typeof options === 'boolean') {
|
|
431
436
|
options = {
|
|
432
437
|
strict: options,
|
|
438
|
+
parseAllBytes: true,
|
|
433
439
|
decodeBitStrings: true
|
|
434
440
|
};
|
|
435
441
|
}
|
|
436
442
|
if(!('strict' in options)) {
|
|
437
443
|
options.strict = true;
|
|
438
444
|
}
|
|
445
|
+
if(!('parseAllBytes' in options)) {
|
|
446
|
+
options.parseAllBytes = true;
|
|
447
|
+
}
|
|
439
448
|
if(!('decodeBitStrings' in options)) {
|
|
440
449
|
options.decodeBitStrings = true;
|
|
441
450
|
}
|
|
@@ -445,7 +454,15 @@ asn1.fromDer = function(bytes, options) {
|
|
|
445
454
|
bytes = forge.util.createBuffer(bytes);
|
|
446
455
|
}
|
|
447
456
|
|
|
448
|
-
|
|
457
|
+
var byteCount = bytes.length();
|
|
458
|
+
var value = _fromDer(bytes, bytes.length(), 0, options);
|
|
459
|
+
if(options.parseAllBytes && bytes.length() !== 0) {
|
|
460
|
+
var error = new Error('Unparsed DER bytes remain after ASN.1 parsing.');
|
|
461
|
+
error.byteCount = byteCount;
|
|
462
|
+
error.remaining = bytes.length();
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
return value;
|
|
449
466
|
};
|
|
450
467
|
|
|
451
468
|
/**
|
|
@@ -566,7 +583,6 @@ function _fromDer(bytes, remaining, depth, options) {
|
|
|
566
583
|
start = bytes.length();
|
|
567
584
|
var subOptions = {
|
|
568
585
|
// enforce strict mode to avoid parsing ASN.1 from plain data
|
|
569
|
-
verbose: options.verbose,
|
|
570
586
|
strict: true,
|
|
571
587
|
decodeBitStrings: true
|
|
572
588
|
};
|
|
@@ -615,6 +631,7 @@ function _fromDer(bytes, remaining, depth, options) {
|
|
|
615
631
|
}
|
|
616
632
|
} else {
|
|
617
633
|
value = bytes.getBytes(length);
|
|
634
|
+
remaining -= length;
|
|
618
635
|
}
|
|
619
636
|
}
|
|
620
637
|
|
|
@@ -1391,7 +1408,16 @@ asn1.prettyPrint = function(obj, level, indentation) {
|
|
|
1391
1408
|
}
|
|
1392
1409
|
rval += '0x' + forge.util.bytesToHex(obj.value);
|
|
1393
1410
|
} else if(obj.type === asn1.Type.UTF8) {
|
|
1394
|
-
|
|
1411
|
+
try {
|
|
1412
|
+
rval += forge.util.decodeUtf8(obj.value);
|
|
1413
|
+
} catch(e) {
|
|
1414
|
+
if(e.message === 'URI malformed') {
|
|
1415
|
+
rval +=
|
|
1416
|
+
'0x' + forge.util.bytesToHex(obj.value) + ' (malformed UTF8)';
|
|
1417
|
+
} else {
|
|
1418
|
+
throw e;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1395
1421
|
} else if(obj.type === asn1.Type.PRINTABLESTRING ||
|
|
1396
1422
|
obj.type === asn1.Type.IA5String) {
|
|
1397
1423
|
rval += obj.value;
|
package/lib/log.js
CHANGED
|
@@ -286,7 +286,7 @@ if(typeof(console) !== 'undefined' && 'log' in console) {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
/*
|
|
289
|
-
* Check for logging control query vars.
|
|
289
|
+
* Check for logging control query vars in current URL.
|
|
290
290
|
*
|
|
291
291
|
* console.level=<level-name>
|
|
292
292
|
* Set's the console log level by name. Useful to override defaults and
|
|
@@ -297,13 +297,10 @@ if(typeof(console) !== 'undefined' && 'log' in console) {
|
|
|
297
297
|
* after console.level is processed. Useful to force a level of verbosity
|
|
298
298
|
* that could otherwise be limited by a user config.
|
|
299
299
|
*/
|
|
300
|
-
if(sConsoleLogger !== null
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
} else {
|
|
305
|
-
query = new URLSearchParams();
|
|
306
|
-
}
|
|
300
|
+
if(sConsoleLogger !== null &&
|
|
301
|
+
typeof window !== 'undefined' && window.location
|
|
302
|
+
) {
|
|
303
|
+
var query = new URL(window.location.href).searchParams;
|
|
307
304
|
if(query.has('console.level')) {
|
|
308
305
|
// set with last value
|
|
309
306
|
forge.log.setLevel(
|
package/lib/oids.js
CHANGED
|
@@ -47,6 +47,10 @@ _IN('1.3.14.3.2.29', 'sha1WithRSASignature');
|
|
|
47
47
|
_IN('2.16.840.1.101.3.4.2.1', 'sha256');
|
|
48
48
|
_IN('2.16.840.1.101.3.4.2.2', 'sha384');
|
|
49
49
|
_IN('2.16.840.1.101.3.4.2.3', 'sha512');
|
|
50
|
+
_IN('2.16.840.1.101.3.4.2.4', 'sha224');
|
|
51
|
+
_IN('2.16.840.1.101.3.4.2.5', 'sha512-224');
|
|
52
|
+
_IN('2.16.840.1.101.3.4.2.6', 'sha512-256');
|
|
53
|
+
_IN('1.2.840.113549.2.2', 'md2');
|
|
50
54
|
_IN('1.2.840.113549.2.5', 'md5');
|
|
51
55
|
|
|
52
56
|
// pkcs#7 content types
|
package/lib/rsa.js
CHANGED
|
@@ -264,6 +264,43 @@ var publicKeyValidator = forge.pki.rsa.publicKeyValidator = {
|
|
|
264
264
|
}]
|
|
265
265
|
};
|
|
266
266
|
|
|
267
|
+
// validator for a DigestInfo structure
|
|
268
|
+
var digestInfoValidator = {
|
|
269
|
+
name: 'DigestInfo',
|
|
270
|
+
tagClass: asn1.Class.UNIVERSAL,
|
|
271
|
+
type: asn1.Type.SEQUENCE,
|
|
272
|
+
constructed: true,
|
|
273
|
+
value: [{
|
|
274
|
+
name: 'DigestInfo.DigestAlgorithm',
|
|
275
|
+
tagClass: asn1.Class.UNIVERSAL,
|
|
276
|
+
type: asn1.Type.SEQUENCE,
|
|
277
|
+
constructed: true,
|
|
278
|
+
value: [{
|
|
279
|
+
name: 'DigestInfo.DigestAlgorithm.algorithmIdentifier',
|
|
280
|
+
tagClass: asn1.Class.UNIVERSAL,
|
|
281
|
+
type: asn1.Type.OID,
|
|
282
|
+
constructed: false,
|
|
283
|
+
capture: 'algorithmIdentifier'
|
|
284
|
+
}, {
|
|
285
|
+
// NULL paramters
|
|
286
|
+
name: 'DigestInfo.DigestAlgorithm.parameters',
|
|
287
|
+
tagClass: asn1.Class.UNIVERSAL,
|
|
288
|
+
type: asn1.Type.NULL,
|
|
289
|
+
// captured only to check existence for md2 and md5
|
|
290
|
+
capture: 'parameters',
|
|
291
|
+
optional: true,
|
|
292
|
+
constructed: false
|
|
293
|
+
}]
|
|
294
|
+
}, {
|
|
295
|
+
// digest
|
|
296
|
+
name: 'DigestInfo.digest',
|
|
297
|
+
tagClass: asn1.Class.UNIVERSAL,
|
|
298
|
+
type: asn1.Type.OCTETSTRING,
|
|
299
|
+
constructed: false,
|
|
300
|
+
capture: 'digest'
|
|
301
|
+
}]
|
|
302
|
+
};
|
|
303
|
+
|
|
267
304
|
/**
|
|
268
305
|
* Wrap digest in DigestInfo object.
|
|
269
306
|
*
|
|
@@ -1092,15 +1129,27 @@ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) {
|
|
|
1092
1129
|
* a Forge PSS object for RSASSA-PSS,
|
|
1093
1130
|
* 'NONE' or null for none, DigestInfo will not be expected, but
|
|
1094
1131
|
* PKCS#1 v1.5 padding will still be used.
|
|
1132
|
+
* @param options optional verify options
|
|
1133
|
+
* _parseAllDigestBytes testing flag to control parsing of all
|
|
1134
|
+
* digest bytes. Unsupported and not for general usage.
|
|
1135
|
+
* (default: true)
|
|
1095
1136
|
*
|
|
1096
1137
|
* @return true if the signature was verified, false if not.
|
|
1097
1138
|
*/
|
|
1098
|
-
key.verify = function(digest, signature, scheme) {
|
|
1139
|
+
key.verify = function(digest, signature, scheme, options) {
|
|
1099
1140
|
if(typeof scheme === 'string') {
|
|
1100
1141
|
scheme = scheme.toUpperCase();
|
|
1101
1142
|
} else if(scheme === undefined) {
|
|
1102
1143
|
scheme = 'RSASSA-PKCS1-V1_5';
|
|
1103
1144
|
}
|
|
1145
|
+
if(options === undefined) {
|
|
1146
|
+
options = {
|
|
1147
|
+
_parseAllDigestBytes: true
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
if(!('_parseAllDigestBytes' in options)) {
|
|
1151
|
+
options._parseAllDigestBytes = true;
|
|
1152
|
+
}
|
|
1104
1153
|
|
|
1105
1154
|
if(scheme === 'RSASSA-PKCS1-V1_5') {
|
|
1106
1155
|
scheme = {
|
|
@@ -1108,9 +1157,51 @@ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) {
|
|
|
1108
1157
|
// remove padding
|
|
1109
1158
|
d = _decodePkcs1_v1_5(d, key, true);
|
|
1110
1159
|
// d is ASN.1 BER-encoded DigestInfo
|
|
1111
|
-
var obj = asn1.fromDer(d
|
|
1160
|
+
var obj = asn1.fromDer(d, {
|
|
1161
|
+
parseAllBytes: options._parseAllDigestBytes
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
// validate DigestInfo
|
|
1165
|
+
var capture = {};
|
|
1166
|
+
var errors = [];
|
|
1167
|
+
if(!asn1.validate(obj, digestInfoValidator, capture, errors)) {
|
|
1168
|
+
var error = new Error(
|
|
1169
|
+
'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' +
|
|
1170
|
+
'DigestInfo value.');
|
|
1171
|
+
error.errors = errors;
|
|
1172
|
+
throw error;
|
|
1173
|
+
}
|
|
1174
|
+
// check hash algorithm identifier
|
|
1175
|
+
// see PKCS1-v1-5DigestAlgorithms in RFC 8017
|
|
1176
|
+
// FIXME: add support to vaidator for strict value choices
|
|
1177
|
+
var oid = asn1.derToOid(capture.algorithmIdentifier);
|
|
1178
|
+
if(!(oid === forge.oids.md2 ||
|
|
1179
|
+
oid === forge.oids.md5 ||
|
|
1180
|
+
oid === forge.oids.sha1 ||
|
|
1181
|
+
oid === forge.oids.sha224 ||
|
|
1182
|
+
oid === forge.oids.sha256 ||
|
|
1183
|
+
oid === forge.oids.sha384 ||
|
|
1184
|
+
oid === forge.oids.sha512 ||
|
|
1185
|
+
oid === forge.oids['sha512-224'] ||
|
|
1186
|
+
oid === forge.oids['sha512-256'])) {
|
|
1187
|
+
var error = new Error(
|
|
1188
|
+
'Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.');
|
|
1189
|
+
error.oid = oid;
|
|
1190
|
+
throw error;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
// special check for md2 and md5 that NULL parameters exist
|
|
1194
|
+
if(oid === forge.oids.md2 || oid === forge.oids.md5) {
|
|
1195
|
+
if(!('parameters' in capture)) {
|
|
1196
|
+
throw new Error(
|
|
1197
|
+
'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' +
|
|
1198
|
+
'DigestInfo value. ' +
|
|
1199
|
+
'Missing algorithm identifer NULL parameters.');
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1112
1203
|
// compare the given digest to the decrypted one
|
|
1113
|
-
return digest ===
|
|
1204
|
+
return digest === capture.digest;
|
|
1114
1205
|
}
|
|
1115
1206
|
};
|
|
1116
1207
|
} else if(scheme === 'NONE' || scheme === 'NULL' || scheme === null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-forge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.",
|
|
5
5
|
"homepage": "https://github.com/digitalbazaar/forge",
|
|
6
6
|
"author": {
|