-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add getProtocol() to TLS sockets #4995
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
return; | ||
} | ||
|
||
const tls = require('tls'); | ||
const fs = require('fs'); | ||
|
||
const clientConfigs = [ | ||
{ secureProtocol: 'TLSv1_method', version: 'TLSv1' }, | ||
{ secureProtocol: 'TLSv1_1_method', version: 'TLSv1.1' }, | ||
{ secureProtocol: 'TLSv1_2_method', version: 'TLSv1.2' } | ||
]; | ||
|
||
const serverConfig = { | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') | ||
}; | ||
|
||
const server = tls.createServer(serverConfig, common.mustCall(function() { | ||
|
||
}, clientConfigs.length)).listen(common.PORT, common.localhostIPv4, function() { | ||
let connected = 0; | ||
clientConfigs.forEach(function(v) { | ||
tls.connect({ | ||
host: common.localhostIPv4, | ||
port: common.PORT, | ||
rejectUnauthorized: false, | ||
secureProtocol: v.secureProtocol | ||
}, common.mustCall(function() { | ||
assert.strictEqual(this.getProtocol(), v.version); | ||
this.on('end', common.mustCall(function() { | ||
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. I really wonder how 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. The callback passed to 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. I see. You are right. Thanks for clarifying :) |
||
assert.strictEqual(this.getProtocol(), null); | ||
})).end(); | ||
if (++connected === clientConfigs.length) | ||
server.close(); | ||
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. Shouldn't this be inside the 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. It doesn't really need to be. 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. Mmmm. Makes sense. Cool then |
||
})); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this
unknown
case be tested?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very easily/reliably as it would probably have to amount to polling or maybe some kind of crazy monkey patching. Even at the stage in which an SNI callback is called, the protocol information is already available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay then. Since we claim that it would return unknown, I thought that it would have been better to have a test to confirm that.