Remove padding mechanism

Not needed anymore since proper encryption is now used under Mono
This commit is contained in:
ORelio 2015-06-19 19:40:18 +02:00
parent 67affc6270
commit 3224c59eab
8 changed files with 7 additions and 101 deletions

View file

@ -197,14 +197,13 @@ namespace MinecraftClient.Crypto
/// </summary> /// </summary>
/// <param name="underlyingStream">Stream to encrypt</param> /// <param name="underlyingStream">Stream to encrypt</param>
/// <param name="AesKey">Key to use</param> /// <param name="AesKey">Key to use</param>
/// <param name="paddingProvider">Padding provider for Mono implementation</param>
/// <returns>Return an appropriate stream depending on the framework being used</returns> /// <returns>Return an appropriate stream depending on the framework being used</returns>
public static IAesStream getAesStream(Stream underlyingStream, byte[] AesKey, IPaddingProvider paddingProvider) public static IAesStream getAesStream(Stream underlyingStream, byte[] AesKey)
{ {
if (Program.isUsingMono) if (Program.isUsingMono)
{ {
return new Streams.MonoAesStream(underlyingStream, AesKey, paddingProvider); return new Streams.MonoAesStream(underlyingStream, AesKey);
} }
else return new Streams.RegularAesStream(underlyingStream, AesKey); else return new Streams.RegularAesStream(underlyingStream, AesKey);
} }

View file

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Crypto
{
/// <summary>
/// Interface for padding provider
/// Allow to get a padding plugin message from the current network protocol implementation.
/// </summary>
public interface IPaddingProvider
{
byte[] getPaddingPacket();
}
}

View file

