@@ -23,6 +23,7 @@ import fs from 'fs';
23
23
import path from 'path' ;
24
24
import { EOL } from 'os' ;
25
25
import { NodeBuffer } from './buf' ;
26
+ import { isLocalHost , ENCRYPTION_NON_LOCAL , ENCRYPTION_OFF } from './util' ;
26
27
import { newError } from './../error' ;
27
28
28
29
let _CONNECTION_IDGEN = 0 ;
@@ -71,7 +72,7 @@ const TrustStrategy = {
71
72
"to verify trust for encrypted connections, but have not configured any " +
72
73
"trustedCertificates. You must specify the path to at least one trusted " +
73
74
"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 + "\" " +
75
76
"in your driver configuration." ) ) ;
76
77
return ;
77
78
}
@@ -89,7 +90,8 @@ const TrustStrategy = {
89
90
" the signing certificate, or the server certificate, to the list of certificates trusted by this driver" +
90
91
" using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " +
91
92
" 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" +
93
95
" options." ) ) ;
94
96
} else {
95
97
onSuccess ( ) ;
@@ -115,7 +117,7 @@ const TrustStrategy = {
115
117
onFailure ( newError ( "You are using a version of NodeJS that does not " +
116
118
"support trust-on-first use encryption. You can either upgrade NodeJS to " +
117
119
"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 + "\" `.") ) ;
119
121
return ;
120
122
}
121
123
@@ -140,7 +142,7 @@ const TrustStrategy = {
140
142
"update the file with the new certificate. You can configure which file the driver " +
141
143
"should use to store this information by setting `knownHosts` to another path in " +
142
144
"your driver configuration - and you can disable encryption there as well using " +
143
- "`encrypted:false `." ) )
145
+ "`encrypted:\"" + ENCRYPTION_OFF + "\" `.") )
144
146
}
145
147
} ) ;
146
148
} ) ;
@@ -150,7 +152,9 @@ const TrustStrategy = {
150
152
} ;
151
153
152
154
function 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 ) ) ) {
154
158
var conn = net . connect ( opts . port , opts . host , onSuccess ) ;
155
159
conn . on ( 'error' , onFailure ) ;
156
160
return conn ;
@@ -160,7 +164,7 @@ function connect( opts, onSuccess, onFailure=(()=>null) ) {
160
164
onFailure ( newError ( "Unknown trust strategy: " + opts . trust + ". Please use either " +
161
165
"trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " +
162
166
"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, " +
164
168
"because this incurs the overhead of encryption without improving security. If " +
165
169
"the driver does not verify that the peer it is connected to is really Neo4j, it " +
166
170
"is very easy for an attacker to bypass the encryption by pretending to be Neo4j." ) ) ;
@@ -190,6 +194,7 @@ class NodeChannel {
190
194
this . _error = null ;
191
195
this . _handleConnectionError = this . _handleConnectionError . bind ( this ) ;
192
196
197
+ this . _encrypted = opts . encrypted ;
193
198
this . _conn = connect ( opts , ( ) => {
194
199
if ( ! self . _open ) {
195
200
return ;
@@ -219,6 +224,10 @@ class NodeChannel {
219
224
}
220
225
}
221
226
227
+ isEncrypted ( ) {
228
+ return this . _encrypted ;
229
+ }
230
+
222
231
/**
223
232
* Write the passed in buffer to connection
224
233
* @param {NodeBuffer } buffer - Buffer to write
0 commit comments