使用TCP连接时,确定SSL连接类型
本文关键字:连接 SSL 类型 确定 TCP 使用 | 更新日期: 2023-09-27 18:19:22
我正在使用以下代码连接到主机:
protected bool OpenSocket(string hostIPAddress, int hostIPPort)
{
try
{
if ((this._tcpSocket != null) && (this._tcpSocket.Connected == true))
return (true);
}
catch { }
// Reset variables
this._isSocketOpen = false;
this._isSSLOpen = false;
string ipAddress = this.GetHostIPAddress(hostIPAddress);
this._tcpSocket = new TcpClient(ipAddress, hostIPPort);
this._tcpipConnectionStream = this._tcpSocket.GetStream();
this._isSocketOpen = true;
return true;
}
在连接到主机时,是否有办法确定SSL连接类型(即SSL2, SSL3, TL1.2) ?我考虑过这样使用:
SslStream sslStream = new SslStream(this._tcpSocket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(hostIPAddress);
然而,我认为这将是设置SSL协议,不是吗,而不是获取它?
可以通过查询SslStream
类型的SslProtocol
属性来判断连接类型
SslStream sslStream = new SslStream(this._tcpSocket.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(hostIPAddress);
Console.WriteLine(sslStream.SslProtocol);
此属性将返回枚举的一个值SslProtocols
有关此属性的详细信息,请参阅MSDN