【问题标题】:Implementing secure webservice calls in c# (window)在 C# 中实现安全的 Web 服务调用(窗口)
【发布时间】:2017-12-02 20:57:54
【问题描述】:

我的客户端应用程序需要与受 TLS1.1 保护的远程 Web 服务通信。我想知道我应该如何配置我的服务器和客户端证书以使其工作。我们从网络服务供应商那里得到了以下示例:

ServicePointManager .ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

然后

WebServiceProxy.AddClientCertificate(cert, password);

据我了解,对于整个应用程序而言,禁用证书是一个糟糕的主意。据我了解,应用程序中应该没有 tls/ssl 配置,我应该将我的证书安装在正确的商店中,然后 http.sys 应该在握手期间协商它们。我说的对吗?

AFAIK 远程 Web 服务证书应该在 Third-Party Root Certification Authorities 中,我的客户端证书应该在 Client Authentication 存储中。我说的对吗?

【问题讨论】:

    标签: ssl certificate windows


    【解决方案1】:

    你是对的。

    在理想情况下,您会将客户端证书安装到 CurrentUser\My 或 LocalMachine\My 商店中。将使用 AIA 从客户端证书中获取中间 CA 证书,并且根 CA 证书已经在受信任的根存储中。服务器证书也是如此,这样每个人都会工作愉快。

    您从网络服务供应商处获得的代码

    ServicePointManager
        .ServerCertificateValidationCallback += 
        (sender, cert, chain, sslPolicyErrors) => true;
    

    禁用证书验证。你很容易受到中间人攻击,但通信仍然是加密的:)

    我不知道为什么有人会应用此代码。也许网络服务供应商正在使用一些不公开的自定义 CA、CRL 端点不公开或类似的东西。

    您可以使用此代码在您的客户端中设置 TLS1.1

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)LocalSecurityProtocolType.Tls11;
    
    /// <summary>
    /// Imported from .NET 4.6.1 : Specifies the security protocols that are supported by the Schannel security package.
    /// </summary>
    [Flags]
    public enum LocalSecurityProtocolType
    {
        /// <summary>
        /// Specifies the Secure Socket Layer (SSL) 3.0 security protocol.
        /// </summary>
        Ssl3 = 48,
    
        /// <summary>
        /// Specifies the Transport Layer Security (TLS) 1.0 security protocol.
        /// </summary>
        Tls = 192,
    
        /// <summary>
        /// Specifies the Transport Layer Security (TLS) 1.1 security protocol.
        /// </summary>
        Tls11 = 768,
    
        /// <summary>
        /// Specifies the Transport Layer Security (TLS) 1.2 security protocol.
        /// </summary>
        Tls12 = 3072
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 2012-01-21
      • 2012-11-24
      • 2013-04-02
      • 1970-01-01
      • 2013-04-08
      相关资源
      最近更新 更多