Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

http2: specify default TLS options for http2 client connection. #61

Closed
wants to merge 4 commits into from

Conversation

jmuk
Copy link
Contributor

@jmuk jmuk commented May 2, 2017

fixes: #59

mcollina

This comment was marked as off-topic.

@jasnell
Copy link
Member

jasnell commented May 2, 2017

Had a different approach in mind for fixing this:

diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 6afc87e6f7..052513289f 100755
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -1077,6 +1077,7 @@ function initializeOptions(options) {
   options = options || {};
   if (typeof options !== 'object')
     throw new TypeError('options must be an object');
+  options = Object.create(options);
   options.allowHalfOpen = true;
   options.settings = options.settings || {};
   if (typeof options.settings !== 'object')
@@ -1084,10 +1085,12 @@ function initializeOptions(options) {
   return options;
 }

-function initializeTLSOptions(options) {
+function initializeTLSOptions(options, host) {
   options = initializeOptions(options);
   options.ALPNProtocols = ['hc', 'h2'];
   options.NPNProtocols = ['hc', 'h2'];
+  if (host !== undefined)
+    options.servername = host;
   return options;
 }

@@ -1235,7 +1238,7 @@ function connect(authority, options, listener) {
       socket = net.connect(port, host);
       break;
     case 'https:':
-      socket = tls.connect(port, host, options);
+      socket = tls.connect(port, host, initializeTLSOptions(options, host));
       break;
     default:
       throw new TypeError(`protocol "${protocol}" in unsupported.`);
james@ubuntu:~/node/http2-jasnell$

This allows us to have a central place for setting the TLS options for both server and client.

jmuk added 2 commits May 2, 2017 14:57
This verifies to send the server name and ALPN protocols
by default.
@jmuk
Copy link
Contributor Author

jmuk commented May 2, 2017

Thank you for the review! Added a test case, and fixed the client code for your latter suggestion.

@jmuk
Copy link
Contributor Author

jmuk commented May 2, 2017

By the way -- where does the ALPN name 'hc' come from? I can't find the document referring that value -- http2 spec would suggest to use h2 only for TLS context, I suppose (see https://http2.github.io/http2-spec/#rfc.section.3.1).

@jasnell
Copy link
Member

jasnell commented May 2, 2017

I think it's an old pre-standard value. One of the browser impls was using it. Whether or not we need to keep it remains to be seen

mcollina

This comment was marked as off-topic.

@jmuk
Copy link
Contributor Author

jmuk commented May 4, 2017

Removed the count, thank you for the background info.

jasnell

This comment was marked as off-topic.

@jasnell
Copy link
Member

jasnell commented May 5, 2017

@mcollina ... ping

mcollina

This comment was marked as off-topic.

@mcollina
Copy link
Member

mcollina commented May 5, 2017

LGTM

jasnell pushed a commit that referenced this pull request May 7, 2017
fixes: #59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: #61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented May 7, 2017

Landed!

@jasnell jasnell closed this May 7, 2017
jasnell pushed a commit that referenced this pull request May 19, 2017
fixes: #59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: #61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit that referenced this pull request May 31, 2017
fixes: #59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: #61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jun 22, 2017
fixes: nodejs#59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: nodejs#61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jul 10, 2017
fixes: nodejs#59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: nodejs#61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jul 14, 2017
fixes: nodejs#59

Also, add a testcase for http2/TLS secure connection.
This verifies to send the server name and ALPN protocols
by default.

PR-URL: nodejs#61
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

a better default configuration for TLS connection of http2
3 participants