【问题标题】:Using custom certificate in FiddlerCore在 FiddlerCore 中使用自定义证书
【发布时间】:2015-11-29 20:43:13
【问题描述】:

这是我遵循的过程:-`

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

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

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 流量。

【问题讨论】:

    标签: fiddler fiddlercore fiddler-dev


    【解决方案1】:

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

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

    【讨论】:

    • 问题确实出在证书上。在下面发布整个答案。
    【解决方案2】:

    正如@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 是必需的,否则证书将不包含私钥。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 1970-01-01
      • 2015-03-07
      • 2020-10-31
      • 1970-01-01
      • 2014-02-19
      相关资源
      最近更新 更多