public static byte[] Create(InitialHandshakePacket handshake, string userName, string password, string database)
		{
			// TODO: verify server capabilities

			var writer = new PayloadWriter();

			writer.WriteInt32((int) (
				ProtocolCapabilities.Protocol41 |
				ProtocolCapabilities.LongPassword |
				ProtocolCapabilities.SecureConnection |
				ProtocolCapabilities.PluginAuth |
				ProtocolCapabilities.PluginAuthLengthEncodedClientData |
				ProtocolCapabilities.MultiStatements |
				ProtocolCapabilities.MultiResults |
				ProtocolCapabilities.PreparedStatementMultiResults |
				(string.IsNullOrWhiteSpace(database) ? 0 : ProtocolCapabilities.ConnectWithDatabase)));
			writer.WriteInt32(0x40000000);
			writer.WriteByte((byte) CharacterSet.Utf8Mb4Binary);
			writer.Write(new byte[23]);
			writer.WriteNullTerminatedString(userName);

			writer.WriteLengthEncodedInteger(20);
			var hashedPassword = AuthenticationUtility.HashPassword(handshake.AuthPluginData, 0, password);
			writer.Write(hashedPassword);

			if (!string.IsNullOrWhiteSpace(database))
				writer.WriteNullTerminatedString(database);

			writer.WriteNullTerminatedString("mysql_native_password");

			return writer.ToBytes();
		}
        public static byte[] Create(InitialHandshakePacket handshake, string userName, string password, string database)
        {
            // TODO: verify server capabilities

            var writer = new PayloadWriter();

            writer.WriteInt32((int)(
                                  ProtocolCapabilities.Protocol41 |
                                  ProtocolCapabilities.LongPassword |
                                  ProtocolCapabilities.SecureConnection |
                                  ProtocolCapabilities.PluginAuth |
                                  ProtocolCapabilities.PluginAuthLengthEncodedClientData |
                                  ProtocolCapabilities.MultiStatements |
                                  ProtocolCapabilities.MultiResults |
                                  ProtocolCapabilities.PreparedStatementMultiResults |
                                  (string.IsNullOrWhiteSpace(database) ? 0 : ProtocolCapabilities.ConnectWithDatabase)));
            writer.WriteInt32(0x40000000);
            writer.WriteByte((byte)CharacterSet.Utf8Mb4Binary);
            writer.Write(new byte[23]);
            writer.WriteNullTerminatedString(userName);

            var authenticationResponse = AuthenticationUtility.CreateAuthenticationResponse(handshake.AuthPluginData, 0, password);

            writer.WriteByte((byte)authenticationResponse.Length);
            writer.Write(authenticationResponse);

            if (!string.IsNullOrWhiteSpace(database))
            {
                writer.WriteNullTerminatedString(database);
            }

            writer.WriteNullTerminatedString("mysql_native_password");

            return(writer.ToBytes());
        }
Example #3
0
        public static PayloadData Create(string user, byte[] authResponse, string schemaName)
        {
            var writer = new PayloadWriter();

            writer.WriteByte((byte)CommandKind.ChangeUser);
            writer.WriteNullTerminatedString(user);
            writer.WriteByte(checked ((byte)authResponse.Length));
            writer.Write(authResponse);
            writer.WriteNullTerminatedString(schemaName ?? "");
            writer.WriteByte((byte)CharacterSet.Utf8Mb4Binary);
            writer.WriteByte(0);
            writer.WriteNullTerminatedString("mysql_native_password");

            return(new PayloadData(new ArraySegment <byte>(writer.ToBytes())));
        }
        public static PayloadData Create(string user, byte[] authResponse, string schemaName)
        {
            var writer = new PayloadWriter();

            writer.WriteByte((byte) CommandKind.ChangeUser);
            writer.WriteNullTerminatedString(user);
            writer.WriteByte(checked((byte) authResponse.Length));
            writer.Write(authResponse);
            writer.WriteNullTerminatedString(schemaName ?? "");
            writer.WriteByte((byte) CharacterSet.Utf8Mb4Binary);
            writer.WriteByte(0);
            writer.WriteNullTerminatedString("mysql_native_password");

            return new PayloadData(new ArraySegment<byte>(writer.ToBytes()));
        }