Skip to content

Commit 71a8e7f

Browse files
committed
crypto: remove unused access of tlsext_hostname
The return value of loadSession is ultimately ignored, so don't fill it in. This inches Node closer to 1.1.0 compatibility and is less code. Also remove a comment which appears to have long since become invalid. It dates to 048e0e7 when the SNI value was actually extracted from the session. This also fixes a segfault should d2i_SSL_SESSION fail to parse the input and return NULL. Add a test for this case based on test-tls-session-cache.js.
1 parent 01b90ee commit 71a8e7f

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

lib/_tls_wrap.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,8 @@ function loadSession(self, hello, cb) {
6666
if (!self._handle)
6767
return cb(new Error('Socket is closed'));
6868

69-
// NOTE: That we have disabled OpenSSL's internal session storage in
70-
// `node_crypto.cc` and hence its safe to rely on getting servername only
71-
// from clienthello or this place.
72-
var ret = self._handle.loadSession(session);
73-
74-
cb(null, ret);
69+
self._handle.loadSession(session);
70+
cb(null);
7571
}
7672

7773
if (hello.sessionId.length <= 0 ||
@@ -148,7 +144,7 @@ function requestOCSP(self, hello, ctx, cb) {
148144
function onclienthello(hello) {
149145
var self = this;
150146

151-
loadSession(self, hello, function(err, session) {
147+
loadSession(self, hello, function(err) {
152148
if (err)
153149
return self.destroy(err);
154150

src/node_crypto.cc

-11
Original file line numberDiff line numberDiff line change
@@ -1822,17 +1822,6 @@ void SSLWrap<Base>::LoadSession(const FunctionCallbackInfo<Value>& args) {
18221822
if (w->next_sess_ != nullptr)
18231823
SSL_SESSION_free(w->next_sess_);
18241824
w->next_sess_ = sess;
1825-
1826-
Local<Object> info = Object::New(env->isolate());
1827-
#ifndef OPENSSL_NO_TLSEXT
1828-
if (sess->tlsext_hostname == nullptr) {
1829-
info->Set(env->servername_string(), False(args.GetIsolate()));
1830-
} else {
1831-
info->Set(env->servername_string(),
1832-
OneByteString(args.GetIsolate(), sess->tlsext_hostname));
1833-
}
1834-
#endif
1835-
args.GetReturnValue().Set(info);
18361825
}
18371826
}
18381827

test/parallel/test-tls-session-cache.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ if (!common.hasCrypto) {
1313

1414
doTest({ tickets: false }, function() {
1515
doTest({ tickets: true }, function() {
16-
console.error('all done');
16+
doTest({ tickets: false, invalidSession: true }, function() {
17+
console.error('all done');
18+
});
1719
});
1820
});
1921

@@ -23,6 +25,7 @@ function doTest(testOptions, callback) {
2325
const fs = require('fs');
2426
const join = require('path').join;
2527
const spawn = require('child_process').spawn;
28+
const Buffer = require('buffer').Buffer;
2629

2730
const keyFile = join(common.fixturesDir, 'agent.key');
2831
const certFile = join(common.fixturesDir, 'agent.crt');
@@ -36,6 +39,7 @@ function doTest(testOptions, callback) {
3639
};
3740
let requestCount = 0;
3841
let resumeCount = 0;
42+
let newSessionCount = 0;
3943
let session;
4044

4145
const server = tls.createServer(options, function(cleartext) {
@@ -50,6 +54,7 @@ function doTest(testOptions, callback) {
5054
cleartext.end();
5155
});
5256
server.on('newSession', function(id, data, cb) {
57+
++newSessionCount;
5358
// Emulate asynchronous store
5459
setTimeout(function() {
5560
assert.ok(!session);
@@ -65,9 +70,17 @@ function doTest(testOptions, callback) {
6570
assert.ok(session);
6671
assert.strictEqual(session.id.toString('hex'), id.toString('hex'));
6772

73+
let data = session.data;
74+
75+
// Return an invalid session to test Node does not crash.
76+
if (testOptions.invalidSession) {
77+
data = Buffer.from('INVALID SESSION');
78+
session = null;
79+
}
80+
6881
// Just to check that async really works there
6982
setTimeout(function() {
70-
callback(null, session.data);
83+
callback(null, data);
7184
}, 100);
7285
});
7386

@@ -118,14 +131,25 @@ function doTest(testOptions, callback) {
118131
});
119132

120133
process.on('exit', function() {
134+
// Each test run connects 6 times: an initial request and 5 reconnect
135+
// requests.
136+
assert.strictEqual(requestCount, 6);
137+
121138
if (testOptions.tickets) {
122-
assert.strictEqual(requestCount, 6);
139+
// No session cache callbacks are called.
123140
assert.strictEqual(resumeCount, 0);
141+
assert.strictEqual(newSessionCount, 0);
142+
} else if (testOptions.invalidSession) {
143+
// The resume callback was called, but each connection established a
144+
// fresh session.
145+
assert.strictEqual(resumeCount, 5);
146+
assert.strictEqual(newSessionCount, 6);
124147
} else {
125-
// initial request + reconnect requests (5 times)
148+
// The resume callback was called, and only the initial connection
149+
// establishes a fresh session.
126150
assert.ok(session);
127-
assert.strictEqual(requestCount, 6);
128151
assert.strictEqual(resumeCount, 5);
152+
assert.strictEqual(newSessionCount, 1);
129153
}
130154
});
131155
}

0 commit comments

Comments
 (0)