Skip to content

Commit b577add

Browse files
committed
Deprecate TRUST_SIGNED_CERTIFICATES
TRUST_SIGNED_CERTIFICATES does different things on different platforms. It has now been deprecated and user should use TRUST_CUSTOM_CA_SIGNED_CERTIFICATES instead.
1 parent fab6d7c commit b577add

File tree

7 files changed

+71
-14
lines changed

7 files changed

+71
-14
lines changed

src/v1/driver.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ let USER_AGENT = "neo4j-javascript/" + VERSION;
191191
* // This means that by default, connections "just work" while still giving you
192192
* // good encrypted protection.
193193
* //
194-
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
194+
* // TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is the classic approach to trust verification -
195195
* // whenever we establish an encrypted connection, we ensure the host is using
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.
199199
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
200200
*
201201
* // List of one or more paths to trusted encryption certificates. This only
202-
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
202+
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
203203
* // The certificate files should be in regular X.509 PEM format.
204204
* // For instance, ['./trusted.pem']
205205
* trustedCertificates: [],

src/v1/internal/ch-node.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,17 @@ function storeFingerprint( serverId, knownHostsPath, fingerprint, cb ) {
104104
}
105105

106106
const 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 " +
@@ -153,7 +161,7 @@ const TrustStrategy = {
153161
// do TOFU, and the safe approach is to fail.
154162
onFailure(newError("You are using a version of NodeJS that does not " +
155163
"support trust-on-first use encryption. You can either upgrade NodeJS to " +
156-
"a newer version, use `trust:TRUST_SIGNED_CERTIFICATES` in your driver " +
164+
"a newer version, use `trust:TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` in your driver " +
157165
"config instead, or disable encryption using `encrypted:false`."));
158166
return;
159167
}
@@ -201,7 +209,7 @@ function connect( opts, onSuccess, onFailure=(()=>null) ) {
201209
return TrustStrategy[opts.trust](opts, onSuccess, onFailure);
202210
} else {
203211
onFailure(newError("Unknown trust strategy: " + opts.trust + ". Please use either " +
204-
"trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " +
212+
"trust:'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " +
205213
"configuration. Alternatively, you can disable encryption by setting " +
206214
"`encrypted:false`. There is no mechanism to use encryption without trust verification, " +
207215
"because this incurs the overhead of encryption without improving security. If " +

src/v1/internal/ch-websocket.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class WebSocketChannel {
4242

4343
let scheme = "ws";
4444
if( opts.encrypted ) {
45-
if( (!opts.trust) || opts.trust === "TRUST_SIGNED_CERTIFICATES" ) {
45+
if( (!opts.trust) || opts.trust === "TRUST_SIGNED_CERTIFICATES" || opts.trust === "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" ) {
4646
scheme = "wss";
4747
} else {
4848
this._error = newError("The browser version of this driver only supports one trust " +
49-
"strategy, 'TRUST_SIGNED_CERTIFICATES'. "+opts.trust+" is not supported. Please " +
50-
"either use TRUST_SIGNED_CERTIFICATES or disable encryption by setting " +
49+
"strategy, 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'. "+opts.trust+" is not supported. Please " +
50+
"either use TRUST_CUSTOM_CA_SIGNED_CERTIFICATES or disable encryption by setting " +
5151
"`encrypted:false` in the driver configuration.");
5252
return;
5353
}

src/v1/internal/connector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function connect( url, config = {}) {
432432
// Default to using encryption if trust-on-first-use is available
433433
encrypted : (config.encrypted == null) ? hasFeature("trust_on_first_use") : config.encrypted,
434434
// Default to using trust-on-first-use if it is available
435-
trust : config.trust || (hasFeature("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_SIGNED_CERTIFICATES"),
435+
trust : config.trust || (hasFeature("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES"),
436436
trustedCertificates : config.trustedCertificates || [],
437437
knownHosts : config.knownHosts
438438
}));

test/internal/tls.test.js

+49
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,55 @@ describe('trust-signed-certificates', function() {
7272
});
7373
});
7474

75+
describe('trust-custom-ca-signed-certificates', function() {
76+
77+
var driver;
78+
79+
it('should reject unknown certificates', function(done) {
80+
// Assuming we only run this test on NodeJS
81+
if( !NodeChannel.available ) {
82+
done();
83+
return;
84+
}
85+
86+
// Given
87+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
88+
encrypted: true,
89+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
90+
trustedCertificates: ["test/resources/random.certificate"]
91+
});
92+
93+
// When
94+
driver.session().run( "RETURN 1").catch( function(err) {
95+
expect( err.message ).toContain( "Server certificate is not trusted" );
96+
done();
97+
});
98+
});
99+
100+
it('should accept known certificates', function(done) {
101+
// Assuming we only run this test on NodeJS with TOFU support
102+
if( !NodeChannel.available ) {
103+
done();
104+
return;
105+
}
106+
107+
// Given
108+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
109+
encrypted: true,
110+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
111+
trustedCertificates: ["build/neo4j/certificates/neo4j.cert"]
112+
});
113+
114+
// When
115+
driver.session().run( "RETURN 1").then( done );
116+
});
117+
118+
afterEach(function(){
119+
if( driver ) {
120+
driver.close();
121+
}
122+
});
123+
});
75124

76125
describe('trust-on-first-use', function() {
77126

test/v1/examples.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('examples', function() {
357357
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
358358
// Note that trust-on-first-use is not available in the browser bundle,
359359
// in NodeJS, trust-on-first-use is the default trust mode. In the browser
360-
// it is TRUST_SIGNED_CERTIFICATES.
360+
// it is TRUST_CUSTOM_CA_SIGNED_CERTIFICATES.
361361
trust: "TRUST_ON_FIRST_USE",
362362
encrypted:true
363363
});
@@ -369,7 +369,7 @@ describe('examples', function() {
369369
var neo4j = neo4jv1;
370370
// tag::tls-signed[]
371371
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
372-
trust: "TRUST_SIGNED_CERTIFICATES",
372+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
373373
// Configuring which certificates to trust here is only available
374374
// in NodeJS. In the browser bundle the browsers list of trusted
375375
// certificates is used, due to technical limitations in some browsers.

test/v1/tck/steps/tlssteps.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = function () {
108108
this.Given(/^a driver configured to use a trusted certificate$/, function (callback) {
109109
this.config = {
110110
encrypted: true,
111-
trust: "TRUST_SIGNED_CERTIFICATES",
111+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
112112
knownHosts: this.knownHosts1,
113113
trustedCertificates: ['./test/resources/root.cert']
114114
};
@@ -133,7 +133,7 @@ module.exports = function () {
133133
//common name is not set to localhost
134134
this.config = {
135135
encrypted: true,
136-
trust: "TRUST_SIGNED_CERTIFICATES",
136+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
137137
knownHosts: this.knownHosts1,
138138
trustedCertificates: [util.neo4jCert]
139139
};

0 commit comments

Comments
 (0)