0

I need to know the exact data-format form an ssl-stream. I only know there is some json like format in the stream.

To get the data I shutdown the server and started my own 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

but during the handshake:

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)
spitzbuaamy
  • 751
  • 2
  • 10
  • 25
  • That probably means the client closed the connection during the handshake, so it may be an issue with the client, not with the server. – mata Oct 07 '16 at 09:20
  • What can be the reason for the client to close the connection? I pass the right cert/key/ca. And the client is working with the original server. – spitzbuaamy Oct 07 '16 at 10:16
  • 1
    Maybe you should add more details about the client and the old server to your question, or try to connect to the old and new server using `openssl s_client` and compare the results, maybe then you see what's different. – mata Oct 07 '16 at 12:57

0 Answers0