-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: allow TLSSocket construction with a list of ALPNProtocols #16655
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
78 changes: 78 additions & 0 deletions
78
test/parallel/test-tls-socket-constructor-alpn-npn-options-parsing.js
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,78 @@ | ||
'use strict'; | ||
|
||
// Test that TLSSocket can take arrays of strings for ALPNProtocols and | ||
// NPNProtocols. | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const tls = require('tls'); | ||
|
||
new tls.TLSSocket(null, { | ||
ALPNProtocols: ['http/1.1'], | ||
NPNProtocols: ['http/1.1'] | ||
}); | ||
|
||
if (!process.features.tls_npn) | ||
common.skip('node compiled without NPN feature of OpenSSL'); | ||
|
||
if (!process.features.tls_alpn) | ||
common.skip('node compiled without ALPN feature of OpenSSL'); | ||
|
||
const assert = require('assert'); | ||
const net = require('net'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const key = fixtures.readKey('agent1-key.pem'); | ||
const cert = fixtures.readKey('agent1-cert.pem'); | ||
|
||
const protocols = []; | ||
|
||
const server = net.createServer(common.mustCall((s) => { | ||
const tlsSocket = new tls.TLSSocket(s, { | ||
isServer: true, | ||
server, | ||
key, | ||
cert, | ||
ALPNProtocols: ['http/1.1'], | ||
NPNProtocols: ['http/1.1'] | ||
}); | ||
|
||
tlsSocket.on('secure', common.mustCall(() => { | ||
protocols.push({ | ||
alpnProtocol: tlsSocket.alpnProtocol, | ||
npnProtocol: tlsSocket.npnProtocol | ||
}); | ||
tlsSocket.end(); | ||
})); | ||
}, 2)); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const alpnOpts = { | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
ALPNProtocols: ['h2', 'http/1.1'] | ||
}; | ||
const npnOpts = { | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
NPNProtocols: ['h2', 'http/1.1'] | ||
}; | ||
|
||
tls.connect(alpnOpts, function() { | ||
this.end(); | ||
|
||
tls.connect(npnOpts, function() { | ||
this.end(); | ||
|
||
server.close(); | ||
|
||
assert.deepStrictEqual(protocols, [ | ||
{ alpnProtocol: 'http/1.1', npnProtocol: false }, | ||
{ alpnProtocol: false, npnProtocol: 'http/1.1' } | ||
]); | ||
}); | ||
}); | ||
})); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is the idea here that the constructor call should work even if ALPN and NPN are disabled?
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.
This was the original test I created for this PR. On master this’ll throw because the constructor expects a buffer (where each option is used). The particular usecase which led to me encountering this issue is a proxy which needs to avoid HTTP/2 (so these options are given without “h2”).