mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
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:
parent
d9f1a77ac2
commit
a8bbb1ac76
55 changed files with 5218 additions and 1174 deletions
79
MinecraftClient/Protocol/ProfileKey/PlayerKeyPair.cs
Normal file
79
MinecraftClient/Protocol/ProfileKey/PlayerKeyPair.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
{
|
||||
public class PlayerKeyPair
|
||||
{
|
||||
public PublicKey PublicKey;
|
||||
|
||||
public PrivateKey PrivateKey;
|
||||
|
||||
public DateTime ExpiresAt;
|
||||
|
||||
public DateTime RefreshedAfter; // Todo: add a timer
|
||||
|
||||
private const string DataTimeFormat = "O";
|
||||
|
||||
public PlayerKeyPair(PublicKey keyPublic, PrivateKey keyPrivate, string expiresAt, string refreshedAfter)
|
||||
{
|
||||
PublicKey = keyPublic;
|
||||
PrivateKey = keyPrivate;
|
||||
ExpiresAt = DateTime.Parse(expiresAt).ToUniversalTime();
|
||||
RefreshedAfter = DateTime.Parse(refreshedAfter).ToUniversalTime();
|
||||
}
|
||||
|
||||
public bool NeedRefresh()
|
||||
{
|
||||
return DateTime.Now.ToUniversalTime() > this.RefreshedAfter;
|
||||
}
|
||||
|
||||
public bool IsExpired()
|
||||
{
|
||||
return DateTime.Now.ToUniversalTime() > this.ExpiresAt;
|
||||
}
|
||||
|
||||
public long GetExpirationMilliseconds()
|
||||
{
|
||||
DateTimeOffset timeOffset = new(ExpiresAt);
|
||||
return timeOffset.ToUnixTimeMilliseconds();
|
||||
}
|
||||
|
||||
public long GetExpirationSeconds()
|
||||
{
|
||||
DateTimeOffset timeOffset = new(ExpiresAt);
|
||||
return timeOffset.ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
public static PlayerKeyPair FromString(string tokenString)
|
||||
{
|
||||
string[] fields = tokenString.Split(',');
|
||||
|
||||
if (fields.Length < 6)
|
||||
throw new InvalidDataException("Invalid string format");
|
||||
|
||||
PublicKey publicKey = new PublicKey(pemKey: fields[0].Trim(),
|
||||
sig: fields[1].Trim(), sigV2: fields[2].Trim());
|
||||
|
||||
PrivateKey privateKey = new PrivateKey(pemKey: fields[3].Trim());
|
||||
|
||||
return new PlayerKeyPair(publicKey, privateKey, fields[4].Trim(), fields[5].Trim());
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
List<string> datas = new List<string>();
|
||||
datas.Add(Convert.ToBase64String(PublicKey.Key));
|
||||
datas.Add(Convert.ToBase64String(PublicKey.Signature));
|
||||
if (PublicKey.SignatureV2 == null)
|
||||
datas.Add(String.Empty);
|
||||
else
|
||||
datas.Add(Convert.ToBase64String(PublicKey.SignatureV2));
|
||||
datas.Add(Convert.ToBase64String(PrivateKey.Key));
|
||||
datas.Add(ExpiresAt.ToString(DataTimeFormat));
|
||||
datas.Add(RefreshedAfter.ToString(DataTimeFormat));
|
||||
return String.Join(",", datas.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue