Skip to content

Refuse min proto version > max proto version#5128

Closed
tiran wants to merge 2 commits intoopenssl:masterfrom
tiran:min_max_proto_validation
Closed

Refuse min proto version > max proto version#5128
tiran wants to merge 2 commits intoopenssl:masterfrom
tiran:min_max_proto_validation

Conversation

@tiran
Copy link
Contributor

@tiran tiran commented Jan 21, 2018

SSL_CTX_set_min_proto_version() and SSL_CTX_set_max_proto_version() as
well as their SSL equivalents now validate that the mininum protocol
version is lower or requal the maximum protocol version.

Add test cases for min/max protocol API

Closes: #5127
Signed-off-by: Christian Heimes christian@python.org

Also see #5126

tiran added 2 commits January 21, 2018 13:17
SSL_CTX_set_min_proto_version() and SSL_CTX_set_max_proto_version() as
well as their SSL equivalents now validate that the mininum protocol
version is lower or requal the maximum protocol version.

Closes: openssl#5127
Signed-off-by: Christian Heimes <christian@python.org>
Signed-off-by: Christian Heimes <christian@python.org>
@kroeckx
Copy link
Member

kroeckx commented Jan 21, 2018 via email

richsalz
richsalz previously approved these changes Jan 21, 2018
Copy link
Contributor

@richsalz richsalz left a comment

Choose a reason for hiding this comment

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

This is awesome! A few nits on the new test program.

int testresult = 0;
version_test t = version_testdata[idx_tst];

ctx = SSL_CTX_new(TLS_server_method());
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 use TEST_PTR for these?


if (!TEST_int_eq(SSL_CTX_set_min_proto_version(ctx, t.min_version), t.min_ok))
goto end;
if (!TEST_int_eq(SSL_CTX_set_max_proto_version(ctx, t.max_version), t.max_ok))
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to cascade all the if tests together for this kind of thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like this? It's still short circuit evaluation.

    if (!TEST_int_eq(SSL_CTX_set_min_proto_version(ctx, t.min_version), t.min_ok) ||
        !TEST_int_eq(SSL_CTX_set_max_proto_version(ctx, t.max_version), t.max_ok) ||
        !TEST_int_eq(SSL_CTX_get_min_proto_version(ctx), t.expected_min) ||
        !TEST_int_eq(SSL_CTX_get_max_proto_version(ctx), t.expected_max)
       )
        goto end;

Copy link
Contributor

Choose a reason for hiding this comment

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

yes like that, except put the || at the start of the line and double-indent the tests and move up the close paren. See enctest.c, etc., for examples.

@richsalz
Copy link
Contributor

richsalz commented Jan 21, 2018

ooops, meant to check 'request changes'

@davidben
Copy link
Contributor

+1 to what @kroeckx said. The problem with this sort of thing is that it causes an interdependence between two config options, which is really messy. (See the complexities around configuring private key and certificate and when you check for consistency.)

For something like this where the check doesn't really do much useful (the handshake will just fail immediately), it's much simpler to defer to that rather than add logic everywhere.

@davidben
Copy link
Contributor

davidben commented Jan 21, 2018

For instance, consider this:

void SetOnlyVersion(SSL *ssl, uint16_t version) {
#if 1
  SSL_set_min_proto_version(ssl, version);
  SSL_set_max_proto_version(ssl, version);
#else
  SSL_set_max_proto_version(ssl, version);
  SSL_set_min_proto_version(ssl, version);
#endif
}

void ChangeMyMind(SSL *ssl) {
  SetOnlyVersion(ssl, TLS1_1_VERSION);  // 1
  SetOnlyVersion(ssl, TLS1_2_VERSION);  // 2
  SetOnlyVersion(ssl, TLS1_VERSION);  // 3
}

Before, either version would work fine. Versions may be temporarily out of sync and fixed later. With this PR, setting the min version first doesn't work because going from 1 to 2 breaks. Setting the max version first doesn't work because going from 2 to 3 breaks.

@kaduk
Copy link
Contributor

kaduk commented Jan 21, 2018

This is similar to the situation in #5057 and #5065, where the configuration APIs can be applied in different orders, and as such is too soon to effectively apply sanity checks to the configured values. As such, I think this PR should be rejected.

