node-forge 0.7.2 → 0.7.6
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 +27 -0
- package/README.md +92 -2
- package/dist/forge.all.min.js +1 -1
- package/dist/forge.min.js +1 -1
- package/lib/baseN.js +186 -0
- package/lib/ed25519.js +996 -0
- package/lib/form.js +1 -1
- package/lib/index.js +1 -0
- package/lib/pkcs7.js +30 -16
- package/lib/util.js +36 -15
- package/package.json +3 -3
package/lib/form.js
CHANGED
|
@@ -17,7 +17,7 @@ var form = module.exports = forge.form = forge.form || {};
|
|
|
17
17
|
/**
|
|
18
18
|
* Regex for parsing a single name property (handles array brackets).
|
|
19
19
|
*/
|
|
20
|
-
var _regex = /(
|
|
20
|
+
var _regex = /([^\[]*?)\[(.*?)\]/g;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Parses a single name property into an array with the name and any
|
package/lib/index.js
CHANGED
package/lib/pkcs7.js
CHANGED
|
@@ -328,8 +328,11 @@ p7.createSignedData = function() {
|
|
|
328
328
|
|
|
329
329
|
/**
|
|
330
330
|
* Signs the content.
|
|
331
|
+
* @param options Options to apply when signing:
|
|
332
|
+
* [detached] boolean. If signing should be done in detached mode. Defaults to false.
|
|
331
333
|
*/
|
|
332
|
-
sign: function() {
|
|
334
|
+
sign: function(options) {
|
|
335
|
+
options = options || {};
|
|
333
336
|
// auto-generate content info
|
|
334
337
|
if(typeof msg.content !== 'object' || msg.contentInfo === null) {
|
|
335
338
|
// use Data ContentInfo
|
|
@@ -349,12 +352,16 @@ p7.createSignedData = function() {
|
|
|
349
352
|
content = forge.util.encodeUtf8(msg.content);
|
|
350
353
|
}
|
|
351
354
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
if (options.detached) {
|
|
356
|
+
msg.detachedContent = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, content);
|
|
357
|
+
} else {
|
|
358
|
+
msg.contentInfo.value.push(
|
|
359
|
+
// [0] EXPLICIT content
|
|
360
|
+
asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, [
|
|
361
|
+
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
|
|
362
|
+
content)
|
|
363
|
+
]));
|
|
364
|
+
}
|
|
358
365
|
}
|
|
359
366
|
}
|
|
360
367
|
|
|
@@ -437,10 +444,22 @@ p7.createSignedData = function() {
|
|
|
437
444
|
}
|
|
438
445
|
|
|
439
446
|
function addSignerInfos(mds) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
447
|
+
var content;
|
|
448
|
+
|
|
449
|
+
if (msg.detachedContent) {
|
|
450
|
+
// Signature has been made in detached mode.
|
|
451
|
+
content = msg.detachedContent;
|
|
452
|
+
} else {
|
|
453
|
+
// Note: ContentInfo is a SEQUENCE with 2 values, second value is
|
|
454
|
+
// the content field and is optional for a ContentInfo but required here
|
|
455
|
+
// since signers are present
|
|
456
|
+
// get ContentInfo content
|
|
457
|
+
content = msg.contentInfo.value[1];
|
|
458
|
+
// skip [0] EXPLICIT content wrapper
|
|
459
|
+
content = content.value[0];
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if(!content) {
|
|
444
463
|
throw new Error(
|
|
445
464
|
'Could not sign PKCS#7 message; there is no content to sign.');
|
|
446
465
|
}
|
|
@@ -448,11 +467,6 @@ p7.createSignedData = function() {
|
|
|
448
467
|
// get ContentInfo content type
|
|
449
468
|
var contentType = asn1.derToOid(msg.contentInfo.value[0].value);
|
|
450
469
|
|
|
451
|
-
// get ContentInfo content
|
|
452
|
-
var content = msg.contentInfo.value[1];
|
|
453
|
-
// skip [0] EXPLICIT content wrapper
|
|
454
|
-
content = content.value[0];
|
|
455
|
-
|
|
456
470
|
// serialize content
|
|
457
471
|
var bytes = asn1.toDer(content);
|
|
458
472
|
|
package/lib/util.js
CHANGED
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @author Dave Longley
|
|
5
5
|
*
|
|
6
|
-
* Copyright (c) 2010-
|
|
6
|
+
* Copyright (c) 2010-2018 Digital Bazaar, Inc.
|
|
7
7
|
*/
|
|
8
8
|
var forge = require('./forge');
|
|
9
|
+
var baseN = require('./baseN');
|
|
9
10
|
|
|
10
11
|
/* Utilities API */
|
|
11
12
|
var util = module.exports = forge.util = forge.util || {};
|
|
12
13
|
|
|
13
14
|
// define setImmediate and nextTick
|
|
14
15
|
(function() {
|
|
15
|
-
// use native nextTick
|
|
16
|
-
|
|
16
|
+
// use native nextTick (unless we're in webpack)
|
|
17
|
+
// webpack (or better node-libs-browser polyfill) sets process.browser.
|
|
18
|
+
// this way we can detect webpack properly
|
|
19
|
+
if(typeof process !== 'undefined' && process.nextTick && !process.browser) {
|
|
17
20
|
util.nextTick = process.nextTick;
|
|
18
21
|
if(typeof setImmediate === 'function') {
|
|
19
22
|
util.setImmediate = setImmediate;
|
|
@@ -159,14 +162,18 @@ function ByteStringBuffer(b) {
|
|
|
159
162
|
if(typeof b === 'string') {
|
|
160
163
|
this.data = b;
|
|
161
164
|
} else if(util.isArrayBuffer(b) || util.isArrayBufferView(b)) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
this.
|
|
165
|
+
if(typeof Buffer !== 'undefined' && b instanceof Buffer) {
|
|
166
|
+
this.data = b.toString('binary');
|
|
167
|
+
} else {
|
|
168
|
+
// convert native buffer to forge buffer
|
|
169
|
+
// FIXME: support native buffers internally instead
|
|
170
|
+
var arr = new Uint8Array(b);
|
|
171
|
+
try {
|
|
172
|
+
this.data = String.fromCharCode.apply(null, arr);
|
|
173
|
+
} catch(e) {
|
|
174
|
+
for(var i = 0; i < arr.length; ++i) {
|
|
175
|
+
this.putByte(arr[i]);
|
|
176
|
+
}
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
179
|
} else if(b instanceof ByteStringBuffer ||
|
|
@@ -1541,6 +1548,9 @@ var _base64Idx = [
|
|
|
1541
1548
|
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
|
1542
1549
|
];
|
|
1543
1550
|
|
|
1551
|
+
// base58 characters (Bitcoin alphabet)
|
|
1552
|
+
var _base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
1553
|
+
|
|
1544
1554
|
/**
|
|
1545
1555
|
* Base64 encodes a 'binary' encoded string of bytes.
|
|
1546
1556
|
*
|
|
@@ -1646,7 +1656,12 @@ util.decodeUtf8 = function(str) {
|
|
|
1646
1656
|
util.binary = {
|
|
1647
1657
|
raw: {},
|
|
1648
1658
|
hex: {},
|
|
1649
|
-
base64: {}
|
|
1659
|
+
base64: {},
|
|
1660
|
+
base58: {},
|
|
1661
|
+
baseN : {
|
|
1662
|
+
encode: baseN.encode,
|
|
1663
|
+
decode: baseN.decode
|
|
1664
|
+
}
|
|
1650
1665
|
};
|
|
1651
1666
|
|
|
1652
1667
|
/**
|
|
@@ -1803,9 +1818,15 @@ util.binary.base64.decode = function(input, output, offset) {
|
|
|
1803
1818
|
}
|
|
1804
1819
|
|
|
1805
1820
|
// make sure result is the exact decoded length
|
|
1806
|
-
return output ?
|
|
1807
|
-
|
|
1808
|
-
|
|
1821
|
+
return output ? (j - offset) : out.subarray(0, j);
|
|
1822
|
+
};
|
|
1823
|
+
|
|
1824
|
+
// add support for base58 encoding/decoding with Bitcoin alphabet
|
|
1825
|
+
util.binary.base58.encode = function(input, maxline) {
|
|
1826
|
+
return util.binary.baseN.encode(input, _base58, maxline);
|
|
1827
|
+
};
|
|
1828
|
+
util.binary.base58.decode = function(input, maxline) {
|
|
1829
|
+
return util.binary.baseN.decode(input, _base58, maxline);
|
|
1809
1830
|
};
|
|
1810
1831
|
|
|
1811
1832
|
// text encoding/decoding tools
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-forge",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
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": {
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"karma-sauce-launcher": "^1.2.0",
|
|
35
35
|
"karma-sourcemap-loader": "^0.3.7",
|
|
36
36
|
"karma-tap-reporter": "0.0.6",
|
|
37
|
-
"karma-webpack": "^2.0.
|
|
37
|
+
"karma-webpack": "^2.0.13",
|
|
38
38
|
"mocha": "^5.0.1",
|
|
39
39
|
"mocha-lcov-reporter": "^1.2.0",
|
|
40
40
|
"nodejs-websocket": "^1.7.1",
|
|
41
|
-
"nyc": "^11.
|
|
41
|
+
"nyc": "^11.5.0",
|
|
42
42
|
"opts": "^1.2.2",
|
|
43
43
|
"webpack": "^3.11.0"
|
|
44
44
|
},
|