5

I'm having problem in connecting MongoDB which is configured using SSL. I have MongoDB enterprise server in Azure virtual machine which has the following configuration.

net:
bindIp: 0.0.0.0
port: 27017
ssl:
    CAFile: 'C:\openssl-0.9.8h-1-bin\bin\rCA.pem'
    PEMKeyFile: 'C:\openssl-0.9.8h-1-bin\bin\rser.pem'
    allowConnectionsWithoutCertificates: false
    allowInvalidHostnames: true
    mode: requireSSL
storage:
    dbPath: 'C:\data\db'

I have a C# sample to connect mongodb with certificate data passed as byte array.

MongoClientSettings settings = new MongoClientSettings
        {
            Server = new MongoServerAddress("mongo_azure_host", 27017),
            UseSsl = true,
            RetryWrites = true
        };
        settings.VerifySslCertificate = false;
        var SslCertificateData = FilePathHelper.ReadFile(Server, mySslClientCertificate);
        var certificate = new X509Certificate2(SslCertificateData, "pwd");
            settings.SslSettings = new SslSettings()
            {
                ClientCertificates = new[] { certificate }
            };
        }
        MongoClient mongoClient = new MongoClient(settings);
        mongoClient.GetServer().Connect();

This works fine if the sample is in my local environment. But if I pubish the same in Azure web app and tried to connect, it throws the following exception

system.componentmodel.win32exception: the credentials supplied to the package were not recognized

Mani Kkr
  • 105
  • 4
  • I suspect it's a certificate issue. Have you looked at the solutions posted in https://stackoverflow.com/questions/7984945/the-credentials-supplied-to-the-package-were-not-recognized-error-when-authent and tried some of them? – kevinadi Feb 19 '19 at 03:22
  • Yes @KevinAdistambha, Checked using Mongodb shell, robomongo and also while debugging the sample in local environment also seems fine. the actual issue occurs when host this sample in Azure web app and connecting Azure MongoDB Server. – Mani Kkr Feb 19 '19 at 04:20

0 Answers0