# 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
    cipher suite (if recognized), and finally we instantiate the write and
    read connection states.
    """
    super(TLS13ServerHello, self).tls_session_update(msg_str)

    s = self.tls_session
    if self.ext:
        for e in self.ext:
            if isinstance(e, TLS_Ext_SupportedVersion_SH):
                s.tls_version = e.version
                break
    s.server_random = self.random_bytes
    s.ciphersuite = self.cipher

    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]

    connection_end = s.connection_end
    if connection_end == "server":
        s.pwcs = writeConnState(
            ciphersuite=cs_cls, connection_end=connection_end, tls_version=s.tls_version
        )

        if not s.middlebox_compatibility:
            s.triggered_pwcs_commit = True
    elif connection_end == "client":
        s.prcs = readConnState(
            ciphersuite=cs_cls, connection_end=connection_end, tls_version=s.tls_version
        )
        if not s.middlebox_compatibility:
            s.triggered_prcs_commit = True

    if s.tls13_early_secret is None:
        # In case the connState was not pre-initialized, we could not
        # compute the early secrets at the ClientHello, so we do it here.
        s.compute_tls13_early_secrets()
    s.compute_tls13_handshake_secrets()
    if connection_end == "server":
        shts = s.tls13_derived_secrets["server_handshake_traffic_secret"]
        s.pwcs.tls13_derive_keys(shts)
    elif connection_end == "client":
        shts = s.tls13_derived_secrets["server_handshake_traffic_secret"]
        s.prcs.tls13_derive_keys(shts)


# 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
    cipher suite (if recognized), and finally we instantiate the write and
    read connection states.
    """
    s = self.tls_session
    s.server_random = self.random_bytes
    s.ciphersuite = self.cipher
    s.tls_version = self.version
    # Check extensions
    if self.ext:
        for e in self.ext:
            if isinstance(e, TLS_Ext_SupportedVersion_SH):
                s.tls_version = e.version
                break

    if s.tls_version < 0x304:
        # This means that the server does not support TLS 1.3 and ignored
        # the initial TLS 1.3 ClientHello. tls_version has been updated
        return TLSServerHello.tls_session_update(self, msg_str)
    else:
        _TLSHandshake.tls_session_update(self, msg_str)

    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]

    connection_end = s.connection_end
    if connection_end == "server":
        s.pwcs = writeConnState(
            ciphersuite=cs_cls, connection_end=connection_end, tls_version=s.tls_version
        )

        if not s.middlebox_compatibility:
            s.triggered_pwcs_commit = True
    elif connection_end == "client":
        s.prcs = readConnState(
            ciphersuite=cs_cls, connection_end=connection_end, tls_version=s.tls_version
        )
        if not s.middlebox_compatibility:
            s.triggered_prcs_commit = True

    if s.tls13_early_secret is None:
        # In case the connState was not pre-initialized, we could not
        # compute the early secrets at the ClientHello, so we do it here.
        s.compute_tls13_early_secrets()
    s.compute_tls13_handshake_secrets()
    if connection_end == "server":
        shts = s.tls13_derived_secrets["server_handshake_traffic_secret"]
        s.pwcs.tls13_derive_keys(shts)
    elif connection_end == "client":
        shts = s.tls13_derived_secrets["server_handshake_traffic_secret"]
        s.prcs.tls13_derive_keys(shts)