Repository navigation
Closed
Description
When upgrading to .NET 5.0 on Linux and connecting to Aurora (v5.7), we're getting a OpenSslCryptographicException.
This occurs due to the default TLS cipher suites changing on .NET 5.0 Linux. It can be fixed by providing a custom CipherSuitesPolicy with a less restrictive cipher set.
This is a request to be able to configure the CipherSuitesPolicy (directly, or via a connection string) on .NET5.0.
Stack Trace
OpenSslCryptographicException: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
AuthenticationException: Authentication failed, see inner exception.
MySqlException: SSL Authentication Error
.NET Breaking Changes Notes
Default TLS cipher suites for .NET on Linux
.NET, on Linux, now respects the OpenSSL configuration for default cipher suites when doing TLS/SSL via the SslStream class or higher-level operations, such as HTTPS via the HttpClient class. When default cipher suites aren't explicitly configured, .NET on Linux uses a tightly restricted list of permitted cipher suites.
Change description
In previous .NET versions, .NET does not respect system configuration for default cipher suites. The default cipher suite list for .NET on Linux is very permissive.
Starting in .NET 5.0, .NET on Linux respects the OpenSSL configuration for default cipher suites when it's specified in openssl.cnf. When cipher suites aren't explicitly configured, the only permitted cipher suites are as follows:
TLS 1.3 cipher suites
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
Since this fallback default doesn't include any cipher suites that are compatible with TLS 1.0 or TLS 1.1, these older protocol versions are effectively disabled by default.
Supplying a CipherSuitePolicy value to SslStream for a specific session will still replace the configuration file content and/or .NET fallback default.
Metadata
Metadata
Assignees
Labels
No labels
Activity
iamcarbon commentedon Nov 11, 2020
@bgrainger Is it possible to configure a CipherSuitePolicy directly on the SSL stream?
iamcarbon commentedon Nov 12, 2020
Manually configuring the CipherSuitesPolicy policy in ServerSession fixes the problem. Still trying to find documentation on what ciphers Aurora supports.
@bgrainger What are your thoughts on adding a configuration option to specify a custom cipher suite policy passed to AuthenticateAsClientAsync?
Something like...
This would enable something like....
[-].NET 5.0 TLS Errors[/-][+].NET 5.0 TLS Errors (Request to manual configure CipherSuitesPolicy)[/+]iamcarbon commentedon Nov 12, 2020
Submitted a PR #905
[-].NET 5.0 TLS Errors (Request to manual configure CipherSuitesPolicy)[/-][+].NET 5.0 TLS Errors[/+]bgrainger commentedon Nov 12, 2020
Link to .NET Breaking Changes list: https://docs.microsoft.com/en-us/dotnet/core/compatibility/3.1-5.0#default-tls-cipher-suites-for-net-on-linux
bgrainger commentedon Nov 12, 2020
@iamcarbon Is modifying the configuration in
/etc/ssl/openssl.cnf(as suggested in the docs), e.g., in theDockerfilefor your application, a viable workaround in your situation?Obviously there is an advantage to having the library work out-of-the-box with Aurora without extra configuration; I need to research that more.
iamcarbon commentedon Nov 12, 2020
@bgrainger : Yes, this also works, but forgoes the other benefits of a locked down default policy for the rest of the application.
I'm also not sure if this will work when we upgrade our Lambda functions in the future as the openssl.cnf won't be editable there.
Another approach would be to allow a CipherSuitesPolicy to be set globally (perhaps off a static setter). This would help users having to edit the openssl.cnf and give them explicit control over what ciphers are negotiated.
iamcarbon commentedon Nov 12, 2020
Revised the PR to allow defining the DefaultCipherSuitesPolicy on .NET5.0. This provides a super simple hook to configure the cipher suites (and avoid touching the openssl.cnf -- which may not be possible in certain environments). This also eliminates any magic behavior -- which may not be relevant for future Aurora updates.
4a4033a
bgrainger commentedon Nov 13, 2020
Since this setting is connection-specific (more specifically, connection-pool specific), I'm tempted to make it part of the connection string. This would let it be configured without using code, is more like every other connection setting, and would be less "magic" than setting a static property. The downside is that is could be extremely verbose to specify multiple cipher suites. MySqlConnector could support specifying any
TlsCipherSuiteenum value either as a named value (with or withoutTLS_prefix) or the underlying integral value. Your thoughts?Some examples:
bgrainger commentedon Nov 13, 2020
To reduce connection string verbosity, an additional mechanism could be
TlsCipherSuiteFile={path-to-file}, where the specified plain text file contains a list of supported cipher suites, one per line. This would be likeCertificateFile,CaCertificateFile, etc., where the file path is provided in the connection string, but the file itself has to be deployed with the consuming application through some other means.bgrainger commentedon Nov 13, 2020
MySQL Connector/J uses
enabledSSLCipherSuitesin its connection options: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-configuration-properties.html; MariaDB Connector/J supports the same option: https://mariadb.com/kb/en/using-tls-ssl-with-mariadb-java-connector/bgrainger commentedon Nov 13, 2020
In practice, the connection string may not be too verbose; only one (mutually supported) cipher suite needs to be listed in order to establish a connection. That is, the minimal Aurora connection string (for .NET 5.0 on Linux) might just be:
Server=server.region.rds.amazonaws.com;User Id=user;Password=***;CACertificateFile=/rds-combined-ca-bundle.pem;TlsCipherSuites=TLS_DHE_RSA_WITH_AES_256_GCM_SHA384.So I'm inclined to just go with that (and not implement
TlsCipherSuiteFile).iamcarbon commentedon Nov 13, 2020
A single TlsCipherSuite matching the .NET enum name is also elegant - ensures a strong cipher is used for non-aurora servers - and allows the library to connect to multiple servers in the same process with different settings. ❤️
bgrainger commentedon Nov 13, 2020
Added a PR for this: #907
Add TlsCipherSuites connection string option. Fixes mysql-net#904
bgrainger commentedon Nov 13, 2020
The right answer is probably for Aurora to support modern cipher suites 😀 but I'll try to have a beta release for testing available later today.
bgrainger commentedon Nov 13, 2020
1.1.1-beta.0.1 is available for download from GHPR; are you able to test with that? https://github.com/mysql-net/MySqlConnector/packages/39735
iamcarbon commentedon Nov 14, 2020
Works, and in production now. Thanks again for the thoughtfulness you put into this!
RyanGhd commentedon Nov 20, 2020
@bgrainger, is there any ETA for this version to be available in nuget?
bgrainger commentedon Nov 25, 2020
I can release a non-beta version to NuGet soon (if you can't pull it from GHPR).
passuied commentedon Nov 25, 2020
@bgrainger I'm experiencing the same issue but connecting to Aurora MySQL 5.6 which only supports TLS v1.0.
Trying to figure out which cipher suite to include (currently in the openssl.cnf file)
I have tried the cipher suite you mention (TLS_DHE_RSA_WITH_AES_256_GCM_SHA384=DHE-RSA-AES256-GCM-SHA384) but it seems it is specific to TLS 1.2
I'm not sure how to find the correct one (can't find anything useful in AWS doc)... Do you know which one applies here? and how/where to find this info?
Thanks in advance
UPDATE: I have now provisioned a test aurora MySQL 5.7 cluster and validated that the above works properly with 5.7... No luck on 5.6... Is net5.0 no longer compatible with TLS 1.0? Didn't see anything about it... Also I looked at my Aurora 5.6 server
Ssl_cipher_listsession variable and it includesDHE-RSA-AES256-GCM-SHA384...UPDATE 2: I have figured it out... It was not really intuitive but I had to raise the Min Tls version to TLSv1.2 in the openssl.cnf file (I think this is so the list of cipher suites can apply). Then I had to explicitly set the TlsVersion to Tlsv1.0 in the Mysql connection string since Aurora MySQL 5.6 supports only 1.0... OUCH!! But it works!
bgrainger commentedon Nov 26, 2020
@RyanGhd This is now available on NuGet in 1.2.0.
RyanGhd commentedon Nov 27, 2020
@bgrainger , thanks so much! really appreciate it.
andre197 commentedon Jun 11, 2021
NuGet version: 1.3.9
.NET version: 5.0
MySql version: 5.6
@bgrainger i'm having the same issue as @passuied. I have used the same solution which he provides but im receiving the following error
The code i run:
The version of the nuget is 1.3.9 on .net 5.0
This is the dockerfile
Code example can be found in this attachment: ConsoleApp1.zip
The solution from @passuied didn't help also the solution from here: #927
didn't help either. So can you advise on what else can i do?
Update: On adding these
TLSCipherSuites=TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384to the end of the connection string i receive this exception:bgrainger commentedon Jun 14, 2021
Are you connecting to Aurora, or to a privately-hosted MySQL Server?
AFAICT, the connection is failing because your client can't negotiate a secure connection. Check the MySQL Manual on how to configure this: https://dev.mysql.com/doc/refman/5.6/en/encrypted-connection-protocols-ciphers.html#encrypted-connection-protocol-negotiation
If you can establish a secure connection with some other client (e.g., MySQL Workbench) execute
SHOW SESSION STATUS LIKE 'Ssl_cipher';to see the cipher it's using, then try to use that in your connection string.