diff --git a/client/src/main/java/online/util/ResponseHandler.java b/client/src/main/java/online/util/ResponseHandler.java index e07c35f..da74760 100644 --- a/client/src/main/java/online/util/ResponseHandler.java +++ b/client/src/main/java/online/util/ResponseHandler.java @@ -25,7 +25,7 @@ public static void handleResponse(String messageStr, String responseStr) throws throw new Throwable("Failed to decrypt response. Server may not be genuine."); } - handleDecryptedResponse(messageStr, responseStr); + handleDecryptedResponse(messageStr, decryptedResponseStr); } public static void handleDecryptedResponse(String messageStr, String responseStr) throws Throwable { Document response = XmlUtil.getDocumentFromXmlString(responseStr); diff --git a/client/src/main/java/util/ClientNotificationRunnable.java b/client/src/main/java/util/ClientNotificationRunnable.java index eecc025..13f717e 100644 --- a/client/src/main/java/util/ClientNotificationRunnable.java +++ b/client/src/main/java/util/ClientNotificationRunnable.java @@ -1,5 +1,6 @@ package util; +import online.util.ResponseHandler; import org.w3c.dom.Document; public class ClientNotificationRunnable implements Runnable @@ -47,7 +48,7 @@ public void run() if (ClientGlobals.INSTANCE.getWebSocketReceiver().canHandleMessage(response)) { ClientGlobals.INSTANCE.getWebSocketReceiver().receiveMessage(response); } else { - client.handleResponse(messageStr, response); + ResponseHandler.handleDecryptedResponse(messageStr, response); } } catch (Throwable t) diff --git a/core/src/main/java/util/EncryptionUtil.java b/core/src/main/java/util/EncryptionUtil.java index 0fb88b2..413881a 100644 --- a/core/src/main/java/util/EncryptionUtil.java +++ b/core/src/main/java/util/EncryptionUtil.java @@ -37,22 +37,13 @@ public static SecretKey reconstructKeyFromString(String keyStr) } public static String encrypt(String messageString, Key key) - { - return encrypt(messageString, key, false); - } - public static String encrypt(String messageString, Key key, boolean asymmetric) { String encryptedString = null; try { byte[] messageBytes = messageString.getBytes(); - String algorithm = ALGORITHM_AES_ECB_PKCS5PADDING; - if (asymmetric) - { - algorithm = ALGORITHM_RSA_ECB_PKCS1PADDING; - } - Cipher cipher = Cipher.getInstance(algorithm); + Cipher cipher = Cipher.getInstance(ALGORITHM_AES_ECB_PKCS5PADDING); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] cipherData = cipher.doFinal(messageBytes); encryptedString = base64Interface.encode(cipherData); @@ -76,22 +67,12 @@ public static String encrypt(String messageString, Key key, boolean asymmetric) } public static String decrypt(String encryptedMessage, Key key) - { - return decrypt(encryptedMessage, key, false); - } - public static String decrypt(String encryptedMessage, Key key, boolean asymmetric) { String messageString = null; try { byte[] cipherData = base64Interface.decode(encryptedMessage); - String algorithm = ALGORITHM_AES_ECB_PKCS5PADDING; - if (asymmetric) - { - algorithm = ALGORITHM_RSA_ECB_PKCS1PADDING; - } - - Cipher cipher = Cipher.getInstance(algorithm); + Cipher cipher = Cipher.getInstance(ALGORITHM_AES_ECB_PKCS5PADDING); cipher.init(Cipher.DECRYPT_MODE, key); byte[] messageBytes = cipher.doFinal(cipherData); messageString = new String(messageBytes); @@ -103,7 +84,6 @@ public static String decrypt(String encryptedMessage, Key key, boolean asymmetri if (messageString != null) { - messageString = messageString.intern(); return messageString.intern(); } diff --git a/core/src/main/kotlin/http/dto/ClientMessage.kt b/core/src/main/kotlin/http/dto/ClientMessage.kt index c700685..2e1827c 100644 --- a/core/src/main/kotlin/http/dto/ClientMessage.kt +++ b/core/src/main/kotlin/http/dto/ClientMessage.kt @@ -7,7 +7,7 @@ import http.ClientMessageType @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, - property = "type", + property = "messageType", ) @JsonSubTypes(JsonSubTypes.Type(value = LobbyResponse::class, name = "LOBBY")) sealed class ClientMessage {