Removed redundant code, fixed some warnings, other minor fixes
This commit is contained in:
parent
82bf0f45ca
commit
09067ddbd1
@ -157,10 +157,7 @@ public class API {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
|
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0, "your@email.com", playerName);
|
||||||
if (!instance.database.saveAuth(auth)) {
|
return instance.database.saveAuth(auth);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -744,9 +744,10 @@ public class FlatFile implements DataSource {
|
|||||||
for (String l : lines) {
|
for (String l : lines) {
|
||||||
bw.write(l + "\n");
|
bw.write(l + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
|
||||||
} finally {
|
} finally {
|
||||||
if (br != null) {
|
if (br != null) {
|
||||||
try {
|
try {
|
||||||
@ -761,7 +762,6 @@ public class FlatFile implements DataSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import fr.xephi.authme.security.pbkdf2.PBKDF2Engine;
|
|||||||
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
|
import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@ -25,7 +26,7 @@ public class CryptPBKDF2 implements EncryptionMethod {
|
|||||||
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
|
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000);
|
||||||
PBKDF2Engine engine = new PBKDF2Engine(params);
|
PBKDF2Engine engine = new PBKDF2Engine(params);
|
||||||
|
|
||||||
return result + String.valueOf(engine.deriveKey(password, 64));
|
return result + Arrays.toString(engine.deriveKey(password, 64));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -41,7 +41,7 @@ public interface PBKDF2 {
|
|||||||
*
|
*
|
||||||
* @return internal byte array
|
* @return internal byte array
|
||||||
*/
|
*/
|
||||||
public abstract byte[] deriveKey(String inputPassword);
|
byte[] deriveKey(String inputPassword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert String-based input to internal byte array, then invoke PBKDF2.
|
* Convert String-based input to internal byte array, then invoke PBKDF2.
|
||||||
@ -51,7 +51,7 @@ public interface PBKDF2 {
|
|||||||
*
|
*
|
||||||
* @return internal byte array
|
* @return internal byte array
|
||||||
*/
|
*/
|
||||||
public abstract byte[] deriveKey(String inputPassword, int dkLen);
|
byte[] deriveKey(String inputPassword, int dkLen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert String-based input to internal byte arrays, then invoke PBKDF2
|
* Convert String-based input to internal byte arrays, then invoke PBKDF2
|
||||||
@ -63,28 +63,28 @@ public interface PBKDF2 {
|
|||||||
* @return <code>true</code> password match; <code>false</code> incorrect
|
* @return <code>true</code> password match; <code>false</code> incorrect
|
||||||
* password
|
* password
|
||||||
*/
|
*/
|
||||||
public abstract boolean verifyKey(String inputPassword);
|
boolean verifyKey(String inputPassword);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow reading of configured parameters.
|
* Allow reading of configured parameters.
|
||||||
*
|
*
|
||||||
* @return Currently set parameters.
|
* @return Currently set parameters.
|
||||||
*/
|
*/
|
||||||
public abstract PBKDF2Parameters getParameters();
|
PBKDF2Parameters getParameters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow setting of configured parameters.
|
* Allow setting of configured parameters.
|
||||||
*
|
*
|
||||||
* @param parameters
|
* @param parameters
|
||||||
*/
|
*/
|
||||||
public abstract void setParameters(PBKDF2Parameters parameters);
|
void setParameters(PBKDF2Parameters parameters);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get currently set Pseudo Random Function.
|
* Get currently set Pseudo Random Function.
|
||||||
*
|
*
|
||||||
* @return Currently set Pseudo Random Function
|
* @return Currently set Pseudo Random Function
|
||||||
*/
|
*/
|
||||||
public abstract PRF getPseudoRandomFunction();
|
PRF getPseudoRandomFunction();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Pseudo Random Function to use. Note that deriveKeys/getPRF does
|
* Set the Pseudo Random Function to use. Note that deriveKeys/getPRF does
|
||||||
@ -93,5 +93,5 @@ public interface PBKDF2 {
|
|||||||
*
|
*
|
||||||
* @param prf Pseudo Random Function to set.
|
* @param prf Pseudo Random Function to set.
|
||||||
*/
|
*/
|
||||||
public abstract void setPseudoRandomFunction(PRF prf);
|
void setPseudoRandomFunction(PRF prf);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public interface PBKDF2Formatter {
|
|||||||
*
|
*
|
||||||
* @return String representation
|
* @return String representation
|
||||||
*/
|
*/
|
||||||
public abstract String toString(PBKDF2Parameters p);
|
String toString(PBKDF2Parameters p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert String to parameters. Depending on actual implementation, it may
|
* Convert String to parameters. Depending on actual implementation, it may
|
||||||
@ -52,5 +52,5 @@ public interface PBKDF2Formatter {
|
|||||||
* @return <code>false</code> syntax OK, <code>true</code> some syntax
|
* @return <code>false</code> syntax OK, <code>true</code> some syntax
|
||||||
* issue.
|
* issue.
|
||||||
*/
|
*/
|
||||||
public abstract boolean fromString(PBKDF2Parameters p, String s);
|
boolean fromString(PBKDF2Parameters p, String s);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class PBKDF2HexFormatter implements PBKDF2Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String[] p123 = s.split(":");
|
String[] p123 = s.split(":");
|
||||||
if (p123 == null || p123.length != 3) {
|
if (p123.length != 3) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public interface PRF {
|
|||||||
* @param P The password supplied as array of bytes. It is the caller's
|
* @param P The password supplied as array of bytes. It is the caller's
|
||||||
* task to convert String passwords to bytes as appropriate.
|
* task to convert String passwords to bytes as appropriate.
|
||||||
*/
|
*/
|
||||||
public void init(byte[] P);
|
void init(byte[] P);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pseudo Random Function
|
* Pseudo Random Function
|
||||||
@ -49,12 +49,12 @@ public interface PRF {
|
|||||||
*
|
*
|
||||||
* @return Random bytes of hLen length.
|
* @return Random bytes of hLen length.
|
||||||
*/
|
*/
|
||||||
public byte[] doFinal(byte[] M);
|
byte[] doFinal(byte[] M);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query block size of underlying algorithm/mechanism.
|
* Query block size of underlying algorithm/mechanism.
|
||||||
*
|
*
|
||||||
* @return block size
|
* @return block size
|
||||||
*/
|
*/
|
||||||
public int getHLen();
|
int getHLen();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -268,6 +268,7 @@ public final class Utils {
|
|||||||
if (target.isDirectory()) {
|
if (target.isDirectory()) {
|
||||||
purgeDirectory(target);
|
purgeDirectory(target);
|
||||||
}
|
}
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
target.delete();
|
target.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,15 +25,12 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class UtilsTest {
|
public class UtilsTest {
|
||||||
|
|
||||||
private AuthMe authMeMock;
|
|
||||||
private PermissionsManager permissionsManagerMock;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUpMocks() {
|
public void setUpMocks() {
|
||||||
AuthMeMockUtil.mockAuthMeInstance();
|
AuthMeMockUtil.mockAuthMeInstance();
|
||||||
authMeMock = AuthMe.getInstance();
|
AuthMe authMeMock = AuthMe.getInstance();
|
||||||
|
|
||||||
permissionsManagerMock = mock(PermissionsManager.class);
|
PermissionsManager permissionsManagerMock = mock(PermissionsManager.class);
|
||||||
when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock);
|
when(authMeMock.getPermissionsManager()).thenReturn(permissionsManagerMock);
|
||||||
|
|
||||||
Server serverMock = mock(Server.class);
|
Server serverMock = mock(Server.class);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user