/// <summary> /// AuthenticateSecurity implements the new 4.1 authentication scheme /// </summary> /// <param name="packet">The in-progress packet we use to complete the authentication</param> /// <param name="password">The password of the user to use</param> private void AuthenticateSecurely(Packet packet, string password) { packet.WriteString("xxxxxxxx", encoding); SendPacket(packet); packet = ReadPacket(); // compute pass1 hash string newPass = password.Replace(" ", "").Replace("\t", ""); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] firstPassBytes = sha.ComputeHash(System.Text.Encoding.Default.GetBytes(newPass)); byte[] salt = packet.GetBuffer(); byte[] input = new byte[firstPassBytes.Length + 4]; salt.CopyTo(input, 0); firstPassBytes.CopyTo(input, 4); byte[] outPass = new byte[100]; byte[] secondPassBytes = sha.ComputeHash(input); byte[] cryptSalt = new byte[20]; Security.ArrayCrypt(salt, 4, cryptSalt, 0, secondPassBytes, 20); Security.ArrayCrypt(cryptSalt, 0, firstPassBytes, 0, firstPassBytes, 20); // send the packet packet = CreatePacket(null); packet.Write(firstPassBytes, 0, 20); SendPacket(packet); }
public void Append(Packet p) { long oldPos = Position; Position = Length; this.Write(p.GetBuffer(), 0, p.Length); Position = oldPos; }
/// <summary> /// Send a single packet to the server. /// </summary> /// <param name="packet">Packet to send to the server</param> /// <remarks>This method will send a single packet to the server /// possibly breaking the packet up into smaller packets that are /// smaller than max_allowed_packet. This method will always send at /// least one packet to the server</remarks> protected void SendPacket(Packet packet) { byte[] buf = packet.GetBuffer(); int len = packet.Length; int index = 0; bool oneSent = false; // make sure we are not trying to send too much if (packet.Length > maxPacketSize && maxPacketSize > 0) { throw new MySqlException("Packet size too large. This MySQL server cannot accept rows larger than " + maxPacketSize + " bytes."); } try { while (len > 0 || !oneSent) { int lenToSend = Math.Min(len, MAX_PACKET_SIZE); // send the data if (useCompression) { SendCompressedBuffer(buf, index, lenToSend); } else { WriteInteger(lenToSend, 3); writer.WriteByte(packetSeq++); writer.Write(buf, index, lenToSend); writer.Flush(); } len -= lenToSend; index += lenToSend; oneSent = true; } writer.Flush(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public byte[] GetFieldBuffer() { return(packet.GetBuffer()); }
/// <summary> /// Send a single packet to the server. /// </summary> /// <param name="packet">Packet to send to the server</param> /// <remarks>This method will send a single packet to the server /// possibly breaking the packet up into smaller packets that are /// smaller than max_allowed_packet. This method will always send at /// least one packet to the server</remarks> protected void SendPacket(Packet packet) { byte[] buf = packet.GetBuffer(); int len = packet.Length; int index = 0; bool oneSent = false; // make sure we are not trying to send too much if (packet.Length > maxPacketSize && maxPacketSize > 0) throw new MySqlException("Packet size too large. This MySQL server cannot accept rows larger than " + maxPacketSize + " bytes."); try { while (len > 0 || ! oneSent) { int lenToSend = Math.Min( len, MAX_PACKET_SIZE ); // send the data if (useCompression) SendCompressedBuffer( buf, index, lenToSend ); else { WriteInteger( lenToSend, 3 ); writer.WriteByte( packetSeq++ ); writer.Write( buf, index, lenToSend ); writer.Flush(); } len -= lenToSend; index += lenToSend; oneSent = true; } writer.Flush(); } catch (Exception ex) { Console.WriteLine( ex.Message ); } }
/// <summary> /// AuthenticateSecurity implements the new 4.1 authentication scheme /// </summary> /// <param name="packet">The in-progress packet we use to complete the authentication</param> /// <param name="password">The password of the user to use</param> private void AuthenticateSecurely( Packet packet, string password ) { packet.WriteString("xxxxxxxx", encoding ); SendPacket(packet); packet = ReadPacket(); // compute pass1 hash string newPass = password.Replace(" ","").Replace("\t",""); SHA1 sha = new SHA1CryptoServiceProvider(); byte[] firstPassBytes = sha.ComputeHash( System.Text.Encoding.Default.GetBytes(newPass)); byte[] salt = packet.GetBuffer(); byte[] input = new byte[ firstPassBytes.Length + 4 ]; salt.CopyTo( input, 0 ); firstPassBytes.CopyTo( input, 4 ); byte[] outPass = new byte[100]; byte[] secondPassBytes = sha.ComputeHash( input ); byte[] cryptSalt = new byte[20]; Security.ArrayCrypt( salt, 4, cryptSalt, 0, secondPassBytes, 20 ); Security.ArrayCrypt( cryptSalt, 0, firstPassBytes, 0, firstPassBytes, 20 ); // send the packet packet = CreatePacket(null); packet.Write( firstPassBytes, 0, 20 ); SendPacket(packet); }
public void Append( Packet p ) { long oldPos = Position; Position = Length; this.Write( p.GetBuffer(), 0, p.Length ); Position = oldPos; }