-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
interface: disable ssl.VERIFY_X509_STRICT for self-signed certs #9258
Conversation
The "ssl.VERIFY_X509_STRICT" flag for openssl verification has been enabled by default in python 3.13+ (it was disabled before that). see python/cpython#107361 and https://discuss.python.org/t/ssl-changing-the-default-sslcontext-verify-flags/30230/16 We explicitly disable it for self-signed certs, thereby restoring the pre-3.13 defaults, as it seems to break lots of servers. For example, using python 3.13 (or setting `sslc.verify_flags |= ssl.VERIFY_X509_STRICT`), - I can connect to `btc.electroncash.dk:60002:s` - but not to `electrum.emzy.de:50002:s` despite both using self-signed certs. We should investigate more why exactly "strict" verification fails for some self-signed certs and not for others, and make sure that at least newly generated certs adhere to the stricter requirements (e.g. update guide in e-x?).
This cert successfully verifies with cert for btc.electroncash.dk:60002:s
This cert fails to verify with cert for electrum.emzy.de:50002:s
I am not sure what magic incantation openssl needs to tell me what the relevant difference between the two certs is. |
try the cert for btc.electroncash.dk is a selfsigned (root) CA cert, which apparently passes |
Ok, so I saved the two certs as files
|
well, with the
Without |
Another problem.. from the 'CA certificates must explicitly include the keyUsage extension.' There is no keyUsage record in |
interface.py accepts both public CA-signed certs and self-signed certs. I mentioned this command electrum/electrum/interface.py Line 502 in f9e342e
electrum/electrum/interface.py Line 515 in f9e342e
for the self-signed-cert-using servers, we are basically just setting cafile to a file that contains only the cert that the server sends us as-is. And this behaviour can apparently be replicated using the openssl verify -CAfile a a command. Additionally passing the -x509_strict replicates the new 3.13 behaviour.
|
Note:
This cert will fail I've found that the following cert passes
Thanks, that was very useful. I think the difference is due to the presence of the For example, the cert generated by the following snippet also validates with strict:
|
Yes, this is exactly as expected. My point is that normal self-signed certificates are NOT CA's.
Yes, adding self-signed NON-CA certs to the
To allow self-signed certificates, we probably should only enforce If the cert is self-signed CA we should |
Which part of the The third command from #9258 (comment) creates a cert that has this:
and that cert also passes strict validation. Anyway, I take it you think we can leave interface.py as-is then (as this PR left it)? |
Hmm, interesting.. In my case the generated cert has
might be a different distro-supplied |
For now I guess it's fine, as it retains the pre-py313 behavior, although I think it's good to eventually use strict checking on non-selfsigned certs.
Your command using |
Well with this PR we are doing whatever is the default (so strict after 3.13, non-strict before) for public CA-signed certs (line 502 and 512), electrum/electrum/interface.py Lines 501 to 519 in 26622a0
Right, sorry, I meant the third the command with all the explicit |
Ah yes, I can't read 🥇 |
The
ssl.VERIFY_X509_STRICT
flag for openssl verification has been enabled by default in python 3.13+ (it was disabled before that). see python/cpython#107361 and https://discuss.python.org/t/ssl-changing-the-default-sslcontext-verify-flags/30230/16We explicitly disable it for self-signed certs, thereby restoring the pre-3.13 defaults, as it seems to break lots of servers.
For example, using python 3.13 (or setting
sslc.verify_flags |= ssl.VERIFY_X509_STRICT
),btc.electroncash.dk:60002:s
electrum.emzy.de:50002:s
despite both using self-signed certs.
We should investigate more why exactly "strict" verification fails for some self-signed certs and not for others, and make sure that at least newly generated certs adhere to the stricter requirements (e.g. update guide in e-x?).