Search in sources :

Example 1 with Reply323Packet

use of com.alibaba.otter.canal.parse.driver.mysql.packets.server.Reply323Packet in project canal by alibaba.

the class MysqlConnector method auth323.

private void auth323(SocketChannel channel, byte packetSequenceNumber, byte[] seed) throws IOException {
    // auth 323
    Reply323Packet r323 = new Reply323Packet();
    if (password != null && password.length() > 0) {
        r323.seed = MySQLPasswordEncrypter.scramble323(password, new String(seed)).getBytes();
    }
    byte[] b323Body = r323.toBytes();
    HeaderPacket h323 = new HeaderPacket();
    h323.setPacketBodyLength(b323Body.length);
    h323.setPacketSequenceNumber((byte) (packetSequenceNumber + 1));
    PacketManager.write(channel, new ByteBuffer[] { ByteBuffer.wrap(h323.toBytes()), ByteBuffer.wrap(b323Body) });
    logger.info("client 323 authentication packet is sent out.");
    // check auth result
    HeaderPacket header = PacketManager.readHeader(channel, 4);
    byte[] body = PacketManager.readBytes(channel, header.getPacketBodyLength());
    assert body != null;
    switch(body[0]) {
        case 0:
            break;
        case -1:
            ErrorPacket err = new ErrorPacket();
            err.fromBytes(body);
            throw new IOException("Error When doing Client Authentication:" + err.toString());
        default:
            throw new IOException("unpexpected packet with field_count=" + body[0]);
    }
}
Also used : HeaderPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket) ErrorPacket(com.alibaba.otter.canal.parse.driver.mysql.packets.server.ErrorPacket) Reply323Packet(com.alibaba.otter.canal.parse.driver.mysql.packets.server.Reply323Packet) IOException(java.io.IOException)

Aggregations

HeaderPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.HeaderPacket)1 ErrorPacket (com.alibaba.otter.canal.parse.driver.mysql.packets.server.ErrorPacket)1 Reply323Packet (com.alibaba.otter.canal.parse.driver.mysql.packets.server.Reply323Packet)1 IOException (java.io.IOException)1