node-forge 0.2.20 → 0.2.24

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/README.md CHANGED
@@ -13,7 +13,131 @@ The Forge software is a fully native implementation of the [TLS][] protocol in
13
13
  JavaScript as well as a set of tools for developing Web Apps that utilize many
14
14
  network resources.
15
15
 
16
+ ## Getting Started
17
+ ------------------
18
+
19
+ ### Node.js ###
20
+
21
+ If you want to use forge with [node.js][], it is available through `npm`:
22
+
23
+ https://npmjs.org/package/node-forge
24
+
25
+ Installation:
26
+
27
+ npm install node-forge
28
+
29
+ You can then use forge as a regular module:
30
+
31
+ var forge = require('node-forge');
32
+
33
+ ### Requirements ###
34
+
35
+ * General
36
+ * Optional: GNU autotools for the build infrastructure if using Flash.
37
+ * Building a Browser Bundle:
38
+ * nodejs
39
+ * npm
40
+ * Testing
41
+ * nodejs
42
+ * Optional: Python and OpenSSL development environment to build
43
+ * a special SSL module with session cache support for testing with flash.
44
+ * http://www.python.org/dev/
45
+ * http://www.openssl.org/
46
+ * Debian users should install python-dev and libssl-dev.
47
+ * Optional: Flash
48
+ * A pre-built SocketPool.swf is included.
49
+ * Adobe Flex 3 SDK to build the Flash socket code.
50
+ * http://opensource.adobe.com/wiki/display/flexsdk/
51
+
52
+ ### Building a browser bundle ###
53
+
54
+ To create a minimized JavaScript bundle, run the following:
55
+
56
+ ```
57
+ npm install
58
+ npm run minify
59
+ ```
60
+
61
+ This will create a single minimized file that can be included in
62
+ the browser:
63
+
64
+ ```
65
+ js/forge.min.js
66
+ ```
67
+
68
+ Include the file via:
69
+
70
+ ```html
71
+ <script src="js/forge.min.js"></script>
72
+ ```
73
+
74
+ To create a single non-minimized file that can be included in
75
+ the browser:
76
+
77
+ ```
78
+ npm install
79
+ npm run bundle
80
+ ```
81
+
82
+ This will create:
83
+
84
+ ```
85
+ js/forge.bundle.js
86
+ ```
87
+
88
+ Include the file via:
89
+
90
+ ```html
91
+ <script src="js/forge.bundle.js"></script>
92
+ ```
93
+
94
+ The above bundles will synchronously create a global 'forge' object.
95
+
96
+ Keep in mind that these bundles will not include any WebWorker
97
+ scripts (eg: prime.worker.js) or their dependencies, so these will
98
+ need to be accessible from the browser if any WebWorkers are used.
99
+
100
+ ### Testing with NodeJS & RequireJS ###
101
+
102
+ A test server for [node.js][] can be found at `./nodejs`. The following are included:
103
+
104
+ * Example of how to use `forge` within NodeJS in the form of a [mocha](http://visionmedia.github.io/mocha/) test.
105
+ * Example of how to serve `forge` to the browser using [RequireJS](http://requirejs.org/).
106
+
107
+ To run:
108
+
109
+ cd nodejs
110
+ npm install
111
+ npm test
112
+ npm start
113
+
114
+
115
+ ### Old build system that includes flash support ###
116
+
117
+ To build the whole project, including Flash, run the following:
118
+
119
+ $ ./build-setup
120
+ $ make
121
+
122
+ This will create the SWF, symlink all the JavaScript files, and build a Python
123
+ SSL module for testing. To see configure options, run `./configure --help`.
124
+
125
+ ### Old test system including flash support ###
126
+
127
+ A test server is provided which can be run in TLS mode and non-TLS mode. Use
128
+ the --help option to get help for configuring ports. The server will print out
129
+ the local URL you can vist to run tests.
130
+
131
+ Some of the simplier tests should be run with just the non-TLS server::
132
+
133
+ $ ./tests/server.py
134
+
135
+ More advanced tests need TLS enabled::
136
+
137
+ $ ./tests/server.py --tls
138
+
16
139
  ## Documentation
140
+ ----------------
17
141
 
18
142
  ### Transports
19
143
 
@@ -114,7 +238,7 @@ var client = forge.tls.createConnection({
114
238
  connected: function(connection) {
115
239
  console.log('connected');
116
240
  // send message to server
117
- connection.prepare('Hi server!');
241
+ connection.prepare(forge.util.encodeUtf8('Hi server!'));
118
242
  },
119
243
  /* provide a client-side cert if you want
120
244
  getCertificate: function(connection, hint) {
@@ -132,7 +256,8 @@ var client = forge.tls.createConnection({
132
256
  },
133
257
  dataReady: function(connection) {
134
258
  // clear data from the server is ready
135
- console.log('the server sent: ' + connection.data.getBytes());
259
+ console.log('the server sent: ' +
260
+ forge.util.decodeUtf8(connection.data.getBytes()));
136
261
  // close connection
137
262
  connection.close();
138
263
  },
@@ -176,7 +301,7 @@ var server = forge.tls.createConnection({
176
301
  connected: function(connection) {
177
302
  console.log('connected');
178
303
  // send message to client
179
- connection.prepare('Hi client!');
304
+ connection.prepare(forge.util.encodeUtf8('Hi client!'));
180
305
  },
181
306
  getCertificate: function(connection, hint) {
182
307
  return myServerCertificate;
@@ -192,7 +317,8 @@ var server = forge.tls.createConnection({
192
317
  },
193
318
  dataReady: function(connection) {
194
319
  // clear data from the client is ready
195
- console.log('the client sent: ' + connection.data.getBytes());
320
+ console.log('the client sent: ' +
321
+ forge.util.decodeUtf8(connection.data.getBytes()));
196
322
  // close connection
197
323
  connection.close();
198
324
  },
@@ -222,7 +348,9 @@ var client = forge.tls.createConnection({
222
348
  },
223
349
  connected: function(connection) {
224
350
  console.log('[tls] connected');
225
- // prepare some data to send
351
+ // prepare some data to send (note that the string is interpreted as
352
+ // 'binary' encoded, which works for HTTP which only uses ASCII, use
353
+ // forge.util.encodeUtf8(str) otherwise
226
354
  client.prepare('GET / HTTP/1.0\r\n\r\n');
227
355
  },
228
356
  tlsDataReady: function(connection) {
@@ -1102,83 +1230,6 @@ Policy. See `mod_fsp/README` for more details. This module makes it easy to
1102
1230
  modify an [Apache][] server to allow cross domain requests to be made to it.
1103
1231
 
1104
1232
 
1105
- ---------------------------------------
1106
-
1107
-
1108
- Getting Started
1109
- ---------------
1110
-
1111
- ### Node.js ###
1112
-
1113
- If you want to use forge with [node.js][], it is available through `npm`:
1114
-
1115
- https://npmjs.org/package/node-forge
1116
-
1117
- Installation:
1118
-
1119
- npm install node-forge
1120
-
1121
- You can then use forge as a regular module:
1122
-
1123
- var forge = require('node-forge');
1124
-
1125
- ### Requirements ###
1126
-
1127
- * General
1128
- * GNU autotools for the build infrastructure.
1129
- * Flash
1130
- * Optional: A pre-built SocketPool.swf is included.
1131
- * Adobe Flex 3 SDK to build the Flash socket code.
1132
- * http://opensource.adobe.com/wiki/display/flexsdk/
1133
- * Testing
1134
- * Optional: Only needed for fast session cache during testing.
1135
- * Python and OpenSSL development environment to build a special SSL module
1136
- with session cache support.
1137
- * http://www.python.org/dev/
1138
- * http://www.openssl.org/
1139
- * Debian users should install python-dev and libssl-dev.
1140
-
1141
- ### Building ###
1142
-
1143
- To build the whole project, run the following::
1144
-
1145
- $ ./build-setup
1146
- $ make
1147
-
1148
- This will create the SWF, symlink all the JavaScript files, and build a Python
1149
- SSL module for testing. To see configure options, run `./configure --help`.
1150
-
1151
- ### Testing ###
1152
-
1153
- A test server is provided which can be run in TLS mode and non-TLS mode. Use
1154
- the --help option to get help for configuring ports. The server will print out
1155
- the local URL you can vist to run tests.
1156
-
1157
- Some of the simplier tests should be run with just the non-TLS server::
1158
-
1159
- $ ./tests/server.py
1160
-
1161
- More advanced tests need TLS enabled::
1162
-
1163
- $ ./tests/server.py --tls
1164
-
1165
-
1166
- NodeJS & RequireJS
1167
- ------------------
1168
-
1169
- A test server for [node.js][] can be found at `./nodejs`. The following are included:
1170
-
1171
- * Example of how to use `forge` within NodeJS in the form of a [mocha](http://visionmedia.github.io/mocha/) test.
1172
- * Example of how to serve `forge` to the browser using [RequireJS](http://requirejs.org/).
1173
-
1174
- To run:
1175
-
1176
- cd nodejs
1177
- npm install
1178
- npm test
1179
- npm start
1180
-
1181
-
1182
1233
  Library Details
1183
1234
  ---------------
1184
1235
 
package/end.frag ADDED
@@ -0,0 +1,3 @@
1
+ window.forge = require('js/forge');
2
+
3
+ })();
package/js/asn1.js CHANGED
@@ -290,7 +290,7 @@ asn1.fromDer = function(bytes, strict) {
290
290
  throw {
291
291
  message: 'Too few bytes to read ASN.1 value.',
292
292
  detail: bytes.length() + ' < ' + length
293
- };
293
+ }
294
294
  }
295
295
  // Note: be lenient with truncated values
296
296
  length = bytes.length();
@@ -366,9 +366,15 @@ asn1.fromDer = function(bytes, strict) {
366
366
  // TODO: do DER to OID conversion and vice-versa in .toDer?
367
367
 
368
368
  if(length === undefined) {
369
- throw {
370
- message: 'Non-constructed ASN.1 object of indefinite length.'
371
- };
369
+ if(strict) {
370
+ throw {
371
+ message: 'Non-constructed ASN.1 object of indefinite length.'
372
+ };
373
+ }
374
+ // be lenient and use remaining bytes
375
+ else {
376
+ length = bytes.length();
377
+ }
372
378
  }
373
379
 
374
380
  if(type === asn1.Type.BMPSTRING) {
package/js/oids.js CHANGED
@@ -39,6 +39,9 @@ oids['sha384WithRSAEncryption'] = '1.2.840.113549.1.1.12';
39
39
  oids['1.2.840.113549.1.1.13'] = 'sha512WithRSAEncryption';
40
40
  oids['sha512WithRSAEncryption'] = '1.2.840.113549.1.1.13';
41
41
 
42
+ oids['1.3.14.3.2.7'] = 'desCBC';
43
+ oids['desCBC'] = '1.3.14.3.2.7';
44
+
42
45
  oids['1.3.14.3.2.26'] = 'sha1';
43
46
  oids['sha1'] = '1.3.14.3.2.26';
44
47
  oids['2.16.840.1.101.3.4.2.1'] = 'sha256';
package/js/pkcs7.js CHANGED
@@ -355,6 +355,7 @@ var _decryptContent = function (msg) {
355
355
  ciph = forge.aes.createDecryptionCipher(msg.encryptedContent.key);
356
356
  break;
357
357
 
358
+ case forge.pki.oids['desCBC']:
358
359
  case forge.pki.oids['des-EDE3-CBC']:
359
360
  ciph = forge.des.createDecryptionCipher(msg.encryptedContent.key);
360
361
  break;
@@ -661,6 +662,7 @@ p7.createEnvelopedData = function() {
661
662
  && privKey !== undefined) {
662
663
  switch(recipient.encryptedContent.algorithm) {
663
664
  case forge.pki.oids.rsaEncryption:
665
+ case forge.pki.oids.desCBC:
664
666
  var key = privKey.decrypt(recipient.encryptedContent.content);
665
667
  msg.encryptedContent.key = forge.util.createBuffer(key);
666
668
  break;
package/js/tls.js CHANGED
@@ -3941,7 +3941,9 @@ tls.createConnection = function(options) {
3941
3941
  * tlsDataReady handler will be called when the TLS record(s) have been
3942
3942
  * prepared.
3943
3943
  *
3944
- * @param data the application data, as a string, to be sent.
3944
+ * @param data the application data, as a raw 'binary' encoded string, to
3945
+ * be sent; to send utf-16/utf-8 string data, use the return value
3946
+ * of util.encodeUtf8(str).
3945
3947
  *
3946
3948
  * @return true on success, false on failure.
3947
3949
  */
package/minify.js ADDED
@@ -0,0 +1,10 @@
1
+ ({
2
+ name: 'node_modules/almond/almond',
3
+ include: ['js/forge'],
4
+ out: 'js/forge.min.js',
5
+ wrap: {
6
+ startFile: 'start.frag',
7
+ endFile: 'end.frag'
8
+ },
9
+ preserveLicenseComments: false
10
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-forge",
3
- "version": "0.2.20",
3
+ "version": "0.2.24",
4
4
  "description": "JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilties.",
5
5
  "homepage": "http://github.com/digitalbazaar/forge",
6
6
  "author": {
@@ -18,6 +18,10 @@
18
18
  "name": "Christoph Dorn",
19
19
  "email": "christoph@christophdorn.com"
20
20
  }],
21
+ "devDependencies": {
22
+ "almond": "~0.2.6",
23
+ "requirejs": "~2.1.8"
24
+ },
21
25
  "repository": {
22
26
  "type" : "git",
23
27
  "url" : "http://github.com/digitalbazaar/forge"
@@ -53,5 +57,9 @@
53
57
  "tls",
54
58
  "x.509",
55
59
  "x509"
56
- ]
60
+ ],
61
+ "scripts": {
62
+ "bundle": "./node_modules/requirejs/bin/r.js -o minify.js optimize=none out=js/forge.bundle.js",
63
+ "minify": "./node_modules/requirejs/bin/r.js -o minify.js"
64
+ }
57
65
  }
package/start.frag ADDED
@@ -0,0 +1 @@
1
+ (function() {