node-forge 0.6.47 → 0.7.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 +106 -0
- package/LICENSE +3 -3
- package/README.md +254 -175
- package/dist/forge.all.min.js +11 -0
- package/dist/forge.all.min.js.map +1 -0
- package/dist/forge.min.js +10 -0
- package/dist/forge.min.js.map +1 -0
- package/dist/prime.worker.min.js +2 -0
- package/dist/prime.worker.min.js.map +1 -0
- package/flash/README.md +48 -0
- package/flash/package.json +28 -0
- package/flash/swf/SocketPool.swf +0 -0
- package/{js → lib}/aes.js +5 -61
- package/{js → lib}/aesCipherSuites.js +4 -58
- package/{js → lib}/asn1.js +371 -132
- package/{js → lib}/cipher.js +3 -59
- package/{js → lib}/cipherModes.js +3 -65
- package/{js → lib}/debug.js +2 -58
- package/{js → lib}/des.js +6 -63
- package/lib/forge.js +13 -0
- package/{js → lib}/form.js +5 -13
- package/{js → lib}/hmac.js +4 -58
- package/{js → lib}/http.js +15 -20
- package/lib/index.all.js +16 -0
- package/lib/index.js +34 -0
- package/{js → lib}/jsbn.js +3 -60
- package/{js → lib}/kem.js +5 -58
- package/{js → lib}/log.js +3 -58
- package/lib/md.all.js +13 -0
- package/lib/md.js +11 -0
- package/{js → lib}/md5.js +4 -60
- package/lib/mgf.js +12 -0
- package/lib/mgf1.js +57 -0
- package/lib/oids.js +159 -0
- package/{js → lib}/pbe.js +29 -79
- package/{js → lib}/pbkdf2.js +10 -64
- package/{js → lib}/pem.js +3 -58
- package/{js → lib}/pkcs1.js +6 -59
- package/{js → lib}/pkcs12.js +15 -74
- package/{js → lib}/pkcs7.js +12 -72
- package/{js → lib}/pkcs7asn1.js +4 -58
- package/{js → lib}/pki.js +12 -71
- package/{js → lib}/prime.js +18 -58
- package/{js → lib}/prime.worker.js +4 -1
- package/{js → lib}/prng.js +5 -62
- package/{js → lib}/pss.js +7 -61
- package/{js → lib}/random.js +11 -57
- package/{js → lib}/rc2.js +13 -73
- package/{js → lib}/rsa.js +13 -71
- package/{js → lib}/sha1.js +4 -60
- package/{js → lib}/sha256.js +4 -60
- package/{js → lib}/sha512.js +19 -61
- package/{js → lib}/socket.js +8 -63
- package/{js → lib}/ssh.js +7 -66
- package/{js → lib}/task.js +5 -58
- package/{js → lib}/tls.js +10 -67
- package/{js → lib}/tlssocket.js +6 -61
- package/{js → lib}/util.js +39 -68
- package/{js → lib}/x509.js +25 -102
- package/{js → lib}/xhr.js +12 -15
- package/package.json +58 -21
- package/js/forge.js +0 -94
- package/js/md.js +0 -75
- package/js/mgf.js +0 -67
- package/js/mgf1.js +0 -112
- package/js/oids.js +0 -288
- package/swf/SocketPool.swf +0 -0
package/{js → lib}/tls.js
RENAMED
|
@@ -230,9 +230,15 @@
|
|
|
230
230
|
* due to the large block size of existing MACs and the small size of the
|
|
231
231
|
* timing signal.
|
|
232
232
|
*/
|
|
233
|
-
(
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
var forge = require('./forge');
|
|
234
|
+
require('./asn1');
|
|
235
|
+
require('./hmac');
|
|
236
|
+
require('./md5');
|
|
237
|
+
require('./pem');
|
|
238
|
+
require('./pki');
|
|
239
|
+
require('./random');
|
|
240
|
+
require('./sha1');
|
|
241
|
+
require('./util');
|
|
236
242
|
|
|
237
243
|
/**
|
|
238
244
|
* Generates pseudo random bytes by mixing the result of two hash functions,
|
|
@@ -4145,7 +4151,7 @@ tls.createConnection = function(options) {
|
|
|
4145
4151
|
};
|
|
4146
4152
|
|
|
4147
4153
|
/* TLS API */
|
|
4148
|
-
forge.tls = forge.tls || {};
|
|
4154
|
+
module.exports = forge.tls = forge.tls || {};
|
|
4149
4155
|
|
|
4150
4156
|
// expose non-functions
|
|
4151
4157
|
for(var key in tls) {
|
|
@@ -4261,66 +4267,3 @@ forge.tls.createSessionCache = tls.createSessionCache;
|
|
|
4261
4267
|
* @return the new TLS connection.
|
|
4262
4268
|
*/
|
|
4263
4269
|
forge.tls.createConnection = tls.createConnection;
|
|
4264
|
-
|
|
4265
|
-
} // end module implementation
|
|
4266
|
-
|
|
4267
|
-
/* ########## Begin module wrapper ########## */
|
|
4268
|
-
var name = 'tls';
|
|
4269
|
-
if(typeof define !== 'function') {
|
|
4270
|
-
// NodeJS -> AMD
|
|
4271
|
-
if(typeof module === 'object' && module.exports) {
|
|
4272
|
-
var nodeJS = true;
|
|
4273
|
-
define = function(ids, factory) {
|
|
4274
|
-
factory(require, module);
|
|
4275
|
-
};
|
|
4276
|
-
} else {
|
|
4277
|
-
// <script>
|
|
4278
|
-
if(typeof forge === 'undefined') {
|
|
4279
|
-
forge = {};
|
|
4280
|
-
}
|
|
4281
|
-
return initModule(forge);
|
|
4282
|
-
}
|
|
4283
|
-
}
|
|
4284
|
-
// AMD
|
|
4285
|
-
var deps;
|
|
4286
|
-
var defineFunc = function(require, module) {
|
|
4287
|
-
module.exports = function(forge) {
|
|
4288
|
-
var mods = deps.map(function(dep) {
|
|
4289
|
-
return require(dep);
|
|
4290
|
-
}).concat(initModule);
|
|
4291
|
-
// handle circular dependencies
|
|
4292
|
-
forge = forge || {};
|
|
4293
|
-
forge.defined = forge.defined || {};
|
|
4294
|
-
if(forge.defined[name]) {
|
|
4295
|
-
return forge[name];
|
|
4296
|
-
}
|
|
4297
|
-
forge.defined[name] = true;
|
|
4298
|
-
for(var i = 0; i < mods.length; ++i) {
|
|
4299
|
-
mods[i](forge);
|
|
4300
|
-
}
|
|
4301
|
-
return forge[name];
|
|
4302
|
-
};
|
|
4303
|
-
};
|
|
4304
|
-
var tmpDefine = define;
|
|
4305
|
-
define = function(ids, factory) {
|
|
4306
|
-
deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
|
|
4307
|
-
if(nodeJS) {
|
|
4308
|
-
delete define;
|
|
4309
|
-
return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
4310
|
-
}
|
|
4311
|
-
define = tmpDefine;
|
|
4312
|
-
return define.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
4313
|
-
};
|
|
4314
|
-
define([
|
|
4315
|
-
'require',
|
|
4316
|
-
'module',
|
|
4317
|
-
'./asn1',
|
|
4318
|
-
'./hmac',
|
|
4319
|
-
'./md',
|
|
4320
|
-
'./pem',
|
|
4321
|
-
'./pki',
|
|
4322
|
-
'./random',
|
|
4323
|
-
'./util'], function() {
|
|
4324
|
-
defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
4325
|
-
});
|
|
4326
|
-
})();
|
package/{js → lib}/tlssocket.js
RENAMED
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2009-2012 Digital Bazaar, Inc.
|
|
7
7
|
*/
|
|
8
|
-
(
|
|
9
|
-
|
|
10
|
-
function initModule(forge) {
|
|
8
|
+
var forge = require('./forge');
|
|
9
|
+
require('./tls');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Wraps a forge.net socket with a TLS layer.
|
|
@@ -40,10 +39,10 @@ forge.tls.wrapSocket = function(options) {
|
|
|
40
39
|
var tlsSocket = {
|
|
41
40
|
id: socket.id,
|
|
42
41
|
// set handlers
|
|
43
|
-
connected: socket.connected || function(e){},
|
|
44
|
-
closed: socket.closed || function(e){},
|
|
45
|
-
data: socket.data || function(e){},
|
|
46
|
-
error: socket.error || function(e){}
|
|
42
|
+
connected: socket.connected || function(e) {},
|
|
43
|
+
closed: socket.closed || function(e) {},
|
|
44
|
+
data: socket.data || function(e) {},
|
|
45
|
+
error: socket.error || function(e) {}
|
|
47
46
|
};
|
|
48
47
|
|
|
49
48
|
// create TLS connection
|
|
@@ -248,57 +247,3 @@ forge.tls.wrapSocket = function(options) {
|
|
|
248
247
|
|
|
249
248
|
return tlsSocket;
|
|
250
249
|
};
|
|
251
|
-
|
|
252
|
-
} // end module implementation
|
|
253
|
-
|
|
254
|
-
/* ########## Begin module wrapper ########## */
|
|
255
|
-
var name = 'tlssocket';
|
|
256
|
-
if(typeof define !== 'function') {
|
|
257
|
-
// NodeJS -> AMD
|
|
258
|
-
if(typeof module === 'object' && module.exports) {
|
|
259
|
-
var nodeJS = true;
|
|
260
|
-
define = function(ids, factory) {
|
|
261
|
-
factory(require, module);
|
|
262
|
-
};
|
|
263
|
-
} else {
|
|
264
|
-
// <script>
|
|
265
|
-
if(typeof forge === 'undefined') {
|
|
266
|
-
forge = {};
|
|
267
|
-
}
|
|
268
|
-
return initModule(forge);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
// AMD
|
|
272
|
-
var deps;
|
|
273
|
-
var defineFunc = function(require, module) {
|
|
274
|
-
module.exports = function(forge) {
|
|
275
|
-
var mods = deps.map(function(dep) {
|
|
276
|
-
return require(dep);
|
|
277
|
-
}).concat(initModule);
|
|
278
|
-
// handle circular dependencies
|
|
279
|
-
forge = forge || {};
|
|
280
|
-
forge.defined = forge.defined || {};
|
|
281
|
-
if(forge.defined[name]) {
|
|
282
|
-
return forge[name];
|
|
283
|
-
}
|
|
284
|
-
forge.defined[name] = true;
|
|
285
|
-
for(var i = 0; i < mods.length; ++i) {
|
|
286
|
-
mods[i](forge);
|
|
287
|
-
}
|
|
288
|
-
return forge[name];
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
var tmpDefine = define;
|
|
292
|
-
define = function(ids, factory) {
|
|
293
|
-
deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
|
|
294
|
-
if(nodeJS) {
|
|
295
|
-
delete define;
|
|
296
|
-
return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
297
|
-
}
|
|
298
|
-
define = tmpDefine;
|
|
299
|
-
return define.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
300
|
-
};
|
|
301
|
-
define(['require', 'module', './tls'], function() {
|
|
302
|
-
defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
303
|
-
});
|
|
304
|
-
})();
|
package/{js → lib}/util.js
RENAMED
|
@@ -5,12 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2010-2014 Digital Bazaar, Inc.
|
|
7
7
|
*/
|
|
8
|
-
(
|
|
9
|
-
/* ########## Begin module implementation ########## */
|
|
10
|
-
function initModule(forge) {
|
|
8
|
+
var forge = require('./forge');
|
|
11
9
|
|
|
12
10
|
/* Utilities API */
|
|
13
|
-
var util = forge.util = forge.util || {};
|
|
11
|
+
var util = module.exports = forge.util = forge.util || {};
|
|
14
12
|
|
|
15
13
|
// define setImmediate and nextTick
|
|
16
14
|
(function() {
|
|
@@ -105,6 +103,10 @@ var util = forge.util = forge.util || {};
|
|
|
105
103
|
util.nextTick = util.setImmediate;
|
|
106
104
|
})();
|
|
107
105
|
|
|
106
|
+
// check if running under Node.js
|
|
107
|
+
util.isNodejs =
|
|
108
|
+
typeof process !== 'undefined' && process.versions && process.versions.node;
|
|
109
|
+
|
|
108
110
|
// define isArray
|
|
109
111
|
util.isArray = Array.isArray || function(x) {
|
|
110
112
|
return Object.prototype.toString.call(x) === '[object Array]';
|
|
@@ -120,6 +122,21 @@ util.isArrayBufferView = function(x) {
|
|
|
120
122
|
return x && util.isArrayBuffer(x.buffer) && x.byteLength !== undefined;
|
|
121
123
|
};
|
|
122
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Ensure a bits param is 8, 16, 24, or 32. Used to validate input for
|
|
127
|
+
* algorithms where bit manipulation, JavaScript limitations, and/or algorithm
|
|
128
|
+
* design only allow for byte operations of a limited size.
|
|
129
|
+
*
|
|
130
|
+
* @param n number of bits.
|
|
131
|
+
*
|
|
132
|
+
* Throw Error if n invalid.
|
|
133
|
+
*/
|
|
134
|
+
function _checkBitsParam(n) {
|
|
135
|
+
if(!(n === 8 || n === 16 || n === 24 || n === 32)) {
|
|
136
|
+
throw new Error('Only 8, 16, 24, or 32 bits supported: ' + n);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
123
140
|
// TODO: set ByteBuffer to best available backing
|
|
124
141
|
util.ByteBuffer = ByteStringBuffer;
|
|
125
142
|
|
|
@@ -351,11 +368,12 @@ util.ByteStringBuffer.prototype.putInt32Le = function(i) {
|
|
|
351
368
|
* Puts an n-bit integer in this buffer in big-endian order.
|
|
352
369
|
*
|
|
353
370
|
* @param i the n-bit integer.
|
|
354
|
-
* @param n the number of bits in the integer.
|
|
371
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
355
372
|
*
|
|
356
373
|
* @return this buffer.
|
|
357
374
|
*/
|
|
358
375
|
util.ByteStringBuffer.prototype.putInt = function(i, n) {
|
|
376
|
+
_checkBitsParam(n);
|
|
359
377
|
var bytes = '';
|
|
360
378
|
do {
|
|
361
379
|
n -= 8;
|
|
@@ -369,11 +387,12 @@ util.ByteStringBuffer.prototype.putInt = function(i, n) {
|
|
|
369
387
|
* complement representation is used.
|
|
370
388
|
*
|
|
371
389
|
* @param i the n-bit integer.
|
|
372
|
-
* @param n the number of bits in the integer.
|
|
390
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
373
391
|
*
|
|
374
392
|
* @return this buffer.
|
|
375
393
|
*/
|
|
376
394
|
util.ByteStringBuffer.prototype.putSignedInt = function(i, n) {
|
|
395
|
+
// putInt checks n
|
|
377
396
|
if(i < 0) {
|
|
378
397
|
i += 2 << (n - 1);
|
|
379
398
|
}
|
|
@@ -492,15 +511,17 @@ util.ByteStringBuffer.prototype.getInt32Le = function() {
|
|
|
492
511
|
|
|
493
512
|
/**
|
|
494
513
|
* Gets an n-bit integer from this buffer in big-endian order and advances the
|
|
495
|
-
* read pointer by n/8.
|
|
514
|
+
* read pointer by ceil(n/8).
|
|
496
515
|
*
|
|
497
|
-
* @param n the number of bits in the integer.
|
|
516
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
498
517
|
*
|
|
499
518
|
* @return the integer.
|
|
500
519
|
*/
|
|
501
520
|
util.ByteStringBuffer.prototype.getInt = function(n) {
|
|
521
|
+
_checkBitsParam(n);
|
|
502
522
|
var rval = 0;
|
|
503
523
|
do {
|
|
524
|
+
// TODO: Use (rval * 0x100) if adding support for 33 to 53 bits.
|
|
504
525
|
rval = (rval << 8) + this.data.charCodeAt(this.read++);
|
|
505
526
|
n -= 8;
|
|
506
527
|
} while(n > 0);
|
|
@@ -511,11 +532,12 @@ util.ByteStringBuffer.prototype.getInt = function(n) {
|
|
|
511
532
|
* Gets a signed n-bit integer from this buffer in big-endian order, using
|
|
512
533
|
* two's complement, and advances the read pointer by n/8.
|
|
513
534
|
*
|
|
514
|
-
* @param n the number of bits in the integer.
|
|
535
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
515
536
|
*
|
|
516
537
|
* @return the integer.
|
|
517
538
|
*/
|
|
518
539
|
util.ByteStringBuffer.prototype.getSignedInt = function(n) {
|
|
540
|
+
// getInt checks n
|
|
519
541
|
var x = this.getInt(n);
|
|
520
542
|
var max = 2 << (n - 2);
|
|
521
543
|
if(x >= max) {
|
|
@@ -674,7 +696,6 @@ util.ByteStringBuffer.prototype.toString = function() {
|
|
|
674
696
|
|
|
675
697
|
/** End Buffer w/BinaryString backing */
|
|
676
698
|
|
|
677
|
-
|
|
678
699
|
/** Buffer w/UInt8Array backing */
|
|
679
700
|
|
|
680
701
|
/**
|
|
@@ -1032,11 +1053,12 @@ util.DataBuffer.prototype.putInt32Le = function(i) {
|
|
|
1032
1053
|
* Puts an n-bit integer in this buffer in big-endian order.
|
|
1033
1054
|
*
|
|
1034
1055
|
* @param i the n-bit integer.
|
|
1035
|
-
* @param n the number of bits in the integer.
|
|
1056
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
1036
1057
|
*
|
|
1037
1058
|
* @return this buffer.
|
|
1038
1059
|
*/
|
|
1039
1060
|
util.DataBuffer.prototype.putInt = function(i, n) {
|
|
1061
|
+
_checkBitsParam(n);
|
|
1040
1062
|
this.accommodate(n / 8);
|
|
1041
1063
|
do {
|
|
1042
1064
|
n -= 8;
|
|
@@ -1055,6 +1077,7 @@ util.DataBuffer.prototype.putInt = function(i, n) {
|
|
|
1055
1077
|
* @return this buffer.
|
|
1056
1078
|
*/
|
|
1057
1079
|
util.DataBuffer.prototype.putSignedInt = function(i, n) {
|
|
1080
|
+
_checkBitsParam(n);
|
|
1058
1081
|
this.accommodate(n / 8);
|
|
1059
1082
|
if(i < 0) {
|
|
1060
1083
|
i += 2 << (n - 1);
|
|
@@ -1151,13 +1174,15 @@ util.DataBuffer.prototype.getInt32Le = function() {
|
|
|
1151
1174
|
* Gets an n-bit integer from this buffer in big-endian order and advances the
|
|
1152
1175
|
* read pointer by n/8.
|
|
1153
1176
|
*
|
|
1154
|
-
* @param n the number of bits in the integer.
|
|
1177
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
1155
1178
|
*
|
|
1156
1179
|
* @return the integer.
|
|
1157
1180
|
*/
|
|
1158
1181
|
util.DataBuffer.prototype.getInt = function(n) {
|
|
1182
|
+
_checkBitsParam(n);
|
|
1159
1183
|
var rval = 0;
|
|
1160
1184
|
do {
|
|
1185
|
+
// TODO: Use (rval * 0x100) if adding support for 33 to 53 bits.
|
|
1161
1186
|
rval = (rval << 8) + this.data.getInt8(this.read++);
|
|
1162
1187
|
n -= 8;
|
|
1163
1188
|
} while(n > 0);
|
|
@@ -1168,11 +1193,12 @@ util.DataBuffer.prototype.getInt = function(n) {
|
|
|
1168
1193
|
* Gets a signed n-bit integer from this buffer in big-endian order, using
|
|
1169
1194
|
* two's complement, and advances the read pointer by n/8.
|
|
1170
1195
|
*
|
|
1171
|
-
* @param n the number of bits in the integer.
|
|
1196
|
+
* @param n the number of bits in the integer (8, 16, 24, or 32).
|
|
1172
1197
|
*
|
|
1173
1198
|
* @return the integer.
|
|
1174
1199
|
*/
|
|
1175
1200
|
util.DataBuffer.prototype.getSignedInt = function(n) {
|
|
1201
|
+
// getInt checks n
|
|
1176
1202
|
var x = this.getInt(n);
|
|
1177
1203
|
var max = 2 << (n - 2);
|
|
1178
1204
|
if(x >= max) {
|
|
@@ -1360,7 +1386,6 @@ util.DataBuffer.prototype.toString = function(encoding) {
|
|
|
1360
1386
|
|
|
1361
1387
|
/** End Buffer w/UInt8Array backing */
|
|
1362
1388
|
|
|
1363
|
-
|
|
1364
1389
|
/**
|
|
1365
1390
|
* Creates a buffer that stores bytes. A value may be given to put into the
|
|
1366
1391
|
* buffer that is either a string of bytes or a UTF-16 string that will
|
|
@@ -2932,57 +2957,3 @@ util.estimateCores = function(options, callback) {
|
|
|
2932
2957
|
}, 0);
|
|
2933
2958
|
}
|
|
2934
2959
|
};
|
|
2935
|
-
|
|
2936
|
-
} // end module implementation
|
|
2937
|
-
|
|
2938
|
-
/* ########## Begin module wrapper ########## */
|
|
2939
|
-
var name = 'util';
|
|
2940
|
-
if(typeof define !== 'function') {
|
|
2941
|
-
// NodeJS -> AMD
|
|
2942
|
-
if(typeof module === 'object' && module.exports) {
|
|
2943
|
-
var nodeJS = true;
|
|
2944
|
-
define = function(ids, factory) {
|
|
2945
|
-
factory(require, module);
|
|
2946
|
-
};
|
|
2947
|
-
} else {
|
|
2948
|
-
// <script>
|
|
2949
|
-
if(typeof forge === 'undefined') {
|
|
2950
|
-
forge = {};
|
|
2951
|
-
}
|
|
2952
|
-
return initModule(forge);
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
// AMD
|
|
2956
|
-
var deps;
|
|
2957
|
-
var defineFunc = function(require, module) {
|
|
2958
|
-
module.exports = function(forge) {
|
|
2959
|
-
var mods = deps.map(function(dep) {
|
|
2960
|
-
return require(dep);
|
|
2961
|
-
}).concat(initModule);
|
|
2962
|
-
// handle circular dependencies
|
|
2963
|
-
forge = forge || {};
|
|
2964
|
-
forge.defined = forge.defined || {};
|
|
2965
|
-
if(forge.defined[name]) {
|
|
2966
|
-
return forge[name];
|
|
2967
|
-
}
|
|
2968
|
-
forge.defined[name] = true;
|
|
2969
|
-
for(var i = 0; i < mods.length; ++i) {
|
|
2970
|
-
mods[i](forge);
|
|
2971
|
-
}
|
|
2972
|
-
return forge[name];
|
|
2973
|
-
};
|
|
2974
|
-
};
|
|
2975
|
-
var tmpDefine = define;
|
|
2976
|
-
define = function(ids, factory) {
|
|
2977
|
-
deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
|
|
2978
|
-
if(nodeJS) {
|
|
2979
|
-
delete define;
|
|
2980
|
-
return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
2981
|
-
}
|
|
2982
|
-
define = tmpDefine;
|
|
2983
|
-
return define.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
2984
|
-
};
|
|
2985
|
-
define(['require', 'module'], function() {
|
|
2986
|
-
defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
2987
|
-
});
|
|
2988
|
-
})();
|
package/{js → lib}/x509.js
RENAMED
|
@@ -107,15 +107,23 @@
|
|
|
107
107
|
* signature BIT STRING
|
|
108
108
|
* }
|
|
109
109
|
*/
|
|
110
|
-
(
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
var forge = require('./forge');
|
|
111
|
+
require('./aes');
|
|
112
|
+
require('./asn1');
|
|
113
|
+
require('./des');
|
|
114
|
+
require('./md');
|
|
115
|
+
require('./mgf');
|
|
116
|
+
require('./oids');
|
|
117
|
+
require('./pem');
|
|
118
|
+
require('./pss');
|
|
119
|
+
require('./rsa');
|
|
120
|
+
require('./util');
|
|
113
121
|
|
|
114
122
|
// shortcut for asn.1 API
|
|
115
123
|
var asn1 = forge.asn1;
|
|
116
124
|
|
|
117
125
|
/* Public Key Infrastructure (PKI) implementation. */
|
|
118
|
-
var pki = forge.pki = forge.pki || {};
|
|
126
|
+
var pki = module.exports = forge.pki = forge.pki || {};
|
|
119
127
|
var oids = pki.oids;
|
|
120
128
|
|
|
121
129
|
// short name OID mappings
|
|
@@ -257,7 +265,8 @@ var x509CertificateValidator = {
|
|
|
257
265
|
tagClass: asn1.Class.UNIVERSAL,
|
|
258
266
|
type: asn1.Type.BITSTRING,
|
|
259
267
|
constructed: false,
|
|
260
|
-
|
|
268
|
+
// TODO: support arbitrary bit length ids
|
|
269
|
+
captureBitStringValue: 'certIssuerUniqueId'
|
|
261
270
|
}]
|
|
262
271
|
}, {
|
|
263
272
|
// subjectUniqueID (optional)
|
|
@@ -271,7 +280,8 @@ var x509CertificateValidator = {
|
|
|
271
280
|
tagClass: asn1.Class.UNIVERSAL,
|
|
272
281
|
type: asn1.Type.BITSTRING,
|
|
273
282
|
constructed: false,
|
|
274
|
-
|
|
283
|
+
// TODO: support arbitrary bit length ids
|
|
284
|
+
captureBitStringValue: 'certSubjectUniqueId'
|
|
275
285
|
}]
|
|
276
286
|
}, {
|
|
277
287
|
// Extensions (optional)
|
|
@@ -307,7 +317,7 @@ var x509CertificateValidator = {
|
|
|
307
317
|
tagClass: asn1.Class.UNIVERSAL,
|
|
308
318
|
type: asn1.Type.BITSTRING,
|
|
309
319
|
constructed: false,
|
|
310
|
-
|
|
320
|
+
captureBitStringValue: 'certSignature'
|
|
311
321
|
}]
|
|
312
322
|
};
|
|
313
323
|
|
|
@@ -478,7 +488,7 @@ var certificationRequestValidator = {
|
|
|
478
488
|
tagClass: asn1.Class.UNIVERSAL,
|
|
479
489
|
type: asn1.Type.BITSTRING,
|
|
480
490
|
constructed: false,
|
|
481
|
-
|
|
491
|
+
captureBitStringValue: 'csrSignature'
|
|
482
492
|
}]
|
|
483
493
|
};
|
|
484
494
|
|
|
@@ -947,6 +957,7 @@ pki.createCertificate = function() {
|
|
|
947
957
|
cert.subject.attributes = attrs;
|
|
948
958
|
delete cert.subject.uniqueId;
|
|
949
959
|
if(uniqueId) {
|
|
960
|
+
// TODO: support arbitrary bit length ids
|
|
950
961
|
cert.subject.uniqueId = uniqueId;
|
|
951
962
|
}
|
|
952
963
|
cert.subject.hash = null;
|
|
@@ -964,6 +975,7 @@ pki.createCertificate = function() {
|
|
|
964
975
|
cert.issuer.attributes = attrs;
|
|
965
976
|
delete cert.issuer.uniqueId;
|
|
966
977
|
if(uniqueId) {
|
|
978
|
+
// TODO: support arbitrary bit length ids
|
|
967
979
|
cert.issuer.uniqueId = uniqueId;
|
|
968
980
|
}
|
|
969
981
|
cert.issuer.hash = null;
|
|
@@ -1264,18 +1276,9 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
|
|
|
1264
1276
|
throw error;
|
|
1265
1277
|
}
|
|
1266
1278
|
|
|
1267
|
-
// ensure signature is not interpreted as an embedded ASN.1 object
|
|
1268
|
-
if(typeof capture.certSignature !== 'string') {
|
|
1269
|
-
var certSignature = '\x00';
|
|
1270
|
-
for(var i = 0; i < capture.certSignature.length; ++i) {
|
|
1271
|
-
certSignature += asn1.toDer(capture.certSignature[i]).getBytes();
|
|
1272
|
-
}
|
|
1273
|
-
capture.certSignature = certSignature;
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
1279
|
// get oid
|
|
1277
1280
|
var oid = asn1.derToOid(capture.publicKeyOid);
|
|
1278
|
-
if(oid !== pki.oids
|
|
1281
|
+
if(oid !== pki.oids.rsaEncryption) {
|
|
1279
1282
|
throw new Error('Cannot read public key. OID is not RSA.');
|
|
1280
1283
|
}
|
|
1281
1284
|
|
|
@@ -1291,10 +1294,7 @@ pki.certificateFromAsn1 = function(obj, computeHash) {
|
|
|
1291
1294
|
cert.siginfo.algorithmOid = forge.asn1.derToOid(capture.certinfoSignatureOid);
|
|
1292
1295
|
cert.siginfo.parameters = _readSignatureParameters(cert.siginfo.algorithmOid,
|
|
1293
1296
|
capture.certinfoSignatureParams, false);
|
|
1294
|
-
|
|
1295
|
-
var signature = forge.util.createBuffer(capture.certSignature);
|
|
1296
|
-
++signature.read;
|
|
1297
|
-
cert.signature = signature.getBytes();
|
|
1297
|
+
cert.signature = capture.certSignature;
|
|
1298
1298
|
|
|
1299
1299
|
var validity = [];
|
|
1300
1300
|
if(capture.certValidity1UTCTime !== undefined) {
|
|
@@ -1646,15 +1646,6 @@ pki.certificationRequestFromAsn1 = function(obj, computeHash) {
|
|
|
1646
1646
|
throw error;
|
|
1647
1647
|
}
|
|
1648
1648
|
|
|
1649
|
-
// ensure signature is not interpreted as an embedded ASN.1 object
|
|
1650
|
-
if(typeof capture.csrSignature !== 'string') {
|
|
1651
|
-
var csrSignature = '\x00';
|
|
1652
|
-
for(var i = 0; i < capture.csrSignature.length; ++i) {
|
|
1653
|
-
csrSignature += asn1.toDer(capture.csrSignature[i]).getBytes();
|
|
1654
|
-
}
|
|
1655
|
-
capture.csrSignature = csrSignature;
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
1649
|
// get oid
|
|
1659
1650
|
var oid = asn1.derToOid(capture.publicKeyOid);
|
|
1660
1651
|
if(oid !== pki.oids.rsaEncryption) {
|
|
@@ -1670,10 +1661,7 @@ pki.certificationRequestFromAsn1 = function(obj, computeHash) {
|
|
|
1670
1661
|
csr.siginfo.algorithmOid = forge.asn1.derToOid(capture.csrSignatureOid);
|
|
1671
1662
|
csr.siginfo.parameters = _readSignatureParameters(
|
|
1672
1663
|
csr.siginfo.algorithmOid, capture.csrSignatureParams, false);
|
|
1673
|
-
|
|
1674
|
-
var signature = forge.util.createBuffer(capture.csrSignature);
|
|
1675
|
-
++signature.read;
|
|
1676
|
-
csr.signature = signature.getBytes();
|
|
1664
|
+
csr.signature = capture.csrSignature;
|
|
1677
1665
|
|
|
1678
1666
|
// keep CertificationRequestInfo to preserve signature when exporting
|
|
1679
1667
|
csr.certificationRequestInfo = capture.certificationRequestInfo;
|
|
@@ -2515,6 +2503,7 @@ pki.getTBSCertificate = function(cert) {
|
|
|
2515
2503
|
tbs.value.push(
|
|
2516
2504
|
asn1.create(asn1.Class.CONTEXT_SPECIFIC, 1, true, [
|
|
2517
2505
|
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false,
|
|
2506
|
+
// TODO: support arbitrary bit length ids
|
|
2518
2507
|
String.fromCharCode(0x00) +
|
|
2519
2508
|
cert.issuer.uniqueId
|
|
2520
2509
|
)
|
|
@@ -2526,6 +2515,7 @@ pki.getTBSCertificate = function(cert) {
|
|
|
2526
2515
|
tbs.value.push(
|
|
2527
2516
|
asn1.create(asn1.Class.CONTEXT_SPECIFIC, 2, true, [
|
|
2528
2517
|
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false,
|
|
2518
|
+
// TODO: support arbitrary bit length ids
|
|
2529
2519
|
String.fromCharCode(0x00) +
|
|
2530
2520
|
cert.subject.uniqueId
|
|
2531
2521
|
)
|
|
@@ -3267,70 +3257,3 @@ pki.verifyCertificateChain = function(caStore, chain, verify) {
|
|
|
3267
3257
|
|
|
3268
3258
|
return true;
|
|
3269
3259
|
};
|
|
3270
|
-
|
|
3271
|
-
} // end module implementation
|
|
3272
|
-
|
|
3273
|
-
/* ########## Begin module wrapper ########## */
|
|
3274
|
-
var name = 'x509';
|
|
3275
|
-
if(typeof define !== 'function') {
|
|
3276
|
-
// NodeJS -> AMD
|
|
3277
|
-
if(typeof module === 'object' && module.exports) {
|
|
3278
|
-
var nodeJS = true;
|
|
3279
|
-
define = function(ids, factory) {
|
|
3280
|
-
factory(require, module);
|
|
3281
|
-
};
|
|
3282
|
-
} else {
|
|
3283
|
-
// <script>
|
|
3284
|
-
if(typeof forge === 'undefined') {
|
|
3285
|
-
forge = {};
|
|
3286
|
-
}
|
|
3287
|
-
return initModule(forge);
|
|
3288
|
-
}
|
|
3289
|
-
}
|
|
3290
|
-
// AMD
|
|
3291
|
-
var deps;
|
|
3292
|
-
var defineFunc = function(require, module) {
|
|
3293
|
-
module.exports = function(forge) {
|
|
3294
|
-
var mods = deps.map(function(dep) {
|
|
3295
|
-
return require(dep);
|
|
3296
|
-
}).concat(initModule);
|
|
3297
|
-
// handle circular dependencies
|
|
3298
|
-
forge = forge || {};
|
|
3299
|
-
forge.defined = forge.defined || {};
|
|
3300
|
-
if(forge.defined[name]) {
|
|
3301
|
-
return forge[name];
|
|
3302
|
-
}
|
|
3303
|
-
forge.defined[name] = true;
|
|
3304
|
-
for(var i = 0; i < mods.length; ++i) {
|
|
3305
|
-
mods[i](forge);
|
|
3306
|
-
}
|
|
3307
|
-
return forge.pki;
|
|
3308
|
-
};
|
|
3309
|
-
};
|
|
3310
|
-
var tmpDefine = define;
|
|
3311
|
-
define = function(ids, factory) {
|
|
3312
|
-
deps = (typeof ids === 'string') ? factory.slice(2) : ids.slice(2);
|
|
3313
|
-
if(nodeJS) {
|
|
3314
|
-
delete define;
|
|
3315
|
-
return tmpDefine.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
3316
|
-
}
|
|
3317
|
-
define = tmpDefine;
|
|
3318
|
-
return define.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
3319
|
-
};
|
|
3320
|
-
define([
|
|
3321
|
-
'require',
|
|
3322
|
-
'module',
|
|
3323
|
-
'./aes',
|
|
3324
|
-
'./asn1',
|
|
3325
|
-
'./des',
|
|
3326
|
-
'./md',
|
|
3327
|
-
'./mgf',
|
|
3328
|
-
'./oids',
|
|
3329
|
-
'./pem',
|
|
3330
|
-
'./pss',
|
|
3331
|
-
'./rsa',
|
|
3332
|
-
'./util'
|
|
3333
|
-
], function() {
|
|
3334
|
-
defineFunc.apply(null, Array.prototype.slice.call(arguments, 0));
|
|
3335
|
-
});
|
|
3336
|
-
})();
|
package/{js → lib}/xhr.js
RENAMED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2010-2013 Digital Bazaar, Inc.
|
|
7
7
|
*/
|
|
8
|
+
var forge = require('./forge');
|
|
9
|
+
require('./socket');
|
|
10
|
+
require('./http');
|
|
11
|
+
|
|
12
|
+
/* XHR API */
|
|
13
|
+
var xhrApi = module.exports = forge.xhr = forge.xhr || {};
|
|
14
|
+
|
|
8
15
|
(function($) {
|
|
9
16
|
|
|
10
17
|
// logging category
|
|
@@ -80,16 +87,9 @@ var _clients = {};
|
|
|
80
87
|
// the default maximum number of concurrents connections per client
|
|
81
88
|
var _maxConnections = 10;
|
|
82
89
|
|
|
83
|
-
// local aliases
|
|
84
|
-
if(typeof forge === 'undefined') {
|
|
85
|
-
forge = {};
|
|
86
|
-
}
|
|
87
90
|
var net = forge.net;
|
|
88
91
|
var http = forge.http;
|
|
89
92
|
|
|
90
|
-
// define the xhr interface
|
|
91
|
-
var xhrApi = {};
|
|
92
|
-
|
|
93
93
|
/**
|
|
94
94
|
* Initializes flash XHR support.
|
|
95
95
|
*
|
|
@@ -328,10 +328,10 @@ xhrApi.create = function(options) {
|
|
|
328
328
|
options = $.extend({
|
|
329
329
|
logWarningOnError: true,
|
|
330
330
|
verbose: false,
|
|
331
|
-
logError: function(){},
|
|
332
|
-
logWarning: function(){},
|
|
333
|
-
logDebug: function(){},
|
|
334
|
-
logVerbose: function(){},
|
|
331
|
+
logError: function() {},
|
|
332
|
+
logWarning: function() {},
|
|
333
|
+
logDebug: function() {},
|
|
334
|
+
logVerbose: function() {},
|
|
335
335
|
url: null
|
|
336
336
|
}, options || {});
|
|
337
337
|
|
|
@@ -446,7 +446,7 @@ xhrApi.create = function(options) {
|
|
|
446
446
|
case 'TRACK':
|
|
447
447
|
throw new Error('CONNECT, TRACE and TRACK methods are disallowed');
|
|
448
448
|
default:
|
|
449
|
-
throw new Error('Invalid method: ' + method)
|
|
449
|
+
throw new Error('Invalid method: ' + method);
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
// TODO: other validation steps in algorithm are not implemented
|
|
@@ -733,7 +733,4 @@ xhrApi.create = function(options) {
|
|
|
733
733
|
return xhr;
|
|
734
734
|
};
|
|
735
735
|
|
|
736
|
-
// expose public api
|
|
737
|
-
forge.xhr = xhrApi;
|
|
738
|
-
|
|
739
736
|
})(jQuery);
|