Skip to content

Fix OpenSSL::SSL::SSLContext#min_version= failure #215

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

Merged
merged 2 commits into from
Oct 29, 2020

Conversation

MariuszCwikla
Copy link
Contributor

This is attempt to fix jruby/jruby#6409.

I couldn't test it with unit tests due to other issues. However I tested it with following script
issue_6409.zip
I compared results between ruby and jruby and it seems it's working almost the same, e.g.

  • different error messages
  • ruby fails when setting min_version to SSLv2
    I believe these discrepancies could be ignored.

I attempted to implement unit test test_minmax_ssl_version however server method fails even on master with no cipher match error. So firstly master branch should be stabilized due to this and other issues before this PR can be finished.

This is still WIP, however comments are welcome.

@djberg96
Copy link

Thanks for tackling this!

ruby fails when setting min_version to SSLv2

Perhaps C Ruby is using whatever is set in the openssl config?

Copy link
Member

@kares kares left a comment

Choose a reason for hiding this comment

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

👍 good work, we need a couple of minor changes as outlined in the comments

if (version.isNil())
return 0;
if (version instanceof RubyFixnum) {
return (int) ((RubyFixnum) version).getLongValue();
Copy link
Member

Choose a reason for hiding this comment

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

let's just to getIntValue() here so we handle overflown values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately there is no getIntValue().
But I double checked and found static int fix2int(RubyFixnum arg)

Copy link
Member

Choose a reason for hiding this comment

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

right, yeah that one doing the int check before cast.

Copy link
Contributor Author

@MariuszCwikla MariuszCwikla Oct 28, 2020

Choose a reason for hiding this comment

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

Done, thanks


#ssl_server = server
begin
ssl_client = client(443, host: "google.com", min_version: OpenSSL::SSL::TLS1_VERSION, max_version: OpenSSL::SSL::TLS1_1_VERSION, ciphers: nil)
Copy link
Member

Choose a reason for hiding this comment

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

believe we want some unit tests (done above except for the set_minmax_proto_version) for the version parsing/mapping instead of an integration tests here.
also not sure hard-coding what google has on their servers atm.
anyhow it's a good start but we might want to do an integration tests for this elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, totally agree.

This PR will still need to be polished, more tests added.
But first I believe that master branch should be stabilized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've added integration test in src/test/integration/ssl_test.rb like you suggested.
test_socket.rb still needs improvement.

Copy link
Member

Choose a reason for hiding this comment

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

should we remove this than, it's very dependend on what google.com has set on its servers, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let me remove it later since I've added the integration test.
What do you think about the integration test then?

Later I will try to rework test in test_socket.rb or remove completely since it cannot be tested now due to another issue (server method fails with no ciphers match) at least on my env.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let me remove it later since I've added the integration test.

sorry but I would prefer not to deal with leftovers as they will bite someone later.
I am fully aware CI testing is broken atm but that is no reason to leave externally dependent tests here.
you can keep it around for yourself in a follow-up branch.

What do you think about the integration test then?

we do not run those atm regularly, so I am fine with having them as you did. thanks.

Copy link
Contributor Author

@MariuszCwikla MariuszCwikla Oct 28, 2020

Choose a reason for hiding this comment

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

Done. I Removed this test.
Instead I've got inspired by test_ssl.rb and implemented parameterized test for this issue.

@@ -214,7 +214,7 @@ def ssl_version=(meth)
raise ArgumentError, "unknown SSL method `%s'" % meth
set_minmax_proto_version(version, version)
@min_proto_version = @max_proto_version = version
end unless method_defined? :ssl_version=
Copy link
Member

Choose a reason for hiding this comment

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

let's keep this as is as it seems unrelated to the PR changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I had a reason to remove this. I compared this with CRuby version: https://github.com/ruby/ruby/blob/ruby_2_6/ext/openssl/lib/openssl/ssl.rb#L213
which does not have unless method_defined? :ssl_version=

I'll double check it and revert if it's fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed.
Only one smalll difference, unrealistic though, (was successful before, now fails with no protocols available):

ctx.ssl_version = "TLSv1"
ctx.min_version = OpenSSL::SSL::TLS1_VERSION
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, will need to 👀 at this since it changed behavior - which I did not expect to happen.

@MariuszCwikla MariuszCwikla force-pushed the issue_6409_ssl_min_version branch 2 times, most recently from 645a219 to 1ff15d2 Compare October 26, 2020 15:58
@MariuszCwikla MariuszCwikla force-pushed the issue_6409_ssl_min_version branch from 1ff15d2 to 4ddcdb0 Compare October 26, 2020 17:25
@MariuszCwikla MariuszCwikla force-pushed the issue_6409_ssl_min_version branch 2 times, most recently from 166bd84 to 303f6c8 Compare October 28, 2020 17:44
@MariuszCwikla MariuszCwikla force-pushed the issue_6409_ssl_min_version branch from 303f6c8 to 2d91787 Compare October 28, 2020 17:47
@MariuszCwikla
Copy link
Contributor Author

I had to rework this due to issue introduce by my previous commit. I hope now it's fine. It's bit greener now.
I've also added a parameterized test in test_ssl.rb to test matrix of cases.

This test also works fine with CRuby. Try this:

ruby src\test\ruby\ssl\test_ssl.rb -n "/test_ssl_minmax_.*/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenSSL::SSL::SSLContext#min_version= failure
4 participants