[2
在.NET应用程序中确定协商的TLS版本此技术利用反思访问内部属性和字段以获取SSL协议版本。 请注意,这取决于内部API,并且可能会随后的.NET更新而发生变化。
方法2:安全连接上下文属性(高级)
此方法通过ecure32.dll
库访问连接上下文属性。 这种方法涉及使用非公共手柄和结构,从而使其便于携带,并可能更加复杂。 (由于复杂性和潜在的不稳定而省略了详细的实现。)[2 。网络版本:
TLS 1.3支持需要.net Framework 4.8或更高版本,或.NET CORE 3.0。[remoteCertificateValidationCallback
:using System.IO.Compression;
using System.Net;
using System.Net.Security;
using System.Reflection;
using System.Security.Authentication;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
// ... other code ...
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Tls13;
// ... other code ...
Uri requestUri = new Uri("https://somesite.com");
var request = WebRequest.CreateHttp(requestUri);
// ... other code ...
using (var requestStream = request.GetRequestStream()) {
// Request stream validated; now extract SSL protocol
SslProtocols sslProtocol = ExtractSslProtocol(requestStream);
if (sslProtocol != SslProtocols.None) {
// Process the sslProtocol value
}
}
// ... ExtractSslProtocol function (implementation would be provided here) ...
TcpClient: Using TcpClient
allows retrieving TLS informationbefore
WebRequest
此信息可帮助开发人员了解和管理其.NET应用程序使用的安全协议。 请记住要仔细考虑与使用反射和与不受管理的库相互作用相关的含义和潜在风险。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3