Skip to content

Commit f8dc7a2

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 dcc7184 commit f8dc7a2

File tree

7 files changed

+72
-14
lines changed

7 files changed

+72
-14
lines changed

src/v1/driver.js

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

src/v1/internal/ch-node.js

Lines changed: 12 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

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

test/internal/tls.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,56 @@ describe('trust-signed-certificates', function() {
9090
});
9191
});
9292

93+
describe('trust-custom-ca-signed-certificates', function() {
94+
95+
var driver;
96+
97+
it('should reject unknown certificates', function(done) {
98+
// Assuming we only run this test on NodeJS
99+
if( !NodeChannel.available ) {
100+
done();
101+
return;
102+
}
103+
104+
// Given
105+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
106+
encrypted: true,
107+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
108+
trustedCertificates: ["test/resources/random.certificate"]
109+
});
110+
111+
// When
112+
driver.session().run( "RETURN 1").catch( function(err) {
113+
expect( err.message ).toContain( "Server certificate is not trusted" );
114+
done();
115+
});
116+
});
117+
118+
it('should accept known certificates', function(done) {
119+
// Assuming we only run this test on NodeJS with TOFU support
120+
if( !NodeChannel.available ) {
121+
done();
122+
return;
123+
}
124+
125+
// Given
126+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
127+
encrypted: true,
128+
trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES",
129+
trustedCertificates: ["build/neo4j/certificates/neo4j.cert"]
130+
});
131+
132+
// When
133+
driver.session().run( "RETURN 1").then( done );
134+
});
135+
136+
afterEach(function(){
137+
if( driver ) {
138+
driver.close();
139+
}
140+
});
141+
});
142+
93143
describe('trust-on-first-use', function() {
94144

95145
var driver;

test/v1/examples.test.js

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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)