1616 * See the License for the specific language governing permissions and
1717 * limitations under the License.
1818 */
19-
20- import net from 'net' ;
21- import tls from 'tls' ;
22- import fs from 'fs' ;
23- import path from 'path' ;
24- import { EOL } from 'os' ;
25- import { NodeBuffer } from './buf' ;
26- import { ENCRYPTION_OFF } from './util' ;
27- import { newError , SESSION_EXPIRED } from './../error' ;
19+ import net from "net" ;
20+ import tls from "tls" ;
21+ import fs from "fs" ;
22+ import path from "path" ;
23+ import { EOL } from "os" ;
24+ import { NodeBuffer } from "./buf" ;
25+ import { ENCRYPTION_OFF , isEmptyObjectOrNull } from "./util" ;
26+ import { newError , SESSION_EXPIRED } from "./../error" ;
2827
2928let _CONNECTION_IDGEN = 0 ;
3029
@@ -119,7 +118,7 @@ const TrustStrategy = {
119118 "to verify trust for encrypted connections, but have not configured any " +
120119 "trustedCertificates. You must specify the path to at least one trusted " +
121120 "X.509 certificate for this to work. Two other alternatives is to use " +
122- "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=\"" + ENCRYPTION_OFF + "\"" +
121+ "TRUST_ALL_CERTIFICATES or to disable encryption by setting encrypted=\"" + ENCRYPTION_OFF + "\"" +
123122 "in your driver configuration." ) ) ;
124123 return ;
125124 }
@@ -227,6 +226,26 @@ const TrustStrategy = {
227226 } ) ;
228227 socket . on ( 'error' , onFailure ) ;
229228 return socket ;
229+ } ,
230+
231+ TRUST_ALL_CERTIFICATES : function ( opts , onSuccess , onFailure ) {
232+ const tlsOpts = {
233+ rejectUnauthorized : false
234+ } ;
235+ const socket = tls . connect ( opts . port , opts . host , tlsOpts , function ( ) {
236+ const certificate = socket . getPeerCertificate ( ) ;
237+ if ( isEmptyObjectOrNull ( certificate ) ) {
238+ onFailure ( newError ( "Secure connection was successful but server did not return any valid " +
239+ "certificates. Such connection can not be trusted. If you are just trying " +
240+ " Neo4j out and are not concerned about encryption, simply disable it using " +
241+ "`encrypted=\"" + ENCRYPTION_OFF + "\"` in the driver options. " +
242+ "Socket responded with: " + socket . authorizationError ) ) ;
243+ } else {
244+ onSuccess ( ) ;
245+ }
246+ } ) ;
247+ socket . on ( 'error' , onFailure ) ;
248+ return socket ;
230249 }
231250} ;
232251
@@ -240,7 +259,7 @@ function connect( opts, onSuccess, onFailure=(()=>null) ) {
240259 return TrustStrategy [ opts . trust ] ( opts , onSuccess , onFailure ) ;
241260 } else {
242261 onFailure ( newError ( "Unknown trust strategy: " + opts . trust + ". Please use either " +
243- "trust:'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE ' in your driver " +
262+ "trust:'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES' or trust:'TRUST_ALL_CERTIFICATES ' in your driver " +
244263 "configuration. Alternatively, you can disable encryption by setting " +
245264 "`encrypted:\"" + ENCRYPTION_OFF + "\"`. There is no mechanism to use encryption without trust verification, " +
246265 "because this incurs the overhead of encryption without improving security. If " +
0 commit comments