[CSHARP-3564] .NET 5.0 on Linux fails to connect to MongoDB 4.0 Atlas Created: 09/Apr/21  Updated: 28/Oct/23  Resolved: 13/Jan/22

Status: Closed
Project: C# Driver
Component/s: Connectivity, Documentation
Affects Version/s: None
Fix Version/s: 2.15.0

Type: Task Priority: Major - P3
Reporter: James Kovacs Assignee: James Kovacs
Resolution: Fixed Votes: 0
Labels: size-xsmall
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Related
Case:
Backwards Compatibility: Fully Compatible

 Description   

.NET 5.0 app running on Linux cannot connect to MongoDB 4.0 on Atlas. It fails with the following exception:

Unhandled exception. System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongodb40tlstest-shard-00-00.ebdql.mongodb.net:27017" }", EndPoint: "Unspecified/mongodb40tlstest-shard-00-00.ebdql.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
 ---> System.IO.IOException:  Received an unexpected EOF or 0 bytes from the transport stream.
... stack trace ...

The same app running on .NET Core 3.1 can connect successfully to MongoDB 4.0 on Atlas.

The same app running on .NET 5.0 can connect successfully to MongoDB 4.2 or later on Atlas.



 Comments   
Comment by James Kovacs [ 01/Feb/22 ]

This change will be included with 2.15.0.

Comment by Githook User [ 01/Feb/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: Revert "CSHARP-3564: Added TLS cipher suite mismatch troubleshooting to the docs. (#717)"

This reverts commit 873fa6c13edfc745437566440738a6f24a14b6a8.
Branch: v2.14.x
https://github.com/mongodb/mongo-csharp-driver/commit/90b3c17e2357af54361161f6058e04d3af2b846f

Comment by Githook User [ 31/Jan/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: CSHARP-3564: Added TLS cipher suite mismatch troubleshooting to the docs. (#717)
Branch: v2.14.x
https://github.com/mongodb/mongo-csharp-driver/commit/873fa6c13edfc745437566440738a6f24a14b6a8

Comment by Githook User [ 13/Jan/22 ]

Author:

{'name': 'James Kovacs', 'email': 'jkovacs@post.harvard.edu', 'username': 'JamesKovacs'}

Message: CSHARP-3564: Added TLS cipher suite mismatch troubleshooting to the docs. (#717)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/5c5d17dd7fbd3a846d6076902ae391119a9c3e8e

Comment by James Kovacs [ 12/Apr/21 ]

Re-opening and changing the task to document this behaviour in:
http://mongodb.github.io/mongo-csharp-driver/2.13/reference/driver/ssl/

We should add a new section on troubleshooting TLS/SSL ciphers, especially the information on the changes Microsoft introduced in .NET 5.0.

Comment by James Kovacs [ 09/Apr/21 ]

The root cause of the problem is a cipher suite mismatch.

MongoDB 4.0 running on Atlas only supports RSA ciphers for key exchange:

$ nmap --script ssl-enum-ciphers -p 27017 mongodb40tlstest-shard-00-00.ebdql.mongodb.net -Pn
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-04-09 14:18 MDT
Nmap scan report for mongodb40tlstest-shard-00-00.ebdql.mongodb.net (54.227.65.151)
Host is up (0.072s latency).
rDNS record for 54.227.65.151: ec2-54-227-65-151.compute-1.amazonaws.com
 
PORT      STATE SERVICE
27017/tcp open  mongod
| ssl-enum-ciphers: 
|   TLSv1.2: 
|     ciphers: 
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 4096) - A
|       TLS_RSA_WITH_CAMELLIA_128_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_CAMELLIA_256_CBC_SHA (rsa 4096) - A
|     compressors: 
|       NULL
|     cipher preference: client
|     warnings: 
|       Forward Secrecy not supported by any cipher
|_  least strength: A
 
Nmap done: 1 IP address (1 host up) scanned in 3.36 seconds

Whereas MongoDB 4.2+ running on Atlas also supports ECDHE ciphers for key exchange:

$ nmap --script ssl-enum-ciphers -p 27017 mongodb42tlstest-shard-00-00.ebdql.mongodb.net -Pn
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-04-09 15:05 MDT
Nmap scan report for mongodb42tlstest-shard-00-00.ebdql.mongodb.net (34.234.219.160)
Host is up (0.069s latency).
rDNS record for 34.234.219.160: ec2-34-234-219-160.compute-1.amazonaws.com
 
PORT      STATE SERVICE
27017/tcp open  mongod
| ssl-enum-ciphers: 
|   TLSv1.2: 
|     ciphers: 
|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA (dh 3072) - A
|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 (dh 3072) - A
|       TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (dh 3072) - A
|       TLS_DHE_RSA_WITH_AES_256_CBC_SHA (dh 3072) - A
|       TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 (dh 3072) - A
|       TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (dh 3072) - A
|       TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA (dh 3072) - A
|       TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA (dh 3072) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (secp256r1) - A
|       TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (secp256r1) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_AES_128_CBC_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_CBC_SHA256 (rsa 4096) - A
|       TLS_RSA_WITH_AES_256_GCM_SHA384 (rsa 4096) - A
|       TLS_RSA_WITH_CAMELLIA_128_CBC_SHA (rsa 4096) - A
|       TLS_RSA_WITH_CAMELLIA_256_CBC_SHA (rsa 4096) - A
|     compressors: 
|       NULL
|     cipher preference: client
|     warnings: 
|       Key exchange (dh 3072) of lower strength than certificate key
|       Key exchange (secp256r1) of lower strength than certificate key
|_  least strength: A
 
Nmap done: 1 IP address (1 host up) scanned in 5.94 seconds

In .NET Core 3.1 and earlier, any cipher suite supported by OpenSSL could be used for key exchange including both RSA and ECDHE. In .NET 5.0, Microsoft hardened the default TLS configuration to only allow ECDHE ciphers for key exchange. If you explicitly configure OpenSSL to allow the RSA cipher for key exchange, .NET 5.0 will respect it, but it will not use it by default. You can find out more in Default TLS cipher suites for .NET on Linux.

Options:

1. Explicitly configure OpenSSL on your Linux app servers to allow RSA ciphers.

  • Not recommended as this will opt into weaker TLS ciphers.
    2. Create a new MongoDB 4.2 or later cluster on MongoDB Atlas, which supports ECDHE.

Note that simply upgrading your MongoDB 4.0 Atlas cluster will not necessarily reprovision your hosts and thus your upgraded cluster may still only be using RSA for key exchange. Please contact our Support Team if you require assistance with reprovisioning your Atlas cluster to support ECDHE.

Generated at Wed Feb 07 21:45:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.