Skip to content

Commit 4287c68

Browse files
committed
Add option TRUST_SYSTEM_CA_SIGNED_CERTIFICATES
1 parent b577add commit 4287c68

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/v1/driver.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ let USER_AGENT = "neo4j-javascript/" + VERSION;
196196
* // an encryption certificate that is in, or is signed by, a certificate listed
197197
* // as trusted. In the web bundle, this list of trusted certificates is maintained
198198
* // by the web browser. In NodeJS, you configure the list with the next config option.
199-
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
199+
* //
200+
* // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES meand that you trust whatever certificates
201+
* // are in the default certificate chain of th
202+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES" | TRUST_CUSTOM_CA_SIGNED_CERTIFICATES | TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
200203
*
201204
* // List of one or more paths to trusted encryption certificates. This only
202205
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".

src/v1/internal/ch-node.js

+23
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

+25
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ describe('trust-custom-ca-signed-certificates', function() {
122122
});
123123
});
124124

125+
describe('trust-system-ca-signed-certificates', function() {
126+
127+
var driver;
128+
129+
fit('should reject unknown certificates', function(done) {
130+
// Assuming we only run this test on NodeJS
131+
if( !NodeChannel.available ) {
132+
done();
133+
return;
134+
}
135+
136+
// Given
137+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
138+
encrypted: true,
139+
trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES"
140+
});
141+
142+
// When
143+
driver.session().run( "RETURN 1").catch( function(err) {
144+
expect( err.message ).toContain( "Server certificate is not trusted" );
145+
done();
146+
});
147+
});
148+
});
149+
125150
describe('trust-on-first-use', function() {
126151

127152
var driver;

0 commit comments

Comments
 (0)