Updated to .Net Core 3.1
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<Import Project="..\..\default.props" />
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<StartupObject>BNetServer.Server</StartupObject>
|
||||
<ApplicationIcon>Red.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
@@ -19,5 +19,4 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Security.Cryptography;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
@@ -31,46 +30,25 @@ namespace Framework.Cryptography
|
||||
if (IsInitialized)
|
||||
throw new InvalidOperationException("PacketCrypt already initialized!");
|
||||
|
||||
_clientDecrypt = new AuthenticatedAesCng();
|
||||
_clientDecrypt.Key = key;
|
||||
_clientDecrypt.CngMode = CngChainingMode.Gcm;
|
||||
_clientDecrypt.TagSize = 96;
|
||||
|
||||
_serverEncrypt = new AuthenticatedAesCng();
|
||||
_serverEncrypt.Key = key;
|
||||
_serverEncrypt.CngMode = CngChainingMode.Gcm;
|
||||
_serverEncrypt.TagSize = 96;
|
||||
_serverEncrypt = new AesGcm(key);
|
||||
_clientDecrypt = new AesGcm(key);
|
||||
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
public bool Encrypt(ref byte[] data, int length, ref byte[] tag)
|
||||
public bool Encrypt(ref byte[] data, ref byte[] tag)
|
||||
{
|
||||
if (IsInitialized)
|
||||
{
|
||||
_serverEncrypt.IV = BitConverter.GetBytes(_serverCounter).Combine(BitConverter.GetBytes(0x52565253));
|
||||
|
||||
using (IAuthenticatedCryptoTransform encryptor = _serverEncrypt.CreateAuthenticatedEncryptor())
|
||||
{
|
||||
data = encryptor.TransformFinalBlock(data, 0, length);
|
||||
tag = encryptor.GetTag();
|
||||
}
|
||||
}
|
||||
_serverEncrypt.Encrypt(BitConverter.GetBytes(_serverCounter).Combine(BitConverter.GetBytes(0x52565253)), data, data, tag);
|
||||
|
||||
++_serverCounter;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Decrypt(ref byte[] data, int length, byte[] tag)
|
||||
public bool Decrypt(ref byte[] data, byte[] tag)
|
||||
{
|
||||
if (IsInitialized)
|
||||
{
|
||||
_clientDecrypt.IV = BitConverter.GetBytes(_clientCounter).Combine(BitConverter.GetBytes(0x544E4C43));
|
||||
_clientDecrypt.Tag = tag;
|
||||
|
||||
using (ICryptoTransform decryptor = _clientDecrypt.CreateDecryptor())
|
||||
data = decryptor.TransformFinalBlock(data, 0, length);
|
||||
}
|
||||
_clientDecrypt.Decrypt(BitConverter.GetBytes(_clientCounter).Combine(BitConverter.GetBytes(0x544E4C43)), data, tag, data);
|
||||
|
||||
++_clientCounter;
|
||||
return true;
|
||||
@@ -83,8 +61,8 @@ namespace Framework.Cryptography
|
||||
|
||||
public bool IsInitialized { get; set; }
|
||||
|
||||
AuthenticatedAesCng _clientDecrypt;
|
||||
AuthenticatedAesCng _serverEncrypt;
|
||||
AesGcm _serverEncrypt;
|
||||
AesGcm _clientDecrypt;
|
||||
ulong _clientCounter;
|
||||
ulong _serverCounter;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
@@ -11,11 +11,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||
<PackageReference Include="MySqlConnector" Version="0.56.0" />
|
||||
<PackageReference Include="Security.Cryptography" Version="1.7.2" />
|
||||
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="MySqlConnector" Version="0.62.0-beta4" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Game.Network
|
||||
var data = new byte[header.Size];
|
||||
Buffer.BlockCopy(GetReceiveBuffer(), 16, data, 0, header.Size);
|
||||
|
||||
if (!_worldCrypt.Decrypt(ref data, header.Size, header.Tag))
|
||||
if (!_worldCrypt.Decrypt(ref data, header.Tag))
|
||||
{
|
||||
Log.outError(LogFilter.Network, $"WorldSocket.ReadHandler(): client {GetRemoteIpAddress().ToString()} failed to decrypt packet (size: {header.Size})");
|
||||
return;
|
||||
@@ -315,7 +315,7 @@ namespace Game.Network
|
||||
|
||||
PacketHeader header = new PacketHeader();
|
||||
header.Size = packetSize;
|
||||
_worldCrypt.Encrypt(ref data, header.Size, ref header.Tag);
|
||||
_worldCrypt.Encrypt(ref data, ref header.Tag);
|
||||
|
||||
ByteBuffer byteBuffer = new ByteBuffer();
|
||||
header.Write(byteBuffer);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Import Project="..\..\default.props" />
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<ApplicationIcon>Blue.ico</ApplicationIcon>
|
||||
<StartupObject>WorldServer.Server</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user