Updated to .Net Core 3.1

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