trevp/tlslite

Sending ClientHellos results in TLSAbruptCloseErrors

Closed this issue · 1 comments

tyll commented

I would like to send ClientHellos with tlslite but I get TLSAbruptCloseErrors when trying to get the server's response. Can you please help?

script:

#!/usr/bin/python -tt
# vim: fileencoding=utf8

import socket


import tlslite


class TLSConnectionTester(tlslite.tlsrecordlayer.TLSRecordLayer):
    def __init__(self, sock):
        tlslite.tlsrecordlayer.TLSRecordLayer.__init__(self, sock)

    def test(
            self,
            cipher=tlslite.constants.CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA):
        session_id = bytearray(0)
        version = (3, 2)
        client_hello = tlslite.messages.ClientHello()
        ciphers = [tlslite.constants.CipherSuite.TLS_EMPTY_RENEGOTIATION_INFO_SCSV,
                             cipher, 52, 58]
        print ciphers
        client_hello.create(version,
                            tlslite.utils.cryptomath.getRandomBytes(32),
                            session_id,
                            ciphers,
                            [tlslite.constants.CertificateType.x509],
                            None, False, False, "")
        self._handshakeStart(client=True)
        for result in self._sendMsg(client_hello):
            yield result
            if result in (0, 1):
                print "wait"
            else:
                break
        for result in self._getMsg(
                tlslite.constants.ContentType.handshake,
                tlslite.constants.HandshakeType.server_hello):
            print result
            if result in (0, 1):
                yield result
            else:
                break
        server_hello = result
        yield server_hello


def makesocket():
    sock = socket.socket()
    sock.connect(("127.0.0.1", 443))
    return sock


if __name__ == "__main__":
    sock = makesocket()
    tlscon = TLSConnectionTester(sock)

    for r in tlscon.test():
        pass

Exception:


TLSAbruptCloseError                       Traceback (most recent call last)
/usr/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    176             else:
    177                 filename = fname
--> 178             __builtin__.execfile(filename, *where)

/home/till/tlslite/tlsscan.py in <module>()
     56     tlscon = TLSConnectionTester(sock)
     57 
---> 58     for r in tlscon.test():
     59         pass

/home/till/tlslite/tlsscan.py in test(self, cipher)
     36         for result in self._getMsg(
     37                 tlslite.constants.ContentType.handshake,
---> 38                 tlslite.constants.HandshakeType.server_hello):
     39             print result
     40             if result in (0, 1):

/home/till/tlslite/tlslite/tlsrecordlayer.pyc in _getMsg(self, expectedType, secondaryType, constructorType)
    666             #  - we receive an empty application-data fragment; we try again
    667             while 1:
--> 668                 for result in self._getNextRecord():
    669                     if result in (0,1):
    670                         yield result

/home/till/tlslite/tlslite/tlsrecordlayer.pyc in _getNextRecord(self)
    840             #If the connection was abruptly closed, raise an error
    841             if len(s)==0:
--> 842                 raise TLSAbruptCloseError()
    843 
    844             b += bytearray(s)

TLSAbruptCloseError: TLSAbruptCloseError()

You could ask for help on the mailing list, I'm not sure this is a tlslite issue though.