[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