gpt4 book ai didi

ssl - 在 c# (window) 中实现安全的 webservice 调用

转载 作者:太空宇宙 更新时间:2023-11-03 14:04:32 25 4
gpt4 key购买 nike

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

服务点管理器
.ServerCertificateValidationCallback +=
(发件人、证书、链、sslPolicyErrors) => true;

然后

WebServiceProxy.AddClientCertificate(cert, password);

据我所知,为整个应用程序禁用证书是一个糟糕的想法。据我所知,应用程序中不应该有 tls/ssl 配置,我应该只在正确的存储中安装我的证书,然后 http.sys 应该在握手期间协商它们。我说得对吗?

AFAIK 远程网络服务证书应该在 第三方根证书颁发机构 中,我的客户端证书应该在 Client Authentication 存储中。我说得对吗?

最佳答案

你是对的。

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

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

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

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

我不知道为什么会有人应用此代码。也许 web 服务供应商正在使用一些非公共(public)的自定义 CA,CRL 端点不是公共(public)的或类似的东西。

您可以使用此代码在您的客户端中设置 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
}

关于ssl - 在 c# (window) 中实现安全的 webservice 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44820366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com