我正在尝试通过Windows上的 TLS 1 连接到服务器。
这是我连接服务器的方式
public void Connect(string hostName, int port)
{
this.tcpClient.Client.Connect(hostName, port);
RemoteCertificateValidationCallback validationCallback = new RemoteCertificateValidationCallback(ServerValidationCallback);
LocalCertificateSelectionCallback selectionCallback = new LocalCertificateSelectionCallback(ClientCertificateSelectionCallback);
EncryptionPolicy encryptionPolicy = EncryptionPolicy.RequireEncryption;
this.sslStream = new SslStream(this.tcpClient.GetStream(), true, validationCallback, selectionCallback, encryptionPolicy);
//handshake
X509CertificateCollection clientCertificates = GetCertificates();
this.sslStream.AuthenticateAsClient(hostName);
//this.sslStream.AuthenticateAsClient(hostName, clientCertificates, SslProtocols.Tls, true);
}
比我通过方法发送消息
this.sslStream.Write(messageBytes);
this.sslStream.Flush();
this.tcpClient.GetStream().Flush();
服务器没有收到我的任何信息。