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); 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()); }
private static byte[] CreateConnectionAttributes() { var attributesWriter = new PayloadWriter(); attributesWriter.WriteLengthEncodedString("_client_name"); attributesWriter.WriteLengthEncodedString("MySqlConnector"); attributesWriter.WriteLengthEncodedString("_client_version"); attributesWriter.WriteLengthEncodedString(typeof(MySqlSession).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion); try { var os = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows" : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "Linux" : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "macOS" : null; var osDetails = RuntimeInformation.OSDescription; var platform = RuntimeInformation.ProcessArchitecture.ToString(); if (os != null) { attributesWriter.WriteLengthEncodedString("_os"); attributesWriter.WriteLengthEncodedString(os); } attributesWriter.WriteLengthEncodedString("_os_details"); attributesWriter.WriteLengthEncodedString(osDetails); attributesWriter.WriteLengthEncodedString("_platform"); attributesWriter.WriteLengthEncodedString(platform); } catch (PlatformNotSupportedException) { } using (var process = Process.GetCurrentProcess()) { attributesWriter.WriteLengthEncodedString("_pid"); attributesWriter.WriteLengthEncodedString(process.Id.ToString(CultureInfo.InvariantCulture)); } var connectionAttributes = attributesWriter.ToBytes(); var writer = new PayloadWriter(); writer.WriteLengthEncodedInteger((ulong)connectionAttributes.Length); writer.Write(connectionAttributes); return(writer.ToBytes()); }