Skip to content

Commit 70da3bb

Browse files
author
Neo Technology Build Agent
committed
JS driver v1.1.0-M01: Checking in transpiled files for bower
1 parent 31f1fa9 commit 70da3bb

12 files changed

+3774
-2814
lines changed

lib/browser/neo4j-web.js

+1,671-1,311
Large diffs are not rendered by default.

lib/browser/neo4j-web.min.js

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser/neo4j-web.test.js

+1,838-1,417
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v1/driver.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ var USER_AGENT = "neo4j-javascript/" + _version.VERSION;
230230
* options are as follows:
231231
*
232232
* {
233-
* // Enable TLS encryption. This is on by default in modern NodeJS installs,
233+
* // Encryption level: one of ENCRYPTION_ON, ENCRYPTION_OFF or ENCRYPTION_NON_LOCAL.
234+
* // ENCRYPTION_NON_LOCAL is on by default in modern NodeJS installs,
234235
* // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
235236
* // due to technical limitations on those platforms.
236-
* encrypted: true|false,
237+
* encrypted: ENCRYPTION_ON|ENCRYPTION_OFF|ENCRYPTION_NON_LOCAL
237238
*
238239
* // Trust strategy to use if encryption is enabled. There is no mode to disable
239240
* // trust other than disabling encryption altogether. The reason for

lib/v1/internal/ch-dummy.js

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ var DummyChannel = (function () {
4444
}
4545

4646
_createClass(DummyChannel, [{
47+
key: "isEncrypted",
48+
value: function isEncrypted() {
49+
return false;
50+
}
51+
}, {
4752
key: "write",
4853
value: function write(buf) {
4954
this.written.push(buf);

lib/v1/internal/ch-node.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var _os = require('os');
4949

5050
var _buf = require('./buf');
5151

52+
var _util = require('./util');
53+
5254
var _error = require('./../error');
5355

5456
var _CONNECTION_IDGEN = 0;
@@ -83,13 +85,17 @@ function loadFingerprint(serverId, knownHostsPath, cb) {
8385
}
8486

8587
function storeFingerprint(serverId, knownHostsPath, fingerprint) {
86-
_fs2['default'].appendFile(knownHostsPath, serverId + " " + fingerprint + _os.EOL, "utf8");
88+
_fs2['default'].appendFile(knownHostsPath, serverId + " " + fingerprint + _os.EOL, "utf8", function (err) {
89+
if (err) {
90+
console.log(err);
91+
}
92+
});
8793
}
8894

8995
var TrustStrategy = {
9096
TRUST_SIGNED_CERTIFICATES: function TRUST_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
9197
if (!opts.trustedCertificates || opts.trustedCertificates.length == 0) {
92-
onFailure((0, _error.newError)("You are using TRUST_SIGNED_CERTIFICATES as the method " + "to verify trust for encrypted connections, but have not configured any " + "trustedCertificates. You must specify the path to at least one trusted " + "X.509 certificate for this to work. Two other alternatives is to use " + "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=false " + "in your driver configuration."));
98+
onFailure((0, _error.newError)("You are using TRUST_SIGNED_CERTIFICATES as the method " + "to verify trust for encrypted connections, but have not configured any " + "trustedCertificates. You must specify the path to at least one trusted " + "X.509 certificate for this to work. Two other alternatives is to use " + "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=\"" + _util.ENCRYPTION_OFF + "\"" + "in your driver configuration."));
9399
return;
94100
}
95101

@@ -102,7 +108,7 @@ var TrustStrategy = {
102108

103109
var socket = _tls2['default'].connect(opts.port, opts.host, tlsOpts, function () {
104110
if (!socket.authorized) {
105-
onFailure((0, _error.newError)("Server certificate is not trusted. If you trust the database you are connecting to, add" + " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" + " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + " is a security measure to protect against man-in-the-middle attacks. If you are just trying " + " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" + " options."));
111+
onFailure((0, _error.newError)("Server certificate is not trusted. If you trust the database you are connecting to, add" + " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" + " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + " is a security measure to protect against man-in-the-middle attacks. If you are just trying " + " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=\"" + _util.ENCRYPTION_OFF + "\"` in the driver" + " options."));
106112
} else {
107113
onSuccess();
108114
}
@@ -124,7 +130,7 @@ var TrustStrategy = {
124130
// the raw cert cannot be accessed (or, at least I couldn't find a way to)
125131
// therefore, we can't generate a SHA512 fingerprint, meaning we can't
126132
// do TOFU, and the safe approach is to fail.
127-
onFailure((0, _error.newError)("You are using a version of NodeJS that does not " + "support trust-on-first use encryption. You can either upgrade NodeJS to " + "a newer version, use `trust:TRUST_SIGNED_CERTIFICATES` in your driver " + "config instead, or disable encryption using `encrypted:false`."));
133+
onFailure((0, _error.newError)("You are using a version of NodeJS that does not " + "support trust-on-first use encryption. You can either upgrade NodeJS to " + "a newer version, use `trust:TRUST_SIGNED_CERTIFICATES` in your driver " + "config instead, or disable encryption using `encrypted:\"" + _util.ENCRYPTION_OFF + "\"`."));
128134
return;
129135
}
130136

@@ -139,7 +145,7 @@ var TrustStrategy = {
139145
storeFingerprint(serverId, knownHostsPath, serverFingerprint);
140146
onSuccess();
141147
} else {
142-
onFailure((0, _error.newError)("Database encryption certificate has changed, and no longer " + "matches the certificate stored for " + serverId + " in `" + knownHostsPath + "`. As a security precaution, this driver will not automatically trust the new " + "certificate, because doing so would allow an attacker to pretend to be the Neo4j " + "instance we want to connect to. The certificate provided by the server looks like: " + serverCert + ". If you trust that this certificate is valid, simply remove the line " + "starting with " + serverId + " in `" + knownHostsPath + "`, and the driver will " + "update the file with the new certificate. You can configure which file the driver " + "should use to store this information by setting `knownHosts` to another path in " + "your driver configuration - and you can disable encryption there as well using " + "`encrypted:false`."));
148+
onFailure((0, _error.newError)("Database encryption certificate has changed, and no longer " + "matches the certificate stored for " + serverId + " in `" + knownHostsPath + "`. As a security precaution, this driver will not automatically trust the new " + "certificate, because doing so would allow an attacker to pretend to be the Neo4j " + "instance we want to connect to. The certificate provided by the server looks like: " + serverCert + ". If you trust that this certificate is valid, simply remove the line " + "starting with " + serverId + " in `" + knownHostsPath + "`, and the driver will " + "update the file with the new certificate. You can configure which file the driver " + "should use to store this information by setting `knownHosts` to another path in " + "your driver configuration - and you can disable encryption there as well using " + "`encrypted:\"" + _util.ENCRYPTION_OFF + "\"`."));
143149
}
144150
});
145151
});
@@ -153,14 +159,15 @@ function connect(opts, onSuccess) {
153159
return null;
154160
} : arguments[2];
155161

156-
if (opts.encrypted === false) {
162+
//still allow boolean for backwards compatibility
163+
if (opts.encrypted === false || opts.encrypted === _util.ENCRYPTION_OFF || opts.encrypted === _util.ENCRYPTION_NON_LOCAL && (0, _util.isLocalHost)(opts.host)) {
157164
var conn = _net2['default'].connect(opts.port, opts.host, onSuccess);
158165
conn.on('error', onFailure);
159166
return conn;
160167
} else if (TrustStrategy[opts.trust]) {
161168
return TrustStrategy[opts.trust](opts, onSuccess, onFailure);
162169
} else {
163-
onFailure((0, _error.newError)("Unknown trust strategy: " + opts.trust + ". Please use either " + "trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " + "configuration. Alternatively, you can disable encryption by setting " + "`encrypted:false`. There is no mechanism to use encryption without trust verification, " + "because this incurs the overhead of encryption without improving security. If " + "the driver does not verify that the peer it is connected to is really Neo4j, it " + "is very easy for an attacker to bypass the encryption by pretending to be Neo4j."));
170+
onFailure((0, _error.newError)("Unknown trust strategy: " + opts.trust + ". Please use either " + "trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " + "configuration. Alternatively, you can disable encryption by setting " + "`encrypted:\"" + _util.ENCRYPTION_OFF + "\"`. There is no mechanism to use encryption without trust verification, " + "because this incurs the overhead of encryption without improving security. If " + "the driver does not verify that the peer it is connected to is really Neo4j, it " + "is very easy for an attacker to bypass the encryption by pretending to be Neo4j."));
164171
}
165172
}
166173

@@ -191,6 +198,7 @@ var NodeChannel = (function () {
191198
this._error = null;
192199
this._handleConnectionError = this._handleConnectionError.bind(this);
193200

201+
this._encrypted = opts.encrypted;
194202
this._conn = connect(opts, function () {
195203
if (!self._open) {
196204
return;
@@ -221,6 +229,11 @@ var NodeChannel = (function () {
221229
this.onerror(err);
222230
}
223231
}
232+
}, {
233+
key: 'isEncrypted',
234+
value: function isEncrypted() {
235+
return this._encrypted;
236+
}
224237

225238
/**
226239
* Write the passed in buffer to connection

lib/v1/internal/ch-websocket.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var _buf = require("./buf");
3333

3434
var _error = require('./../error');
3535

36+
var _util = require('./util');
37+
3638
/**
3739
* Create a new WebSocketChannel to be used in web browsers.
3840
* @access private
@@ -55,12 +57,15 @@ var WebSocketChannel = (function () {
5557
this._error = null;
5658
this._handleConnectionError = this._handleConnectionError.bind(this);
5759

60+
this._encrypted = opts.encrypted;
61+
5862
var scheme = "ws";
59-
if (opts.encrypted) {
63+
//Allow boolean for backwards compatibility
64+
if (opts.encrypted === true || opts.encrypted === _util.ENCRYPTION_ON || opts.encrypted === _util.ENCRYPTION_NON_LOCAL && !(0, _util.isLocalHost)(opts.host)) {
6065
if (!opts.trust || opts.trust === "TRUST_SIGNED_CERTIFICATES") {
6166
scheme = "wss";
6267
} else {
63-
this._error = (0, _error.newError)("The browser version of this driver only supports one trust " + "strategy, 'TRUST_SIGNED_CERTIFICATES'. " + opts.trust + " is not supported. Please " + "either use TRUST_SIGNED_CERTIFICATES or disable encryption by setting " + "`encrypted:false` in the driver configuration.");
68+
this._error = (0, _error.newError)("The browser version of this driver only supports one trust " + "strategy, 'TRUST_SIGNED_CERTIFICATES'. " + opts.trust + " is not supported. Please " + "either use TRUST_SIGNED_CERTIFICATES or disable encryption by setting " + "`encrypted:\"" + _util.ENCRYPTION_OFF + "\"` in the driver configuration.");
6469
return;
6570
}
6671
}
@@ -106,6 +111,11 @@ var WebSocketChannel = (function () {
106111
}
107112
}
108113
}
114+
}, {
115+
key: "isEncrypted",
116+
value: function isEncrypted() {
117+
return this._encrypted;
118+
}
109119

110120
/**
111121
* Write the passed in buffer to connection

lib/v1/internal/connector.js

+50-9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ var _integer = require('../integer');
5959

6060
var _error = require('./../error');
6161

62+
var _util = require('./util');
63+
6264
var Channel = undefined;
6365
if (_chWebsocket2["default"].available) {
6466
Channel = _chWebsocket2["default"].channel;
@@ -193,6 +195,7 @@ var _mappers = {
193195
*/
194196

195197
var Connection = (function () {
198+
196199
/**
197200
* @constructor
198201
* @param channel - channel with a 'write' function and a 'onmessage'
@@ -370,42 +373,60 @@ var Connection = (function () {
370373
}, {
371374
key: "initialize",
372375
value: function initialize(clientName, token, observer) {
376+
var _this2 = this;
377+
373378
this._queueObserver(observer);
374-
this._packer.packStruct(INIT, [clientName, token]);
379+
this._packer.packStruct(INIT, [this._packable(clientName), this._packable(token)], function (err) {
380+
return _this2._handleFatalError(err);
381+
});
375382
this._chunker.messageBoundary();
376383
}
377384

378385
/** Queue a RUN-message to be sent to the database */
379386
}, {
380387
key: "run",
381388
value: function run(statement, params, observer) {
389+
var _this3 = this;
390+
382391
this._queueObserver(observer);
383-
this._packer.packStruct(RUN, [statement, params]);
392+
this._packer.packStruct(RUN, [this._packable(statement), this._packable(params)], function (err) {
393+
return _this3._handleFatalError(err);
394+
});
384395
this._chunker.messageBoundary();
385396
}
386397

387398
/** Queue a PULL_ALL-message to be sent to the database */
388399
}, {
389400
key: "pullAll",
390401
value: function pullAll(observer) {
402+
var _this4 = this;
403+
391404
this._queueObserver(observer);
392-
this._packer.packStruct(PULL_ALL);
405+
this._packer.packStruct(PULL_ALL, [], function (err) {
406+
return _this4._handleFatalError(err);
407+
});
393408
this._chunker.messageBoundary();
394409
}
395410

396411
/** Queue a DISCARD_ALL-message to be sent to the database */
397412
}, {
398413
key: "discardAll",
399414
value: function discardAll(observer) {
415+
var _this5 = this;
416+
400417
this._queueObserver(observer);
401-
this._packer.packStruct(DISCARD_ALL);
418+
this._packer.packStruct(DISCARD_ALL, [], function (err) {
419+
return _this5._handleFatalError(err);
420+
});
402421
this._chunker.messageBoundary();
403422
}
404423

405424
/** Queue a RESET-message to be sent to the database */
406425
}, {
407426
key: "reset",
408427
value: function reset(observer) {
428+
var _this6 = this;
429+
409430
this._isHandlingFailure = true;
410431
var self = this;
411432
var wrappedObs = {
@@ -419,16 +440,22 @@ var Connection = (function () {
419440
}
420441
};
421442
this._queueObserver(wrappedObs);
422-
this._packer.packStruct(RESET);
443+
this._packer.packStruct(RESET, [], function (err) {
444+
return _this6._handleFatalError(err);
445+
});
423446
this._chunker.messageBoundary();
424447
}
425448

426449
/** Queue a ACK_FAILURE-message to be sent to the database */
427450
}, {
428451
key: "_ackFailure",
429452
value: function _ackFailure(observer) {
453+
var _this7 = this;
454+
430455
this._queueObserver(observer);
431-
this._packer.packStruct(ACK_FAILURE);
456+
this._packer.packStruct(ACK_FAILURE, [], function (err) {
457+
return _this7._handleFatalError(err);
458+
});
432459
this._chunker.messageBoundary();
433460
}
434461
}, {
@@ -467,6 +494,11 @@ var Connection = (function () {
467494
value: function isOpen() {
468495
return !this._isBroken && this._ch._open;
469496
}
497+
}, {
498+
key: "isEncrypted",
499+
value: function isEncrypted() {
500+
return this._ch.isEncrypted();
501+
}
470502

471503
/**
472504
* Call close on the channel.
@@ -477,6 +509,15 @@ var Connection = (function () {
477509
value: function close(cb) {
478510
this._ch.close(cb);
479511
}
512+
}, {
513+
key: "_packable",
514+
value: function _packable(value) {
515+
var _this8 = this;
516+
517+
return this._packer.packable(value, function (err) {
518+
return _this8._handleFatalError(err);
519+
});
520+
}
480521
}]);
481522

482523
return Connection;
@@ -489,9 +530,9 @@ function connect(url) {
489530
return new Connection(new Ch({
490531
host: host(url),
491532
port: port(url) || 7687,
492-
// Default to using encryption if trust-on-first-use is available
493-
encrypted: config.encrypted == null ? (0, _features2["default"])("trust_on_first_use") : config.encrypted,
494-
// Default to using trust-on-first-use if it is available
533+
// Default to using ENCRYPTION_NON_LOCAL if trust-on-first-use is available
534+
encrypted: (0, _util.shouldEncrypt)(config.encrypted, (0, _features2["default"])("trust_on_first_use") ? _util.ENCRYPTION_NON_LOCAL : _util.ENCRYPTION_OFF, host(url)),
535+
// Default to using TRUST_ON_FIRST_USE if it is available
495536
trust: config.trust || ((0, _features2["default"])("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_SIGNED_CERTIFICATES"),
496537
trustedCertificates: config.trustedCertificates || [],
497538
knownHosts: config.knownHosts

0 commit comments

Comments
 (0)