Skip to content
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: do not crash on STARTTLS when OCSP requested #10706

Closed
wants to merge 7 commits into from

Conversation

indutny
Copy link
Member

@indutny indutny commented Jan 9, 2017

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

tls

TLSSocket should not have a hard dependency on tls.Server, since it
may be running without it in cases like STARTTLS.

Fix: #10704

`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: nodejs#10704
@nodejs-github-bot nodejs-github-bot added tls Issues and PRs related to the tls subsystem. lts-watch-v6.x labels Jan 9, 2017
@indutny
Copy link
Member Author

indutny commented Jan 9, 2017

cc @nodejs/crypto

@indutny
Copy link
Member Author

indutny commented Jan 9, 2017

cc @nodejs/collaborators

@jasnell
Copy link
Member

jasnell commented Jan 9, 2017

this looks like semver-patch but just to be safe, is there any possibility that this could break anything? (I highly doubt it but given the removal of the requirement there's always a slight possibility)

}),

SNICallback: common.mustCall((hostname, callback) => {
assert.equal(hostname, 'test.test');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to assert.strictEqual().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and removed that console.log() below.

@indutny
Copy link
Member Author

indutny commented Jan 9, 2017

@jasnell no possibility, everything that hit that code path was broken until this patch

};

const client = tls.connect(opts, function() {
client.end();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just use this, and delete the const client =

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

return;
}

const assert = require('assert');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort requires

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

SNICallback: common.mustCall((hostname, callback) => {
assert.deepEqual(hostname, 'test.test');

callback(null, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://github.com/nodejs/node/blob/master/doc/api/tls.md#tlscreateserveroptions-secureconnectionlistener

SNICallback should invoke cb(null, ctx), where ctx is a SecureContext instance.

Is (null, null) valid? Should it be valid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is valid and it should be valid.

@@ -0,0 +1,49 @@
'use strict';
const common = require('../common');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md#test-structure

A test should start with a comment containing a brief description of what it is designed to test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggested tweek to in-source comment, otherwise LGTM

lib/_tls_wrap.js Outdated
@@ -114,6 +114,12 @@ function requestOCSP(self, hello, ctx, cb) {

if (!ctx)
ctx = self.server._sharedCreds;

// Running on non-TLS server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment confused me when I read it, and I only understood when reading the unit test and PR history. Can I suggest:

TLS socket is using a net.Server, instead of a tls.TLSServer, so some TLS properties will not be present.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this comment is rather cryptic.

@webertrlz
Copy link

Do you have any information on when this will be merged and released?

@sam-github
Copy link
Contributor

@nodejs/crypto a review from one of you is required, I believe.

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if you clarify the comment.

lib/_tls_wrap.js Outdated
@@ -114,6 +114,12 @@ function requestOCSP(self, hello, ctx, cb) {

if (!ctx)
ctx = self.server._sharedCreds;

// Running on non-TLS server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed this comment is rather cryptic.

@webertrlz
Copy link

Is it possible to catch this crash as an exception? I didn't succeed so far. This would be a good workaround until this is packaged.

@indutny
Copy link
Member Author

indutny commented Feb 3, 2017

Pushed the fix to the comment, PTAL. Landing if the wording is fine.

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a suggestion.

lib/_tls_wrap.js Outdated
@@ -115,7 +115,8 @@ function requestOCSP(self, hello, ctx, cb) {
if (!ctx)
ctx = self.server._sharedCreds;

// Running on non-TLS server
// TLS socket is using a `net.Server` instead of a tls.TLSServer.
// Some TLS properties will not be present.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider giving one or two examples of properties that won't be there.

@indutny
Copy link
Member Author

indutny commented Feb 3, 2017

@bnoordhuis ACK

@addaleax
Copy link
Member

@webertrlz
Copy link

hello,

sorry for asking this but I'd like to know if there is any planning on merging+packaging this PR.
otherwise I'll have to build a version with this fix for my production environment.

Thanks.

@jasnell
Copy link
Member

jasnell commented Feb 22, 2017

@webertrlz Yes, this should land assuming that CI comes back good.

@sam-github
Copy link
Contributor

Landed in a1802e6

@sam-github sam-github closed this Feb 22, 2017
sam-github pushed a commit that referenced this pull request Feb 22, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@sam-github
Copy link
Contributor

Won't show up packaged until the next 7.x release, which will be a couple weeks at least.

@webertrlz
Copy link

The post above means that it won't go packaged for 6.XX LTS?

@addaleax
Copy link
Member

@webertrlz The rules are that changes first have to live an a Current release for two weeks before they are applied to the LTS branches. This change will almost certainly be available in the next one or two v6.x releases, and probably v4.x as well.

@webertrlz
Copy link

@addaleax understood! Thanks!

addaleax pushed a commit that referenced this pull request Feb 22, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@italoacasas italoacasas mentioned this pull request Feb 25, 2017
jasnell pushed a commit that referenced this pull request Mar 7, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
jasnell pushed a commit that referenced this pull request Mar 7, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@MylesBorins MylesBorins mentioned this pull request Mar 9, 2017
MylesBorins pushed a commit that referenced this pull request Mar 9, 2017
`TLSSocket` should not have a hard dependency on `tls.Server`, since it
may be running without it in cases like `STARTTLS`.

Fix: #10704
PR-URL: #10706
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@MylesBorins MylesBorins mentioned this pull request Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants