1

这是我遵循的过程:-`

var certX = Fiddler.CertMaker.oCertProvider.GetCertificateForHost("<Machine Name>");
File.WriteAllBytes(@"D:\PFX.pfx", certX.Export(X509ContentType.SerializedCert));

一旦完成此操作。我重新启动了演示应用程序并尝试从磁盘加载证书

X509Certificate2 certTry = new X509Certificate2(@"D:\PFX.PFX", "1", X509KeyStorageFlags.UserKeySet |
                                        X509KeyStorageFlags.PersistKeySet |
                                        X509KeyStorageFlags.Exportable);

oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, certTry);

这有效,但当我这样做时。

WriteCommandResponse("Result: " + Fiddler.CertMaker.trustRootCert().ToString());

它失败并显示无法信任根证书的错误;未找到

我在这里做错了什么?我的意图是使用自定义证书解密 HTTPS 流量。

4

2 回答 2

1

让我们退后一步——您希望通过将 Fiddler 生成的证书存储到磁盘,然后稍后重新加载来完成什么?

这里可能的问题是您的方法没有将私钥写入目标 PFX 文件,因此您不能随后使用 PFX 加密流量。

于 2015-12-04T21:51:52.193 回答
0

正如@EricLaw 指出的那样,问题出在 PFX 上。证明

    Fiddler.CertMaker.GetRootCertificate();

生成没有证书的私钥。所以要保存证书,只写上面的证书是不够的。解决方法是打开用户的根证书存储,然后将证书连同它的私钥一起取出(下面的代码示例)。然后可以在以后的会话中使用此证书。

    X509Store certStore = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
        // Try to open the store.

        certStore.Open(OpenFlags.ReadOnly);
        // Find the certificate that matches the name.
        X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindBySubjectName, "DO_NOT_TRUST_FiddlerRoot", false);

        X509Certificate2 certTry = new X509Certificate2(@"D:\PFX.PFX", "1", X509KeyStorageFlags.UserKeySet |
                                    X509KeyStorageFlags.PersistKeySet |
                                    X509KeyStorageFlags.Exportable);

Exportable 是可选的,但 PersistKeySet 是必需的,否则证书将不包含私钥。

于 2015-12-20T16:18:43.593 回答