mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Changes for fixing Mono issues
- Detect missing HTTPS certificates - Give the mozroots command for importing certificates - Use a specific workaround AesStream class made for Mono - It only process 128bits blocks because Mono is not CFB-8 ready
This commit is contained in:
parent
58d7b0734f
commit
26a2fdd517
3 changed files with 186 additions and 9 deletions
|
|
@ -192,10 +192,22 @@ namespace MinecraftClient
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
||||
/// Interface for AES stream
|
||||
/// Allows to use any object which has a Read() and Write() method.
|
||||
/// </summary>
|
||||
|
||||
public class AesStream : System.IO.Stream
|
||||
public interface IAesStream
|
||||
{
|
||||
int Read(byte[] buffer, int offset, int count);
|
||||
void Write(byte[] buffer, int offset, int count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
||||
/// This is the regular AesStream class used with the regular .NET framework from Microsoft.
|
||||
/// </summary>
|
||||
|
||||
public class AesStream : System.IO.Stream, IAesStream
|
||||
{
|
||||
CryptoStream enc;
|
||||
CryptoStream dec;
|
||||
|
|
@ -286,5 +298,140 @@ namespace MinecraftClient
|
|||
return cipher;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
||||
/// This is a mono-compatible adaptation which only sends and receive 16 bytes at a time, and manually transforms blocks.
|
||||
/// Data is cached before reaching the 128bits block size necessary for mono which is not CFB-8 compatible.
|
||||
/// </summary>
|
||||
|
||||
public class MonoAesStream : System.IO.Stream, IAesStream
|
||||
{
|
||||
ICryptoTransform enc;
|
||||
ICryptoTransform dec;
|
||||
List<byte> dec_cache = new List<byte>();
|
||||
List<byte> tosend_cache = new List<byte>();
|
||||
public MonoAesStream(System.IO.Stream stream, byte[] key)
|
||||
{
|
||||
BaseStream = stream;
|
||||
RijndaelManaged aes = GenerateAES(key);
|
||||
enc = aes.CreateEncryptor();
|
||||
dec = aes.CreateDecryptor();
|
||||
}
|
||||
public System.IO.Stream BaseStream { get; set; }
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
BaseStream.Flush();
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
byte[] temp = new byte[1];
|
||||
Read(temp, 0, 1);
|
||||
return temp[0];
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
while (dec_cache.Count < count)
|
||||
{
|
||||
byte[] temp_in = new byte[16];
|
||||
byte[] temp_out = new byte[16];
|
||||
int read = 0;
|
||||
while (read < 16)
|
||||
read += BaseStream.Read(temp_in, read, 16 - read);
|
||||
dec.TransformBlock(temp_in, 0, 16, temp_out, 0);
|
||||
foreach (byte b in temp_out)
|
||||
dec_cache.Add(b);
|
||||
}
|
||||
|
||||
for (int i = offset; i - offset < count; i++)
|
||||
{
|
||||
buffer[i] = dec_cache[0];
|
||||
dec_cache.RemoveAt(0);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b)
|
||||
{
|
||||
Write(new byte[] { b }, 0, 1);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
for (int i = offset; i - offset < count; i++)
|
||||
tosend_cache.Add(buffer[i]);
|
||||
|
||||
while (tosend_cache.Count > 16)
|
||||
{
|
||||
byte[] temp_in = new byte[16];
|
||||
byte[] temp_out = new byte[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
temp_in[i] = tosend_cache[0];
|
||||
tosend_cache.RemoveAt(0);
|
||||
}
|
||||
enc.TransformBlock(temp_in, 0, 16, temp_out, 0);
|
||||
BaseStream.Write(temp_out, 0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
private RijndaelManaged GenerateAES(byte[] key)
|
||||
{
|
||||
RijndaelManaged cipher = new RijndaelManaged();
|
||||
cipher.Mode = CipherMode.CFB;
|
||||
cipher.Padding = PaddingMode.None;
|
||||
cipher.KeySize = 128;
|
||||
cipher.FeedbackSize = 8;
|
||||
cipher.Key = key;
|
||||
cipher.IV = key;
|
||||
return cipher;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue