mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Basic support for 1.19.2
This commit is contained in:
parent
af1485c753
commit
c34dd46067
14 changed files with 703 additions and 129 deletions
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
{
|
||||
|
|
@ -13,6 +14,8 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
private readonly RSA rsa;
|
||||
|
||||
private byte[]? precedingSignature = null;
|
||||
|
||||
public PrivateKey(string pemKey)
|
||||
{
|
||||
this.Key = KeyUtils.DecodePemKey(pemKey, "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----");
|
||||
|
|
@ -26,7 +29,15 @@ namespace MinecraftClient.Protocol.Keys
|
|||
return rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
|
||||
}
|
||||
|
||||
public byte[] SignMessage(string message, string uuid, DateTimeOffset timestamp, ref byte[] salt)
|
||||
/// <summary>
|
||||
/// Sign message - 1.19
|
||||
/// </summary>
|
||||
/// <param name="message">Message content</param>
|
||||
/// <param name="uuid">Sender uuid</param>
|
||||
/// <param name="timestamp">Timestamp</param>
|
||||
/// <param name="salt">Salt</param>
|
||||
/// <returns>Signature data</returns>
|
||||
public byte[] SignMessage(string message, Guid uuid, DateTimeOffset timestamp, ref byte[] salt)
|
||||
{
|
||||
string messageJson = "{\"text\":\"" + KeyUtils.EscapeString(message) + "\"}";
|
||||
|
||||
|
|
@ -35,5 +46,27 @@ namespace MinecraftClient.Protocol.Keys
|
|||
return SignData(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sign message - 1.19.1 and above
|
||||
/// </summary>
|
||||
/// <param name="message">Message content</param>
|
||||
/// <param name="uuid">Sender uuid</param>
|
||||
/// <param name="timestamp">Timestamp</param>
|
||||
/// <param name="salt">Salt</param>
|
||||
/// <param name="lastSeenMessages">LastSeenMessageList</param>
|
||||
/// <returns>Signature data</returns>
|
||||
public byte[] SignMessage(string message, Guid uuid, DateTimeOffset timestamp, ref byte[] salt, LastSeenMessageList lastSeenMessages)
|
||||
{
|
||||
byte[] bodySignData = KeyUtils.GetSignatureData(message, timestamp, ref salt, lastSeenMessages);
|
||||
byte[] bodyDigest = KeyUtils.ComputeHash(bodySignData);
|
||||
|
||||
byte[] msgSignData = KeyUtils.GetSignatureData(precedingSignature, uuid, bodyDigest);
|
||||
byte[] msgSign = SignData(msgSignData);
|
||||
|
||||
this.precedingSignature = msgSign;
|
||||
|
||||
return msgSign;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue