-
-
Notifications
You must be signed in to change notification settings - Fork 1.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 hostname check #2708
TLS hostname check #2708
Conversation
I might be wrong, but I think trusty does not come with openssl 1.0.2+. I don't mind using either this or a manual check. |
is there option to disable check? |
9abc081
to
820ee56
Compare
context = OpenSSL::SSL::Context::Client.new | ||
context.verify_mode = OpenSSL::SSL::VerifyMode::NONE | ||
connect_to(host, context).should be_true | ||
end |
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.
@kostya No checks are actually performed unless the verify mode is peer.
this branch not compiled on ubuntu 14.04:
openssl1.0.1f |
I'm aware, CI is failing for the same reason. Still working on it. |
ifdef darwin | ||
OPENSSL_102 = false | ||
else | ||
OPENSSL_102 = {{`(pkg-config --atleast-version=1.0.2 libcrypto && echo true) || echo false`.id}} |
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.
Well, that would have been too easy I guess. In the latter {% if
s this is still a MacroExpression
. @asterite how do I run something at compile time once and use its result in different places at compile time without running it again and again? Alternatively I'd be already happy if I could run the macro expression to get its value and don't have to repeat that thing here all over the place.
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.
Note: darwin may have OpenSSL 1.0.2 installed (brew install openssl
) and it's perfectly possible to link against it --link-flags="-L/usr/local/opt/openssl/lib"
.
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.
Hence my question below as to whether we could detect that with pkg-config
on OS X too.
There is a single reason it's hard to enforce OpenSSL 1.0.2: it's barely available on stable distributions:
It would be very nice to have 1.0.2. Any older version isn't capable to negotiate HTTP/2 (ALPN is required) plus your case, the hostname verification, has become really simple. |
So let's find a way to optionally use 1.0.2 features. There's another question/comment I've already written, I wanted to wait for @asterite whether he sees a way to make something like the above possible, but since you brought OS X up, here it goes: How common is Whether we include this or not, implementing manual hostname verification will take the same amount of time, so this does provide better security for people running OpenSSL 1.0.2 at least, compared to doing it for nobody. |
OpenSSL is a great showcase for bundling CrystalLib into Crystal itself —as long as it doesn't fail when a symbol isn't found (this is expected). Generate the LibSSL bindings on-the-fly, then run feature detection: {% if LibSSL.methods.includes?("x509_verify_param_set1_host".id) %}
param = param = LibSSL.get0_param(@handle)
LibSSL.x509_verify_param_set1_host(param, hostname, 0)
{% else %}
# the hard way
{% end %} Another, harder way, would be to use DL and verify the presence of functions at runtime... |
@ysbaddaden In fact we thought about something like that with @waj, well, actually, giving more power to |
Maybe even having |
Could we not get too sidetracked here please? Any solution to this problem we can apply now? |
Looks like I found a workaround. So the last part to figure out is how to link to the homebrew OpenSSL on OS X automatically if available. I had a friend check and sadly even if |
Aside: I'm trying the manual validation, to enable it on previous OpenSSL releases, but it's tedious, thanks to the numerous nested macro defines of OpenSSL... so it will take some time. |
@jhass do you need help testing on OS X? |
I had a friend do a few more checks and it looks like that if crystal was installed through homebrew and there's a homebrew openssl available,
returns at various situations/places. @ysbaddaden since this now does degrade gracefully, I'd vote to merge this so you can base your work upon it. |
Based on #2707
With 1.0.2 OpenSSL gained support for doing hostname checks, see https://wiki.openssl.org/index.php/Hostname_validation
However is it okay to depend on 1.0.2? Should we implement our own hostname checking like Ruby does? Or given we find a way to detect the OpenSSL version (how?), should we use this only for OpenSSL 1.0.2+ or either this or a manual check?
I included a network dependent integration spec that should only manually be run, as well as API to enable CRL checks fairly easily, see #2707 and #2709.