-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLS: improve compliance with shutdown standard
RFC 5246 section-7.2.1 requires that the implementation must immediately stop using the stream, as it is no longer TLS-encrypted. The stream is permitted to still pump events (and errors) to other users, but those are now unencrypted, so we should not process them here. But therefore, we do not want to stop the underlying stream, as there could be another user of it, but we do remove ourselves as a listener. The section also states that the application must destroy the stream immediately (discarding any pending writes, and sending a close_notify response back), but we leave that to the upper layer of the application here, as it should be sufficient to permit standards compliant usage just to be ignoring read events. Fixes: nodejs/node#35904 Closes: nodejs/node#35946 Co-authored-by: Momtchil Momtchev <[email protected]>
- Loading branch information
Showing
4 changed files
with
73 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const tls = require('tls'); | ||
const fixtures = require('../common/fixtures'); | ||
const https = require('https'); | ||
const key = fixtures.readKey('agent1-key.pem'); | ||
const cert = fixtures.readKey('agent1-cert.pem'); | ||
const net = require('net'); | ||
const { Duplex } = require('stream'); | ||
|
||
class CustomAgent extends https.Agent { | ||
createConnection(options, cb) { | ||
const realSocket = net.createConnection(options); | ||
const stream = new Duplex({ | ||
emitClose: false, | ||
read(n) { | ||
(function retry() { | ||
const data = realSocket.read(); | ||
if (data === null) | ||
return realSocket.once('readable', retry); | ||
stream.push(data); | ||
})(); | ||
}, | ||
write(chunk, enc, callback) { | ||
realSocket.write(chunk, enc, callback); | ||
}, | ||
}); | ||
realSocket.on('end', () => { | ||
stream.push(null); | ||
}); | ||
|
||
stream.on('end', common.mustCall()); | ||
return tls.connect({ ...options, socket: stream }); | ||
} | ||
} | ||
|
||
const httpsServer = https.createServer({ | ||
key, | ||
cert, | ||
}, (req, res) => { | ||
httpsServer.close(); | ||
res.end('hello world!'); | ||
}); | ||
httpsServer.listen(0, 'localhost', () => { | ||
const agent = new CustomAgent(); | ||
https.get({ | ||
host: 'localhost', | ||
port: httpsServer.address().port, | ||
agent, | ||
headers: { Connection: 'close' }, | ||
rejectUnauthorized: false | ||
}, (res) => { | ||
res.resume(); | ||
}); | ||
}); |