Skip to content

Instantly share code, notes, and snippets.

@yavor87
Created April 29, 2019 21:21
Show Gist options
  • Save yavor87/216b73b2e2e04e540c8568129f178420 to your computer and use it in GitHub Desktop.
Save yavor87/216b73b2e2e04e540c8568129f178420 to your computer and use it in GitHub Desktop.
public class Startup {
private string clientCertPath;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataAccess.ClientDatabaseContext>(options =>
options.UseNpgsql(this.connectionString, opt => {
opt.RemoteCertificateValidationCallback(RemoteCertificateValidation);
opt.UseAdminDatabase("defaultdb");
}));
}
private bool RemoteCertificateValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
X509Chain chain0 = new X509Chain();
chain0.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
// add all your extra certificate chain
chain0.ChainPolicy.ExtraStore.Add(new X509Certificate2(this.clientCertPath));
chain0.ChainPolicy.VerificationFlags = X509VerificationFlags.AllowUnknownCertificateAuthority;
return chain0.Build((X509Certificate2)certificate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment