2016-11-04 20:37:36 +01:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2017-10-06 18:52:35 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-11-04 20:37:36 +01:00
|
|
|
|
|
|
|
// Tests that calling disableRenegotiation on a TLSSocket stops renegotiation.
|
|
|
|
|
2017-07-17 19:32:25 +02:00
|
|
|
if (!common.hasCrypto)
|
2016-11-04 20:37:36 +01:00
|
|
|
common.skip('missing crypto');
|
2017-07-17 19:32:25 +02:00
|
|
|
|
2016-11-04 20:37:36 +01:00
|
|
|
const tls = require('tls');
|
|
|
|
|
|
|
|
const options = {
|
2017-10-06 18:52:35 +02:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2016-11-04 20:37:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const server = tls.Server(options, common.mustCall((socket) => {
|
|
|
|
socket.on('error', common.mustCall((err) => {
|
2017-12-20 12:58:03 +01:00
|
|
|
common.expectsError({
|
|
|
|
type: Error,
|
|
|
|
code: 'ERR_TLS_RENEGOTIATION_DISABLED',
|
|
|
|
message: 'TLS session renegotiation disabled for this socket'
|
|
|
|
})(err);
|
2016-11-04 20:37:36 +01:00
|
|
|
socket.destroy();
|
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
// Disable renegotiation after the first chunk of data received.
|
|
|
|
// Demonstrates that renegotiation works successfully up until
|
|
|
|
// disableRenegotiation is called.
|
|
|
|
socket.on('data', common.mustCall((chunk) => {
|
|
|
|
socket.write(chunk);
|
|
|
|
socket.disableRenegotiation();
|
|
|
|
}));
|
|
|
|
socket.on('secure', common.mustCall(() => {
|
|
|
|
assert(socket._handle.handshakes < 2,
|
|
|
|
`Too many handshakes [${socket._handle.handshakes}]`);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const port = server.address().port;
|
2017-07-22 18:20:53 +02:00
|
|
|
const options = {
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
port
|
|
|
|
};
|
2016-11-04 20:37:36 +01:00
|
|
|
const client =
|
2017-07-22 18:20:53 +02:00
|
|
|
tls.connect(options, common.mustCall(() => {
|
2016-11-04 20:37:36 +01:00
|
|
|
client.write('');
|
|
|
|
// Negotiation is still permitted for this first
|
|
|
|
// attempt. This should succeed.
|
|
|
|
client.renegotiate(
|
2017-07-22 18:20:53 +02:00
|
|
|
{ rejectUnauthorized: false },
|
2016-11-04 20:37:36 +01:00
|
|
|
common.mustCall(() => {
|
|
|
|
// Once renegotiation completes, we write some
|
|
|
|
// data to the socket, which triggers the on
|
|
|
|
// data event on the server. After that data
|
|
|
|
// is received, disableRenegotiation is called.
|
|
|
|
client.write('data', common.mustCall(() => {
|
|
|
|
client.write('');
|
|
|
|
// This second renegotiation attempt should fail
|
|
|
|
// and the callback should never be invoked. The
|
|
|
|
// server will simply drop the connection after
|
|
|
|
// emitting the error.
|
|
|
|
client.renegotiate(
|
2017-07-22 18:20:53 +02:00
|
|
|
{ rejectUnauthorized: false },
|
2016-11-04 20:37:36 +01:00
|
|
|
common.mustNotCall());
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|