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