Rename XF class into XFBCRYPT.

This commit is contained in:
DNx5 2016-01-07 06:15:39 +07:00
parent 781a005c25
commit da5de58afb
6 changed files with 20 additions and 28 deletions

View File

@ -7,7 +7,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.security.crypts.XF; import fr.xephi.authme.security.crypts.XFBCRYPT;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.StringUtils;
@ -300,14 +300,14 @@ public class MySQL implements DataSource {
.build(); .build();
rs.close(); rs.close();
pst.close(); pst.close();
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;"); pst = con.prepareStatement("SELECT data FROM xf_user_authenticate WHERE " + columnID + "=?;");
pst.setInt(1, id); pst.setInt(1, id);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
Blob blob = rs.getBlob("data"); Blob blob = rs.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setPassword(new HashedPassword(XF.getHashFromBlob(bytes))); pAuth.setPassword(new HashedPassword(XFBCRYPT.getHashFromBlob(bytes)));
} }
} }
} catch (SQLException ex) { } catch (SQLException ex) {
@ -490,7 +490,7 @@ public class MySQL implements DataSource {
} }
rs.close(); rs.close();
pst.close(); pst.close();
} else if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { } else if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
pst = con.prepareStatement("SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
rs = pst.executeQuery(); rs = pst.executeQuery();
@ -544,7 +544,7 @@ public class MySQL implements DataSource {
} }
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
String sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"; String sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, user); pst.setString(1, user);
@ -641,7 +641,7 @@ public class MySQL implements DataSource {
try (Connection con = getConnection()) { try (Connection con = getConnection()) {
String sql; String sql;
PreparedStatement pst; PreparedStatement pst;
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;"; sql = "SELECT " + columnID + " FROM " + tableName + " WHERE " + columnName + "=?;";
pst = con.prepareStatement(sql); pst = con.prepareStatement(sql);
pst.setString(1, user); pst.setString(1, user);
@ -942,14 +942,14 @@ public class MySQL implements DataSource {
.groupId(group) .groupId(group)
.build(); .build();
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
int id = rs.getInt(columnID); int id = rs.getInt(columnID);
pst.setInt(1, id); pst.setInt(1, id);
ResultSet rs2 = pst.executeQuery(); ResultSet rs2 = pst.executeQuery();
if (rs2.next()) { if (rs2.next()) {
Blob blob = rs2.getBlob("data"); Blob blob = rs2.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setPassword(new HashedPassword(XF.getHashFromBlob(bytes))); pAuth.setPassword(new HashedPassword(XFBCRYPT.getHashFromBlob(bytes)));
} }
rs2.close(); rs2.close();
} }
@ -989,14 +989,14 @@ public class MySQL implements DataSource {
.groupId(group) .groupId(group)
.build(); .build();
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XFBCRYPT) {
int id = rs.getInt(columnID); int id = rs.getInt(columnID);
pst.setInt(1, id); pst.setInt(1, id);
ResultSet rs2 = pst.executeQuery(); ResultSet rs2 = pst.executeQuery();
if (rs2.next()) { if (rs2.next()) {
Blob blob = rs2.getBlob("data"); Blob blob = rs2.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setPassword(new HashedPassword(XF.getHashFromBlob(bytes))); pAuth.setPassword(new HashedPassword(XFBCRYPT.getHashFromBlob(bytes)));
} }
rs2.close(); rs2.close();
} }

View File

@ -35,7 +35,7 @@ public enum HashAlgorithm {
WHIRLPOOL(fr.xephi.authme.security.crypts.WHIRLPOOL.class), WHIRLPOOL(fr.xephi.authme.security.crypts.WHIRLPOOL.class),
WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class), WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class),
XAUTH(fr.xephi.authme.security.crypts.XAUTH.class), XAUTH(fr.xephi.authme.security.crypts.XAUTH.class),
XENFORO(fr.xephi.authme.security.crypts.XF.class), XFBCRYPT(fr.xephi.authme.security.crypts.XFBCRYPT.class),
CUSTOM(null); CUSTOM(null);
private final Class<? extends EncryptionMethod> clazz; private final Class<? extends EncryptionMethod> clazz;

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.security.crypts;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class XF extends BCRYPT { public class XFBCRYPT extends BCRYPT {
private static final Pattern HASH_PATTERN = Pattern.compile("\"hash\";s.*\"(.*)?\""); private static final Pattern HASH_PATTERN = Pattern.compile("\"hash\";s.*\"(.*)?\"");
@Override @Override

View File

@ -515,11 +515,6 @@ public final class Settings {
set("Xenoforo.predefinedSalt", null); set("Xenoforo.predefinedSalt", null);
changes = true; changes = true;
} }
if (configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA1") ||
configFile.getString("settings.security.passwordHash", "SHA256").toUpperCase().equals("XFSHA256")) {
set("settings.security.passwordHash", "XENFORO");
changes = true;
}
if (!contains("Protection.enableProtection")) { if (!contains("Protection.enableProtection")) {
set("Protection.enableProtection", false); set("Protection.enableProtection", false);
changes = true; changes = true;
@ -528,10 +523,6 @@ public final class Settings {
set("settings.restrictions.removeSpeed", true); set("settings.restrictions.removeSpeed", true);
changes = true; changes = true;
} }
if (!contains("DataSource.mySQLMaxConections")) {
set("DataSource.mySQLMaxConections", 25);
changes = true;
}
if (!contains("Protection.countries")) { if (!contains("Protection.countries")) {
countries = new ArrayList<>(); countries = new ArrayList<>();
countries.add("US"); countries.add("US");
@ -741,6 +732,7 @@ public final class Settings {
} }
if (changes) { if (changes) {
save();
plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me"); plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me");
plugin.getLogger().warning("Please check your config.yml file for new configs!"); plugin.getLogger().warning("Please check your config.yml file for new configs!");
} }

View File

@ -48,8 +48,8 @@ public class HashAlgorithmIntegrationTest {
// given / when / then // given / when / then
for (HashAlgorithm algorithm : HashAlgorithm.values()) { for (HashAlgorithm algorithm : HashAlgorithm.values()) {
// TODO #137: Remove this check // TODO #137: Remove this check
if (HashAlgorithm.XENFORO.equals(algorithm)) { if (HashAlgorithm.XFBCRYPT.equals(algorithm)) {
System.out.println("Note: Currently skipping XENFORO hash (TODO #137: Fix it)"); System.out.println("Note: Currently skipping XFBCRYPT hash (TODO #137: Fix it)");
continue; continue;
} }

View File

@ -4,16 +4,16 @@ import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
/** /**
* Test for {@link XF}. * Test for {@link XFBCRYPT}.
*/ */
@Ignore @Ignore
// TODO #137: Create a test class as for the other encryption methods. Simply run the following test and copy the // TODO #137: Create a test class as for the other encryption methods. Simply run the following test and copy the
// output -- that's your test class! (Once XF.java actually works properly) // output -- that's your test class! (Once XFBCRYPT.java actually works properly)
// @org.junit.Test public void a() { AbstractEncryptionMethodTest.generateTest(new XF()); } // @org.junit.Test public void a() { AbstractEncryptionMethodTest.generateTest(new XFBCRYPT()); }
public class XFTest { public class XFBCRYPTTest {
@Test @Test
public void shouldComputeHash() { public void shouldComputeHash() {
System.out.println(new XF().computeHash("Test", "name")); System.out.println(new XFBCRYPT().computeHash("Test", "name"));
} }
} }