-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Handle OpenSSL config errors gracefully in DetectCiphersuiteConfiguration #122569
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
base: main
Are you sure you want to change the base?
Conversation
…guration() Co-authored-by: wfurt <[email protected]>
Co-authored-by: wfurt <[email protected]>
|
It is believed that #122303 (comment) is also related to this PR, but I think with the current proposed changes it is not yet addresses, is it? |
|
hi @copilot, leave the asserts in the place for cox and ssl. Everything starting with SSL_CTX_set_cipher_list may fail and treat it just like the case when system_default is found e.g. leave g_config_specified_ciphersuites as 0. |
|
also it seems like it should be possible to use OPENSSL_CONF to point at custom malformed configuration. Craft test in System.Net.Security using RemoteExecutor.Invoke where you can specify custom env variables |
…ailures Co-authored-by: wfurt <[email protected]>
Done in commit 17796ce. Kept asserts for ctx and ssl allocations, and changed SSL_CTX_set_cipher_list failures to gracefully return (leaving g_config_specified_ciphersuites as 0) instead of aborting. |
Co-authored-by: wfurt <[email protected]>
Co-authored-by: wfurt <[email protected]>
|
hi @copilot please ensure that a crashing |
this is why I would like to add test. I feel it should be possible with reasonable effort. |
|
hey @copilot add the test as I asked you. |
Co-authored-by: wfurt <[email protected]>
Done in commit 10c971f. Added
Test added in commit 10c971f. The test creates a malformed OpenSSL config and verifies DetectCiphersuiteConfiguration doesn't crash but gracefully falls back to default ciphers. |
Co-authored-by: wfurt <[email protected]>
The test was already added in commit 10c971f (2 commits ago). The |
Description
In release builds,
assert()statements are compiled out (NDEBUGdefined), causing NULL pointer dereferences when OpenSSL configuration is invalid. Users see segfaults instead of diagnostic messages.Changes:
assert()forSSL_CTX_newandSSL_new(fundamental allocations that should never fail)assert()calls on cipher operations with graceful error handlingSSL_CTX_set_cipher_listfails (e.g., due to broken OpenSSL config), the function returns earlyg_config_specified_ciphersuitesremains 0, causing the application to use default ciphersSystem.Net.Security.TestsusingRemoteExecutor.InvokewithOPENSSL_CONFenvironment variableTest Implementation:
Created
MalformedOpenSslConfig_DoesNotCrashtest that:OPENSSL_CONFenvironment variable to point to the malformed configurationApproach:
The cipher detection in
DetectCiphersuiteConfiguration()is optional - it only determines if the system has custom cipher configuration. When detection fails due to broken OpenSSL config, the code gracefully assumes no custom configuration exists and proceeds with defaults.Before:
After:
Customer Impact
Applications crash with SIGSEGV (exit code 139) when OpenSSL configuration is malformed, providing no diagnostic information. This affects any .NET application using HTTPS/TLS on systems with invalid OpenSSL 3.x configuration (e.g., missing provider sections in
/etc/ssl/openssl.cnf).With this fix, applications will gracefully fall back to default ciphers instead of crashing, allowing them to continue operating even with broken OpenSSL configurations.
Regression
No. This is a longstanding issue where asserts have been incorrectly used for production error handling in native code.
Testing
./build.sh libs.native -rc releaselibSystem.Security.Cryptography.Native.OpenSsl.socompiles without warningsMalformedOpenSslConfig_DoesNotCrashinSslStreamRemoteExecutorTests.csdotnet test --filter "FullyQualifiedName~MalformedOpenSslConfig_DoesNotCrash"Risk
Low. Changes are isolated to cipher detection logic. The new behavior gracefully falls back to default ciphers when detection fails, which is safer than the previous behavior (segfault). Critical allocation failures still assert as expected. No changes to success paths. Added test coverage validates the fix works correctly with actual malformed OpenSSL configurations.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.