-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
tls: fix bugs of double TLS #48796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tls: fix bugs of double TLS #48796
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,8 @@ class TLSWrap : public AsyncWrap, | |
v8::Local<v8::Object> obj, | ||
Kind kind, | ||
StreamBase* stream, | ||
SecureContext* sc); | ||
SecureContext* sc, | ||
bool stream_has_active_write); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking nit: I'm generally not a fan of bool arguments to methods, largely because just seeing the |
||
|
||
static void SSLInfoCallback(const SSL* ssl_, int where, int ret); | ||
void InitSSL(); | ||
|
@@ -217,6 +218,8 @@ class TLSWrap : public AsyncWrap, | |
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
static void VerifyError(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
static void Wrap(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
static void WritesIssuedByPrevListenerDone( | ||
const v8::FunctionCallbackInfo<v8::Value>& args); | ||
|
||
#ifdef SSL_set_max_send_fragment | ||
static void SetMaxSendFragment( | ||
|
@@ -284,6 +287,8 @@ class TLSWrap : public AsyncWrap, | |
|
||
BIOPointer bio_trace_; | ||
|
||
bool has_active_write_issued_by_prev_listener_ = false; | ||
|
||
public: | ||
std::vector<unsigned char> alpn_protos_; // Accessed by SelectALPNCallback. | ||
bool alpn_callback_enabled_ = false; // Accessed by SelectALPNCallback. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
if (!common.hasCrypto) common.skip('missing crypto'); | ||
const fixtures = require('../common/fixtures'); | ||
const tls = require('tls'); | ||
|
||
// In reality, this can be a HTTP CONNECT message, signaling the incoming | ||
// data is TLS encrypted | ||
const HEAD = 'XXXX'; | ||
|
||
const subserver = tls.createServer({ | ||
key: fixtures.readKey('agent1-key.pem'), | ||
cert: fixtures.readKey('agent1-cert.pem'), | ||
}) | ||
.on('secureConnection', common.mustCall(() => { | ||
process.exit(0); | ||
})); | ||
|
||
const server = tls.createServer({ | ||
key: fixtures.readKey('agent1-key.pem'), | ||
cert: fixtures.readKey('agent1-cert.pem'), | ||
}) | ||
.listen(client) | ||
.on('secureConnection', (serverTlsSock) => { | ||
serverTlsSock.on('data', (chunk) => { | ||
assert.strictEqual(chunk.toString(), HEAD); | ||
subserver.emit('connection', serverTlsSock); | ||
}); | ||
}); | ||
|
||
function client() { | ||
const down = tls.connect({ | ||
host: '127.0.0.1', | ||
port: server.address().port, | ||
rejectUnauthorized: false | ||
}).on('secureConnect', () => { | ||
down.write(HEAD, common.mustSucceed()); | ||
|
||
// Sending tls data on a client TLSSocket with an active write led to a crash: | ||
// | ||
// node[16862]: ../src/crypto/crypto_tls.cc:963:virtual int node::crypto::TLSWrap::DoWrite(node::WriteWrap*, | ||
// uv_buf_t*, size_t, uv_stream_t*): Assertion `!current_write_' failed. | ||
// 1: 0xb090e0 node::Abort() [node] | ||
// 2: 0xb0915e [node] | ||
// 3: 0xca8413 node::crypto::TLSWrap::DoWrite(node::WriteWrap*, uv_buf_t*, unsigned long, uv_stream_s*) [node] | ||
// 4: 0xcaa549 node::StreamBase::Write(uv_buf_t*, unsigned long, uv_stream_s*, v8::Local<v8::Object>) [node] | ||
// 5: 0xca88d7 node::crypto::TLSWrap::EncOut() [node] | ||
// 6: 0xd3df3e [node] | ||
// 7: 0xd3f35f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node] | ||
// 8: 0x15d9ef9 [node] | ||
// Aborted | ||
tls.connect({ | ||
socket: down, | ||
rejectUnauthorized: false | ||
}); | ||
}); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.