1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4if (!common.hasCrypto) common.skip('missing crypto'); 5const fixtures = require('../common/fixtures'); 6const tls = require('tls'); 7 8// In reality, this can be a HTTP CONNECT message, signaling the incoming 9// data is TLS encrypted 10const HEAD = 'XXXX'; 11 12const subserver = tls.createServer({ 13 key: fixtures.readKey('agent1-key.pem'), 14 cert: fixtures.readKey('agent1-cert.pem'), 15}) 16 .on('secureConnection', common.mustCall(() => { 17 process.exit(0); 18 })); 19 20const server = tls.createServer({ 21 key: fixtures.readKey('agent1-key.pem'), 22 cert: fixtures.readKey('agent1-cert.pem'), 23}) 24 .listen(client) 25 .on('secureConnection', (serverTlsSock) => { 26 serverTlsSock.on('data', (chunk) => { 27 assert.strictEqual(chunk.toString(), HEAD); 28 subserver.emit('connection', serverTlsSock); 29 }); 30 }); 31 32function client() { 33 const down = tls.connect({ 34 host: '127.0.0.1', 35 port: server.address().port, 36 rejectUnauthorized: false 37 }).on('secureConnect', () => { 38 down.write(HEAD, common.mustSucceed()); 39 40 // Sending tls data on a client TLSSocket with an active write led to a crash: 41 // 42 // node[16862]: ../src/crypto/crypto_tls.cc:963:virtual int node::crypto::TLSWrap::DoWrite(node::WriteWrap*, 43 // uv_buf_t*, size_t, uv_stream_t*): Assertion `!current_write_' failed. 44 // 1: 0xb090e0 node::Abort() [node] 45 // 2: 0xb0915e [node] 46 // 3: 0xca8413 node::crypto::TLSWrap::DoWrite(node::WriteWrap*, uv_buf_t*, unsigned long, uv_stream_s*) [node] 47 // 4: 0xcaa549 node::StreamBase::Write(uv_buf_t*, unsigned long, uv_stream_s*, v8::Local<v8::Object>) [node] 48 // 5: 0xca88d7 node::crypto::TLSWrap::EncOut() [node] 49 // 6: 0xd3df3e [node] 50 // 7: 0xd3f35f v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node] 51 // 8: 0x15d9ef9 [node] 52 // Aborted 53 tls.connect({ 54 socket: down, 55 rejectUnauthorized: false 56 }); 57 }); 58} 59