def on_request(self, request):
        if not self.ssl:
            return request
        try:
            record, remaining = tls.parse_tls(request)
            message = record.messages[0]
            if not self.clienthello_adjusted:
                self.clienthello_adjusted = True
                hello = message.obj
                # Force a full handshake (and thus a key exchange) by preventing
                # session resumption by clearing session ID and SessionTicket.
                hello.session_id = []
                for ext in hello.extension_list:
                    if ext.type == Extension.TYPE.SESSIONTICKET:
                        ext.raw_data = []
                # Retain in ClientHello only cipher suites which require the
                # server to send a ServerKeyExchange message: ephemeral (EC)DH
                # and RSA_EXPORT cipher suites. Also retain pseudo/signalling
                # cipher suites because they don't affect this attack/test.
                hello.ciphers = [c for c in hello.ciphers
                    if ("_DHE_" in str(c) or
                       "_ECDHE_" in str(c) or
                       "_RSA_EXPORT_" in str(c) or
                       str(c).endswith("_SCSV"))]
                return record.to_bytes()
            if self.signature_tampered:
                # The client MUST reply with an alert and close the connection.
                # Just closing the connection is also acceptable.
                if not self.first_alert_received_after_tampering:
                    if isinstance(message, Alert):
                        self.first_alert_received_after_tampering = message
                        return request

                self.vuln_detected = True
                self.log(
                    logging.CRITICAL,
                    ("Client is vulnerable to server key substitution"
                    " attack! Client reply: %s" % str(message)))
                self.connection.vuln_notify(
                    util.vuln.VULN_TLS_SERVER_KEY_REPLACEMENT)
                self.log_attack_event()
                self.connection.close()
                return request

        except __HOLE__:
            # Failed to parse TLS, this is probably due to a short read of a TLS
            # record.
            pass
        return request
dataset/ETHPy150Open google/nogotofail/nogotofail/mitm/connection/handlers/connection/serverkeyreplace.py/ServerKeyReplacementMITM.on_request