mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Drop lombok tool
This commit is contained in:
@ -31,7 +31,6 @@ import com.google.common.hash.Hasher;
|
|||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
import com.google.common.primitives.Longs;
|
import com.google.common.primitives.Longs;
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
@ -41,6 +40,7 @@ import javax.crypto.SecretKey;
|
|||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
@ -53,6 +53,7 @@ import java.security.PublicKey;
|
|||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
import java.security.spec.KeySpec;
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -198,9 +199,9 @@ final class EncryptionUtil {
|
|||||||
|
|
||||||
private static PublicKey loadMojangSessionKey()
|
private static PublicKey loadMojangSessionKey()
|
||||||
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
val keyUrl = FastLoginBukkit.class.getClassLoader().getResource("yggdrasil_session_pubkey.der");
|
URL keyUrl = FastLoginBukkit.class.getClassLoader().getResource("yggdrasil_session_pubkey.der");
|
||||||
val keyData = Resources.toByteArray(keyUrl);
|
byte[] keyData = Resources.toByteArray(keyUrl);
|
||||||
val keySpec = new X509EncodedKeySpec(keyData);
|
KeySpec keySpec = new X509EncodedKeySpec(keyData);
|
||||||
|
|
||||||
return KeyFactory.getInstance("RSA").generatePublic(keySpec);
|
return KeyFactory.getInstance("RSA").generatePublic(keySpec);
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import com.comphenix.protocol.utility.MinecraftVersion;
|
|||||||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||||
import com.comphenix.protocol.wrappers.Converters;
|
import com.comphenix.protocol.wrappers.Converters;
|
||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
|
||||||
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
||||||
@ -48,7 +49,6 @@ import com.mojang.datafixers.util.Either;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
import lombok.val;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
import org.geysermc.floodgate.api.player.FloodgatePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -245,8 +245,9 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
// public key is sent separate
|
// public key is sent separate
|
||||||
clientKey = Optional.empty();
|
clientKey = Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
val profileKey = packet.getOptionals(BukkitConverters.getWrappedPublicKeyDataConverter())
|
Optional<Optional<WrappedProfileKeyData>> profileKey = packet.getOptionals(
|
||||||
.optionRead(0);
|
BukkitConverters.getWrappedPublicKeyDataConverter()
|
||||||
|
).optionRead(0);
|
||||||
|
|
||||||
clientKey = profileKey.flatMap(Function.identity()).flatMap(data -> {
|
clientKey = profileKey.flatMap(Function.identity()).flatMap(data -> {
|
||||||
Instant expires = data.getExpireTime();
|
Instant expires = data.getExpireTime();
|
||||||
|
@ -50,7 +50,6 @@ import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
|||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
import com.github.games647.fastlogin.bukkit.InetUtils;
|
import com.github.games647.fastlogin.bukkit.InetUtils;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
||||||
import lombok.val;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
@ -307,7 +306,7 @@ public class VerifyResponseTask implements Runnable {
|
|||||||
startPacket.getStrings().write(0, username);
|
startPacket.getStrings().write(0, username);
|
||||||
|
|
||||||
EquivalentConverter<WrappedProfileKeyData> converter = BukkitConverters.getWrappedPublicKeyDataConverter();
|
EquivalentConverter<WrappedProfileKeyData> converter = BukkitConverters.getWrappedPublicKeyDataConverter();
|
||||||
val wrappedKey = Optional.ofNullable(clientKey).map(key ->
|
Optional<WrappedProfileKeyData> wrappedKey = Optional.ofNullable(clientKey).map(key ->
|
||||||
new WrappedProfileKeyData(clientKey.expiry(), clientKey.key(), clientKey.signature())
|
new WrappedProfileKeyData(clientKey.expiry(), clientKey.key(), clientKey.signature())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -25,20 +25,38 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.games647.fastlogin.bukkit.listener.protocollib.packet;
|
package com.github.games647.fastlogin.bukkit.listener.protocollib.packet;
|
||||||
|
|
||||||
import lombok.Value;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
@Accessors(fluent = true)
|
|
||||||
@Value(staticConstructor = "of")
|
|
||||||
public class ClientPublicKey {
|
public class ClientPublicKey {
|
||||||
Instant expiry;
|
|
||||||
PublicKey key;
|
private final Instant expiry;
|
||||||
byte[] signature;
|
private final PublicKey key;
|
||||||
|
private final byte[] signature;
|
||||||
|
|
||||||
|
public Instant expiry() {
|
||||||
|
return expiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublicKey key() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] signature() {
|
||||||
|
return signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientPublicKey(Instant expiry, PublicKey key, byte[] signature) {
|
||||||
|
this.expiry = expiry;
|
||||||
|
this.key = key;
|
||||||
|
this.signature = signature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClientPublicKey of(Instant expiry, PublicKey key, byte[] signature) {
|
||||||
|
return new ClientPublicKey(expiry, key, signature);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isExpired(Instant verifyTimestamp) {
|
public boolean isExpired(Instant verifyTimestamp) {
|
||||||
return !verifyTimestamp.isBefore(expiry);
|
return !verifyTimestamp.isBefore(expiry);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
package com.github.games647.fastlogin.bukkit;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.CommonUtil;
|
import com.github.games647.fastlogin.core.CommonUtil;
|
||||||
import lombok.val;
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -37,13 +37,13 @@ class FastLoginBukkitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRGB() {
|
void testRGB() {
|
||||||
val message = "&x00002a00002b&lText";
|
String message = "&x00002a00002b&lText";
|
||||||
val msg = CommonUtil.translateColorCodes(message);
|
String msg = CommonUtil.translateColorCodes(message);
|
||||||
assertEquals(msg, "§x00002a00002b§lText");
|
assertEquals(msg, "§x00002a00002b§lText");
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
val components = TextComponent.fromLegacyText(msg);
|
BaseComponent[] components = TextComponent.fromLegacyText(msg);
|
||||||
val expected = "{\"bold\":true,\"color\":\"#00a00b\",\"text\":\"Text\"}";
|
String expected = "{\"bold\":true,\"color\":\"#00a00b\",\"text\":\"Text\"}";
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
assertEquals(ComponentSerializer.toString(components), expected);
|
assertEquals(ComponentSerializer.toString(components), expected);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib;
|
|||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -37,7 +36,7 @@ public class Base64Adapter extends TypeAdapter<byte[]> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, byte[] value) throws IOException {
|
public void write(JsonWriter out, byte[] value) throws IOException {
|
||||||
val encoded = Base64.getEncoder().encodeToString(value);
|
String encoded = Base64.getEncoder().encodeToString(value);
|
||||||
out.value(encoded);
|
out.value(encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib;
|
|||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.SignatureTestData.SignatureData;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.SignatureTestData.SignatureData;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.packet.ClientPublicKey;
|
||||||
|
import com.google.common.hash.Hasher;
|
||||||
import com.google.common.hash.Hashing;
|
import com.google.common.hash.Hashing;
|
||||||
import lombok.val;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
@ -51,6 +51,7 @@ import java.security.SignatureException;
|
|||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testVerifyToken() {
|
void testVerifyToken() {
|
||||||
val random = ThreadLocalRandom.current();
|
Random random = ThreadLocalRandom.current();
|
||||||
byte[] token = EncryptionUtil.generateVerifyToken(random);
|
byte[] token = EncryptionUtil.generateVerifyToken(random);
|
||||||
|
|
||||||
assertAll(
|
assertAll(
|
||||||
@ -88,10 +89,10 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExpiredClientKey() throws Exception {
|
void testExpiredClientKey() throws Exception {
|
||||||
val clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key.json");
|
ClientPublicKey clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key.json");
|
||||||
|
|
||||||
// Client expires at the exact second mentioned, so use it for verification
|
// Client expires at the exact second mentioned, so use it for verification
|
||||||
val expiredTimestamp = clientKey.expiry();
|
Instant expiredTimestamp = clientKey.expiry();
|
||||||
assertFalse(EncryptionUtil.verifyClientKey(clientKey, expiredTimestamp, null));
|
assertFalse(EncryptionUtil.verifyClientKey(clientKey, expiredTimestamp, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ class EncryptionUtilTest {
|
|||||||
"client_keys/invalid_wrong_signature.json"
|
"client_keys/invalid_wrong_signature.json"
|
||||||
})
|
})
|
||||||
void testInvalidClientKey(String clientKeySource) throws Exception {
|
void testInvalidClientKey(String clientKeySource) throws Exception {
|
||||||
val clientKey = ResourceLoader.loadClientKey(clientKeySource);
|
ClientPublicKey clientKey = ResourceLoader.loadClientKey(clientKeySource);
|
||||||
Instant expireTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
Instant expireTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
||||||
|
|
||||||
assertFalse(EncryptionUtil.verifyClientKey(clientKey, expireTimestamp, null));
|
assertFalse(EncryptionUtil.verifyClientKey(clientKey, expireTimestamp, null));
|
||||||
@ -113,34 +114,34 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValidClientKey() throws Exception {
|
void testValidClientKey() throws Exception {
|
||||||
val clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key.json");
|
ClientPublicKey clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key.json");
|
||||||
val verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
Instant verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
||||||
|
|
||||||
assertTrue(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, null));
|
assertTrue(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValid191ClientKey() throws Exception {
|
void testValid191ClientKey() throws Exception {
|
||||||
val clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key_19_1.json");
|
ClientPublicKey clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key_19_1.json");
|
||||||
val verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
Instant verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
||||||
|
|
||||||
val ownerPremiumId = UUID.fromString("0aaa2c13-922a-411b-b655-9b8c08404695");
|
UUID ownerPremiumId = UUID.fromString("0aaa2c13-922a-411b-b655-9b8c08404695");
|
||||||
assertTrue(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, ownerPremiumId));
|
assertTrue(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, ownerPremiumId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIncorrect191ClientOwner() throws Exception {
|
void testIncorrect191ClientOwner() throws Exception {
|
||||||
val clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key_19_1.json");
|
ClientPublicKey clientKey = ResourceLoader.loadClientKey("client_keys/valid_public_key_19_1.json");
|
||||||
val verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
Instant verificationTimestamp = clientKey.expiry().minus(5, ChronoUnit.HOURS);
|
||||||
|
|
||||||
val ownerPremiumId = UUID.fromString("61699b2e-d327-4a01-9f1e-0ea8c3f06bc6");
|
UUID ownerPremiumId = UUID.fromString("61699b2e-d327-4a01-9f1e-0ea8c3f06bc6");
|
||||||
assertFalse(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, ownerPremiumId));
|
assertFalse(EncryptionUtil.verifyClientKey(clientKey, verificationTimestamp, ownerPremiumId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDecryptSharedSecret() throws Exception {
|
void testDecryptSharedSecret() throws Exception {
|
||||||
KeyPair serverPair = EncryptionUtil.generateKeyPair();
|
KeyPair serverPair = EncryptionUtil.generateKeyPair();
|
||||||
val serverPK = serverPair.getPublic();
|
PublicKey serverPK = serverPair.getPublic();
|
||||||
|
|
||||||
SecretKey secretKey = generateSharedKey();
|
SecretKey secretKey = generateSharedKey();
|
||||||
byte[] encryptedSecret = encrypt(serverPK, secretKey.getEncoded());
|
byte[] encryptedSecret = encrypt(serverPK, secretKey.getEncoded());
|
||||||
@ -152,7 +153,7 @@ class EncryptionUtilTest {
|
|||||||
private static byte[] encrypt(PublicKey receiverKey, byte... message)
|
private static byte[] encrypt(PublicKey receiverKey, byte... message)
|
||||||
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
|
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
|
||||||
IllegalBlockSizeException, BadPaddingException {
|
IllegalBlockSizeException, BadPaddingException {
|
||||||
val encryptCipher = Cipher.getInstance(receiverKey.getAlgorithm());
|
Cipher encryptCipher = Cipher.getInstance(receiverKey.getAlgorithm());
|
||||||
encryptCipher.init(Cipher.ENCRYPT_MODE, receiverKey);
|
encryptCipher.init(Cipher.ENCRYPT_MODE, receiverKey);
|
||||||
return encryptCipher.doFinal(message);
|
return encryptCipher.doFinal(message);
|
||||||
}
|
}
|
||||||
@ -168,9 +169,9 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testServerIdHash() throws Exception {
|
void testServerIdHash() throws Exception {
|
||||||
val serverId = "";
|
String serverId = "";
|
||||||
val sharedSecret = generateSharedKey();
|
SecretKeySpec sharedSecret = generateSharedKey();
|
||||||
val serverPK = ResourceLoader.loadClientKey("client_keys/valid_public_key.json").key();
|
PublicKey serverPK = ResourceLoader.loadClientKey("client_keys/valid_public_key.json").key();
|
||||||
|
|
||||||
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
||||||
assertEquals(EncryptionUtil.getServerIdHashString(serverId, sharedSecret, serverPK), sessionHash);
|
assertEquals(EncryptionUtil.getServerIdHashString(serverId, sharedSecret, serverPK), sessionHash);
|
||||||
@ -185,7 +186,7 @@ class EncryptionUtilTest {
|
|||||||
// sha1.update(server's encoded public key from Encryption Request)
|
// sha1.update(server's encoded public key from Encryption Request)
|
||||||
// hash := sha1.hexdigest() # String of hex characters
|
// hash := sha1.hexdigest() # String of hex characters
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
val hasher = Hashing.sha1().newHasher();
|
Hasher hasher = Hashing.sha1().newHasher();
|
||||||
hasher.putString(serverId, StandardCharsets.US_ASCII);
|
hasher.putString(serverId, StandardCharsets.US_ASCII);
|
||||||
hasher.putBytes(sharedSecret.getEncoded());
|
hasher.putBytes(sharedSecret.getEncoded());
|
||||||
hasher.putBytes(serverPK.getEncoded());
|
hasher.putBytes(serverPK.getEncoded());
|
||||||
@ -198,9 +199,9 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testServerIdHashWrongSecret() throws Exception {
|
void testServerIdHashWrongSecret() throws Exception {
|
||||||
val serverId = "";
|
String serverId = "";
|
||||||
val sharedSecret = generateSharedKey();
|
SecretKeySpec sharedSecret = generateSharedKey();
|
||||||
val serverPK = ResourceLoader.loadClientKey("client_keys/valid_public_key.json").key();
|
PublicKey serverPK = ResourceLoader.loadClientKey("client_keys/valid_public_key.json").key();
|
||||||
|
|
||||||
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
||||||
assertNotEquals(EncryptionUtil.getServerIdHashString("", generateSharedKey(), serverPK), sessionHash);
|
assertNotEquals(EncryptionUtil.getServerIdHashString("", generateSharedKey(), serverPK), sessionHash);
|
||||||
@ -208,12 +209,12 @@ class EncryptionUtilTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testServerIdHashWrongServerKey() {
|
void testServerIdHashWrongServerKey() {
|
||||||
val serverId = "";
|
String serverId = "";
|
||||||
val sharedSecret = generateSharedKey();
|
SecretKeySpec sharedSecret = generateSharedKey();
|
||||||
val serverPK = EncryptionUtil.generateKeyPair().getPublic();
|
PublicKey serverPK = EncryptionUtil.generateKeyPair().getPublic();
|
||||||
|
|
||||||
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
String sessionHash = getServerHash(serverId, sharedSecret, serverPK);
|
||||||
val wrongPK = EncryptionUtil.generateKeyPair().getPublic();
|
PublicKey wrongPK = EncryptionUtil.generateKeyPair().getPublic();
|
||||||
assertNotEquals(EncryptionUtil.getServerIdHashString("", sharedSecret, wrongPK), sessionHash);
|
assertNotEquals(EncryptionUtil.getServerIdHashString("", sharedSecret, wrongPK), sessionHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +258,8 @@ class EncryptionUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
void testNonce() throws Exception {
|
void testNonce() throws Exception {
|
||||||
byte[] expected = {1, 2, 3, 4};
|
byte[] expected = {1, 2, 3, 4};
|
||||||
val serverKey = EncryptionUtil.generateKeyPair();
|
KeyPair serverKey = EncryptionUtil.generateKeyPair();
|
||||||
val encryptedNonce = encrypt(serverKey.getPublic(), expected);
|
byte[] encryptedNonce = encrypt(serverKey.getPublic(), expected);
|
||||||
|
|
||||||
assertTrue(EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce));
|
assertTrue(EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce));
|
||||||
}
|
}
|
||||||
@ -266,19 +267,19 @@ class EncryptionUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
void testNonceIncorrect() throws Exception {
|
void testNonceIncorrect() throws Exception {
|
||||||
byte[] expected = {1, 2, 3, 4};
|
byte[] expected = {1, 2, 3, 4};
|
||||||
val serverKey = EncryptionUtil.generateKeyPair();
|
KeyPair serverKey = EncryptionUtil.generateKeyPair();
|
||||||
|
|
||||||
// flipped first character
|
// flipped first character
|
||||||
val encryptedNonce = encrypt(serverKey.getPublic(), new byte[]{0, 2, 3, 4});
|
byte[] encryptedNonce = encrypt(serverKey.getPublic(), new byte[]{0, 2, 3, 4});
|
||||||
assertFalse(EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce));
|
assertFalse(EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNonceFailedDecryption() throws Exception {
|
void testNonceFailedDecryption() throws Exception {
|
||||||
byte[] expected = {1, 2, 3, 4};
|
byte[] expected = {1, 2, 3, 4};
|
||||||
val serverKey = EncryptionUtil.generateKeyPair();
|
KeyPair serverKey = EncryptionUtil.generateKeyPair();
|
||||||
// generate a new keypair that is different
|
// generate a new keypair that is different
|
||||||
val encryptedNonce = encrypt(EncryptionUtil.generateKeyPair().getPublic(), expected);
|
byte[] encryptedNonce = encrypt(EncryptionUtil.generateKeyPair().getPublic(), expected);
|
||||||
|
|
||||||
assertThrows(GeneralSecurityException.class,
|
assertThrows(GeneralSecurityException.class,
|
||||||
() -> EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce)
|
() -> EncryptionUtil.verifyNonce(expected, serverKey.getPrivate(), encryptedNonce)
|
||||||
@ -288,7 +289,7 @@ class EncryptionUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
void testNonceIncorrectEmpty() {
|
void testNonceIncorrectEmpty() {
|
||||||
byte[] expected = {1, 2, 3, 4};
|
byte[] expected = {1, 2, 3, 4};
|
||||||
val serverKey = EncryptionUtil.generateKeyPair();
|
KeyPair serverKey = EncryptionUtil.generateKeyPair();
|
||||||
byte[] encryptedNonce = {};
|
byte[] encryptedNonce = {};
|
||||||
|
|
||||||
assertThrows(GeneralSecurityException.class,
|
assertThrows(GeneralSecurityException.class,
|
||||||
|
@ -28,16 +28,16 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib;
|
|||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.annotations.JsonAdapter;
|
import com.google.gson.annotations.JsonAdapter;
|
||||||
import lombok.val;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class SignatureTestData {
|
public class SignatureTestData {
|
||||||
|
|
||||||
public static SignatureTestData fromResource(String resourceName) throws IOException {
|
public static SignatureTestData fromResource(String resourceName) throws IOException {
|
||||||
val keyUrl = Resources.getResource(resourceName);
|
URL keyUrl = Resources.getResource(resourceName);
|
||||||
val encodedSignature = Resources.toString(keyUrl, StandardCharsets.US_ASCII);
|
String encodedSignature = Resources.toString(keyUrl, StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
return new Gson().fromJson(encodedSignature, SignatureTestData.class);
|
return new Gson().fromJson(encodedSignature, SignatureTestData.class);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package com.github.games647.fastlogin.bukkit.task;
|
package com.github.games647.fastlogin.bukkit.task;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
import lombok.val;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@ -36,7 +35,7 @@ class DelayedAuthHookTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createNewReflectiveInstance() throws ReflectiveOperationException {
|
void createNewReflectiveInstance() throws ReflectiveOperationException {
|
||||||
val authHook = new DelayedAuthHook(null);
|
DelayedAuthHook authHook = new DelayedAuthHook(null);
|
||||||
assertNotNull(authHook.newInstance(DummyHook.class));
|
assertNotNull(authHook.newInstance(DummyHook.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
pom.xml
8
pom.xml
@ -218,14 +218,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Use lombok to use some newer Java syntax features in Java 8 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombook.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
Reference in New Issue
Block a user