Basic support for minecraft 1.19 (#2084)

* merge commit from milutinke
* chat signature & encrypted login
* Bug fix :EncryptionResponse format error below 1.18.2
* Implemented chat command signature
* Chat message parsing and verification for 1.19
* Add signature settings
* Update Simplified Chinese Translation
* Clear up comments
* Fix wrong variable naming
* Bug fix: SignatureV2 Processing
This commit is contained in:
BruceChen 2022-08-15 23:55:44 +08:00 committed by GitHub
parent d9f1a77ac2
commit a8bbb1ac76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 5218 additions and 1174 deletions

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MinecraftClient.Protocol.Keys;
namespace MinecraftClient.Protocol
{
public class PlayerInfo
{
public readonly Guid UUID;
public readonly string Name;
// Tuple<Name, Value, Signature(empty if there is no signature)
public readonly Tuple<string, string, string>[]? Property;
public int Gamemode;
public int Ping;
public string? DisplayName;
private readonly PublicKey? PublicKey;
private readonly DateTime? KeyExpiresAt;
public PlayerInfo(Guid uuid, string name, Tuple<string, string, string>[]? property, int gamemode, int ping, string? displayName, long? timeStamp, byte[]? publicKey, byte[]? signature)
{
UUID = uuid;
Name = name;
if (property != null)
Property = property;
Gamemode = gamemode;
Ping = ping;
DisplayName = displayName;
if (timeStamp != null && publicKey != null && signature != null)
{
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds((long)timeStamp);
KeyExpiresAt = dateTimeOffset.UtcDateTime;
try
{
PublicKey = new PublicKey(publicKey, signature);
}
catch (System.Security.Cryptography.CryptographicException)
{
PublicKey = null;
}
}
}
public PlayerInfo(string name, Guid uuid)
{
Name = name;
UUID = uuid;
Gamemode = -1;
Ping = 0;
}
public bool IsKeyVaild()
{
return PublicKey != null && DateTime.Now.ToUniversalTime() > this.KeyExpiresAt;
}
public bool VerifyMessage(string message, Guid uuid, long timestamp, long salt, ref byte[] signature)
{
if (PublicKey == null)
return false;
else
{
string uuidString = uuid.ToString().Replace("-", string.Empty);
DateTimeOffset timeOffset = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);
byte[] saltByte = BitConverter.GetBytes(salt);
Array.Reverse(saltByte);
return PublicKey.VerifyMessage(message, uuidString, timeOffset, ref saltByte, ref signature);
}
}
}
}