当我尝试从客户端使用python的ssl套接字服务器接收消息时,出现错误,我可以发送消息,但是我无法接收消息,因为我收到此错误。
这很奇怪,因为如果我做client.getpeername()
会返回连接类型{ ('TLS_AES_256_GCM_SHA384', 'TLSv1.3', 256)}
服务器:
HOST = *
PORT = *
BUFSIZ = 10240
ADDR = (HOST, PORT)
print(addresses)
SERVER = socket(AF_INET, SOCK_STREAM)
SERVER.bind(ADDR)
SERVER.listen(5)
print("Waiting for connection...")
newsocket, client_address = SERVER.accept()
ssl.SSLContext()
client=ssl.wrap_socket(newsocket,server_side=True,certfile="server.crt",keyfile="server.key")
print (client.getpeername())
print("%s:%s has connected." % client_address)
msg= client.recv(BUFSIZ)
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "testser.py", line 57, in handle_client
name = login(client)
File "testser.py", line 43, in login
logindet = client.recv(BUFSIZ).decode("utf8")
File "/usr/lib/python3.7/ssl.py", line 1037, in recv
return self.read(buflen)
File "/usr/lib/python3.7/ssl.py", line 913, in read
return self._sslobj.read(len)
ssl.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:2488)
客户端:
Traceback (most recent call last):
File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File " chat [Doos Version].py", line 97, in login_verify
msgdec = client_socket.recv(BUFSIZ).decode("utf8")
File "/usr/lib/python3.7/ssl.py", line 1056, in recv
return self.read(buflen)
File "/usr/lib/python3.7/ssl.py", line 931, in read
return self._sslobj.read(len)
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:2508)