node-forge 0.7.0 → 0.7.4

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/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 = /(.*?)\[(.*?)\]/g;
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
@@ -12,6 +12,7 @@ require('./asn1');
12
12
  require('./cipher');
13
13
  require('./debug');
14
14
  require('./des');
15
+ require('./ed25519');
15
16
  require('./hmac');
16
17
  require('./kem');
17
18
  require('./log');
package/lib/oids.js CHANGED
@@ -35,6 +35,8 @@ _IN('1.2.840.113549.1.1.11', 'sha256WithRSAEncryption');
35
35
  _IN('1.2.840.113549.1.1.12', 'sha384WithRSAEncryption');
36
36
  _IN('1.2.840.113549.1.1.13', 'sha512WithRSAEncryption');
37
37
 
38
+ _IN('1.2.840.10040.4.3', 'dsa-with-sha1');
39
+
38
40
  _IN('1.3.14.3.2.7', 'desCBC');
39
41
 
40
42
  _IN('1.3.14.3.2.26', 'sha1');
package/lib/pkcs7.js CHANGED
@@ -142,9 +142,11 @@ p7.createSignedData = function() {
142
142
  msg.contentInfo = null;
143
143
  msg.signerInfos = [];
144
144
 
145
- var certs = msg.rawCapture.certificates.value;
146
- for(var i = 0; i < certs.length; ++i) {
147
- msg.certificates.push(forge.pki.certificateFromAsn1(certs[i]));
145
+ if(msg.rawCapture.certificates) {
146
+ var certs = msg.rawCapture.certificates.value;
147
+ for(var i = 0; i < certs.length; ++i) {
148
+ msg.certificates.push(forge.pki.certificateFromAsn1(certs[i]));
149
+ }
148
150
  }
149
151
 
150
152
  // TODO: parse crls
package/lib/prng.js CHANGED
@@ -48,7 +48,9 @@ prng.create = function(plugin) {
48
48
  // number of reseeds so far
49
49
  reseeds: 0,
50
50
  // amount of data generated so far
51
- generated: 0
51
+ generated: 0,
52
+ // no initial key bytes
53
+ keyBytes: ''
52
54
  };
53
55
 
54
56
  // create 32 entropy pools (each is a message digest)
@@ -85,7 +87,11 @@ prng.create = function(plugin) {
85
87
  var formatSeed = ctx.plugin.formatSeed;
86
88
  var b = forge.util.createBuffer();
87
89
 
88
- // reset key for every request
90
+ // paranoid deviation from Fortuna:
91
+ // reset key for every request to protect previously
92
+ // generated random bytes should the key be discovered;
93
+ // there is no 100ms based reseeding because of this
94
+ // forced reseed for every `generate` call
89
95
  ctx.key = null;
90
96
 
91
97
  generate();
@@ -139,7 +145,11 @@ prng.create = function(plugin) {
139
145
  var formatKey = ctx.plugin.formatKey;
140
146
  var formatSeed = ctx.plugin.formatSeed;
141
147
 
142
- // reset key for every request
148
+ // paranoid deviation from Fortuna:
149
+ // reset key for every request to protect previously
150
+ // generated random bytes should the key be discovered;
151
+ // there is no 100ms based reseeding because of this
152
+ // forced reseed for every `generateSync` call
143
153
  ctx.key = null;
144
154
 
145
155
  var b = forge.util.createBuffer();
@@ -205,35 +215,44 @@ prng.create = function(plugin) {
205
215
  * Private function that seeds a generator once enough bytes are available.
206
216
  */
207
217
  function _seed() {
218
+ // update reseed count
219
+ ctx.reseeds = (ctx.reseeds === 0xffffffff) ? 0 : ctx.reseeds + 1;
220
+
221
+ // goal is to update `key` via:
222
+ // key = hash(key + s)
223
+ // where 's' is all collected entropy from selected pools, then...
224
+
208
225
  // create a plugin-based message digest
209
226
  var md = ctx.plugin.md.create();
210
227
 
211
- // digest pool 0's entropy and restart it
212
- md.update(ctx.pools[0].digest().getBytes());
213
- ctx.pools[0].start();
214
-
215
- // digest the entropy of other pools whose index k meet the
216
- // condition '2^k mod n == 0' where n is the number of reseeds
217
- var k = 1;
218
- for(var i = 1; i < 32; ++i) {
219
- // prevent signed numbers from being used
220
- k = (k === 31) ? 0x80000000 : (k << 2);
221
- if(k % ctx.reseeds === 0) {
222
- md.update(ctx.pools[i].digest().getBytes());
223
- ctx.pools[i].start();
228
+ // consume current key bytes
229
+ md.update(ctx.keyBytes);
230
+
231
+ // digest the entropy of pools whose index k meet the
232
+ // condition 'n mod 2^k == 0' where n is the number of reseeds
233
+ var _2powK = 1;
234
+ for(var k = 0; k < 32; ++k) {
235
+ if(ctx.reseeds % _2powK === 0) {
236
+ md.update(ctx.pools[k].digest().getBytes());
237
+ ctx.pools[k].start();
224
238
  }
239
+ _2powK = _2powK << 1;
225
240
  }
226
241
 
227
- // get digest for key bytes and iterate again for seed bytes
228
- var keyBytes = md.digest().getBytes();
242
+ // get digest for key bytes
243
+ ctx.keyBytes = md.digest().getBytes();
244
+
245
+ // paranoid deviation from Fortuna:
246
+ // update `seed` via `seed = hash(key)`
247
+ // instead of initializing to zero once and only
248
+ // ever incrementing it
229
249
  md.start();
230
- md.update(keyBytes);
250
+ md.update(ctx.keyBytes);
231
251
  var seedBytes = md.digest().getBytes();
232
252
 
233
- // update
234
- ctx.key = ctx.plugin.formatKey(keyBytes);
253
+ // update state
254
+ ctx.key = ctx.plugin.formatKey(ctx.keyBytes);
235
255
  ctx.seed = ctx.plugin.formatSeed(seedBytes);
236
- ctx.reseeds = (ctx.reseeds === 0xffffffff) ? 0 : ctx.reseeds + 1;
237
256
  ctx.generated = 0;
238
257
  }
239
258
 
package/lib/sha512.js CHANGED
@@ -79,12 +79,26 @@ sha512.create = function(algorithm) {
79
79
  _w[wi] = new Array(2);
80
80
  }
81
81
 
82
+ // determine digest length by algorithm name (default)
83
+ var digestLength = 64;
84
+ switch (algorithm) {
85
+ case 'SHA-384':
86
+ digestLength = 48;
87
+ break;
88
+ case 'SHA-512/256':
89
+ digestLength = 32;
90
+ break;
91
+ case 'SHA-512/224':
92
+ digestLength = 28;
93
+ break;
94
+ }
95
+
82
96
  // message digest object
83
97
  var md = {
84
98
  // SHA-512 => sha512
85
99
  algorithm: algorithm.replace('-', '').toLowerCase(),
86
100
  blockLength: 128,
87
- digestLength: 64,
101
+ digestLength: digestLength,
88
102
  // 56-bit length of message so far (does not including padding)
89
103
  messageLength: 0,
90
104
  // true message length
package/lib/util.js CHANGED
@@ -3,9 +3,10 @@
3
3
  *
4
4
  * @author Dave Longley
5
5
  *
6
- * Copyright (c) 2010-2014 Digital Bazaar, Inc.
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 || {};
@@ -159,14 +160,18 @@ function ByteStringBuffer(b) {
159
160
  if(typeof b === 'string') {
160
161
  this.data = b;
161
162
  } else if(util.isArrayBuffer(b) || util.isArrayBufferView(b)) {
162
- // convert native buffer to forge buffer
163
- // FIXME: support native buffers internally instead
164
- var arr = new Uint8Array(b);
165
- try {
166
- this.data = String.fromCharCode.apply(null, arr);
167
- } catch(e) {
168
- for(var i = 0; i < arr.length; ++i) {
169
- this.putByte(arr[i]);
163
+ if(typeof Buffer !== 'undefined' && b instanceof Buffer) {
164
+ this.data = b.toString('binary');
165
+ } else {
166
+ // convert native buffer to forge buffer
167
+ // FIXME: support native buffers internally instead
168
+ var arr = new Uint8Array(b);
169
+ try {
170
+ this.data = String.fromCharCode.apply(null, arr);
171
+ } catch(e) {
172
+ for(var i = 0; i < arr.length; ++i) {
173
+ this.putByte(arr[i]);
174
+ }
170
175
  }
171
176
  }
172
177
  } else if(b instanceof ByteStringBuffer ||
@@ -1541,6 +1546,9 @@ var _base64Idx = [
1541
1546
  39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
1542
1547
  ];
1543
1548
 
1549
+ // base58 characters (Bitcoin alphabet)
1550
+ var _base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
1551
+
1544
1552
  /**
1545
1553
  * Base64 encodes a 'binary' encoded string of bytes.
1546
1554
  *
@@ -1646,7 +1654,12 @@ util.decodeUtf8 = function(str) {
1646
1654
  util.binary = {
1647
1655
  raw: {},
1648
1656
  hex: {},
1649
- base64: {}
1657
+ base64: {},
1658
+ base58: {},
1659
+ baseN : {
1660
+ encode: baseN.encode,
1661
+ decode: baseN.decode
1662
+ }
1650
1663
  };
1651
1664
 
1652
1665
  /**
@@ -1803,9 +1816,15 @@ util.binary.base64.decode = function(input, output, offset) {
1803
1816
  }
1804
1817
 
1805
1818
  // make sure result is the exact decoded length
1806
- return output ?
1807
- (j - offset) :
1808
- out.subarray(0, j);
1819
+ return output ? (j - offset) : out.subarray(0, j);
1820
+ };
1821
+
1822
+ // add support for base58 encoding/decoding with Bitcoin alphabet
1823
+ util.binary.base58.encode = function(input, maxline) {
1824
+ return util.binary.baseN.encode(input, _base58, maxline);
1825
+ };
1826
+ util.binary.base58.decode = function(input, maxline) {
1827
+ return util.binary.baseN.decode(input, _base58, maxline);
1809
1828
  };
1810
1829
 
1811
1830
  // text encoding/decoding tools
package/lib/x509.js CHANGED
@@ -1085,6 +1085,9 @@ pki.createCertificate = function() {
1085
1085
  case 'sha256WithRSAEncryption':
1086
1086
  md = forge.md.sha256.create();
1087
1087
  break;
1088
+ case 'sha384WithRSAEncryption':
1089
+ md = forge.md.sha384.create();
1090
+ break;
1088
1091
  case 'sha512WithRSAEncryption':
1089
1092
  md = forge.md.sha512.create();
1090
1093
  break;
@@ -1340,6 +1343,9 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
1340
1343
  case 'sha256WithRSAEncryption':
1341
1344
  cert.md = forge.md.sha256.create();
1342
1345
  break;
1346
+ case 'sha384WithRSAEncryption':
1347
+ cert.md = forge.md.sha384.create();
1348
+ break;
1343
1349
  case 'sha512WithRSAEncryption':
1344
1350
  cert.md = forge.md.sha512.create();
1345
1351
  break;
@@ -1681,6 +1687,9 @@ pki.certificationRequestFromAsn1 = function(obj, computeHash) {
1681
1687
  case 'sha256WithRSAEncryption':
1682
1688
  csr.md = forge.md.sha256.create();
1683
1689
  break;
1690
+ case 'sha384WithRSAEncryption':
1691
+ csr.md = forge.md.sha384.create();
1692
+ break;
1684
1693
  case 'sha512WithRSAEncryption':
1685
1694
  csr.md = forge.md.sha512.create();
1686
1695
  break;
@@ -1848,6 +1857,9 @@ pki.createCertificationRequest = function() {
1848
1857
  case 'sha256WithRSAEncryption':
1849
1858
  md = forge.md.sha256.create();
1850
1859
  break;
1860
+ case 'sha384WithRSAEncryption':
1861
+ md = forge.md.sha384.create();
1862
+ break;
1851
1863
  case 'sha512WithRSAEncryption':
1852
1864
  md = forge.md.sha512.create();
1853
1865
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-forge",
3
- "version": "0.7.0",
3
+ "version": "0.7.4",
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": {
@@ -15,31 +15,32 @@
15
15
  "Christoph Dorn <christoph@christophdorn.com>"
16
16
  ],
17
17
  "devDependencies": {
18
- "browserify": "^13.1.1",
19
- "commander": "^2.9.0",
20
- "express": "^4.14.1",
21
- "istanbul": "^0.4.5",
18
+ "browserify": "^16.1.0",
19
+ "commander": "^2.14.1",
20
+ "cross-env": "^5.1.3",
21
+ "express": "^4.16.2",
22
22
  "jscs": "^3.0.7",
23
- "jshint": "^2.9.4",
24
- "karma": "^1.4.1",
25
- "karma-browserify": "^5.1.1",
26
- "karma-chrome-launcher": "^2.0.0",
27
- "karma-edge-launcher": "^0.2.0",
28
- "karma-firefox-launcher": "^1.0.0",
23
+ "jshint": "^2.9.5",
24
+ "karma": "^2.0.0",
25
+ "karma-browserify": "^5.2.0",
26
+ "karma-chrome-launcher": "^2.2.0",
27
+ "karma-edge-launcher": "^0.4.2",
28
+ "karma-firefox-launcher": "^1.1.0",
29
29
  "karma-ie-launcher": "^1.0.0",
30
30
  "karma-mocha": "^1.3.0",
31
- "karma-mocha-reporter": "^2.2.2",
31
+ "karma-mocha-reporter": "^2.2.5",
32
32
  "karma-phantomjs-launcher": "^1.0.2",
33
33
  "karma-safari-launcher": "^1.0.0",
34
- "karma-sauce-launcher": "^1.1.0",
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.2",
38
- "mocha": "^3.2.0",
37
+ "karma-webpack": "^2.0.13",
38
+ "mocha": "^5.0.1",
39
39
  "mocha-lcov-reporter": "^1.2.0",
40
40
  "nodejs-websocket": "^1.7.1",
41
+ "nyc": "^11.5.0",
41
42
  "opts": "^1.2.2",
42
- "webpack": "^2.2.0"
43
+ "webpack": "^3.11.0"
43
44
  },
44
45
  "repository": {
45
46
  "type": "git",
@@ -93,20 +94,24 @@
93
94
  "prepublish": "npm run build",
94
95
  "build": "webpack",
95
96
  "test-build": "webpack --config webpack-tests.config.js",
96
- "test": "mocha -t 30000 -R spec tests/unit/index.js",
97
+ "test": "cross-env NODE_ENV=test mocha -t 30000 -R ${REPORTER:-spec} tests/unit/index.js",
97
98
  "test-karma": "karma start",
98
99
  "test-karma-sauce": "karma start karma-sauce.conf",
99
100
  "test-server": "node tests/server.js",
100
101
  "test-server-ws": "node tests/websockets/server-ws.js",
101
102
  "test-server-webid": "node tests/websockets/server-webid.js",
102
- "coverage": "rm -rf coverage && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- -u exports -t 30000 -R spec tests/unit/index.js",
103
- "coverage-lcov": "rm -rf coverage && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -u exports -t 30000 -R spec tests/unit/index.js",
104
- "coverage-report": "./node_modules/.bin/istanbul report",
103
+ "coverage": "rm -rf coverage && nyc --reporter=lcov --reporter=text-summary npm test",
104
+ "coverage-report": "nyc report",
105
105
  "jscs": "jscs *.js lib/*.js tests/*.js tests/unit/*.js tests/legacy/*.js tests/issues/*.js tests/websockets/*.js",
106
106
  "jshint": "jshint *.js lib/*.js tests/unit/*.js tests/legacy/*.js tests/issues/*.js tests/websockets/*.js",
107
107
  "_jscs": "jscs *.js lib/*.js tests/*.js tests/unit/*.js tests/legacy/*.js tests/issues/*.js tests/websockets/*.js",
108
108
  "_jshint": "jshint *.js lib/*.js tests/*.js tests/unit/*.js tests/legacy/*.js tests/issues/*.js tests/websockets/*.js"
109
109
  },
110
+ "nyc": {
111
+ "exclude": [
112
+ "tests"
113
+ ]
114
+ },
110
115
  "jspm": {
111
116
  "format": "amd"
112
117
  },
@@ -1,28 +0,0 @@
1
- {
2
- "name": "node-forge-flash",
3
- "version": "0.0.0",
4
- "private": true,
5
- "description": "Flash build support for Forge.",
6
- "homepage": "https://github.com/digitalbazaar/forge",
7
- "author": {
8
- "name": "Digital Bazaar, Inc.",
9
- "email": "support@digitalbazaar.com",
10
- "url": "http://digitalbazaar.com/"
11
- },
12
- "devDependencies": {
13
- "flex-sdk": ""
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/digitalbazaar/forge"
18
- },
19
- "bugs": {
20
- "url": "https://github.com/digitalbazaar/forge/issues",
21
- "email": "support@digitalbazaar.com"
22
- },
23
- "license": "(BSD-3-Clause OR GPL-2.0)",
24
- "scripts": {
25
- "build": "mxmlc -debug=false -define=CONFIG::debugging,false -define=CONFIG::release,true -compiler.source-path=. -static-link-runtime-shared-libraries -output=swf/SocketPool.swf SocketPool.as",
26
- "build-debug": "mxmlc -debug=true -define=CONFIG::debugging,true -define=CONFIG::release,false -compiler.source-path=. -static-link-runtime-shared-libraries -output=swf/SocketPool.swf SocketPool.as"
27
- }
28
- }