Skip to content

Commit

Permalink
Don't use config option
Browse files Browse the repository at this point in the history
  • Loading branch information
kuroppoi committed Jan 10, 2024
1 parent 774794f commit 8e614e0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/main/java/entralinked/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public record Configuration(
boolean clearPlayerDreamInfoOnWake,
boolean allowOverwritingPlayerDreamInfo,
boolean allowPlayerGameVersionMismatch,
boolean allowWfcRegistrationThroughLogin,
boolean logSensitiveInfo) {
boolean allowWfcRegistrationThroughLogin) {

public static final Configuration DEFAULT = new Configuration("local", true, false, false, true, false);
public static final Configuration DEFAULT = new Configuration("local", true, false, false, true);
}
9 changes: 6 additions & 3 deletions src/main/java/entralinked/model/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ public User(String id, String password) {
}

public String getFormattedId() {
return getFormattedId(false);
return "%s000".formatted(id).replaceAll("(.{4})(?!$)", "$1-");
}

public String getFormattedId(boolean redact) {
return redact ? "%s-XXXX-XXXX-XXXX".formatted(id.substring(0, 4)) : "%s000".formatted(id).replaceAll("(.{4})(?!$)", "$1-");
/**
* @return The user's id, redacted for logging.
*/
public String getRedactedId() {
return "%s-XXXX-XXXX-XXXX".formatted(id.substring(0, 4));
}

public String getId() {
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/entralinked/network/gamespy/GameSpyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import entralinked.Configuration;
import entralinked.Entralinked;
import entralinked.model.user.GameProfile;
import entralinked.model.user.ServiceSession;
Expand Down Expand Up @@ -38,7 +37,6 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>

private static final Logger logger = LogManager.getLogger();
private final SecureRandom secureRandom = new SecureRandom();
private final Configuration configuration;
private final UserManager userManager;
private Channel channel;
private String serverChallenge;
Expand All @@ -47,7 +45,6 @@ public class GameSpyHandler extends SimpleChannelInboundHandler<GameSpyRequest>
private GameProfile profile;

public GameSpyHandler(Entralinked entralinked) {
this.configuration = entralinked.getConfiguration();
this.userManager = entralinked.getUserManager();
}

Expand All @@ -65,7 +62,7 @@ public void channelActive(ChannelHandlerContext ctx) {

@Override
public void channelInactive(ChannelHandlerContext ctx) {
logger.debug("User {} disconnected from GameSpy server", user == null ? null : user.getFormattedId(!configuration.logSensitiveInfo()));
logger.debug("User {} disconnected from GameSpy server", user == null ? null : user.getRedactedId());

// Clear data
serverChallenge = null;
Expand All @@ -89,7 +86,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E

// Handle timeout
if(cause instanceof ReadTimeoutException) {
logger.debug("User {} timed out", user == null ? null : user.getFormattedId(!configuration.logSensitiveInfo()));
logger.debug("User {} timed out", user == null ? null : user.getRedactedId());
return;
}

Expand Down Expand Up @@ -145,7 +142,7 @@ public void handleLoginRequest(GameSpyLoginRequest request) {
userManager.saveUser(user); // It's not too big of a deal if this fails for some reason
}

logger.info("User {} logged in with profile {}", user.getFormattedId(!configuration.logSensitiveInfo()), profile.getId());
logger.info("User {} logged in with profile {}", user.getRedactedId(), profile.getId());

// Prepare and send response
sessionKey = secureRandom.nextInt(Integer.MAX_VALUE);
Expand Down Expand Up @@ -200,7 +197,7 @@ protected String createCredentialHash(String passwordHash, String user, String i
}

public void handleLogout() {
logger.info("User {} logged out of profile {}", user.getFormattedId(!configuration.logSensitiveInfo()), profile.getId());
logger.info("User {} logged out of profile {}", user.getRedactedId(), profile.getId());
sessionKey = -1; // Is there a point?
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/entralinked/network/http/nas/NasHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private void handleLogin(NasRequest request, Context ctx) throws IOException {

// Should *never* return null in this location
user = userManager.authenticateUser(userId, request.password());
logger.info("Created account for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created account for user {}", user.getRedactedId());
}

// Prepare GameSpy server credentials
ServiceCredentials credentials = userManager.createServiceSession(user, "gamespy", request.branchCode());
logger.info("Created GameSpy session for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created GameSpy session for user {}", user.getRedactedId());
result(ctx, new NasLoginResponse("gamespy.com", credentials.authToken(), credentials.challenge()));
}

Expand All @@ -120,7 +120,7 @@ private void handleCreateAccount(NasRequest request, Context ctx) throws IOExcep
return;
}

logger.info("Created account for user {}", user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Created account for user {}", user.getRedactedId());
result(ctx, NasReturnCode.REGISTRATION_SUCCESS);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private void handleRetrieveServiceLocation(NasRequest request, Context ctx) thro
// Prepare user credentials
ServiceCredentials credentials = userManager.createServiceSession(user, service, null);
logger.info("Created {} session for user {}",
type.equals("0000") ? "PGL" : type.equals("9000") ? "DLS1" : "this should never be logged", user.getFormattedId(!configuration.logSensitiveInfo()));
type.equals("0000") ? "PGL" : type.equals("9000") ? "DLS1" : "this should never be logged", user.getRedactedId());
result(ctx, new NasServiceLocationResponse(true, service, credentials.authToken()));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/entralinked/network/http/pgl/PglHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void handleDownloadSaveData(PglRequest request, Context ctx) throws IOEx
return;
}

logger.info("Player {} is downloading save data as user {}", player.getGameSyncId(), user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Player {} is downloading save data as user {}", player.getGameSyncId(), user.getRedactedId());

// Write status code
writeStatusCode(outputStream, 0);
Expand Down Expand Up @@ -369,7 +369,7 @@ private void handleMemoryLink(PglRequest request, Context ctx) throws IOExceptio
return;
}

logger.info("User {} is Memory Linking with player {}", user.getFormattedId(!configuration.logSensitiveInfo()), player.getGameSyncId());
logger.info("User {} is Memory Linking with player {}", user.getRedactedId(), player.getGameSyncId());

// Send the save data!
try(FileInputStream inputStream = new FileInputStream(file)) {
Expand Down Expand Up @@ -450,7 +450,7 @@ private void handleUploadSaveData(PglRequest request, Context ctx) throws IOExce
return;
}

logger.info("Player {} is uploading save data as user {}", player.getGameSyncId(), user.getFormattedId(!configuration.logSensitiveInfo()));
logger.info("Player {} is uploading save data as user {}", player.getGameSyncId(), user.getRedactedId());

// Try to store save data
if(!playerManager.storePlayerGameSaveFile(player, ctx.bodyInputStream())) {
Expand Down

0 comments on commit 8e614e0

Please sign in to comment.