Always specify Locale on toLowerCase and toUpperCase usages, fixes AuthMe not working correctly on machines with turkish locale. ('I'.toLowerCase() => 'ı')

This commit is contained in:
Gabriele C
2022-08-20 04:41:04 +02:00
parent c38e2aba28
commit 75b3a571e1
67 changed files with 217 additions and 143 deletions
@@ -6,6 +6,7 @@ import fr.xephi.authme.util.expiring.ExpiringMap;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
/**
@@ -32,7 +33,7 @@ public class GenerateTotpService implements HasCleanup {
*/
public TotpGenerationResult generateTotpKey(Player player) {
TotpGenerationResult credentials = totpAuthenticator.generateTotpKey(player);
totpKeys.put(player.getName().toLowerCase(), credentials);
totpKeys.put(player.getName().toLowerCase(Locale.ROOT), credentials);
return credentials;
}
@@ -43,11 +44,11 @@ public class GenerateTotpService implements HasCleanup {
* @return TOTP generation result
*/
public TotpGenerationResult getGeneratedTotpKey(Player player) {
return totpKeys.get(player.getName().toLowerCase());
return totpKeys.get(player.getName().toLowerCase(Locale.ROOT));
}
public void removeGenerateTotpKey(Player player) {
totpKeys.remove(player.getName().toLowerCase());
totpKeys.remove(player.getName().toLowerCase(Locale.ROOT));
}
/**
@@ -58,7 +59,7 @@ public class GenerateTotpService implements HasCleanup {
* @return true if the input code is correct, false if the code is invalid or no unexpired totp key is available
*/
public boolean isTotpCodeCorrectForGeneratedTotpKey(Player player, String totpCode) {
TotpGenerationResult totpDetails = totpKeys.get(player.getName().toLowerCase());
TotpGenerationResult totpDetails = totpKeys.get(player.getName().toLowerCase(Locale.ROOT));
return totpDetails != null && totpAuthenticator.checkCode(player.getName(), totpDetails.getTotpKey(), totpCode);
}
@@ -15,6 +15,8 @@ import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.util.Locale;
import static fr.xephi.authme.util.Utils.MILLIS_PER_MINUTE;
/**
@@ -54,7 +56,7 @@ public class TotpAuthenticator implements HasCleanup {
* @return true if code is valid, false otherwise
*/
public boolean checkCode(String playerName, String totpKey, String inputCode) {
String nameLower = playerName.toLowerCase();
String nameLower = playerName.toLowerCase(Locale.ROOT);
Integer totpCode = Ints.tryParse(inputCode);
if (totpCode != null && !usedCodes.contains(nameLower, totpCode)
&& authenticator.authorize(totpKey, totpCode)) {