mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Remove padding mechanism
Not needed anymore since proper encryption is now used under Mono
This commit is contained in:
parent
67affc6270
commit
3224c59eab
8 changed files with 7 additions and 101 deletions
|
|
@ -197,14 +197,13 @@ namespace MinecraftClient.Crypto
|
|||
/// </summary>
|
||||
/// <param name="underlyingStream">Stream to encrypt</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>
|
||||
|
||||
public static IAesStream getAesStream(Stream underlyingStream, byte[] AesKey, IPaddingProvider paddingProvider)
|
||||
public static IAesStream getAesStream(Stream underlyingStream, byte[] AesKey)
|
||||
{
|
||||
if (Program.isUsingMono)
|
||||
{
|
||||
return new Streams.MonoAesStream(underlyingStream, AesKey, paddingProvider);
|
||||
return new Streams.MonoAesStream(underlyingStream, AesKey);
|
||||
}
|
||||
else return new Streams.RegularAesStream(underlyingStream, AesKey);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -19,15 +19,13 @@ namespace MinecraftClient.Crypto.Streams
|
|||
|
||||
public class MonoAesStream : Stream, IAesStream
|
||||
{
|
||||
IPaddingProvider pad;
|
||||
CipherStream cstream;
|
||||
public MonoAesStream(System.IO.Stream stream, byte[] key, IPaddingProvider provider)
|
||||
public MonoAesStream(System.IO.Stream stream, byte[] key)
|
||||
{
|
||||
BaseStream = stream;
|
||||
BufferedBlockCipher enc = GenerateAES(key, true);
|
||||
BufferedBlockCipher dec = GenerateAES(key, false);
|
||||
cstream = new CipherStream(stream, dec, enc);
|
||||
pad = provider;
|
||||
}
|
||||
public System.IO.Stream BaseStream { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@
|
|||
<Compile Include="Protocol\Handlers\ZlibUtils.cs" />
|
||||
<Compile Include="Protocol\Handlers\ChatParser.cs" />
|
||||
<Compile Include="Crypto\IAesStream.cs" />
|
||||
<Compile Include="Crypto\IPaddingProvider.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="McTcpClient.cs" />
|
||||
|
|
|
|||
|
|
@ -42,19 +42,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
private void Updater()
|
||||
{
|
||||
int keep_alive_interval = 100;
|
||||
int keep_alive_timer = 100;
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
keep_alive_timer--;
|
||||
if (keep_alive_timer <= 0)
|
||||
{
|
||||
Send(getPaddingPacket());
|
||||
keep_alive_timer = keep_alive_interval;
|
||||
}
|
||||
}
|
||||
while (Update());
|
||||
}
|
||||
|
|
@ -504,7 +496,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (pid[0] == 0xFC)
|
||||
{
|
||||
readData(4);
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this);
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
|
||||
encrypted = true;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -652,18 +644,6 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
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)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -45,19 +45,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
private void Updater()
|
||||
{
|
||||
int keep_alive_interval = 100;
|
||||
int keep_alive_timer = 100;
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
keep_alive_timer--;
|
||||
if (keep_alive_timer <= 0)
|
||||
{
|
||||
Send(getPaddingPacket());
|
||||
keep_alive_timer = keep_alive_interval;
|
||||
}
|
||||
}
|
||||
while (Update());
|
||||
}
|
||||
|
|
@ -431,7 +423,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
Send(encryption_response_tosend);
|
||||
|
||||
//Start client-side encryption
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this);
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
|
||||
encrypted = true;
|
||||
|
||||
//Read and skip the next packet
|
||||
|
|
@ -444,24 +436,6 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
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>
|
||||
/// Send a chat message to the server
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -46,19 +46,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
private void Updater()
|
||||
{
|
||||
int keep_alive_interval = 100;
|
||||
int keep_alive_timer = 100;
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
keep_alive_timer--;
|
||||
if (keep_alive_timer <= 0)
|
||||
{
|
||||
SendRAW(getPaddingPacket());
|
||||
keep_alive_timer = keep_alive_interval;
|
||||
}
|
||||
}
|
||||
while (Update());
|
||||
}
|
||||
|
|
@ -531,7 +523,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
SendPacket(0x01, concatBytes(key_len, key_enc, token_len, token_enc));
|
||||
|
||||
//Start client-side encryption
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey, this);
|
||||
s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
|
||||
encrypted = true;
|
||||
|
||||
//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>
|
||||
/// Send a chat message to the server
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace MinecraftClient.Protocol
|
|||
/// The protocol handler will take care of parsing and building the appropriate network packets.
|
||||
/// </summary>
|
||||
|
||||
public interface IMinecraftCom : IDisposable, IAutoComplete, IPaddingProvider
|
||||
public interface IMinecraftCom : IDisposable, IAutoComplete
|
||||
{
|
||||
/// <summary>
|
||||
/// Start the login procedure once connected to the server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue