未经认证的客户端连接时,Python ssl服务器会阻塞
嗨,我已经写了一个echo ssl服务器。我对未经认证的用户有问题!当一个用户通过认证时,一切正常,多个用户可以与服务器通信。但是,当一个未经认证的用户到来时,它会在接受请求时阻止服务器!有没有办法解决这个问题?有没有办法拒绝未经认证的客户??? server是一个包含server_套接字的类,当创建server时,它会将server_套接字绑定到端口并开始侦听。ConnectionRead是一个负责处理与客户端通信的类未经认证的客户端连接时,Python ssl服务器会阻塞,python,sockets,python-3.x,ssl,python-multithreading,Python,Sockets,Python 3.x,Ssl,Python Multithreading,嗨,我已经写了一个echo ssl服务器。我对未经认证的用户有问题!当一个用户通过认证时,一切正常,多个用户可以与服务器通信。但是,当一个未经认证的用户到来时,它会在接受请求时阻止服务器!有没有办法解决这个问题?有没有办法拒绝未经认证的客户??? server是一个包含server_套接字的类,当创建server时,它会将server_套接字绑定到端口并开始侦听。ConnectionRead是一个负责处理与客户端通信的类 s = Server(port, secure=SSL)
s = Server(port, secure=SSL)
while True:
count += 1
client_socket, addr = s.server_socket.accept()
if s.secure:
# when we have set the server to follow SSL protocol
try:
ssl_client = ssl.wrap_socket(
client_socket, keyfile=keypath,
certfile=certpath, server_side=True,
cert_reqs=ssl.CERT_REQUIRED, ca_certs=certpath)
if ssl_client:
print("Connected to client through SSL" + str(count) + str(ssl_client.getpeername()))
print("CERTIFICATES: ")
print(pprint.pformat(ssl_client.getpeercert()))
client = ConnectionThread(ssl_client)
client.client_socket.sendall("Thanks for connecting to me\n".encode())
client.start()
else:
print(" connection request is refused! ")
except ssl.SSLError as e:
print("connection to the client failed : " + str(e.args))
continue
#error after stopping the server main processes with Cntr+c
CTraceback (most recent call last): File "echo_server.py", line 74, in <module> cert_reqs=ssl.CERT_REQUIRED, ca_certs=certpath) File "/home/user/miniconda3/lib/python3.3/ssl.py", line 630, in wrap_socket ciphers=ciphers) File "/home/user/miniconda3/lib/python3.3/ssl.py", line 346, in init self.do_handshake() File "/home/user/miniconda3/lib/python3.3/ssl.py", line 553, in do_handshake self._sslobj.do_handshake() KeyboardInterrupt
您确定它在s.server_socket.accept上阻塞吗?如果在后台将SIGINT发送到服务器Ctrl+C,会得到什么回溯?嗨,塞巴斯蒂安!谢谢你的关注。当我使用Ctr+C关闭该客户端进程时,服务器将开始响应其他想要连接到服务器并已被阻止的已认证客户端:捕获ssl后的错误。SSLError:8,“EOF违反了协议_ssl.c:548”我的意思是如果你中断服务器会发生什么-调用accept的过程我也指前台调试不要把它放在评论中,而是你的问题。使用正确的格式好的,对不起!我把它放在问题里了!