Skip to content

Commit

Permalink
usc wrangling to try and connect new+old way
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Sep 22, 2024
1 parent ae4fc28 commit 421e996
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 787 deletions.
3 changes: 1 addition & 2 deletions client/src/main/java/online/util/ResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public static void handleResponse(String messageStr, String responseStr) throws
handleKickOff(root);
return;
}

MessageUtil.setShuttingDown(false);

if (responseName.equals(RESPONSE_TAG_CHANGE_PASSWORD))
{
handleChangePasswordResponse(root);
Expand Down
95 changes: 0 additions & 95 deletions client/src/main/java/online/util/XmlBuilderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,106 +18,11 @@

public class XmlBuilderClient implements XmlConstants
{
/**
* Used for symmetricKey requests
*/
public static boolean sendSymmetricKeyRequest()
{
//1. Clear the old key and cache a new one in the 'temporary' space
MessageUtil.symmetricKey = null;
SecretKey symmetricKey = KeyGeneratorUtil.generateSymmetricKey();
MessageUtil.tempSymmetricKey = symmetricKey;

//2. Factory the request and fire it off in the same thread
Document symmetricKeyRequest = factoryNewSymmetricKeyRequest(symmetricKey);
String responseStr = AbstractClient.getInstance().sendSync(symmetricKeyRequest, false);

//3. If the response is valid, swap the temporary key into the permanent space
if (validSymmetricKeyResponse(responseStr))
{
if (MessageUtil.tempSymmetricKey != null)
{
MessageUtil.symmetricKey = MessageUtil.tempSymmetricKey;
MessageUtil.tempSymmetricKey = null;
}

return true;
}

return false;
}

private static boolean validSymmetricKeyResponse(String responseStr)
{
//1. If the response is null (e.g. we had some kind of timeout), return false
if (responseStr == null)
{
return false;
}

//2. We must be able to decrypt the response using the temporary symmetric key
responseStr = EncryptionUtil.decrypt(responseStr, MessageUtil.tempSymmetricKey);
if (responseStr == null)
{
Debug.stackTrace("Failed to decrypt symmetric key response: " + responseStr + " - Server may not be genuine.");
return false;
}

//3. Check the response decrypts to valid XML and that it is a valid symmetric key response
Document response = XmlUtil.getDocumentFromXmlString(responseStr);
Element root = response.getDocumentElement();
String responseName = root.getNodeName();
if (responseName.equals(RESPONSE_TAG_CHANGE_PORT))
{
//We've been told to change port because someone else with the same IP is connected
boolean success = MessageUtil.changeCachedPort(root);
if (!success)
{
return false;
}

return XmlBuilderClient.sendSymmetricKeyRequest();
}

if (!responseName.equals(RESPONSE_TAG_SYMMETRIC_KEY))
{
Debug.stackTrace("Unexpected responseName in response to symmetric key request: " + responseName);
return false;
}

return true;
}

private static Document factoryNewSymmetricKeyRequest(SecretKey symmetricKey)
{
String symmetricKeyString = EncryptionUtil.convertSecretKeyToString(symmetricKey);
String encryptedKey = EncryptionUtil.encrypt(symmetricKeyString, MessageUtil.publicKey, true);

Document document = XmlUtil.factoryNewDocument();
Element rootElement = document.createElement(ROOT_TAG_NEW_SYMMETRIC_KEY);
rootElement.setAttribute("EncryptedKey", encryptedKey);

document.appendChild(rootElement);
return document;
}

public static Document factoryHeartbeat(String username)
{
return XmlUtil.factorySimpleMessage(username, ROOT_TAG_HEARTBEAT);
}

public static Document factoryNewAccountRequest(String username, String passwordHash, String email)
{
Document document = XmlUtil.factoryNewDocument();
Element rootElement = document.createElement(ROOT_TAG_NEW_ACCOUNT_REQUEST);
rootElement.setAttribute("Username", username);
rootElement.setAttribute("Password", passwordHash);
rootElement.setAttribute("Email", email);

document.appendChild(rootElement);
return document;
}

public static Document factoryChangePasswordRequest(String username, String oldPasswordHash, String newPasswordHash)
{
Document document = XmlUtil.factoryNewDocument();
Expand Down
261 changes: 0 additions & 261 deletions client/src/main/java/screen/LoadTesterDialog.java

This file was deleted.

Loading

0 comments on commit 421e996

Please sign in to comment.