Skip to content

Commit

Permalink
fix silly snafu. Deserialising ClientMessage isn't working currently.
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Oct 12, 2024
1 parent e5af584 commit a989bba
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion client/src/main/java/online/util/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion client/src/main/java/util/ClientNotificationRunnable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package util;

import online.util.ResponseHandler;
import org.w3c.dom.Document;

public class ClientNotificationRunnable implements Runnable
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 2 additions & 22 deletions core/src/main/java/util/EncryptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -103,7 +84,6 @@ public static String decrypt(String encryptedMessage, Key key, boolean asymmetri

if (messageString != null)
{
messageString = messageString.intern();
return messageString.intern();
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/http/dto/ClientMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a989bba

Please sign in to comment.