使用 Windows 证书存储中的 Npgsql 加载客户端证书时,无法识别提供给包的凭据

问题描述

证书已导入到 Windows 证书存储中,使用以下命令和选项生成的 pfx:

openssl pkcs12 -export -out postgres.pfx -inkey postgres.key -in postgres.crt -certfile root.crt -CSP "Microsoft Software Key Storage Provider"

如果未指定 CSP 选项,它会起作用。我指定 csp 选项的原因是因为我想看看我是否可以通过稍后使用 certutil 导入到 Windows 证书存储区来将私钥存储在 TPM 中...有谁知道这是否可能?

certutil.exe -csp "Microsoft Platform Crypto Provider" -p test -importPFX CA postgres.pfx NoExport
using (var connection = new NpgsqlConnection(connString))
{
    connection.ProvideClientCertificatesCallback += certificates =>
    {
        var store = new X509Store("CA",StoreLocation.LocalMachine);
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

        var results = store.Certificates
            .Find(X509FindType.FindBySubjectName,"postgres",false);
        
        var clientCert = results[0];
        certificates.Add(clientCert);
    };
    connection.open();
    
    connection.Close();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)