【问题标题】:Certificate Pinning on .NET.NET 上的证书固定
【发布时间】:2013-01-29 18:44:26
【问题描述】:

我想限制我的 .NET 应用程序只接受已知证书。那么如何在 .NET 上强制执行证书固定?最佳做法是什么?只验证指纹可以吗?

【问题讨论】:

    标签: .net ssl application-security


    【解决方案1】:

    根据OWASP,您可以使用.NET 的ServicePointManager 类实现证书和公钥固定

    【讨论】:

      【解决方案2】:

      https://www.owasp.org/index.php/Certificate_and_Public_Key_Pinning#.Net

      这个网址已经有一个很好的例子。

      // Encoded RSAPublicKey
      private static String PUB_KEY = "30818902818100C4A06B7B52F8D17DC1CCB47362" +
          "C64AB799AAE19E245A7559E9CEEC7D8AA4DF07CB0B21FDFD763C63A313A668FE9D764E" +
          "D913C51A676788DB62AF624F422C2F112C1316922AA5D37823CD9F43D1FC54513D14B2" +
          "9E36991F08A042C42EAAEEE5FE8E2CB10167174A359CEBF6FACC2C9CA933AD403137EE" +
          "2C3F4CBED9460129C72B0203010001";
      
      public static void Main(string[] args)
      {
        ServicePointManager.ServerCertificateValidationCallback = PinPublicKey;
        WebRequest wr = WebRequest.Create("https://encrypted.google.com/");
        wr.GetResponse();
      }
      
      public static bool PinPublicKey(object sender, X509Certificate certificate, X509Chain chain,
                                      SslPolicyErrors sslPolicyErrors)
      {
        if (null == certificate)
          return false;
      
        String pk = certificate.GetPublicKeyString();
        if (pk.Equals(PUB_KEY))
          return true;
      
        // Bad dog
        return false;
      }
      

      【讨论】:

        猜你喜欢
        • 2019-08-04
        • 2019-02-16
        • 2017-08-26
        • 2018-10-28
        • 2012-01-31
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多