Skip to content

Don't set SNI by default if hostname is not dNS name; fixes #8083#8175

Closed
iamihalcea wants to merge 4 commits intoopenssl:masterfrom
iamihalcea:master
Closed

Don't set SNI by default if hostname is not dNS name; fixes #8083#8175
iamihalcea wants to merge 4 commits intoopenssl:masterfrom
iamihalcea:master

Conversation

@iamihalcea
Copy link
Copy Markdown

@iamihalcea iamihalcea commented Feb 6, 2019

Don't set SNI by default (i.e. when -servername is not set) in clientHello if hostname is not dNS name

CLA not yet completed, will do asap

Fixes #8083

Checklist
  • documentation is added or updated
  • tests are added or updated

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Feb 6, 2019
Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown

@vdukhovni vdukhovni left a comment

Choose a reason for hiding this comment

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

The code looks fine. Please address the requested changes in the comments and documentation. Finally, I might note that "all-numeric" does not take "-" into account. Thus "12-34.56-78" will be considered "all-numeric", which it is not, but I don't expect we need to handle these by adding all_numeric = 0 when a hyphen is found.

Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The second sentence of the second comment paragraph is about X.509 and does not apply here. Delete it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed

Comment thread doc/man1/s_client.pod Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This text is surely wrong. When -servername <name> is given, then that name and not the name from -connect will I expect be sent. Also the above sentence is poorly phrased. Could use some grammar editing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated - please have a look and let me know if it makes more sense now. Had to rearrange some bits.

Copy link
Copy Markdown

@vdukhovni vdukhovni left a comment

Choose a reason for hiding this comment

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

Provisional approval, modulo others not viewing the style nits as "must fix".

Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cosmetic: (@mattcaswell do we care?) We don't normally camel case internal functions in OpenSSL. To comport with the style of the existing code, perhaps this should be just is_dns_name()? Secondly, perhaps this function should be in apps.c just in case some other app will find use for it? I'm approving the PR, but if Matt or someone else wants the style issued addressed, please speak up...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are other names like this already in this file (e.g. ldap_ExtendedResponse_parse) so I don't find it so jarring in this case. I think the function is fine in this file for now. We can always move it to apps.c later if appropriate.

@mattcaswell
Copy link
Copy Markdown
Member

Close/reopen to kick CLA bot

@mattcaswell mattcaswell reopened this Feb 11, 2019
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Feb 11, 2019
@mattcaswell mattcaswell added branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) labels Feb 11, 2019
Comment thread apps/s_client.c Outdated
Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

EBCDIC issue here too

Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Drop XXX: from here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MAX_LABEL_LENGTH, i, length and label_length all seem to be more appropriately declared as size_t.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In cn2dnsid the original input is ASN.1 string, and the API for converting those to UTF8 uses integer lengths, so size_t was not an option there. Here, the hostname comes from the command-line, so size_t is possible, but does not add any measure of security, I am not aware of any OS where one can execute a program with a 2GB command-line argument... Still this code could size_t just to "unask" the question.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll change just to make it consistent with the "contents" of the variables

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right - my point wasn't really about security. More about using an appropriate and consistent type.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed

@mattcaswell
Copy link
Copy Markdown
Member

Oh...one other point. Please rebase this to remove the "merge" commit. We don't allow merge commits.

@iamihalcea
Copy link
Copy Markdown
Author

Oh...one other point. Please rebase this to remove the "merge" commit. We don't allow merge commits.

Fixed

Copy link
Copy Markdown

@vdukhovni vdukhovni left a comment

Choose a reason for hiding this comment

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

One minor style issue. I'm leaving it to Matt to decide how much EBCDIC support is appropriate to require here.

Comment thread apps/s_client.c Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Delete the blank line here, keeping all the declarations together.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Member

@mattcaswell mattcaswell left a comment

Choose a reason for hiding this comment

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

Approved subject to the minor styling nit that @vdukhovni noted being fixed.

Copy link
Copy Markdown

@vdukhovni vdukhovni left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

Copy link
Copy Markdown
Contributor

@kaduk kaduk left a comment

Choose a reason for hiding this comment

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

Most of this could have been fixed by the committer, but I think we need to check the length of all labels and not just the last one.

Comment thread apps/s_client.c
servername = (host == NULL) ? "localhost" : host;
if (!SSL_set_tlsext_host_name(con, servername)) {
if (servername == NULL) {
if(host == NULL || is_dNS_name(host))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: missing space in if (

Comment thread apps/s_client.c

/*
* Host dNS Name verifier: used for checking that the hostname is in dNS format
* before setting it as SNI
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: end the sentence with a period.

Comment thread apps/s_client.c
&& host[i + 1] != '.'
&& host[i - 1] != '-'
&& host[i + 1] != '-') {
label_length = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't we need to check label_length against MAX_LABEL_LENGTH here? At present I can only see us making that check for the final label (which is probably a TLD anyway).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The check is done for all labels - see end condition on the for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So it is, my apologies. (It seems that I got interrupted mid-review and lost some state.)
That said, the RFC allows a label of length exactly 63, but my first read of the for loop (and this check) would be that it would reject such a label.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does, though, suggest that we may want some test cases with 63- and 64-byte labels.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think attempting to test this would need the test itself to make calls across the network so I'll avoid doing that, but if there's a way to mock said calls I could give it a go - @mattcaswell ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't really have a good way to do that at the moment.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looking at the comment by @kaduk I also agree that the code seems to reject 63-octet labels, which are rare, but legal.

Comment thread apps/s_client.c
}

/* dNS name must not be all numeric and labels must be shorter than 64 characters. */
isdnsname &= !all_numeric && !(label_length == MAX_LABEL_LENGTH);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've been thinking of these variables as booleans, but &= is a bitwise operator.
And we don't do anything with isdnsname afterward anyway; can't we just return this expression?

Copy link
Copy Markdown
Author

@iamihalcea iamihalcea Feb 14, 2019

Choose a reason for hiding this comment

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

It is indeed a bitwise operator, but the effect is very much the same.
And I didn't return isdnsname && something_else because for a function named is_dNS_name, I find that confusing. I could change the name of the isdnsname variable, but efficiency-wise, the compiler should take care of it.

Copy link
Copy Markdown
Contributor

@kaduk kaduk left a comment

Choose a reason for hiding this comment

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

Having thought about this overnight, in the broader context of where this fits in, I don't think we necessarily need to hold it up on the precise details; even as-is it's a bit improvement over the previous status quo.

@richsalz
Copy link
Copy Markdown
Contributor

The command-line is also used for testing. Using the hostname automatically as the SNI if it looks like a hostname is the requirement. Enforcing all DNS requirements is not.

levitte pushed a commit that referenced this pull request Feb 19, 2019
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #8175)

(cherry picked from commit 8e98105)
@mattcaswell
Copy link
Copy Markdown
Member

Pushed to master and 1.1.1. Thanks!

levitte pushed a commit that referenced this pull request Feb 19, 2019
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #8175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch: master Applies to master branch branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants