2021年3月9日星期二

How to make the equivalent to openssl s_server in python?

I need to do exactly what this terminal command does in python.

openssl s_server -accept localhost:4443 -tls1_2 -cipher ADH-AES256-GCM-SHA384:@SECLEVEL=0 -nocert  

I'm trying to use the ssl module but hitting a dead end. The code I'm trying is:

context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)  context.set_ciphers("ADH-AES256-GCM-SHA384:@SECLEVEL=0")  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)  sock.bind(("localhost", 4443))  sock.listen(0)  ssock = context.wrap_socket(sock, server_side=True)  

But upon accepting connections, I get:

Traceback (most recent call last):    File "server.py", line 11, in <module>      ssock.accept()    File "/usr/lib/python3.8/ssl.py", line 1355, in accept      newsock = self.context.wrap_socket(newsock,    File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket      return self.sslsocket_class._create(    File "/usr/lib/python3.8/ssl.py", line 1040, in _create      self.do_handshake()    File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake      self._sslobj.do_handshake()  ssl.SSLError: [SSL: NO_SHARED_CIPHER] no shared cipher (_ssl.c:1123)  
https://stackoverflow.com/questions/66557775/how-to-make-the-equivalent-to-openssl-s-server-in-python March 10, 2021 at 11:06AM

没有评论:

发表评论