Added some error checking on encrypt/decrypt, will disconect user and not crash the server.
This commit is contained in:
@@ -22,9 +22,6 @@ namespace Framework.Cryptography
|
|||||||
{
|
{
|
||||||
public sealed class WorldCrypt : IDisposable
|
public sealed class WorldCrypt : IDisposable
|
||||||
{
|
{
|
||||||
static readonly byte[] ServerEncryptionKey = { 0x08, 0xF1, 0x95, 0x9F, 0x47, 0xE5, 0xD2, 0xDB, 0xA1, 0x3D, 0x77, 0x8F, 0x3F, 0x3E, 0xE7, 0x00 };
|
|
||||||
static readonly byte[] ServerDecryptionKey = { 0x40, 0xAA, 0xD3, 0x92, 0x26, 0x71, 0x43, 0x47, 0x3A, 0x31, 0x08, 0xA6, 0xE7, 0xDC, 0x98, 0x2A };
|
|
||||||
|
|
||||||
public void Initialize(byte[] key)
|
public void Initialize(byte[] key)
|
||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
@@ -37,6 +34,8 @@ namespace Framework.Cryptography
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool Encrypt(ref byte[] data, ref byte[] tag)
|
public bool Encrypt(ref byte[] data, ref byte[] tag)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
_serverEncrypt.Encrypt(BitConverter.GetBytes(_serverCounter).Combine(BitConverter.GetBytes(0x52565253)), data, data, tag);
|
_serverEncrypt.Encrypt(BitConverter.GetBytes(_serverCounter).Combine(BitConverter.GetBytes(0x52565253)), data, data, tag);
|
||||||
@@ -44,8 +43,15 @@ namespace Framework.Cryptography
|
|||||||
++_serverCounter;
|
++_serverCounter;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (CryptographicException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Decrypt(byte[] data, byte[] tag)
|
public bool Decrypt(byte[] data, byte[] tag)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
_clientDecrypt.Decrypt(BitConverter.GetBytes(_clientCounter).Combine(BitConverter.GetBytes(0x544E4C43)), data, tag, data);
|
_clientDecrypt.Decrypt(BitConverter.GetBytes(_clientCounter).Combine(BitConverter.GetBytes(0x544E4C43)), data, tag, data);
|
||||||
@@ -53,6 +59,11 @@ namespace Framework.Cryptography
|
|||||||
++_clientCounter;
|
++_clientCounter;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (CryptographicException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@@ -66,5 +77,4 @@ namespace Framework.Cryptography
|
|||||||
ulong _clientCounter;
|
ulong _clientCounter;
|
||||||
ulong _serverCounter;
|
ulong _serverCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user