Skip to content

Commit 5e65c20

Browse files
committed
Remove ENCRYPTION_NON_LOCAL
It was added in one of 1.1.0 pre-releases and can be removed without prior deprecation.
1 parent d4b6555 commit 5e65c20

File tree

6 files changed

+18
-66
lines changed

6 files changed

+18
-66
lines changed

src/v1/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ let USER_AGENT = "neo4j-javascript/" + VERSION;
5858
* options are as follows:
5959
*
6060
* {
61-
* // Encryption level: one of ENCRYPTION_ON, ENCRYPTION_OFF or ENCRYPTION_NON_LOCAL.
62-
* // ENCRYPTION_NON_LOCAL is on by default in modern NodeJS installs,
63-
* // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
64-
* // due to technical limitations on those platforms.
65-
* encrypted: ENCRYPTION_ON|ENCRYPTION_OFF|ENCRYPTION_NON_LOCAL
61+
* // Encryption level: ENCRYPTION_ON or ENCRYPTION_OFF.
62+
* encrypted: ENCRYPTION_ON|ENCRYPTION_OFF
6663
*
6764
* // Trust strategy to use if encryption is enabled. There is no mode to disable
6865
* // trust other than disabling encryption altogether. The reason for

src/v1/internal/ch-node.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import fs from 'fs';
2323
import path from 'path';
2424
import {EOL} from 'os';
2525
import {NodeBuffer} from './buf';
26-
import {isLocalHost, ENCRYPTION_NON_LOCAL, ENCRYPTION_OFF} from './util';
26+
import {ENCRYPTION_OFF} from './util';
2727
import {newError, SESSION_EXPIRED} from './../error';
2828

2929
let _CONNECTION_IDGEN = 0;
@@ -226,8 +226,7 @@ const TrustStrategy = {
226226

227227
function connect( opts, onSuccess, onFailure=(()=>null) ) {
228228
//still allow boolean for backwards compatibility
229-
if (opts.encrypted === false || opts.encrypted === ENCRYPTION_OFF ||
230-
(opts.encrypted === ENCRYPTION_NON_LOCAL && isLocalHost(opts.host))) {
229+
if (opts.encrypted === false || opts.encrypted === ENCRYPTION_OFF) {
231230
var conn = net.connect(opts.port, opts.host, onSuccess);
232231
conn.on('error', onFailure);
233232
return conn;

src/v1/internal/ch-websocket.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
* limitations under the License.
1818
*/
1919

20-
import debug from "./log";
21-
import {HeapBuffer} from "./buf";
20+
import {HeapBuffer} from './buf';
2221
import {newError} from './../error';
23-
import {isLocalHost, ENCRYPTION_NON_LOCAL, ENCRYPTION_ON, ENCRYPTION_OFF} from './util';
22+
import {ENCRYPTION_ON, ENCRYPTION_OFF} from './util';
2423

2524
/**
2625
* Create a new WebSocketChannel to be used in web browsers.
@@ -45,8 +44,7 @@ class WebSocketChannel {
4544

4645
let scheme = "ws";
4746
//Allow boolean for backwards compatibility
48-
if( opts.encrypted === true || opts.encrypted === ENCRYPTION_ON ||
49-
(opts.encrypted === ENCRYPTION_NON_LOCAL && !isLocalHost(opts.host)) ) {
47+
if( opts.encrypted === true || opts.encrypted === ENCRYPTION_ON) {
5048
if((!opts.trust) || opts.trust === "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" ) {
5149
scheme = "wss";
5250
} else {

src/v1/internal/connector.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
import WebSocketChannel from "./ch-websocket";
21-
import NodeChannel from "./ch-node";
19+
import WebSocketChannel from './ch-websocket';
20+
import NodeChannel from './ch-node';
2221
import {Dechunker, Chunker} from "./chunking";
23-
import hasFeature from "./features";
24-
import {Packer,Unpacker} from "./packstream";
25-
import {alloc, CombinedBuffer} from "./buf";
26-
import {Node, Relationship, UnboundRelationship, Path, PathSegment} from '../graph-types';
27-
import {int, isInt} from '../integer';
22+
import hasFeature from './features';
23+
import {Packer, Unpacker} from './packstream';
24+
import {alloc} from './buf';
25+
import {Node, Relationship, UnboundRelationship, Path, PathSegment} from '../graph-types'
2826
import {newError} from './../error';
29-
import {ENCRYPTION_NON_LOCAL, ENCRYPTION_OFF, shouldEncrypt} from './util';
3027

3128
let Channel;
3229
if( WebSocketChannel.available ) {
@@ -470,8 +467,8 @@ function connect( url, config = {}) {
470467
return new Connection( new Ch({
471468
host: parseHost(url),
472469
port: parsePort(url) || 7687,
473-
// Default to using ENCRYPTION_NON_LOCAL if trust-on-first-use is available
474-
encrypted : shouldEncrypt(config.encrypted, (hasFeature("trust_on_first_use") ? ENCRYPTION_NON_LOCAL : ENCRYPTION_OFF), parseHost(url)),
470+
// Default to using encryption if trust-on-first-use is available
471+
encrypted : (config.encrypted == null) ? hasFeature("trust_on_first_use") : config.encrypted,
475472
// Default to using TRUST_ON_FIRST_USE if it is available
476473
trust : config.trust || (hasFeature("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES"),
477474
trustedCertificates : config.trustedCertificates || [],

src/v1/internal/util.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,10 @@
1717
* limitations under the License.
1818
*/
1919

20-
let LOCALHOST_MATCHER = /^(localhost|127(\.\d+){3})$/i;
21-
let ENCRYPTION_ON = "ENCRYPTION_ON";
22-
let ENCRYPTION_OFF = "ENCRYPTION_OFF";
23-
let ENCRYPTION_NON_LOCAL = "ENCRYPTION_NON_LOCAL";
24-
25-
function isLocalHost(host) {
26-
return LOCALHOST_MATCHER.test(host);
27-
}
28-
29-
/* Coerce an encryption setting to a definitive boolean value,
30-
* given a valid default and a target host. If encryption is
31-
* explicitly set on or off, then the mapping is a simple
32-
* conversion to true or false respectively. If set to
33-
* ENCRYPTION_NON_LOCAL then respond according to whether or
34-
* not the host is localhost/127.x.x.x. In all other cases
35-
* (including undefined) then fall back to the default and
36-
* re-evaluate.
37-
*/
38-
function shouldEncrypt(encryption, encryptionDefault, host) {
39-
if (encryption === ENCRYPTION_ON || encryption === true) return true;
40-
if (encryption === ENCRYPTION_OFF || encryption === false) return false;
41-
if (encryption === ENCRYPTION_NON_LOCAL) return !isLocalHost(host);
42-
return shouldEncrypt(encryptionDefault, ENCRYPTION_OFF, host);
43-
}
20+
const ENCRYPTION_ON = "ENCRYPTION_ON";
21+
const ENCRYPTION_OFF = "ENCRYPTION_OFF";
4422

4523
export {
46-
isLocalHost,
47-
shouldEncrypt,
4824
ENCRYPTION_ON,
49-
ENCRYPTION_OFF,
50-
ENCRYPTION_NON_LOCAL
25+
ENCRYPTION_OFF
5126
}

test/internal/tls.test.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var neo4j = require("../../lib/v1");
2121
var fs = require("fs");
2222
var path = require('path');
2323
var hasFeature = require("../../lib/v1/internal/features").default;
24-
var isLocalHost = require("../../lib/v1/internal/util").isLocalHost;
2524

2625
describe('trust-signed-certificates', function() {
2726

@@ -359,19 +358,6 @@ describe('trust-on-first-use', function() {
359358
});
360359
});
361360

362-
it('should detect localhost', function() {
363-
expect(isLocalHost('localhost')).toBe(true);
364-
expect(isLocalHost('LOCALHOST')).toBe(true);
365-
expect(isLocalHost('localHost')).toBe(true);
366-
expect(isLocalHost('127.0.0.1')).toBe(true);
367-
expect(isLocalHost('127.0.0.11')).toBe(true);
368-
expect(isLocalHost('127.1.0.0')).toBe(true);
369-
370-
expect(isLocalHost('172.1.0.0')).toBe(false);
371-
expect(isLocalHost('127.0.0.0.0')).toBe(false);
372-
expect(isLocalHost("google.com")).toBe(false);
373-
});
374-
375361
afterEach(function(){
376362
if( driver ) {
377363
driver.close();

0 commit comments

Comments
 (0)