@ -19,15 +19,13 @@ namespace MinecraftClient.Crypto.Streams
public class MonoAesStream : Stream, IAesStream public class MonoAesStream : Stream, IAesStream
{ {
IPaddingProvider pad;
CipherStream cstream; CipherStream cstream;
public MonoAesStream(System.IO.Stream stream, byte[] key, IPaddingProvider provider) public MonoAesStream(System.IO.Stream stream, byte[] key)
{ {
BaseStream = stream; BaseStream = stream;
BufferedBlockCipher enc = GenerateAES(key, true); BufferedBlockCipher enc = GenerateAES(key, true);
BufferedBlockCipher dec = GenerateAES(key, false); BufferedBlockCipher dec = GenerateAES(key, false);
cstream = new CipherStream(stream, dec, enc); cstream = new CipherStream(stream, dec, enc);
pad = provider;
} }
public System.IO.Stream BaseStream { get; set; } public System.IO.Stream BaseStream { get; set; }

View file

@ -127,7 +127,6 @@
<Compile Include="Protocol\Handlers\ZlibUtils.cs" /> <Compile Include="Protocol\Handlers\ZlibUtils.cs" />
<Compile Include="Protocol\Handlers\ChatParser.cs" /> <Compile Include="Protocol\Handlers\ChatParser.cs" />
<Compile Include="Crypto\IAesStream.cs" /> <Compile Include="Crypto\IAesStream.cs" />
<Compile Include="Crypto\IPaddingProvider.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="McTcpClient.cs" /> <Compile Include="McTcpClient.cs" />

View file

@ -42,19 +42,11 @@ namespace MinecraftClient.Protocol.Handlers
private void Updater() private void Updater()
{ {
int keep_alive_interval = 100;
int keep_alive_timer = 100;
try try
{ {
do do
{ {
Thread.Sleep(100); Thread.Sleep(100);
keep_alive_timer--;
if (keep_alive_timer <= 0)
{
Send(getPaddingPacket());
keep_alive_timer = keep_alive_interval;
}
} }
while (Update()); while (Update());
} }
@ -504,7 +496,7 @@ namespace MinecraftClient.Protocol.Handlers
if (pid[0] == 0xFC) if (pid[0] == 0xFC)
{ {
readData(4); readData(4);
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this); s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
encrypted = true; encrypted = true;
return true; return true;
} }
@ -652,18 +644,6 @@ namespace MinecraftClient.Protocol.Handlers
return result.ToArray(); return result.ToArray();
} }
public byte[] getPaddingPacket()
{
//Will generate a 15-bytes long padding packet
byte[] id = new byte[1] { 0xFA }; //Plugin Message
byte[] channel_name = Encoding.BigEndianUnicode.GetBytes("MCC|");
byte[] channel_name_len = BitConverter.GetBytes((short)channel_name.Length); Array.Reverse(channel_name_len);
byte[] data = new byte[] { 0x00, 0x00 };
byte[] data_len = BitConverter.GetBytes((short)data.Length); Array.Reverse(data_len);
byte[] packet_data = concatBytes(id, channel_name_len, channel_name, data_len, data);
return packet_data;
}
public static bool doPing(string host, int port, ref int protocolversion) public static bool doPing(string host, int port, ref int protocolversion)
{ {
try try

View file

@ -45,19 +45,11 @@ namespace MinecraftClient.Protocol.Handlers
private void Updater() private void Updater()
{ {
int keep_alive_interval = 100;
int keep_alive_timer = 100;
try try
{ {
do do
{ {
Thread.Sleep(100); Thread.Sleep(100);
keep_alive_timer--;
if (keep_alive_timer <= 0)
{
Send(getPaddingPacket());
keep_alive_timer = keep_alive_interval;
}
} }
while (Update()); while (Update());
} }
@ -431,7 +423,7 @@ namespace MinecraftClient.Protocol.Handlers
Send(encryption_response_tosend); Send(encryption_response_tosend);
//Start client-side encryption //Start client-side encryption
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this); s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
encrypted = true; encrypted = true;
//Read and skip the next packet //Read and skip the next packet
@ -444,24 +436,6 @@ namespace MinecraftClient.Protocol.Handlers
return encryption_success; return encryption_success;
} }
/// <summary>
/// Useless padding packet for solving Mono issue.
/// </summary>
/// <returns>The padding packet</returns>
public byte[] getPaddingPacket()
{
//Will generate a 15-bytes long padding packet
byte[] id = getVarInt(0x17); //Plugin Message
byte[] channel_name = Encoding.UTF8.GetBytes("MCC|Pad");
byte[] channel_name_len = getVarInt(channel_name.Length);
byte[] data = new byte[] { 0x00, 0x00, 0x00 };
byte[] data_len = BitConverter.GetBytes((short)data.Length); Array.Reverse(data_len);
byte[] packet_data = concatBytes(id, channel_name_len, channel_name, data_len, data);
byte[] packet_length = getVarInt(packet_data.Length);
return concatBytes(packet_length, packet_data);
}
/// <summary> /// <summary>
/// Send a chat message to the server /// Send a chat message to the server
/// </summary> /// </summary>

View file

@ -46,19 +46,11 @@ namespace MinecraftClient.Protocol.Handlers
private void Updater() private void Updater()
{ {
int keep_alive_interval = 100;
int keep_alive_timer = 100;
try try
{ {
do do
{ {
Thread.Sleep(100); Thread.Sleep(100);
keep_alive_timer--;
if (keep_alive_timer <= 0)
{
SendRAW(getPaddingPacket());
keep_alive_timer = keep_alive_interval;
}
} }
while (Update()); while (Update());
} }
@ -531,7 +523,7 @@ namespace MinecraftClient.Protocol.Handlers
SendPacket(0x01, concatBytes(key_len, key_enc, token_len, token_enc)); SendPacket(0x01, concatBytes(key_len, key_enc, token_len, token_enc));
//Start client-side encryption //Start client-side encryption
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this); s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
encrypted = true; encrypted = true;
//Process the next packet //Process the next packet
@ -555,25 +547,6 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
/// <summary>
/// Useless padding packet for solving Mono issue.
/// </summary>
/// <returns>The padding packet</returns>
public byte[] getPaddingPacket()
{
//Will generate a 15-bytes long padding packet
byte[] compression = compression_treshold >= 0 ? getVarInt(0) : new byte[] { };
byte[] id = getVarInt(0x17); //Plugin Message
byte[] channel_name = Encoding.UTF8.GetBytes("MCC|Pad");
byte[] channel_name_len = getVarInt(channel_name.Length);
byte[] data = compression_treshold >= 0 ? new byte[] { 0x00, 0x00, 0x00 } : new byte[] { 0x00, 0x00, 0x00, 0x00 };
byte[] data_len = getVarInt(data.Length);
byte[] packet_data = concatBytes(compression, id, channel_name_len, channel_name, data_len, data);
byte[] packet_length = getVarInt(packet_data.Length);
return concatBytes(packet_length, packet_data);
}
/// <summary> /// <summary>
/// Send a chat message to the server /// Send a chat message to the server
/// </summary> /// </summary>

View file

@ -13,7 +13,7 @@ namespace MinecraftClient.Protocol
/// The protocol handler will take care of parsing and building the appropriate network packets. /// The protocol handler will take care of parsing and building the appropriate network packets.
/// </summary> /// </summary>
public interface IMinecraftCom : IDisposable, IAutoComplete, IPaddingProvider public interface IMinecraftCom : IDisposable, IAutoComplete
{ {
/// <summary> /// <summary>
/// Start the login procedure once connected to the server /// Start the login procedure once connected to the server