我了解到客户端身份验证是可选的,因此我尝试连接到SSL服务器,而不在客户端进行身份验证。执行此操作时,服务器上出现以下错误:
, in accept_connection
ssl_version=ssl.PROTOCOL_SSLv23
File "/usr/lib/python2.7/ssl.py", line 933, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 601, in __init__
self.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 830, in do_handshake
self._sslobj.do_handshake()
SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)
这是工作的服务器和客户端代码,当我在客户端进行身份验证时,一切正常,但当我对该行进行注释时,错误就会显示出来。
服务器(python):
def accept_connection(self, sock):
client, (addr, port) = sock.accept()
sslclient = ssl.wrap_socket(
client,
server_side=True,
certfile=self.ssl_cert_file,
keyfile=self.ssl_key_file,
ssl_version=ssl.PROTOCOL_SSLv23
)
客户端(C#):
public bool Connect()
{
try
{
client = new TcpClient(this.ServerAddress, this.ServerPort);
sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateCert),
null
);
try
{
sslStream.AuthenticateAsClient(this.ServerAddress);
}
catch (AuthenticationException e)
{
sslStream = null;
client.Close();
client = null;
return false;
}
}
catch (Exception e)
{
return false;
}
return true;
}
以上是没有错误的工作代码。
当我在客户端上注释掉以下代码时:
//sslStream.AuthenticateAsClient(this.ServerAddress);
出现上述python错误,客户端连接不会引发任何异常并继续运行,直到第一次读取为止,然后出现以下故障:
This operation is only allowed using a successfully authenticated context.
如果我不打电话,我该怎么做
AuthenticateAsClient
?
这是我如何生成certfile和keyfile的
openssl req -x509 -newkey rsa:1024 -keyout my.key -out my.crt -days 365 -nodes -subj "/C=US/ST=VA/L=Junk/O=None/OU=Junk/CN=example.local"
Python是版本2。
也许我只是被错误地告知
AuthenticateAscient
是否可选?