@mattcaswell mattcaswell added this to the 1.1.1 milestone Jan 24, 2018
levitte pushed a commit that referenced this pull request Jan 24, 2018
The getters for min and max proto version wrongly passed NULL instead of
0 as third argument to SSL_ctrl() and SSL_CTX_ctrl(). The third argument
is not used, but the error results in a compiler warning:

warning: passing argument 3 of ‘SSL_CTX_ctrl’ makes integer from pointer without a cast [-Wint-conversion]
int v = SSL_CTX_get_max_proto_version(self->ctx);

See #4364

Signed-off-by: Christian Heimes <christian@python.org>

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from #5128)
levitte pushed a commit that referenced this pull request Jan 24, 2018
The getters for min and max proto version wrongly passed NULL instead of
0 as third argument to SSL_ctrl() and SSL_CTX_ctrl(). The third argument
is not used, but the error results in a compiler warning:

warning: passing argument 3 of ‘SSL_CTX_ctrl’ makes integer from pointer without a cast [-Wint-conversion]
int v = SSL_CTX_get_max_proto_version(self->ctx);

See #4364

Signed-off-by: Christian Heimes <christian@python.org>

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from #5128)

(cherry picked from commit 1f82eba)
@kaduk
Copy link
Contributor

kaduk commented Jan 24, 2018

Whoops, I put some links in commits to this pull request that were supposed to go to #5126.
So, for future reference...

@kroeckx
Copy link
Member

kroeckx commented Jan 26, 2018

So I think we should just keep the test suite changes?

@tiran
Copy link
Contributor Author

tiran commented Jan 26, 2018

@kroeckx Sounds reasonable to me.

I'm currently at a conference. I'll attend to this PR and my other PRs either next week or the week after.

@kaduk
Copy link
Contributor

kaduk commented Feb 28, 2018

@tiran it sounds like we are waiting for an update to trim this down to just the tes suite changes, does that match your understanding?

@tiran
Copy link
Contributor Author

tiran commented Feb 28, 2018

Yes.

I'm sorry that I haven't had time to rework my patches. I spent all my free OSS time to get Python 3.7 improvement done before final beta freeze.

@kaduk
Copy link
Contributor

kaduk commented Feb 28, 2018

Understandable. (But note that we've only got two weeks until the openssl 1.1.1 feature freeze with the current schedule, https://www.openssl.org/policies/releasestrat.html)

@mattcaswell
Copy link
Member

Ping @tiran

@levitte
Copy link
Member

levitte commented Mar 29, 2018

This needs a rebase, and code needs to be corrected (see the CI results)

@levitte
Copy link
Member

levitte commented Mar 29, 2018

Actually, looking more closely at the CI issues, I figure that a rebase will fix them as well.

@richsalz richsalz dismissed their stale review April 18, 2018 19:47

Going to change to just the test cases.

@levitte
Copy link
Member

levitte commented Jun 21, 2018

I think we lost @tiran. I can take this over like I've done with others... good idea?

@richsalz
Copy link
Contributor

Please do take it over! I gave it a try and failed.

@levitte
Copy link
Member

levitte commented Jun 21, 2018

Continued in #6553, closing this

@levitte levitte closed this Jun 21, 2018
patricthysell pushed a commit to archive-br-automation-com/openssl-ar-dev that referenced this pull request Sep 7, 2020
 from Refuse min proto version > max proto version openssl#5128, otherwise ssl_ctx_test / iteration 4 fails  openssl@3bc53c8
liljaq pushed a commit to archive-br-automation-com/openssl-ar-dev that referenced this pull request Sep 4, 2024
 from Refuse min proto version > max proto version openssl#5128, otherwise ssl_ctx_test / iteration 4 fails  openssl@3bc53c8
liljaq pushed a commit to archive-br-automation-com/openssl-ar-dev that referenced this pull request Sep 5, 2024
 from Refuse min proto version > max proto version openssl#5128, otherwise ssl_ctx_test / iteration 4 fails  openssl@3bc53c8
liljaq pushed a commit to archive-br-automation-com/openssl-ar-dev that referenced this pull request Oct 21, 2024
 from Refuse min proto version > max proto version openssl#5128, otherwise ssl_ctx_test / iteration 4 fails  openssl@3bc53c8
liljaq added a commit to archive-br-automation-com/openssl-ar-dev that referenced this pull request Nov 14, 2024
This reverts commit 89a2668.

The fix is not needed anymore, as the test have been changed to reflect
that min is allowed to be larger than max. See link below for more
information:

openssl#10337
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.

7 participants