cleanup encryption

This commit is contained in:
DNx5 2015-09-19 14:10:48 +07:00
parent b427d14bcb
commit 53fcfb5b43
2 changed files with 39 additions and 45 deletions

View File

@ -1,17 +1,5 @@
package fr.xephi.authme.process.join; package fr.xephi.authme.process.join;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.Utils; import fr.xephi.authme.Utils;
@ -32,6 +20,17 @@ import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask; import fr.xephi.authme.task.TimeoutTask;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
public class AsyncronousJoin { public class AsyncronousJoin {
@ -62,10 +61,7 @@ public class AsyncronousJoin {
} }
if (plugin.ess != null && Settings.disableSocialSpy) { if (plugin.ess != null && Settings.disableSocialSpy) {
try { plugin.ess.getUser(player).setSocialSpyEnabled(false);
plugin.ess.getUser(player.getName().toLowerCase()).setSocialSpyEnabled(false);
} catch (NoSuchMethodError e) {
}
} }
final String ip = plugin.getIP(player); final String ip = plugin.getIP(player);

View File

@ -1,19 +1,18 @@
package fr.xephi.authme.security; package fr.xephi.authme.security;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
import org.bukkit.Bukkit;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.events.PasswordEncryptionEvent; import fr.xephi.authme.events.PasswordEncryptionEvent;
import fr.xephi.authme.security.crypts.BCRYPT; import fr.xephi.authme.security.crypts.BCRYPT;
import fr.xephi.authme.security.crypts.EncryptionMethod; import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
public class PasswordSecurity { public class PasswordSecurity {
@ -132,27 +131,25 @@ public class PasswordSecurity {
try { try {
if (algo != HashAlgorithm.CUSTOM) if (algo != HashAlgorithm.CUSTOM)
method = (EncryptionMethod) algo.getclasse().newInstance(); method = (EncryptionMethod) algo.getclasse().newInstance();
else method = null; else
} catch (InstantiationException | IllegalAccessException e) { method = null;
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
}
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName); PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
method = event.getMethod(); method = event.getMethod();
if (method == null) if (method == null)
throw new NoSuchAlgorithmException("Unknown hash algorithm"); throw new NoSuchAlgorithmException("Unknown hash algorithm");
try {
if (method.comparePassword(hash, password, playerName)) if (method.comparePassword(hash, password, playerName))
return true; return true;
} catch (Exception e) {
}
if (Settings.supportOldPassword) { if (Settings.supportOldPassword) {
try {
if (compareWithAllEncryptionMethod(password, hash, playerName)) if (compareWithAllEncryptionMethod(password, hash, playerName))
return true; return true;
} catch (Exception e) {
} }
} catch (InstantiationException | IllegalAccessException e) {
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
} }
return false; return false;
} }
@ -160,7 +157,7 @@ public class PasswordSecurity {
private static boolean compareWithAllEncryptionMethod(String password, private static boolean compareWithAllEncryptionMethod(String password,
String hash, String playerName) throws NoSuchAlgorithmException { String hash, String playerName) throws NoSuchAlgorithmException {
for (HashAlgorithm algo : HashAlgorithm.values()) { for (HashAlgorithm algo : HashAlgorithm.values()) {
if (algo != HashAlgorithm.CUSTOM) if (algo != HashAlgorithm.CUSTOM) {
try { try {
EncryptionMethod method = (EncryptionMethod) algo.getclasse().newInstance(); EncryptionMethod method = (EncryptionMethod) algo.getclasse().newInstance();
if (method.comparePassword(hash, password, playerName)) { if (method.comparePassword(hash, password, playerName)) {
@ -173,7 +170,8 @@ public class PasswordSecurity {
} }
return true; return true;
} }
} catch (Exception e) { } catch (Exception ignored) {
}
} }
} }
return false; return false;