(self, plugin_name, auth_packet)
| 1031 | print("Succeed to auth") |
| 1032 | |
| 1033 | def _process_auth(self, plugin_name, auth_packet): |
| 1034 | handler = self._get_auth_plugin_handler(plugin_name) |
| 1035 | if handler: |
| 1036 | try: |
| 1037 | return handler.authenticate(auth_packet) |
| 1038 | except AttributeError: |
| 1039 | if plugin_name != b"dialog": |
| 1040 | raise err.OperationalError( |
| 1041 | CR.CR_AUTH_PLUGIN_CANNOT_LOAD, |
| 1042 | f"Authentication plugin '{plugin_name}'" |
| 1043 | f" not loaded: - {type(handler)!r} missing authenticate method", |
| 1044 | ) |
| 1045 | if plugin_name == b"caching_sha2_password": |
| 1046 | return _auth.caching_sha2_password_auth(self, auth_packet) |
| 1047 | elif plugin_name == b"sha256_password": |
| 1048 | return _auth.sha256_password_auth(self, auth_packet) |
| 1049 | elif plugin_name == b"mysql_native_password": |
| 1050 | data = _auth.scramble_native_password(self.password, auth_packet.read_all()) |
| 1051 | elif plugin_name == b"client_ed25519": |
| 1052 | data = _auth.ed25519_password(self.password, auth_packet.read_all()) |
| 1053 | elif plugin_name == b"mysql_old_password": |
| 1054 | data = ( |
| 1055 | _auth.scramble_old_password(self.password, auth_packet.read_all()) |
| 1056 | + b"\0" |
| 1057 | ) |
| 1058 | elif plugin_name == b"mysql_clear_password": |
| 1059 | # https://dev.mysql.com/doc/internals/en/clear-text-authentication.html |
| 1060 | data = self.password + b"\0" |
| 1061 | elif plugin_name == b"dialog": |
| 1062 | pkt = auth_packet |
| 1063 | while True: |
| 1064 | flag = pkt.read_uint8() |
| 1065 | echo = (flag & 0x06) == 0x02 |
| 1066 | last = (flag & 0x01) == 0x01 |
| 1067 | prompt = pkt.read_all() |
| 1068 | |
| 1069 | if prompt == b"Password: ": |
| 1070 | self.write_packet(self.password + b"\0") |
| 1071 | elif handler: |
| 1072 | resp = "no response - TypeError within plugin.prompt method" |
| 1073 | try: |
| 1074 | resp = handler.prompt(echo, prompt) |
| 1075 | self.write_packet(resp + b"\0") |
| 1076 | except AttributeError: |
| 1077 | raise err.OperationalError( |
| 1078 | CR.CR_AUTH_PLUGIN_CANNOT_LOAD, |
| 1079 | f"Authentication plugin '{plugin_name}'" |
| 1080 | f" not loaded: - {handler!r} missing prompt method", |
| 1081 | ) |
| 1082 | except TypeError: |
| 1083 | raise err.OperationalError( |
| 1084 | CR.CR_AUTH_PLUGIN_ERR, |
| 1085 | f"Authentication plugin '{plugin_name}'" |
| 1086 | f" {handler!r} didn't respond with string. Returned '{resp!r}' to prompt {prompt!r}", |
| 1087 | ) |
| 1088 | else: |
| 1089 | raise err.OperationalError( |
| 1090 | CR.CR_AUTH_PLUGIN_CANNOT_LOAD, |
no test coverage detected