python ssl-server-socket - 握手时的异常

时间:2016-10-07 08:36:15

标签: python openssl pyopenssl

我需要知道ssl-stream的确切数据格式。我只知道流中有一些json格式。

要获取数据,我关闭了服务器并启动了自己的ssl-server-socket:

import socket
import ssl

HOST, PORT = '0.0.0.0', 44444

SERVER_KEY = ...
SERVER_CERT = ... 
SERVER_CA_CERT = ...

def write_to_file(filename, buf):
    fp = open(filename, 'wb')
    fp.write(buf)
    fp.close()

#create server socket
Ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

#wrap server socket
SwrappedSocket = ssl.wrap_socket(Ssock, certfile=SERVER_CERT, server_side=True, keyfile=SERVER_KEY, ca_certs=SERVER_CA_CERT)
SwrappedSocket.bind(('0.0.0.0', PORT))

#listen for client connections
SwrappedSocket.listen(5)
#accept conncetions
print "start listening on port: " + str(PORT)
i = 0
while 1:
    (clientsocket, address) = SwrappedSocket.accept()
    print "Connection from client established"
    in_buffer = clientsocket.recv(66000)
    filename = '/root/received_data' + str(i) + '.log'
    write_to_file(filename, in_buffer)
    i+=1

但在握手期间:

Traceback (most recent call last):
  File "intercept.py", line 68, in <module>
    (clientsocket, address) = SwrappedSocket.accept()
  File "/usr/lib/python2.7/ssl.py", line 840, in accept
    server_side=True)
  File "/usr/lib/python2.7/ssl.py", line 350, in wrap_socket
    _context=self)
  File "/usr/lib/python2.7/ssl.py", line 566, in __init__
    self.do_handshake()
  File "/usr/lib/python2.7/ssl.py", line 788, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)

0 个答案:

没有答案