[CSHARP-3172] Getting "Authentication failed because the remote party has closed the transport stream" while connection mongodb V4.0 using C# driver. Created: 27/Jul/20 Updated: 13/Aug/20 Resolved: 13/Aug/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Configuration, Connectivity |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Bhaskar Avisha | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Production |
||
| Issue Links: |
|
||||||||
| Description |
|
We are trying to implement SSL authentication with the MongoDB 4.0 version using the below connection string and facing authentication issues. mongodb://username:password@hostname:27017/?authSource=admin&readPreference=primary&ssl=true&sslPEMKeyFile=C:/etc/ssl/client.pem" At MongoDB log, we see the application connections are closing immediately with error message : encountered a network error during SourceMessage: SocketException: no shared cipher application log: , SourceContext: "Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware", ConnectionId: "0HLTM5FID0INL", Application: "DCDService" } |
| Comments |
| Comment by Jeffrey Yemin [ 13/Aug/20 ] | ||||
|
Hi there, thank you for reaching out. As this sounds like a support issue, I wanted to give you some resources to get this questioned answered more quickly:
Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue. Thank you! P.S. Please double-check that you have followed all the steps in https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/, in particular https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/#add-x-509-certificate-subject-as-a-user. | ||||
| Comment by Bhaskar Avisha [ 27/Jul/20 ] | ||||
|
Hello, I have followed by steps mentioned in Previous ticket 1) Create a pfx format file using below instructions
2) Code Snippet from the app config file Here is the code used to connect with the x509 cert: public static IContextOptions UseMongoFactory(this IContextOptions options, DatabaseSettings settings) { var setting = new MongoClientSettings { // if a username is null, the distinguished name from the certificate will be used Credential = MongoCredential.CreateMongoX509Credential(null), SslSettings = new SslSettings { ClientCertificates = new List<X509Certificate>() { // Instert Pem File Location and Passphrase new X509Certificate2(settings.CertificatePath, settings.Passphrase) } , }, UseTls = true, Server = new MongoServerAddress(settings.ServerName, settings.PortNumber), // For testing using self-signed certs, use this option to skip validation. // DO NOT USE THIS OPTION FOR PRODUCTION USES AllowInsecureTls = true }; var context = new MongoClient(setting); options.DatabaseName = settings.DatabaseName; options.Logger = Log.Logger; options.Factory = new MongoFactory(options, context); return options; } Exception Details : Exception: MongoDB.Driver.MongoAuthenticationException HResult=0x80131500 Message=Unable to authenticate username '' using protocol 'MONGODB-X509'. Source=MongoDB.Driver StackTrace: at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression) at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at RemoteDbContextStd.MongoEntity`1.ToList() in C:\Users\gbaril\source\repos\Experiments\RemoteDbContextStd\RemoteDbContextStd\MongoEntity.cs:line 143 at ConfigServer.Features.ConfigServer.Services.ConfigServices.<GetConfigCollection>b__5_0() in C:\Users\gbaril\source\repos\ConfigService\ConfigService\Features\ConfigServer\Services\ConfigServices.cs:line 81 at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
|