cleanup encryption
This commit is contained in:
parent
b427d14bcb
commit
53fcfb5b43
@ -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);
|
||||||
@ -289,7 +285,7 @@ public class AsyncronousJoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void placePlayerSafely(final Player player,
|
private void placePlayerSafely(final Player player,
|
||||||
final Location spawnLoc) {
|
final Location spawnLoc) {
|
||||||
Location loc = null;
|
Location loc = null;
|
||||||
if (spawnLoc == null)
|
if (spawnLoc == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ public class PasswordSecurity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getHash(HashAlgorithm alg, String password,
|
public static String getHash(HashAlgorithm alg, String password,
|
||||||
String playerName) throws NoSuchAlgorithmException {
|
String playerName) throws NoSuchAlgorithmException {
|
||||||
EncryptionMethod method;
|
EncryptionMethod method;
|
||||||
try {
|
try {
|
||||||
if (alg != HashAlgorithm.CUSTOM)
|
if (alg != HashAlgorithm.CUSTOM)
|
||||||
@ -126,41 +125,39 @@ public class PasswordSecurity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean comparePasswordWithHash(String password, String hash,
|
public static boolean comparePasswordWithHash(String password, String hash,
|
||||||
String playerName) throws NoSuchAlgorithmException {
|
String playerName) throws NoSuchAlgorithmException {
|
||||||
HashAlgorithm algo = Settings.getPasswordHash;
|
HashAlgorithm algo = Settings.getPasswordHash;
|
||||||
EncryptionMethod method;
|
EncryptionMethod method;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,8 +170,9 @@ public class PasswordSecurity {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user