微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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 举报,一经查实,本站将立刻删除。