C
C#17mo ago
Velcer

❔ Trouble with C# certificates

Greetings, In a local environment I have no issues at all. When I push my Game Server (the client) to a hosted environment, I get an error saying the following: {"Type":"InvalidAuth","Message":"This server requires client certificate for authentication, but none was provided by the client. Did you forget to install the certificate?"} I contacted Ravendb support and they said the following: Basically it's about the X509 certificate's private key. In a lot of platform you need to allow the app to load that certificate explicitly e.g. by providing its thumbprint. My assumption of this response is that I need to first install the certificate on said machine before I can use it. The problem is that I don't have permissions to install a certificate on that machine. I am wondering what can be done. The following code is what I am using:
using Raven.Client.Documents;
using Raven.Client.Documents.Conventions;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

public static class DocumentStoreHolder
{
private const string CERTIFICATE_PASSWORD = "B8ABC07EA75BC5B18DB92386A726F93A";
private static string CERTIFICATE_PATH = Path.GetFullPath("certificate.pfx");

public static X509Certificate2 GetCertificate()
{
return new X509Certificate2(CERTIFICATE_PATH, CERTIFICATE_PASSWORD);
}
public static void Initialize()
{
var certificate = GetCertificate();

LazyStore = new Lazy<IDocumentStore>(() =>
{
var store = new DocumentStore
{
Urls = new[] { "https://a.free.starmmo.ravendb.cloud" },
Database = "StarMMO",
Certificate = certificate,


};
return store.Initialize();
});

}

private static Lazy<IDocumentStore> LazyStore;

public static IDocumentStore Store => LazyStore.Value;
}
using Raven.Client.Documents;
using Raven.Client.Documents.Conventions;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

public static class DocumentStoreHolder
{
private const string CERTIFICATE_PASSWORD = "B8ABC07EA75BC5B18DB92386A726F93A";
private static string CERTIFICATE_PATH = Path.GetFullPath("certificate.pfx");

public static X509Certificate2 GetCertificate()
{
return new X509Certificate2(CERTIFICATE_PATH, CERTIFICATE_PASSWORD);
}
public static void Initialize()
{
var certificate = GetCertificate();

LazyStore = new Lazy<IDocumentStore>(() =>
{
var store = new DocumentStore
{
Urls = new[] { "https://a.free.starmmo.ravendb.cloud" },
Database = "StarMMO",
Certificate = certificate,


};
return store.Initialize();
});

}

private static Lazy<IDocumentStore> LazyStore;

public static IDocumentStore Store => LazyStore.Value;
}
3 Replies
Tvde1
Tvde117mo ago
you can bundle the certificate along with your program, it doesn't have to be installed on the pc
Velcer
VelcerOP17mo ago
That is what I am doing presently. The certificate is bundled with the program, and I load it from the file as you can see in the above code. That above code works on my local environment but fails in production. I have verified that the production server does have the file. I've verified the correct path. I've verified that the certificate goes into memory (loaded by the C# program). And I get the error.
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server