@@ -23,6 +23,7 @@ import fs from 'fs';
2323import path from 'path' ;
2424import { EOL } from 'os' ;
2525import { NodeBuffer } from './buf' ;
26+ import { isLocalHost , ENCRYPTION_NON_LOCAL , ENCRYPTION_OFF } from './util' ;
2627import { newError } from './../error' ;
2728
2829let _CONNECTION_IDGEN = 0 ;
@@ -71,7 +72,7 @@ const TrustStrategy = {
7172 "to verify trust for encrypted connections, but have not configured any " +
7273 "trustedCertificates. You must specify the path to at least one trusted " +
7374 "X.509 certificate for this to work. Two other alternatives is to use " +
74- "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=false " +
75+ "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=\"" + ENCRYPTION_OFF + "\" " +
7576 "in your driver configuration." ) ) ;
7677 return ;
7778 }
@@ -89,7 +90,8 @@ const TrustStrategy = {
8990 " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" +
9091 " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " +
9192 " is a security measure to protect against man-in-the-middle attacks. If you are just trying " +
92- " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" +
93+ " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=\"" + ENCRYPTION_OFF +
94+ "\"` in the driver" +
9395 " options." ) ) ;
9496 } else {
9597 onSuccess ( ) ;
@@ -115,7 +117,7 @@ const TrustStrategy = {
115117 onFailure ( newError ( "You are using a version of NodeJS that does not " +
116118 "support trust-on-first use encryption. You can either upgrade NodeJS to " +
117119 "a newer version, use `trust:TRUST_SIGNED_CERTIFICATES` in your driver " +
118- "config instead, or disable encryption using `encrypted:false `." ) ) ;
120+ "config instead, or disable encryption using `encrypted:\"" + ENCRYPTION_OFF + "\" `.") ) ;
119121 return ;
120122 }
121123
@@ -140,7 +142,7 @@ const TrustStrategy = {
140142 "update the file with the new certificate. You can configure which file the driver " +
141143 "should use to store this information by setting `knownHosts` to another path in " +
142144 "your driver configuration - and you can disable encryption there as well using " +
143- "`encrypted:false `." ) )
145+ "`encrypted:\"" + ENCRYPTION_OFF + "\" `.") )
144146 }
145147 } ) ;
146148 } ) ;
@@ -150,7 +152,9 @@ const TrustStrategy = {
150152} ;
151153
152154function connect ( opts , onSuccess , onFailure = ( ( ) => null ) ) {
153- if ( opts . encrypted === false ) {
155+ //still allow boolean for backwards compatibility
156+ if ( opts . encrypted === false || opts . encrypted === ENCRYPTION_OFF ||
157+ ( opts . encrypted === ENCRYPTION_NON_LOCAL && isLocalHost ( opts . host ) ) ) {
154158 var conn = net . connect ( opts . port , opts . host , onSuccess ) ;
155159 conn . on ( 'error' , onFailure ) ;
156160 return conn ;
@@ -160,7 +164,7 @@ function connect( opts, onSuccess, onFailure=(()=>null) ) {
160164 onFailure ( newError ( "Unknown trust strategy: " + opts . trust + ". Please use either " +
161165 "trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " +
162166 "configuration. Alternatively, you can disable encryption by setting " +
163- "`encrypted:false `. There is no mechanism to use encryption without trust verification, " +
167+ "`encrypted:\"" + ENCRYPTION_OFF + "\" `. There is no mechanism to use encryption without trust verification, " +
164168 "because this incurs the overhead of encryption without improving security. If " +
165169 "the driver does not verify that the peer it is connected to is really Neo4j, it " +
166170 "is very easy for an attacker to bypass the encryption by pretending to be Neo4j." ) ) ;
@@ -190,6 +194,7 @@ class NodeChannel {
190194 this . _error = null ;
191195 this . _handleConnectionError = this . _handleConnectionError . bind ( this ) ;
192196
197+ this . _encrypted = opts . encrypted ;
193198 this . _conn = connect ( opts , ( ) => {
194199 if ( ! self . _open ) {
195200 return ;
@@ -219,6 +224,10 @@ class NodeChannel {
219224 }
220225 }
221226
227+ isEncrypted ( ) {
228+ return this . _encrypted ;
229+ }
230+
222231 /**
223232 * Write the passed in buffer to connection
224233 * @param {NodeBuffer } buffer - Buffer to write
0 commit comments