{"record":{"id":"b6fac46e95056faa","repo":"apache/shardingsphere","slug":"1043","errorCode":"1043","errorMessage":"Bad handshake","messagePattern":"Bad handshake","errorType":"exception","errorClass":"HandshakeException","httpStatus":null,"severity":"error","filePath":"proxy/frontend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java","lineNumber":119,"sourceCode":"            authenticateMismatchedMethod((MySQLPacketPayload) payload);\n        }\n        Grantee grantee = new Grantee(currentAuthResult.getUsername(), getHostAddress(context));\n        ShardingSpherePreconditions.checkState(login(rule, grantee, authResponse), () -> new AccessDeniedException(currentAuthResult.getUsername(), grantee.getHostname(), 0 != authResponse.length));\n        ShardingSpherePreconditions.checkState(authorizeDatabase(rule, grantee, currentAuthResult.getDatabase()),\n                () -> new DatabaseAccessDeniedException(currentAuthResult.getUsername(), grantee.getHostname(), currentAuthResult.getDatabase()));\n        writeOKPacket(context);\n        return AuthenticationResultBuilder.finished(grantee.getUsername(), grantee.getHostname(), currentAuthResult.getDatabase(), currentAuthResult.getConnectionAttributes());\n    }\n    \n    private AuthenticationResult authenticatePhaseFastPath(final ChannelHandlerContext context, final PacketPayload payload, final AuthorityRule rule) {\n        MySQLHandshakeResponse41Packet handshakeResponsePacket;\n        try {\n            handshakeResponsePacket = new MySQLHandshakeResponse41Packet((MySQLPacketPayload) payload);\n        } catch (final IndexOutOfBoundsException ex) {\n            if (log.isWarnEnabled()) {\n                log.warn(\"Received bad handshake from client {}: \\n{}\", context.channel(), ByteBufUtil.prettyHexDump(payload.getByteBuf().resetReaderIndex()));\n            }\n            throw new HandshakeException();\n        }\n        authResponse = handshakeResponsePacket.getAuthResponse();\n        setMultiStatementsOption(context, handshakeResponsePacket);\n        setCharacterSet(context, handshakeResponsePacket);\n        setConnectionAttributes(context, handshakeResponsePacket);\n        String database = handshakeResponsePacket.getDatabase();\n        ShardingSpherePreconditions.checkState(Strings.isNullOrEmpty(database) || ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().containsDatabase(database),\n                () -> new UnknownDatabaseException(database));\n        String username = handshakeResponsePacket.getUsername();\n        String hostname = getHostAddress(context);\n        ShardingSphereUser user = rule.findUser(new Grantee(username, hostname)).orElseGet(() -> new ShardingSphereUser(username, \"\", hostname));\n        Authenticator authenticator = new AuthenticatorFactory<>(MySQLAuthenticatorType.class, rule).newInstance(user);\n        Map<String, String> connectionAttributes = handshakeResponsePacket.getConnectionAttributes();\n        if (0 == authResponse.length || isClientPluginAuthenticate(handshakeResponsePacket) && !authenticator.getAuthenticationMethodName().equals(handshakeResponsePacket.getAuthPluginName())) {\n            connectionPhase = MySQLConnectionPhase.AUTHENTICATION_METHOD_MISMATCH;\n            context.writeAndFlush(new MySQLAuthSwitchRequestPacket(authenticator.getAuthenticationMethodName(), authPluginData));\n            return AuthenticationResultBuilder.continued(username, hostname, database, connectionAttributes);\n        }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/proxy/frontend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/authentication/MySQLAuthenticationEngine.java#L101-L137","documentation":"Error \"Bad handshake\" thrown in apache/shardingsphere.","triggerScenarios":"MySQL handshake authentication fails in MySQLAuthenticationEngine, e.g. wrong credentials or protocol mismatch.","commonSituations":"Bad password, unsupported client auth plugin, or TLS/packet corruption during the initial handshake.","solutions":["Verify username and password used by the client.","Ensure the client and server agree on the authentication plugin and protocol version.","Check that the connection was not interrupted or corrupted during the handshake."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}