我读到客户端身份验证是可选的,因此我尝试连接到我的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。
也许我只是被误导了对的调用AuthenticateAsClient是可选的?
天涯尽头无女友
相关分类