mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Use PublicKey instead of byte representation
This commit is contained in:
@ -56,8 +56,6 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
/**
|
/**
|
||||||
* Encryption and decryption minecraft util for connection between servers
|
* Encryption and decryption minecraft util for connection between servers
|
||||||
* and paid Minecraft account clients.
|
* and paid Minecraft account clients.
|
||||||
*
|
|
||||||
* @see net.minecraft.server.MinecraftEncryption
|
|
||||||
*/
|
*/
|
||||||
class EncryptionUtil {
|
class EncryptionUtil {
|
||||||
|
|
||||||
@ -170,7 +168,7 @@ class EncryptionUtil {
|
|||||||
|
|
||||||
private static String toSignable(ClientPublicKey clientPublicKey) {
|
private static String toSignable(ClientPublicKey clientPublicKey) {
|
||||||
long expiry = clientPublicKey.getExpiry().toEpochMilli();
|
long expiry = clientPublicKey.getExpiry().toEpochMilli();
|
||||||
String encoded = KEY_ENCODER.encodeToString(clientPublicKey.getKey());
|
String encoded = KEY_ENCODER.encodeToString(clientPublicKey.getKey().getEncoded());
|
||||||
return expiry + "-----BEGIN RSA PUBLIC KEY-----\n" + encoded + "\n-----END RSA PUBLIC KEY-----\n";
|
return expiry + "-----BEGIN RSA PUBLIC KEY-----\n" + encoded + "\n-----END RSA PUBLIC KEY-----\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,8 +193,7 @@ class EncryptionUtil {
|
|||||||
return cipher.doFinal(data);
|
return cipher.doFinal(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getServerIdHash(
|
private static byte[] getServerIdHash(String sessionId, PublicKey publicKey, SecretKey sharedSecret)
|
||||||
String sessionId, PublicKey publicKey, SecretKey sharedSecret)
|
|
||||||
throws NoSuchAlgorithmException {
|
throws NoSuchAlgorithmException {
|
||||||
// byte[] a(String var0, PublicKey var1, SecretKey var2)
|
// byte[] a(String var0, PublicKey var1, SecretKey var2)
|
||||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||||
|
@ -179,7 +179,7 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
Instant expires = profileKey.getExpireTime();
|
Instant expires = profileKey.getExpireTime();
|
||||||
PublicKey key = profileKey.getKey();
|
PublicKey key = profileKey.getKey();
|
||||||
byte[] signature = profileKey.getSignature();
|
byte[] signature = profileKey.getSignature();
|
||||||
ClientPublicKey clientKey = new ClientPublicKey(expires, key.getEncoded(), signature);
|
ClientPublicKey clientKey = new ClientPublicKey(expires, key, signature);
|
||||||
try {
|
try {
|
||||||
return EncryptionUtil.verifyClientKey(clientKey, Instant.now());
|
return EncryptionUtil.verifyClientKey(clientKey, Instant.now());
|
||||||
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException ex) {
|
} catch (SignatureException | InvalidKeyException | NoSuchAlgorithmException ex) {
|
||||||
|
@ -25,15 +25,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.games647.fastlogin.bukkit.listener.protocollib.packet;
|
package com.github.games647.fastlogin.bukkit.listener.protocollib.packet;
|
||||||
|
|
||||||
|
import java.security.PublicKey;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
public class ClientPublicKey {
|
public class ClientPublicKey {
|
||||||
|
|
||||||
private final Instant expiry;
|
private final Instant expiry;
|
||||||
private final byte[] key;
|
private final PublicKey key;
|
||||||
private final byte[] signature;
|
private final byte[] signature;
|
||||||
|
|
||||||
public ClientPublicKey(Instant expiry, byte[] key, byte[] signature) {
|
public ClientPublicKey(Instant expiry, PublicKey key, byte[] signature) {
|
||||||
this.expiry = expiry;
|
this.expiry = expiry;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
@ -43,7 +44,7 @@ public class ClientPublicKey {
|
|||||||
return expiry;
|
return expiry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getKey() {
|
public PublicKey getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public class EncryptionUtilTest {
|
|||||||
RSAPublicKey publicKey = parsePublicKey(key);
|
RSAPublicKey publicKey = parsePublicKey(key);
|
||||||
|
|
||||||
byte[] signature = Base64.getDecoder().decode(object.getAsJsonPrimitive("signature").getAsString());
|
byte[] signature = Base64.getDecoder().decode(object.getAsJsonPrimitive("signature").getAsString());
|
||||||
return new ClientPublicKey(expires, publicKey.getEncoded(), signature);
|
return new ClientPublicKey(expires, publicKey, signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RSAPublicKey parsePublicKey(String lines)
|
private RSAPublicKey parsePublicKey(String lines)
|
||||||
@ -126,7 +126,6 @@ public class EncryptionUtilTest {
|
|||||||
Reader reader = new StringReader(lines);
|
Reader reader = new StringReader(lines);
|
||||||
PemReader pemReader = new PemReader(reader)
|
PemReader pemReader = new PemReader(reader)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
PemObject pemObject = pemReader.readPemObject();
|
PemObject pemObject = pemReader.readPemObject();
|
||||||
byte[] content = pemObject.getContent();
|
byte[] content = pemObject.getContent();
|
||||||
var pubKeySpec = new X509EncodedKeySpec(content);
|
var pubKeySpec = new X509EncodedKeySpec(content);
|
||||||
|
Reference in New Issue
Block a user