# Buggy code
def tls_session_update(self, msg_str):
    """
    Either for parsing or building, we store the server_random
    along with the raw string representing this handshake message.
    We also store the session_id, the cipher suite (if recognized),
    the compression method, and finally we instantiate the pending write
    and read connection states. Usually they get updated later on in the
    negotiation when we learn the session keys, and eventually they
    are committed once a ChangeCipherSpec has been sent/received.
    """
    super(TLSServerHello, self).tls_session_update(msg_str)

    self.tls_session.tls_version = self.version
    self.random_bytes = msg_str[10:38]
    self.tls_session.server_random = (
        struct.pack("!I", self.gmt_unix_time) + self.random_bytes
    )
    self.tls_session.sid = self.sid

    cs_cls = None
    if self.cipher:
        cs_val = self.cipher
        if cs_val not in _tls_cipher_suites_cls:
            warning("Unknown cipher suite %d from ServerHello" % cs_val)
            # we do not try to set a default nor stop the execution
        else:
            cs_cls = _tls_cipher_suites_cls[cs_val]

    comp_cls = Comp_NULL
    if self.comp:
        comp_val = self.comp[0]
        if comp_val not in _tls_compression_algs_cls:
            err = "Unknown compression alg %d from ServerHello" % comp_val
            warning(err)
            comp_val = 0
        comp_cls = _tls_compression_algs_cls[comp_val]

    connection_end = self.tls_session.connection_end
    self.tls_session.pwcs = writeConnState(
        ciphersuite=cs_cls,
        compression_alg=comp_cls,
        connection_end=connection_end,
        tls_version=self.version,
    )
    self.tls_session.prcs = readConnState(
        ciphersuite=cs_cls,
        compression_alg=comp_cls,
        connection_end=connection_end,
        tls_version=self.version,
    )


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-4c9f13dcdcd8> in <module>
----> 1 r2 = TLS(pcap[1].load, tls_session=r1.tls_session.mirror())

~/scapy_venv/lib/python3.7/site-packages/scapy/base_classes.py in __call__(cls, *args, **kargs)
264                 cls = config.conf.raw_layer
265         i = cls.__new__(cls, cls.__name__, cls.__bases__, cls.__dict__)
--> 266         i.__init__(*args, **kargs)
267         return i
268

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/record.py in __init__(self, *args, **kargs)
302     def __init__(self, *args, **kargs):
303         self.deciphered_len = kargs.get("deciphered_len", None)
--> 304         super(TLS, self).__init__(*args, **kargs)
305
306     @classmethod

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, _pkt, post_transform, _internal, _underlayer, tls_session, **fields)
902         Packet.__init__(self, _pkt=_pkt, post_transform=post_transform,
903                         _internal=_internal, _underlayer=_underlayer,
--> 904                         **fields)
905
906     def __getattr__(self, attr):

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in __init__(self, _pkt, post_transform, _internal, _underlayer, **fields)
156         self.sniffed_on = None
157         if _pkt:
--> 158             self.dissect(_pkt)
159             if not _internal:
160                 self.dissection_done(self)

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in dissect(self, s)
873         s = self.pre_dissect(s)
874
--> 875         s = self.do_dissect(s)
876
877         s = self.post_dissect(s)

~/scapy_venv/lib/python3.7/site-packages/scapy/packet.py in do_dissect(self, s)
837             if not s:
838                 break
--> 839             s, fval = f.getfield(self, s)
840             # We need to track fields with mutable values to discard
841             # .raw_packet_cache when needed.

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/record.py in getfield(self, pkt, s)
166                 if isinstance(p, _GenericTLSSessionInheritance):
167                     if not p.tls_session.frozen:
--> 168                         p.post_dissection_tls_session_update(raw_msg)
169
170                 lst.append(p)

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in post_dissection_tls_session_update(self, msg_str)
924
925     def post_dissection_tls_session_update(self, msg_str):
--> 926         self.tls_session_update(msg_str)
927
928     def copy(self):

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/handshake.py in tls_session_update(self, msg_str)
648             s.prcs = readConnState(ciphersuite=cs_cls,
649                                    connection_end=connection_end,
--> 650                                    tls_version=s.tls_version)
651             if not s.middlebox_compatibility:
652                 s.triggered_prcs_commit = True

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, **kargs)
279 class readConnState(connState):
280     def __init__(self, **kargs):
--> 281         connState.__init__(self, read_or_write="read", **kargs)
282
283

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/session.py in __init__(self, connection_end, read_or_write, seq_num, compression_alg, ciphersuite, tls_version)
89             from scapy.layers.tls.crypto.suites import TLS_NULL_WITH_NULL_NULL
90             ciphersuite = TLS_NULL_WITH_NULL_NULL
---> 91         self.ciphersuite = ciphersuite(tls_version=tls_version)
92
93         if not self.ciphersuite.usable:

~/scapy_venv/lib/python3.7/site-packages/scapy/layers/tls/crypto/suites.py in __init__(self, tls_version)
140         """
141         super(_GenericCipherSuite, self).__init__()
--> 142         if tls_version <= 0x301:
143             self.key_block_len = self._key_block_len_v1_0
144

TypeError: '<=' not supported between instances of 'NoneType' and 'int'

# Fixed code
def tls_session_update(self, msg_str):
    """
    Either for parsing or building, we store the server_random
    along with the raw string representing this handshake message.
    We also store the session_id, the cipher suite (if recognized),
    the compression method, and finally we instantiate the pending write
    and read connection states. Usually they get updated later on in the
    negotiation when we learn the session keys, and eventually they
    are committed once a ChangeCipherSpec has been sent/received.
    """
    super(TLSServerHello, self).tls_session_update(msg_str)

    s = self.tls_session
    s.tls_version = self.version
    if hasattr(self, "gmt_unix_time"):
        self.random_bytes = msg_str[10:38]
        s.server_random = struct.pack("!I", self.gmt_unix_time) + self.random_bytes
    else:
        s.server_random = self.random_bytes
    s.sid = self.sid

    cs_cls = None
    if self.cipher:
        cs_val = self.cipher
        if cs_val not in _tls_cipher_suites_cls:
            warning("Unknown cipher suite %d from ServerHello" % cs_val)
            # we do not try to set a default nor stop the execution
        else:
            cs_cls = _tls_cipher_suites_cls[cs_val]

    comp_cls = Comp_NULL
    if self.comp:
        comp_val = self.comp[0]
        if comp_val not in _tls_compression_algs_cls:
            err = "Unknown compression alg %d from ServerHello" % comp_val
            warning(err)
            comp_val = 0
        comp_cls = _tls_compression_algs_cls[comp_val]

    connection_end = s.connection_end
    s.pwcs = writeConnState(
        ciphersuite=cs_cls,
        compression_alg=comp_cls,
        connection_end=connection_end,
        tls_version=self.version,
    )
    s.prcs = readConnState(
        ciphersuite=cs_cls,
        compression_alg=comp_cls,
        connection_end=connection_end,
        tls_version=self.version,
    )