Example #1
0
        public void Test()
        {
            var password = Encoding.ASCII.GetBytes("random_password");
            var seed     = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };

            Assert.AreEqual("145db9d431bc9c5958ffe0379d235ab86e5df00424",
                            NativePassword.Encrypt(password, seed).Aggregate("", (s, b) => s += b.ToString("x2")));
        }
Example #2
0
        private byte[] InitializeConnection(Options options)
        {
            var packet    = ReadPacket();
            var handshake = HandshakeRequest.Decode(packet, options.Encoding);

            ServerInfo.Capabilities  = handshake.Capabilities;
            ServerInfo.CharacterSet  = handshake.CharacterSet;
            ServerInfo.ConnectionId  = handshake.ConnectionId;
            ServerInfo.ServerVersion = handshake.ServerVersion;

            var mycaps = DefaultCapabilities;

            if (options.UseCompression)
            {
                mycaps |= CapabilityFlags.ClientCompress;
            }

            SendPacket(new HandshakeResponse
            {
                Capabilities  = mycaps,
                MaxPacketSize = 65536,
                CharacterSet  = 33,
                User          = options.User,
                Database      = options.Database,
                Password      = NativePassword.Encrypt(options.Encoding.GetBytes(options.Password), handshake.AuthData)
            }.Encode(options.Encoding), false);

            var response = ReadPacket();

            if (!PacketReader.IsOkPacket(response))
            {
                throw new MyRawException("Unrecognized packet in handshake: " + PacketReader.PacketToString(response));
            }

            if (ServerInfo.Capabilities.HasFlag(CapabilityFlags.ClientCompress) && options.UseCompression)
            {
                Handler = new CompressedPacketHandler(Handler);
            }

            return(response);
        }