This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Description
This script works up until node v0.11.3. I can bisect the exact commit a bit later...
var fs = require('fs');
var net = require('net');
var tls = require('tls');
var assert = require('assert');
var options, a, b, portA, portB;
var gotHello = false;
options = {
key: fs.readFileSync(__dirname + '/test/server.key'),
cert: fs.readFileSync(__dirname + '/test/server.crt')
};
// the "proxy" server
a = tls.createServer(options, function (socket) {
var options = {
host: '127.0.0.1',
port: b.address().port
};
var dest = net.connect(options);
dest.pipe(socket);
socket.pipe(dest);
});
options = {
key: fs.readFileSync(__dirname + '/test/proxy.key'),
cert: fs.readFileSync(__dirname + '/test/proxy.crt')
};
// the "target" server
b = tls.createServer(options, function (socket) {
socket.end('hello');
});
process.on('exit', function () {
assert(gotHello);
});
a.listen(function () {
b.listen(function () {
options = {
host: '127.0.0.1',
port: a.address().port,
rejectUnauthorized: false
};
var socket = tls.connect(options);
var ssl;
ssl = tls.connect({
socket: socket,
rejectUnauthorized: false
});
ssl.setEncoding('utf8');
ssl.once('data', function (data) {
assert.equal('hello', data);
gotHello = true;
});
ssl.on('end', function () {
ssl.end();
a.close();
b.close();
});
});
});
Causes:
☮ ~ (master) ∴ node -v
v0.11.7
☮ ~ (master) ∴ node tls-over-tls-fail.js
Assertion failed: (uv__stream_fd(stream) >= 0), function uv__read_start_common, file ../deps/uv/src/unix/stream.c, line 1331.
Abort trap: 6