Update 3.1.1

//Changes 3.1.1://
* Do /login correctly in the correct thread
* Add a way to force some commands after /login
* Try a fix for bungeecord , let's see ...
* Fix Logout command ( pos + inventory )
* Fix PHPBB support + random salt
* Add a bypass antibot perm : authme.bypassantibot
* Translation file will automatically update now
* Some other fixes
This commit is contained in:
Xephi
2013-12-12 05:34:44 +01:00
parent 10b4eaeca7
commit bc8d11ebd6
63 changed files with 1424 additions and 501 deletions
@@ -36,4 +36,5 @@ public enum HashAlgorithm {
public Class<?> getclass() {
return classe;
}
}
@@ -6,6 +6,8 @@ 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.cache.auth.PlayerAuth;
import fr.xephi.authme.events.PasswordEncryptionEvent;
@@ -19,7 +21,7 @@ public class PasswordSecurity {
private static SecureRandom rnd = new SecureRandom();
public static HashMap<String, String> userSalt = new HashMap<String, String>();
private static String createSalt(int length) throws NoSuchAlgorithmException {
public static String createSalt(int length) throws NoSuchAlgorithmException {
byte[] msg = new byte[40];
rnd.nextBytes(msg);
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
@@ -41,64 +43,68 @@ public class PasswordSecurity {
}
String salt = "";
switch (alg) {
case MD5:
case SHA1:
case WHIRLPOOL:
case PHPBB:
case PLAINTEXT:
case XENFORO:
case SHA512:
case DOUBLEMD5:
case WORDPRESS:
case CUSTOM:
break;
case SHA256:
salt = createSalt(16);
break;
case MD5VB:
salt = createSalt(16);
break;
case XAUTH:
salt = createSalt(12);
break;
case MYBB:
salt = createSalt(8);
userSalt.put(playerName, salt);
break;
case IPB3:
salt = createSalt(5);
userSalt.put(playerName, salt);
break;
case PHPFUSION:
salt = createSalt(12);
userSalt.put(playerName, salt);
break;
case SALTED2MD5:
salt = createSalt(Settings.saltLength);
userSalt.put(playerName, salt);
break;
case JOOMLA:
salt = createSalt(32);
userSalt.put(playerName, salt);
break;
case BCRYPT:
salt = BCRYPT.gensalt(Settings.bCryptLog2Rounds);
userSalt.put(playerName, salt);
break;
case WBB3:
salt = createSalt(40);
userSalt.put(playerName, salt);
break;
case PBKDF2:
salt = createSalt(12);
userSalt.put(playerName, salt);
break;
case SMF:
return method.getHash(password, playerName.toLowerCase());
default:
throw new NoSuchAlgorithmException("Unknown hash algorithm");
case SHA256:
salt = createSalt(16);
break;
case MD5VB:
salt = createSalt(16);
break;
case XAUTH:
salt = createSalt(12);
break;
case MYBB:
salt = createSalt(8);
userSalt.put(playerName, salt);
break;
case IPB3:
salt = createSalt(5);
userSalt.put(playerName, salt);
break;
case PHPFUSION:
salt = createSalt(12);
userSalt.put(playerName, salt);
break;
case SALTED2MD5:
salt = createSalt(Settings.saltLength);
userSalt.put(playerName, salt);
break;
case JOOMLA:
salt = createSalt(32);
userSalt.put(playerName, salt);
break;
case BCRYPT:
salt = BCRYPT.gensalt(Settings.bCryptLog2Rounds);
userSalt.put(playerName, salt);
break;
case WBB3:
salt = createSalt(40);
userSalt.put(playerName, salt);
break;
case PBKDF2:
salt = createSalt(12);
userSalt.put(playerName, salt);
break;
case SMF:
return method.getHash(password, playerName.toLowerCase());
case PHPBB:
salt = createSalt(16);
userSalt.put(playerName, salt);
break;
case MD5:
case SHA1:
case WHIRLPOOL:
case PLAINTEXT:
case XENFORO:
case SHA512:
case DOUBLEMD5:
case WORDPRESS:
case CUSTOM:
break;
default:
throw new NoSuchAlgorithmException("Unknown hash algorithm");
}
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
Bukkit.getPluginManager().callEvent(event);
method = event.getMethod();
if (method == null)
throw new NoSuchAlgorithmException("Unknown hash algorithm");
@@ -118,6 +124,7 @@ public class PasswordSecurity {
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
}
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
Bukkit.getPluginManager().callEvent(event);
method = event.getMethod();
if (method == null)
throw new NoSuchAlgorithmException("Unknown hash algorithm");
@@ -136,8 +143,9 @@ public class PasswordSecurity {
private static boolean compareWithAllEncryptionMethod(String password, String hash, String playerName) throws NoSuchAlgorithmException {
for (HashAlgorithm algo : HashAlgorithm.values()) {
try {
if (algo != HashAlgorithm.CUSTOM)
if (((EncryptionMethod) algo.getclass().newInstance()).comparePassword(hash, password, playerName)) {
EncryptionMethod method = (EncryptionMethod) algo.getclass().newInstance();
if (algo != HashAlgorithm.CUSTOM) {
if (method.comparePassword(hash, password, playerName)) {
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
if (nAuth != null) {
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
@@ -147,9 +155,8 @@ public class PasswordSecurity {
}
return true;
}
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
}
} catch (Exception e) {}
}
return false;
}
@@ -18,9 +18,6 @@ import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import fr.xephi.authme.AuthMe;
/**
* BCrypt implements OpenBSD-style Blowfish password hashing using
* the scheme described in "A Future-Adaptable Password Scheme" by
@@ -762,7 +759,6 @@ public class BCRYPT implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(hashpw(password, salt));
return checkpw(password, hash);
}
}
@@ -18,14 +18,14 @@ public class PHPBB implements EncryptionMethod {
private String itoa64 =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public String phpbb_hash(String password) {
String random_state = unique_id();
public String phpbb_hash(String password, String salt) {
String random_state = salt;
String random = "";
int count = 6;
if (random.length() < count) {
random = "";
for (int i = 0; i < count; i += 16) {
random_state = md5(unique_id() + random_state);
random_state = md5(salt + random_state);
random += pack(md5(random_state));
}
random = random.substring(0, count);
@@ -37,15 +37,6 @@ public class PHPBB implements EncryptionMethod {
return md5(password);
}
private String unique_id() {
return unique_id("c");
}
private String unique_id(String extra) {
//TODO: Maybe check the salt?
return "1234567890abcdef";
}
private String _hash_gensalt_private(String input, String itoa64) {
return _hash_gensalt_private(input, itoa64, 6);
}
@@ -162,7 +153,7 @@ private String _hash_gensalt_private(
@Override
public String getHash(String password, String salt)
throws NoSuchAlgorithmException {
return phpbb_hash(password);
return phpbb_hash(password, salt);
}
@Override
@@ -61,8 +61,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
public class WHIRLPOOL implements EncryptionMethod {
public WHIRLPOOL() {}
/**
* The message digest size (in bits)
@@ -181,6 +179,9 @@ public class WHIRLPOOL implements EncryptionMethod {
protected long[] block = new long[8];
protected long[] state = new long[8];
public WHIRLPOOL() {
}
/**
* The core Whirlpool transform.
*/
@@ -7,8 +7,7 @@ public class XAUTH implements EncryptionMethod {
@Override
public String getHash(String password, String salt)
throws NoSuchAlgorithmException {
WHIRLPOOL w = new WHIRLPOOL();
String hash = w.getHash((salt + password).toLowerCase(), "");
String hash = getWhirlpool(salt + password).toLowerCase();
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
return hash.substring(0, saltPos) + salt + hash.substring(saltPos);
}
@@ -21,4 +20,13 @@ public class XAUTH implements EncryptionMethod {
return hash.equals(getHash(password, salt));
}
public static String getWhirlpool(String message) {
WHIRLPOOL w = new WHIRLPOOL();
byte[] digest = new byte[WHIRLPOOL.DIGESTBYTES];
w.NESSIEinit();
w.NESSIEadd(message);
w.NESSIEfinalize(digest);
return WHIRLPOOL.display(digest);
}
}