You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LibreSSL does not tolerate setting minimum_version greater than maximum_version #78182
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/tiran'closed_at=<Date2021-04-17.19:36:30.716>created_at=<Date2018-06-29.16:09:13.706>labels= ['3.7', 'expert-SSL', '3.8', 'type-bug', 'tests']
title='LibreSSL does not tolerate setting minimum_version greater than maximum_version'updated_at=<Date2021-04-17.19:36:30.716>user='https://github.com/alanhuang122'
LibreSSL has a function called ssl_clamp_version_range that is called before attempting to set the minimum and maximum protocol versions in ssl_version_set_{min,max}. The function disallows setting ranges that are invalid (i.e., where minimum_version > maximum_version). OpenSSL does not disallow this behavior.
As a result, attempting to set a minimum_version greater than a maximum_version results in a ValueError when Python is built with LibreSSL.
There are two things that might need fixing here:
Replace the ValueError "Unsupported protocol version 0x%x" message with a more generic one. The assumption that the only way the operation can fail is if the underlying library does not support the protocol version is incorrect.
This can be done by either making the message more generic or by introducing another error message to handle this case.
Change test_min_max_version lines 3575-3576 to set the maximum_version before the minimum_version.
Here's some Python code to reproduce the above-mentioned error:
import ssl
ctx = ssl.SSLContext()
ctx.maximum_version = ssl.TLSVersion.TLSv1_1
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alan/src/cpython/Lib/ssl.py", line 491, in minimum_version
super(SSLContext, SSLContext).minimum_version.__set__(self, value)
ValueError: Unsupported protocol version 0x303
Here's some example C code:
#include <openssl/ssl.h>
#include <openssl/ossl_typ.h>
#include <stdio.h>
int main(){
SSL_CTX *ctx = NULL;
ctx = SSL_CTX_new(TLS_method());
printf("setting max to TLSv1.1: ");
if(SSL_CTX_set_max_proto_version(ctx, TLS1_1_VERSION)){
printf("success\n");
}
else{
printf("failure\n");
}
printf("setting min to TLSv1.2: ");
if(SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION)){
printf("success\n");
}
else{
printf("failure\n");
}
printf("min ver: %d\n", SSL_CTX_get_min_proto_version(ctx));
printf("max ver: %d\n", SSL_CTX_get_max_proto_version(ctx));
return 0;
}
Under LibreSSL 2.7.4, this produces:
setting max to TLSv1.1: success
setting min to TLSv1.2: failure
min ver: 769
max ver: 770
Under OpenSSL 1.1.0g, this produces:
setting max to TLSv1.1: success
setting min to TLSv1.2: success
min ver: 771
max ver: 770
The test that failed:
======================================================================
ERROR: test_min_max_version (test.test_ssl.ThreadedTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/alan/src/cpython/Lib/test/test_ssl.py", line 3575, in test_min_max_version
server_context.minimum_version = ssl.TLSVersion.TLSv1_2
File "/home/alan/src/cpython/Lib/ssl.py", line 491, in minimum_versionsuper(SSLContext, SSLContext).minimum_version.__set__(self, value)
ValueError: Unsupported protocol version 0x303
Strangely, LibreSSL's ssl_clamp_version_range function is perfectly happy to accept minimum protocol versions lower than the lowest supported protocol version, and likewise is happy to accept maximum protocol versions higher than the highest supported protocol version.
In said case, the minimum/maximum protocol version is set to clamp_min/clamp_max (i.e., the minimum/maximum protocol version supported by the internal method).
As such, the assertion test ctx.minimum_version = 42 on line 1127 in test_min_max_version in test_ssl.py fails.
A possible fix would be to add another check in set_min_max_proto_version _ssl.c that checks if the current set protocol version is equal to the value passed (with exceptions for the magic constants of MINIMUM_SUPPORTED and MAXIMUM_SUPPORTED), and if not, raise a ValueError as well.
One dilemma is whether to reset the respective version back to what it was before the attempt, which I think should be done.
Activity
alanhuang122 commentedon Jun 29, 2018
LibreSSL has a function called
ssl_clamp_version_rangethat is called before attempting to set the minimum and maximum protocol versions inssl_version_set_{min,max}. The function disallows setting ranges that are invalid (i.e., where minimum_version > maximum_version). OpenSSL does not disallow this behavior.As a result, attempting to set a minimum_version greater than a maximum_version results in a ValueError when Python is built with LibreSSL.
There are two things that might need fixing here:
This can be done by either making the message more generic or by introducing another error message to handle this case.
Here's some Python code to reproduce the above-mentioned error:
Here's some example C code:
Under LibreSSL 2.7.4, this produces:
Under OpenSSL 1.1.0g, this produces:
The test that failed:
======================================================================
ERROR: test_min_max_version (test.test_ssl.ThreadedTests)
----------------------------------------------------------------------
alanhuang122 commentedon Jul 2, 2018
Strangely, LibreSSL's
ssl_clamp_version_rangefunction is perfectly happy to accept minimum protocol versions lower than the lowest supported protocol version, and likewise is happy to accept maximum protocol versions higher than the highest supported protocol version.In said case, the minimum/maximum protocol version is set to clamp_min/clamp_max (i.e., the minimum/maximum protocol version supported by the internal method).
As such, the assertion test
ctx.minimum_version = 42on line 1127 in test_min_max_version in test_ssl.py fails.A possible fix would be to add another check in
set_min_max_proto_version_ssl.c that checks if the current set protocol version is equal to the value passed (with exceptions for the magic constants ofMINIMUM_SUPPORTEDandMAXIMUM_SUPPORTED), and if not, raise a ValueError as well.One dilemma is whether to reset the respective version back to what it was before the attempt, which I think should be done.
Yhg1s commentedon Sep 11, 2019
New changeset c9bc49c by T. Wouters (Christian Heimes) in branch 'master':
bpo-34001: Fix test_ssl with LibreSSL (GH-13783)
c9bc49c
matrixise commentedon Sep 11, 2019
New changeset d6ac67f by Stéphane Wirtel (Miss Islington (bot)) in branch '3.8':
bpo-34001: Fix test_ssl with LibreSSL (GH-13783) (bpo-15997)
d6ac67f
Fix test for LibreSSL
Fix test_tls_version for LibreSSL
Fix test_tls_version for LibreSSL
Fix test_tls_version for LibreSSL (#974)