Replace all '/' in path to File.separator - Code Refactor

This commit is contained in:
Xephi
2014-08-25 03:12:28 +02:00
parent 12795436a0
commit d7cb60c1fe
104 changed files with 2470 additions and 3690 deletions
@@ -29,15 +29,15 @@ public enum HashAlgorithm {
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
CUSTOM(Null.class);
Class<?> classe;
HashAlgorithm(Class<?> classe) {
this.classe = classe;
}
public Class<?> getclass() {
return classe;
this.classe = classe;
}
}
public Class<?> getclass() {
return classe;
}
}
@@ -26,23 +26,20 @@ public class PasswordSecurity {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.reset();
byte[] digest = sha1.digest(msg);
return String.format("%0" + (digest.length << 1) + "x",
new BigInteger(1, digest)).substring(0, length);
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest)).substring(0, length);
}
public static String getHash(HashAlgorithm alg, String password,
String playerName) throws NoSuchAlgorithmException {
EncryptionMethod method;
try {
if (alg != HashAlgorithm.CUSTOM) method = (EncryptionMethod) alg
.getclass().newInstance();
if (alg != HashAlgorithm.CUSTOM)
method = (EncryptionMethod) alg.getclass().newInstance();
else method = null;
} catch (InstantiationException e) {
throw new NoSuchAlgorithmException(
"Problem with this hash algorithm");
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
} catch (IllegalAccessException e) {
throw new NoSuchAlgorithmException(
"Problem with this hash algorithm");
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
}
String salt = "";
switch (alg) {
@@ -112,12 +109,11 @@ public class PasswordSecurity {
default:
throw new NoSuchAlgorithmException("Unknown hash algorithm");
}
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method,
playerName);
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
Bukkit.getPluginManager().callEvent(event);
method = event.getMethod();
if (method == null) throw new NoSuchAlgorithmException(
"Unknown hash algorithm");
if (method == null)
throw new NoSuchAlgorithmException("Unknown hash algorithm");
return method.getHash(password, salt, playerName);
}
@@ -126,30 +122,29 @@ public class PasswordSecurity {
HashAlgorithm algo = Settings.getPasswordHash;
EncryptionMethod method;
try {
if (algo != HashAlgorithm.CUSTOM) method = (EncryptionMethod) algo
.getclass().newInstance();
if (algo != HashAlgorithm.CUSTOM)
method = (EncryptionMethod) algo.getclass().newInstance();
else method = null;
} catch (InstantiationException e) {
throw new NoSuchAlgorithmException(
"Problem with this hash algorithm");
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
} catch (IllegalAccessException e) {
throw new NoSuchAlgorithmException(
"Problem with this hash algorithm");
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
}
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method,
playerName);
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
Bukkit.getPluginManager().callEvent(event);
method = event.getMethod();
if (method == null) throw new NoSuchAlgorithmException(
"Unknown hash algorithm");
if (method == null)
throw new NoSuchAlgorithmException("Unknown hash algorithm");
try {
if (method.comparePassword(hash, password, playerName)) return true;
if (method.comparePassword(hash, password, playerName))
return true;
} catch (Exception e) {
}
if (Settings.supportOldPassword) {
try {
if (compareWithAllEncryptionMethod(password, hash, playerName)) return true;
if (compareWithAllEncryptionMethod(password, hash, playerName))
return true;
} catch (Exception e) {
}
}
@@ -159,23 +154,21 @@ public class PasswordSecurity {
private static boolean compareWithAllEncryptionMethod(String password,
String hash, String playerName) throws NoSuchAlgorithmException {
for (HashAlgorithm algo : HashAlgorithm.values()) {
if (algo != HashAlgorithm.CUSTOM) try {
EncryptionMethod method = (EncryptionMethod) algo.getclass()
.newInstance();
if (method.comparePassword(hash, password, playerName)) {
PlayerAuth nAuth = AuthMe.getInstance().database
.getAuth(playerName);
if (nAuth != null) {
nAuth.setHash(getHash(Settings.getPasswordHash,
password, playerName));
nAuth.setSalt(userSalt.get(playerName));
AuthMe.getInstance().database.updatePassword(nAuth);
AuthMe.getInstance().database.updateSalt(nAuth);
if (algo != HashAlgorithm.CUSTOM)
try {
EncryptionMethod method = (EncryptionMethod) algo.getclass().newInstance();
if (method.comparePassword(hash, password, playerName)) {
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
if (nAuth != null) {
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
nAuth.setSalt(userSalt.get(playerName));
AuthMe.getInstance().database.updatePassword(nAuth);
AuthMe.getInstance().database.updateSalt(nAuth);
}
return true;
}
return true;
} catch (Exception e) {
}
} catch (Exception e) {
}
}
return false;
}
@@ -22,8 +22,8 @@ public class RandomString {
private final char[] buf;
public RandomString(int length) {
if (length < 1) throw new IllegalArgumentException("length < 1: "
+ length);
if (length < 1)
throw new IllegalArgumentException("length < 1: " + length);
buf = new char[length];
}
File diff suppressed because one or more lines are too long
@@ -7,14 +7,12 @@ import java.security.NoSuchAlgorithmException;
public class CRAZYCRYPT1 implements EncryptionMethod {
protected final Charset charset = Charset.forName("UTF-8");
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
private static final char[] CRYPTCHARS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name
+ "__+IÄIH§%NK " + password;
final String text = "ÜÄaeut//&/=I " + password + "7421€547" + name + "__+IÄIH§%NK " + password;
try {
final MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(text.getBytes(charset), 0, text.length());
@@ -11,8 +11,7 @@ public class CryptPBKDF2 implements EncryptionMethod {
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String result = "pbkdf2_sha256$10000$" + salt + "$";
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII",
salt.getBytes(), 10000);
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
PBKDF2Engine engine = new PBKDF2Engine(params);
return result + engine.deriveKey(password, 64).toString();
@@ -24,8 +23,7 @@ public class CryptPBKDF2 implements EncryptionMethod {
String[] line = hash.split("\\$");
String salt = line[2];
String derivedKey = line[3];
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII",
salt.getBytes(), 10000, derivedKey.getBytes());
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000, derivedKey.getBytes());
PBKDF2Engine engine = new PBKDF2Engine(params);
return engine.verifyKey(password);
}
@@ -24,8 +24,7 @@ public class DOUBLEMD5 implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -17,8 +17,7 @@ public class IPB3 implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, playerName));
}
@@ -28,7 +27,6 @@ public class IPB3 implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -25,7 +25,6 @@ public class JOOMLA implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -24,7 +24,6 @@ public class MD5 implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -25,8 +25,7 @@ public class MD5VB implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -17,8 +17,7 @@ public class MYBB implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, playerName));
}
@@ -28,7 +27,6 @@ public class MYBB implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -14,6 +14,7 @@ import java.security.NoSuchAlgorithmException;
* @author stefano
*/
public class PHPBB implements EncryptionMethod {
private static final int PHP_VERSION = 4;
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -29,9 +30,9 @@ public class PHPBB implements EncryptionMethod {
}
random = random.substring(0, count);
}
String hash = _hash_crypt_private(password,
_hash_gensalt_private(random, itoa64));
if (hash.length() == 34) return hash;
String hash = _hash_crypt_private(password, _hash_gensalt_private(random, itoa64));
if (hash.length() == 34)
return hash;
return md5(password);
}
@@ -46,8 +47,7 @@ public class PHPBB implements EncryptionMethod {
iteration_count_log2 = 8;
}
String output = "$H$";
output += itoa64.charAt(Math.min(iteration_count_log2
+ ((PHP_VERSION >= 5) ? 5 : 3), 30));
output += itoa64.charAt(Math.min(iteration_count_log2 + ((PHP_VERSION >= 5) ? 5 : 3), 30));
output += _hash_encode64(input, 6);
return output;
}
@@ -61,12 +61,16 @@ public class PHPBB implements EncryptionMethod {
do {
int value = input.charAt(i++);
output += itoa64.charAt(value & 0x3f);
if (i < count) value |= input.charAt(i) << 8;
if (i < count)
value |= input.charAt(i) << 8;
output += itoa64.charAt((value >> 6) & 0x3f);
if (i++ >= count) break;
if (i < count) value |= input.charAt(i) << 16;
if (i++ >= count)
break;
if (i < count)
value |= input.charAt(i) << 16;
output += itoa64.charAt((value >> 12) & 0x3f);
if (i++ >= count) break;
if (i++ >= count)
break;
output += itoa64.charAt((value >> 18) & 0x3f);
} while (i < count);
return output;
@@ -74,12 +78,15 @@ public class PHPBB implements EncryptionMethod {
String _hash_crypt_private(String password, String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$")) return output;
if (!setting.substring(0, 3).equals("$H$"))
return output;
int count_log2 = itoa64.indexOf(setting.charAt(3));
if (count_log2 < 7 || count_log2 > 30) return output;
if (count_log2 < 7 || count_log2 > 30)
return output;
int count = 1 << count_log2;
String salt = setting.substring(4, 12);
if (salt.length() != 8) return output;
if (salt.length() != 8)
return output;
String m1 = md5(salt + password);
String hash = pack(m1);
do {
@@ -91,8 +98,8 @@ public class PHPBB implements EncryptionMethod {
}
public boolean phpbb_check_hash(String password, String hash) {
if (hash.length() == 34) return _hash_crypt_private(password, hash)
.equals(hash);
if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash);
else return md5(password).equals(hash);
}
@@ -110,9 +117,11 @@ public class PHPBB implements EncryptionMethod {
}
static int hexToInt(char ch) {
if (ch >= '0' && ch <= '9') return ch - '0';
if (ch >= '0' && ch <= '9')
return ch - '0';
ch = Character.toUpperCase(ch);
if (ch >= 'A' && ch <= 'F') return ch - 'A' + 0xA;
if (ch >= 'A' && ch <= 'F')
return ch - 'A' + 0xA;
throw new IllegalArgumentException("Not a hex character: " + ch);
}
@@ -120,7 +129,8 @@ public class PHPBB implements EncryptionMethod {
StringBuffer r = new StringBuffer(32);
for (int i = 0; i < bytes.length; i++) {
String x = Integer.toHexString(bytes[i] & 0xff);
if (x.length() < 2) r.append("0");
if (x.length() < 2)
r.append("0");
r.append(x);
}
return r.toString();
@@ -20,8 +20,7 @@ public class PHPFUSION implements EncryptionMethod {
String algo = "HmacSHA256";
String keyString = getSHA1(salt);
try {
SecretKeySpec key = new SecretKeySpec(
(keyString).getBytes("UTF-8"), algo);
SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo);
Mac mac = Mac.getInstance(algo);
mac.init(key);
byte[] bytes = mac.doFinal(password.getBytes("ASCII"));
@@ -44,8 +43,7 @@ public class PHPFUSION implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, ""));
}
@@ -55,8 +53,7 @@ public class PHPFUSION implements EncryptionMethod {
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -20,8 +20,7 @@ public class ROYALAUTH implements EncryptionMethod {
byte byteData[] = md.digest();
StringBuilder sb = new StringBuilder();
for (byte aByteData : byteData)
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16)
.substring(1));
sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1));
return sb.toString();
}
@@ -17,8 +17,7 @@ public class SALTED2MD5 implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getMD5(getMD5(password) + salt));
}
@@ -28,7 +27,6 @@ public class SALTED2MD5 implements EncryptionMethod {
md5.reset();
md5.update(message.getBytes());
byte[] digest = md5.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -24,8 +24,7 @@ public class SHA1 implements EncryptionMethod {
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -25,8 +25,7 @@ public class SHA256 implements EncryptionMethod {
sha256.reset();
sha256.update(message.getBytes());
byte[] digest = sha256.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -24,7 +24,6 @@ public class SHA512 implements EncryptionMethod {
sha512.reset();
sha512.update(message.getBytes());
byte[] digest = sha512.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -24,7 +24,6 @@ public class SMF implements EncryptionMethod {
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -17,8 +17,7 @@ public class WBB3 implements EncryptionMethod {
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(getHash(password, salt, ""));
}
@@ -28,7 +27,6 @@ public class WBB3 implements EncryptionMethod {
sha1.reset();
sha1.update(message.getBytes());
byte[] digest = sha1.digest();
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(
1, digest));
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
}
}
@@ -84,22 +84,7 @@ public class WHIRLPOOL implements EncryptionMethod {
/**
* The substitution box.
*/
private static final String sbox = "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152"
+ "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57"
+ "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85"
+ "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8"
+ "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333"
+ "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0"
+ "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE"
+ "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d"
+ "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF"
+ "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A"
+ "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c"
+ "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04"
+ "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB"
+ "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9"
+ "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1"
+ "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
private static final String sbox = "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152" + "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57" + "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85" + "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8" + "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333" + "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0" + "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE" + "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d" + "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF" + "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A" + "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c" + "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04" + "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB" + "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9" + "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1" + "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";
private static long[][] C = new long[8][256];
private static long[] rc = new long[R + 1];
@@ -126,8 +111,7 @@ public class WHIRLPOOL implements EncryptionMethod {
* build the circulant table C[0][x] = S[x].[1, 1, 4, 1, 8, 5, 2,
* 9]:
*/
C[0][x] = (v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32)
| (v8 << 24) | (v5 << 16) | (v2 << 8) | (v9);
C[0][x] = (v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32) | (v8 << 24) | (v5 << 16) | (v2 << 8) | (v9);
/*
* build the remaining circulant tables C[t][x] = C[0][x] rotr t
*/
@@ -144,14 +128,7 @@ public class WHIRLPOOL implements EncryptionMethod {
*/
for (int r = 1; r <= R; r++) {
int i = 8 * (r - 1);
rc[r] = (C[0][i] & 0xff00000000000000L)
^ (C[1][i + 1] & 0x00ff000000000000L)
^ (C[2][i + 2] & 0x0000ff0000000000L)
^ (C[3][i + 3] & 0x000000ff00000000L)
^ (C[4][i + 4] & 0x00000000ff000000L)
^ (C[5][i + 5] & 0x0000000000ff0000L)
^ (C[6][i + 6] & 0x000000000000ff00L)
^ (C[7][i + 7] & 0x00000000000000ffL);
rc[r] = (C[0][i] & 0xff00000000000000L) ^ (C[1][i + 1] & 0x00ff000000000000L) ^ (C[2][i + 2] & 0x0000ff0000000000L) ^ (C[3][i + 3] & 0x000000ff00000000L) ^ (C[4][i + 4] & 0x00000000ff000000L) ^ (C[5][i + 5] & 0x0000000000ff0000L) ^ (C[6][i + 6] & 0x000000000000ff00L) ^ (C[7][i + 7] & 0x00000000000000ffL);
}
}
@@ -195,14 +172,7 @@ public class WHIRLPOOL implements EncryptionMethod {
* map the buffer to a block:
*/
for (int i = 0, j = 0; i < 8; i++, j += 8) {
block[i] = (((long) buffer[j]) << 56)
^ (((long) buffer[j + 1] & 0xffL) << 48)
^ (((long) buffer[j + 2] & 0xffL) << 40)
^ (((long) buffer[j + 3] & 0xffL) << 32)
^ (((long) buffer[j + 4] & 0xffL) << 24)
^ (((long) buffer[j + 5] & 0xffL) << 16)
^ (((long) buffer[j + 6] & 0xffL) << 8)
^ (((long) buffer[j + 7] & 0xffL));
block[i] = (((long) buffer[j]) << 56) ^ (((long) buffer[j + 1] & 0xffL) << 48) ^ (((long) buffer[j + 2] & 0xffL) << 40) ^ (((long) buffer[j + 3] & 0xffL) << 32) ^ (((long) buffer[j + 4] & 0xffL) << 24) ^ (((long) buffer[j + 5] & 0xffL) << 16) ^ (((long) buffer[j + 6] & 0xffL) << 8) ^ (((long) buffer[j + 7] & 0xffL));
}
/*
* compute and apply K^0 to the cipher state:
@@ -294,8 +264,7 @@ public class WHIRLPOOL implements EncryptionMethod {
while (sourceBits > 8) { // at least source[sourcePos] and
// source[sourcePos+1] contain data.
// take a byte from the source:
b = ((source[sourcePos] << sourceGap) & 0xff)
| ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap));
b = ((source[sourcePos] << sourceGap) & 0xff) | ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap));
if (b < 0 || b >= 256) {
throw new RuntimeException("LOGIC ERROR");
}
@@ -7,6 +7,7 @@ import java.security.SecureRandom;
import java.util.Arrays;
public class WORDPRESS implements EncryptionMethod {
private static String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private int iterationCountLog2 = 8;
private SecureRandom randomGen = new SecureRandom();
@@ -47,8 +48,7 @@ public class WORDPRESS implements EncryptionMethod {
private String crypt(String password, String setting) {
String output = "*0";
if (((setting.length() < 2) ? setting : setting.substring(0, 2))
.equalsIgnoreCase(output)) {
if (((setting.length() < 2) ? setting : setting.substring(0, 2)).equalsIgnoreCase(output)) {
output = "*1";
}
String id = (setting.length() < 3) ? setting : setting.substring(0, 3);
@@ -95,8 +95,7 @@ public class WORDPRESS implements EncryptionMethod {
try {
return string.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(
"This system doesn't support UTF-8!", e);
throw new UnsupportedOperationException("This system doesn't support UTF-8!", e);
}
}
@@ -8,16 +8,14 @@ public class XAUTH implements EncryptionMethod {
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
String hash = getWhirlpool(salt + password).toLowerCase();
int saltPos = (password.length() >= hash.length() ? hash.length() - 1
: password.length());
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
return hash.substring(0, saltPos) + salt + hash.substring(saltPos);
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
int saltPos = (password.length() >= hash.length() ? hash.length() - 1
: password.length());
int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
String salt = hash.substring(saltPos, saltPos + 12);
return hash.equals(getHash(password, salt, ""));
}
@@ -14,17 +14,14 @@ public class XF implements EncryptionMethod {
@Override
public String getHash(String password, String salt, String name)
throws NoSuchAlgorithmException {
return getSHA256(getSHA256(password)
+ regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt));
}
@Override
public boolean comparePassword(String hash, String password,
String playerName) throws NoSuchAlgorithmException {
String salt = AuthMe.getInstance().database.getAuth(playerName)
.getSalt();
return hash
.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
return hash.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt));
}
public String getSHA256(String password) throws NoSuchAlgorithmException {
@@ -33,8 +30,7 @@ public class XF implements EncryptionMethod {
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (byte element : byteData) {
sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(
1));
sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1));
}
StringBuffer hexString = new StringBuffer();
for (byte element : byteData) {
@@ -31,6 +31,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public class BinTools {
public static final String hex = "0123456789ABCDEF";
/**
@@ -101,9 +102,7 @@ public class BinTools {
if (c >= 'a' && c <= 'f') {
return (c - 'a' + 10);
}
throw new IllegalArgumentException(
"Input string may only contain hex digits, but found '" + c
+ "'");
throw new IllegalArgumentException("Input string may only contain hex digits, but found '" + c + "'");
}
public static void main(String[] args) {
@@ -42,6 +42,7 @@ import javax.crypto.spec.SecretKeySpec;
* @version 1.0
*/
public class MacBasedPRF implements PRF {
protected Mac mac;
protected int hLen;
@@ -32,6 +32,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public interface PBKDF2 {
/**
* Convert String-based input to internal byte array, then invoke PBKDF2.
* Desired key length defaults to Pseudo Random Function block size.
@@ -70,6 +70,7 @@ import java.security.SecureRandom;
* @version 1.0
*/
public class PBKDF2Engine implements PBKDF2 {
protected PBKDF2Parameters parameters;
protected PRF prf;
@@ -135,8 +136,7 @@ public class PBKDF2Engine implements PBKDF2 {
if (dkLen == 0) {
dkLen = prf.getHLen();
}
r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(),
dkLen);
r = PBKDF2(prf, parameters.getSalt(), parameters.getIterationCount(), dkLen);
return r;
}
@@ -337,8 +337,7 @@ public class PBKDF2Engine implements PBKDF2 {
byte[] salt = new byte[8];
sr.nextBytes(salt);
int iterations = 1000;
PBKDF2Parameters p = new PBKDF2Parameters("HmacSHA1", "ISO-8859-1",
salt, iterations);
PBKDF2Parameters p = new PBKDF2Parameters("HmacSHA1", "ISO-8859-1", salt, iterations);
PBKDF2Engine e = new PBKDF2Engine(p);
p.setDerivedKey(e.deriveKey(password));
candidate = formatter.toString(p);
@@ -349,9 +348,7 @@ public class PBKDF2Engine implements PBKDF2 {
p.setHashAlgorithm("HmacSHA1");
p.setHashCharset("ISO-8859-1");
if (formatter.fromString(p, candidate)) {
throw new IllegalArgumentException(
"Candidate data does not have correct format (\""
+ candidate + "\")");
throw new IllegalArgumentException("Candidate data does not have correct format (\"" + candidate + "\")");
}
PBKDF2Engine e = new PBKDF2Engine(p);
boolean verifyOK = e.verifyKey(password);
@@ -32,6 +32,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public interface PBKDF2Formatter {
/**
* Convert parameters to String.
*
@@ -32,6 +32,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public class PBKDF2HexFormatter implements PBKDF2Formatter {
public boolean fromString(PBKDF2Parameters p, String s) {
if (p == null || s == null) {
return true;
@@ -53,9 +54,7 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter {
}
public String toString(PBKDF2Parameters p) {
String s = BinTools.bin2hex(p.getSalt()) + ":"
+ String.valueOf(p.getIterationCount()) + ":"
+ BinTools.bin2hex(p.getDerivedKey());
String s = BinTools.bin2hex(p.getSalt()) + ":" + String.valueOf(p.getIterationCount()) + ":" + BinTools.bin2hex(p.getDerivedKey());
return s;
}
}
@@ -37,6 +37,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public class PBKDF2Parameters {
protected byte[] salt;
protected int iterationCount;
@@ -32,6 +32,7 @@ package fr.xephi.authme.security.pbkdf2;
* @version 1.0
*/
public interface PRF {
/**
* Initialize this instance with the user-supplied password.
*