def _inject_ccs(self, record, hello_message_index):
        """Inject an early CCS while preserving the rest of the data."""
        version = record.version

        ccs = TlsRecord(
            TlsRecord.CONTENT_TYPE.CHANGE_CIPHER_SPEC,
            version,
            [tls.types.ChangeCipherSpec(1)])

        rec = TlsRecord(
            TlsRecord.CONTENT_TYPE.HANDSHAKE,
            version,
            record.messages[:hello_message_index + 1])

        # Split the record if there are more messages after the ServerHello.
        remaining = record.messages[hello_message_index + 1:]
        if remaining:
            rest = TlsRecord(
                TlsRecord.CONTENT_TYPE.HANDSHAKE,
                version,
                remaining).to_bytes()
        else:
            rest = ""

        return rec.to_bytes() + ccs.to_bytes() + rest
Inject an early CCS while preserving the rest of the data.
nogotofail/mitm/connection/handlers/connection/ccs.py