I am new to EF6 and trying to implement the ProvideClientCertificatesCallback so as to use certificate based authentication.
I have (barely) managed to get EF6 to use my custom IDbConnectionFactory but it seems to require hard-cording the connection string (as the default is only called if the connection string isn't specified, and my attempts at overriding with DbConfiguration.Loaded seem not to work).
Even so, the callback never seems to be called.
public class clientCertFactory: IDbConnectionFactory
{
internal string _clientCertPath = "";
public DbConnection CreateConnection(string nameOrConnectionString)
{
var c = new NpgsqlConnection("SSL Mode=Require;Username=xxx;Host=yyy;Database=zzz");
if (ConfigurationManager.AppSettings.Get("clientCert") != null)
{
_clientCertPath = ConfigurationManager.AppSettings.Get("clientCert");
/*c.ProvideClientCertificatesCallback += new ProvideClientCertificatesCallback((X509CertificateCollection clientCerts) => {
X509Certificate2 cert = new X509Certificate2(_clientCertPath);
clientCerts.Add(cert);
});*/
c.ProvideClientCertificatesCallback += new ProvideClientCertificatesCallback(ProvideClientCertificates);
}
return c;
}
internal void ProvideClientCertificates(X509CertificateCollection clientCerts)
{
System.Console.WriteLine(String.Format("Attempting to apply cert: {0}", _clientCertPath));
X509Certificate2 cert = new X509Certificate2(_clientCertPath);
clientCerts.Add(cert);
}
}
Is client cert auth supported by EF6.Npgsql and if so, what is the recommended way of implementing it?
I am new to EF6 and trying to implement the
ProvideClientCertificatesCallbackso as to use certificate based authentication.I have (barely) managed to get EF6 to use my custom
IDbConnectionFactorybut it seems to require hard-cording the connection string (as the default is only called if the connection string isn't specified, and my attempts at overriding with DbConfiguration.Loaded seem not to work).Even so, the callback never seems to be called.
Is client cert auth supported by EF6.Npgsql and if so, what is the recommended way of implementing it?