Skip to content

Commit 01b76b0

Browse files
committed
Add option TRUST_SYSTEM_CA_SIGNED_CERTIFICATES
1 parent f8dc7a2 commit 01b76b0

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/v1/driver.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ let USER_AGENT = "neo4j-javascript/" + VERSION;
201201
* // an encryption certificate that is in, or is signed by, a certificate listed
202202
* // as trusted. In the web bundle, this list of trusted certificates is maintained
203203
* // by the web browser. In NodeJS, you configure the list with the next config option.
204-
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
204+
* //
205+
* // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES meand that you trust whatever certificates
206+
* // are in the default certificate chain of th
207+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES" | TRUST_CUSTOM_CA_SIGNED_CERTIFICATES | TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
205208
*
206209
* // List of one or more paths to trusted encryption certificates. This only
207210
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".

src/v1/internal/ch-node.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ const TrustStrategy = {
145145
socket.on('error', onFailure);
146146
return socket;
147147
},
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+
},
148171
TRUST_ON_FIRST_USE : function( opts, onSuccess, onFailure ) {
149172
let tlsOpts = {
150173
// Because we manually verify the certificate against known_hosts

test/internal/tls.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ describe('trust-custom-ca-signed-certificates', function() {
140140
});
141141
});
142142

143+
describe('trust-system-ca-signed-certificates', function() {
144+
145+
var driver;
146+
147+
fit('should reject unknown certificates', function(done) {
148+
// Assuming we only run this test on NodeJS
149+
if( !NodeChannel.available ) {
150+
done();
151+
return;
152+
}
153+
154+
// Given
155+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
156+
encrypted: true,
157+
trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES"
158+
});
159+
160+
// When
161+
driver.session().run( "RETURN 1").catch( function(err) {
162+
expect( err.message ).toContain( "Server certificate is not trusted" );
163+
done();
164+
});
165+
});
166+
});
167+
143168
describe('trust-on-first-use', function() {
144169

145170
var driver;

0 commit comments

Comments
 (0)