【发布时间】:2014-08-20 21:42:36
【问题描述】:
由于Heartbleed,我们的网关服务器已更新,并且出现了这个问题。
由于POODLE,不再支持 SSLv3。
- 注意,这个问题只出现在 Win7+ 机器上; WinXP 盒子可以正常工作(相同的代码,不同的操作系统 = 问题);授予 WinXP 不再是有效的操作系统,只是想记下功能。
客户端应用程序 (.NET 2.0) 位于 Windows 7(或 8)机器上。服务器在网关服务器后面的 DMZ 中运行。需要注意的是,我发现这个问题在 .NET 4.0+ 上不再存在 - 但是由于遗留代码,我没有更新的余地。
Gateway Server 是运行带有 SSL 的 Apache HTTP Server 的传递框。它的位置在DMZ之外,用于访问DMZ内的Server。网关服务器上运行的软件版本为 Apache/2.2.25 (Win32)、mod_jk/1.2.39、mod_ssl/2.2.25、OpenSSL/1.0.1g
这是客户端应用程序上使用的代码(添加了大量的日志记录)...注意,“serverName”通常包含诸如“https://some.url.com”之类的值
private bool ConnectAndAuthenicate(string serverName, out TcpClient client, out SslStream sslStream)
{
client = null;
sslStream = null;
try
{
client = new TcpClient(serverName, 443); // Create a TCP/IP client; ctor attempts connection
Log("ConnectAndAuthenicate: Client CONNECTED"));
sslStream = new SslStream(client.GetStream(), false, ValidateServerCertificate, null);
Log("ConnectAndAuthenicate: SSL Stream CREATED"));
}
catch (Exception x)
{
Log("ConnectAndAuthenicate: EXCEPTION >> CONNECTING to server: {0}", x.ToString()));
if (x is SocketException)
{
SocketException s = x as SocketException;
Log("ConnectAndAuthenicate: EXCEPTION >> CONNECTING to server: Socket.ErrorCode: {0}", s.ErrorCode));
}
if (client != null) { client.Close(); client = null; }
if (sslStream != null) { sslStream.Close(); sslStream = null; }
}
if (sslStream == null) return false;
try
{
sslStream.ReadTimeout = 10000; // wait 10 seconds for a response ...
Log("ConnectAndAuthenicate: AuthenticateAsClient CALLED ({0})", serverName));
sslStream.AuthenticateAsClient(serverName);
Log("ConnectAndAuthenicate: AuthenticateAsClient COMPLETED SUCCESSFULLY"));
return true;
}
catch (Exception x)
{
Log("ConnectAndAuthenicate: EXCEPTION >> AuthenticateAsClient: {0}", x.ToString()));
client.Close(); client = null;
sslStream.Close(); sslStream = null;
}
return false;
}
注意 - 与 ServicePointManager 相关的 answers posted 绝对不会影响此应用程序的结果。
应用程序在 Win 7+ 机器上运行时,每次调用 AuthenicateAsClient() 时,都会发生异常 - 如果应用程序在 WinXP 机器上运行,代码可以正常工作而不会出现异常。
非常欢迎任何关于解决方案的想法。
【问题讨论】:
标签: c#-2.0 tcpclient ioexception sslstream