@@ -105,9 +105,17 @@ function storeFingerprint( serverId, knownHostsPath, fingerprint, cb ) {
105105}
106106
107107const TrustStrategy = {
108- TRUST_SIGNED_CERTIFICATES : function ( opts , onSuccess , onFailure ) {
108+ /**
109+ * @deprecated Since version 1.0. Will be deleted in a future version. TRUST_CUSTOM_CA_SIGNED_CERTIFICATES.
110+ */
111+ TRUST_SIGNED_CERTIFICATES : function ( opts , onSuccess , onFailure ) {
112+ console . log ( "`TRUST_SIGNED_CERTIFICATES` has been deprecated as option and will be removed in a future version of " +
113+ "the driver. Pleas use `TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead." ) ;
114+ return TrustStrategy . TRUST_CUSTOM_CA_SIGNED_CERTIFICATES ( opts , onSuccess , onFailure ) ;
115+ } ,
116+ TRUST_CUSTOM_CA_SIGNED_CERTIFICATES : function ( opts , onSuccess , onFailure ) {
109117 if ( ! opts . trustedCertificates || opts . trustedCertificates . length == 0 ) {
110- onFailure ( newError ( "You are using TRUST_SIGNED_CERTIFICATES as the method " +
118+ onFailure ( newError ( "You are using TRUST_CUSTOM_CA_SIGNED_CERTIFICATES as the method " +
111119 "to verify trust for encrypted connections, but have not configured any " +
112120 "trustedCertificates. You must specify the path to at least one trusted " +
113121 "X.509 certificate for this to work. Two other alternatives is to use " +
@@ -139,6 +147,29 @@ const TrustStrategy = {
139147 socket . on ( 'error' , onFailure ) ;
140148 return socket ;
141149 } ,
150+ TRUST_SYSTEM_CA_SIGNED_CERTIFICATES : function ( opts , onSuccess , onFailure ) {
151+
152+ let tlsOpts = {
153+ // Because we manually check for this in the connect callback, to give
154+ // a more helpful error to the user
155+ rejectUnauthorized : false
156+ } ;
157+ let socket = tls . connect ( opts . port , opts . host , tlsOpts , function ( ) {
158+ if ( ! socket . authorized ) {
159+ onFailure ( newError ( "Server certificate is not trusted. If you trust the database you are connecting to, use " +
160+ "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES and add" +
161+ " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" +
162+ " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " +
163+ " is a security measure to protect against man-in-the-middle attacks. If you are just trying " +
164+ " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" +
165+ " options." ) ) ;
166+ } else {
167+ onSuccess ( ) ;
168+ }
169+ } ) ;
170+ socket . on ( 'error' , onFailure ) ;
171+ return socket ;
172+ } ,
142173 TRUST_ON_FIRST_USE : function ( opts , onSuccess , onFailure ) {
143174 let tlsOpts = {
144175 // Because we manually verify the certificate against known_hosts
@@ -155,7 +186,7 @@ const TrustStrategy = {
155186 // do TOFU, and the safe approach is to fail.
156187 onFailure ( newError ( "You are using a version of NodeJS that does not " +
157188 "support trust-on-first use encryption. You can either upgrade NodeJS to " +
158- "a newer version, use `trust:TRUST_SIGNED_CERTIFICATES ` in your driver " +
189+ "a newer version, use `trust:TRUST_CUSTOM_CA_SIGNED_CERTIFICATES ` in your driver " +
159190 "config instead, or disable encryption using `encrypted:\"" + ENCRYPTION_OFF + "\"`." ) ) ;
160191 return ;
161192 }
@@ -205,7 +236,7 @@ function connect( opts, onSuccess, onFailure=(()=>null) ) {
205236 return TrustStrategy [ opts . trust ] ( opts , onSuccess , onFailure ) ;
206237 } else {
207238 onFailure ( newError ( "Unknown trust strategy: " + opts . trust + ". Please use either " +
208- "trust:'TRUST_SIGNED_CERTIFICATES ' or trust:'TRUST_ON_FIRST_USE' in your driver " +
239+ "trust:'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES ' or trust:'TRUST_ON_FIRST_USE' in your driver " +
209240 "configuration. Alternatively, you can disable encryption by setting " +
210241 "`encrypted:\"" + ENCRYPTION_OFF + "\"`. There is no mechanism to use encryption without trust verification, " +
211242 "because this incurs the overhead of encryption without improving security. If " +
0 commit comments