Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 347-config-rewrite
# Conflicts: # src/main/java/fr/xephi/authme/AuthMe.java
This commit is contained in:
commit
4a85eedd2c
@ -525,8 +525,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
Collection<? extends Player> players = Utils.getOnlinePlayers();
|
Collection<? extends Player> players = Utils.getOnlinePlayers();
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
savePlayer(player);
|
savePlayer(player);
|
||||||
// TODO: add a MessageKey
|
|
||||||
player.kickPlayer("Server is restarting or AuthMe plugin was disabled.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do backup on stop if enabled
|
// Do backup on stop if enabled
|
||||||
@ -752,7 +750,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
PlayerCache.getInstance().removePlayer(name);
|
||||||
player.saveData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the player to kick when a vip player join the server when full
|
// Select the player to kick when a vip player join the server when full
|
||||||
|
|||||||
@ -41,15 +41,8 @@ public class PasswordSecurity {
|
|||||||
|
|
||||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
||||||
EncryptionMethod method = initializeEncryptionMethod(algorithm, playerName);
|
EncryptionMethod method = initializeEncryptionMethod(algorithm, playerName);
|
||||||
// User is not in data source, so the result will invariably be wrong because an encryption
|
|
||||||
// method with hasSeparateSalt() == true NEEDS the salt to evaluate the password
|
|
||||||
String salt = hashedPassword.getSalt();
|
|
||||||
if (method.hasSeparateSalt() && salt == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String playerLowerCase = playerName.toLowerCase();
|
String playerLowerCase = playerName.toLowerCase();
|
||||||
return method.comparePassword(password, hashedPassword, playerLowerCase)
|
return methodMatches(method, password, hashedPassword, playerLowerCase)
|
||||||
|| supportOldAlgorithm && compareWithAllEncryptionMethods(password, hashedPassword, playerLowerCase);
|
|| supportOldAlgorithm && compareWithAllEncryptionMethods(password, hashedPassword, playerLowerCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +62,7 @@ public class PasswordSecurity {
|
|||||||
for (HashAlgorithm algorithm : HashAlgorithm.values()) {
|
for (HashAlgorithm algorithm : HashAlgorithm.values()) {
|
||||||
if (!HashAlgorithm.CUSTOM.equals(algorithm)) {
|
if (!HashAlgorithm.CUSTOM.equals(algorithm)) {
|
||||||
EncryptionMethod method = initializeEncryptionMethodWithoutEvent(algorithm);
|
EncryptionMethod method = initializeEncryptionMethodWithoutEvent(algorithm);
|
||||||
if (method != null && method.comparePassword(password, hashedPassword, playerName)) {
|
if (methodMatches(method, password, hashedPassword, playerName)) {
|
||||||
hashPasswordForNewAlgorithm(password, playerName);
|
hashPasswordForNewAlgorithm(password, playerName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -78,6 +71,22 @@ public class PasswordSecurity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify with the given encryption method whether the password matches the hash after checking that
|
||||||
|
* the method can be called safely with the given data.
|
||||||
|
*
|
||||||
|
* @param method The encryption method to use
|
||||||
|
* @param password The password to check
|
||||||
|
* @param hashedPassword The hash to check against
|
||||||
|
* @param playerName The name of the player
|
||||||
|
* @return True if the password matched, false otherwise
|
||||||
|
*/
|
||||||
|
private static boolean methodMatches(EncryptionMethod method, String password,
|
||||||
|
HashedPassword hashedPassword, String playerName) {
|
||||||
|
return method != null && (!method.hasSeparateSalt() || hashedPassword.getSalt() != null)
|
||||||
|
&& method.comparePassword(password, hashedPassword, playerName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the encryption method from the given {@link HashAlgorithm} value and emit a
|
* Get the encryption method from the given {@link HashAlgorithm} value and emit a
|
||||||
* {@link PasswordEncryptionEvent}. The encryption method from the event is then returned,
|
* {@link PasswordEncryptionEvent}. The encryption method from the event is then returned,
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package fr.xephi.authme.security.crypts;
|
package fr.xephi.authme.security.crypts;
|
||||||
|
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.security.crypts.description.Recommendation;
|
import fr.xephi.authme.security.crypts.description.Recommendation;
|
||||||
import fr.xephi.authme.security.crypts.description.Usage;
|
import fr.xephi.authme.security.crypts.description.Usage;
|
||||||
|
import fr.xephi.authme.util.StringUtils;
|
||||||
|
|
||||||
@Recommendation(Usage.DOES_NOT_WORK)
|
@Recommendation(Usage.DOES_NOT_WORK)
|
||||||
public class WBB4 extends HexSaltedMethod {
|
public class WBB4 extends HexSaltedMethod {
|
||||||
@ -13,7 +15,12 @@ public class WBB4 extends HexSaltedMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
|
||||||
return BCRYPT.checkpw(password, hashedPassword.getHash(), 2);
|
try {
|
||||||
|
return BCRYPT.checkpw(password, hashedPassword.getHash(), 2);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
ConsoleLogger.showError("WBB4 compare password returned: " + StringUtils.formatException(e));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Binary file not shown.
@ -7,6 +7,7 @@ import fr.xephi.authme.security.crypts.HashedPassword;
|
|||||||
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
import fr.xephi.authme.security.crypts.EncryptionMethod;
|
||||||
import fr.xephi.authme.security.crypts.JOOMLA;
|
import fr.xephi.authme.security.crypts.JOOMLA;
|
||||||
import fr.xephi.authme.security.crypts.PHPBB;
|
import fr.xephi.authme.security.crypts.PHPBB;
|
||||||
|
import fr.xephi.authme.util.WrapperMock;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -42,6 +43,7 @@ public class PasswordSecurityTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpMocks() {
|
public void setUpMocks() {
|
||||||
|
WrapperMock.createInstance();
|
||||||
pluginManager = mock(PluginManager.class);
|
pluginManager = mock(PluginManager.class);
|
||||||
dataSource = mock(DataSource.class);
|
dataSource = mock(DataSource.class);
|
||||||
method = mock(EncryptionMethod.class);
|
method = mock(EncryptionMethod.class);
|
||||||
@ -209,7 +211,7 @@ public class PasswordSecurityTest {
|
|||||||
HashedPassword hashedPassword = new HashedPassword("~T!est#Hash");
|
HashedPassword hashedPassword = new HashedPassword("~T!est#Hash");
|
||||||
given(method.computeHash(password, username)).willReturn(hashedPassword);
|
given(method.computeHash(password, username)).willReturn(hashedPassword);
|
||||||
given(method.hasSeparateSalt()).willReturn(true);
|
given(method.hasSeparateSalt()).willReturn(true);
|
||||||
PasswordSecurity security = new PasswordSecurity(dataSource, HashAlgorithm.XAUTH, pluginManager, true);
|
PasswordSecurity security = new PasswordSecurity(dataSource, HashAlgorithm.XAUTH, pluginManager, false);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = security.comparePassword(password, hashedPassword, username);
|
boolean result = security.comparePassword(password, hashedPassword, username);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user