mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix all warnings & Trim (#2226)
* Fix AutoFishing crash * Fix all warnings * Remove DotNetZip. * Fix the usage of HttpClient.
This commit is contained in:
parent
4aa6c1c99f
commit
1d52d1eadd
227 changed files with 2201 additions and 43564 deletions
|
|
@ -1,10 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MinecraftClient.Protocol.Handlers;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ namespace MinecraftClient.Protocol.Keys
|
|||
{
|
||||
private const string KeysCacheFilePlaintext = "ProfileKeyCache.ini";
|
||||
|
||||
private static FileMonitor cachemonitor;
|
||||
private static Dictionary<string, PlayerKeyPair> keys = new Dictionary<string, PlayerKeyPair>();
|
||||
private static Timer updatetimer = new Timer(100);
|
||||
private static List<KeyValuePair<string, PlayerKeyPair>> pendingadds = new List<KeyValuePair<string, PlayerKeyPair>>();
|
||||
private static BinaryFormatter formatter = new BinaryFormatter();
|
||||
private static FileMonitor? cachemonitor;
|
||||
private static readonly Dictionary<string, PlayerKeyPair> keys = new();
|
||||
private static readonly Timer updatetimer = new(100);
|
||||
private static readonly List<KeyValuePair<string, PlayerKeyPair>> pendingadds = new();
|
||||
private static readonly BinaryFormatter formatter = new();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve whether KeysCache contains a keys for the given login.
|
||||
|
|
@ -93,7 +93,7 @@ namespace MinecraftClient.Protocol.Keys
|
|||
/// </summary>
|
||||
/// <param name="sender">Sender</param>
|
||||
/// <param name="e">Event data</param>
|
||||
private static void HandlePending(object sender, ElapsedEventArgs e)
|
||||
private static void HandlePending(object? sender, ElapsedEventArgs e)
|
||||
{
|
||||
updatetimer.Stop();
|
||||
LoadFromDisk();
|
||||
|
|
@ -177,9 +177,11 @@ namespace MinecraftClient.Protocol.Keys
|
|||
if (Settings.DebugMessages)
|
||||
Translations.WriteLineFormatted("cache.saving_keys");
|
||||
|
||||
List<string> KeysCacheLines = new List<string>();
|
||||
KeysCacheLines.Add("# Generated by MCC v" + Program.Version + " - Keep it secret & Edit at own risk!");
|
||||
KeysCacheLines.Add("# ProfileKey=PublicKey(base64),PublicKeySignature(base64),PublicKeySignatureV2(base64),PrivateKey(base64),ExpiresAt,RefreshAfter");
|
||||
List<string> KeysCacheLines = new()
|
||||
{
|
||||
"# Generated by MCC v" + Program.Version + " - Keep it secret & Edit at own risk!",
|
||||
"# ProfileKey=PublicKey(base64),PublicKeySignature(base64),PublicKeySignatureV2(base64),PrivateKey(base64),ExpiresAt,RefreshAfter"
|
||||
};
|
||||
foreach (KeyValuePair<string, PlayerKeyPair> entry in keys)
|
||||
KeysCacheLines.Add(entry.Key + '=' + entry.Value.ToString());
|
||||
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
public bool NeedRefresh()
|
||||
{
|
||||
return DateTime.Now.ToUniversalTime() > this.RefreshedAfter;
|
||||
return DateTime.Now.ToUniversalTime() > RefreshedAfter;
|
||||
}
|
||||
|
||||
public bool IsExpired()
|
||||
{
|
||||
return DateTime.Now.ToUniversalTime() > this.ExpiresAt;
|
||||
return DateTime.Now.ToUniversalTime() > ExpiresAt;
|
||||
}
|
||||
|
||||
public long GetExpirationMilliseconds()
|
||||
|
|
@ -61,17 +61,17 @@ namespace MinecraftClient.Protocol.Keys
|
|||
if (fields.Length < 6)
|
||||
throw new InvalidDataException("Invalid string format");
|
||||
|
||||
PublicKey publicKey = new PublicKey(pemKey: fields[0].Trim(),
|
||||
PublicKey publicKey = new(pemKey: fields[0].Trim(),
|
||||
sig: fields[1].Trim(), sigV2: fields[2].Trim());
|
||||
|
||||
PrivateKey privateKey = new PrivateKey(pemKey: fields[3].Trim());
|
||||
PrivateKey privateKey = new(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>();
|
||||
List<string> datas = new();
|
||||
datas.Add(Convert.ToBase64String(PublicKey.Key));
|
||||
if (PublicKey.Signature == null)
|
||||
datas.Add(String.Empty);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
|
|
@ -18,10 +14,10 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
public PrivateKey(string pemKey)
|
||||
{
|
||||
this.Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----");
|
||||
Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----");
|
||||
|
||||
this.rsa = RSA.Create();
|
||||
rsa.ImportPkcs8PrivateKey(this.Key, out _);
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportPkcs8PrivateKey(Key, out _);
|
||||
}
|
||||
|
||||
public byte[] SignData(byte[] data)
|
||||
|
|
@ -62,8 +58,8 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
byte[] msgSignData = KeyUtils.GetSignatureData(precedingSignature, uuid, bodyDigest);
|
||||
byte[] msgSign = SignData(msgSignData);
|
||||
|
||||
this.precedingSignature = msgSign;
|
||||
|
||||
precedingSignature = msgSign;
|
||||
|
||||
return msgSign;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
|
|
@ -18,26 +14,26 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
public PublicKey(string pemKey, string? sig = null, string? sigV2 = null)
|
||||
{
|
||||
this.Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----");
|
||||
Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----");
|
||||
|
||||
this.rsa = RSA.Create();
|
||||
rsa.ImportSubjectPublicKeyInfo(this.Key, out _);
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportSubjectPublicKeyInfo(Key, out _);
|
||||
|
||||
if (!string.IsNullOrEmpty(sig))
|
||||
this.Signature = Convert.FromBase64String(sig);
|
||||
Signature = Convert.FromBase64String(sig);
|
||||
|
||||
if (!string.IsNullOrEmpty(sigV2))
|
||||
this.SignatureV2 = Convert.FromBase64String(sigV2!);
|
||||
SignatureV2 = Convert.FromBase64String(sigV2!);
|
||||
}
|
||||
|
||||
public PublicKey(byte[] key, byte[] signature)
|
||||
{
|
||||
this.Key = key;
|
||||
Key = key;
|
||||
|
||||
this.rsa = RSA.Create();
|
||||
rsa.ImportSubjectPublicKeyInfo(this.Key, out _);
|
||||
rsa = RSA.Create();
|
||||
rsa.ImportSubjectPublicKeyInfo(Key, out _);
|
||||
|
||||
this.Signature = signature;
|
||||
Signature = signature;
|
||||
}
|
||||
|
||||
public bool VerifyData(byte[] data, byte[] signature)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue