Fix Java 9 support for Pbkdf2Django (#1390)

* Replace DatatypeConverter in Pbkdf2Django to support Java 9

* Fix NPE in AuthMeInitializer and CastException in Recovery tests

* Set logger for SetPasswordTest to prevent NPE on logging

* Use TestHelper for initializing ConsoleLogger
This commit is contained in:
games647 2017-10-29 12:11:24 +01:00 committed by ljacqu
parent d8d87c8b67
commit 316f8fc642
5 changed files with 15 additions and 7 deletions

View File

@ -6,7 +6,9 @@ addons:
- git
language: java
jdk: oraclejdk8
jdk:
- oraclejdk8
- oraclejdk9
before_script:
- "sudo git clone https://www.github.com/P-H-C/phc-winner-argon2.git argon2-src"

View File

@ -5,7 +5,7 @@ import de.rtner.security.auth.spi.PBKDF2Parameters;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.security.crypts.description.AsciiRestricted;
import javax.xml.bind.DatatypeConverter;
import java.util.Base64;
@AsciiRestricted
public class Pbkdf2Django extends HexSaltedMethod {
@ -18,7 +18,7 @@ public class Pbkdf2Django extends HexSaltedMethod {
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), DEFAULT_ITERATIONS);
PBKDF2Engine engine = new PBKDF2Engine(params);
return result + DatatypeConverter.printBase64Binary(engine.deriveKey(password, 32));
return result + Base64.getEncoder().encodeToString(engine.deriveKey(password, 32));
}
@Override
@ -35,7 +35,7 @@ public class Pbkdf2Django extends HexSaltedMethod {
return false;
}
String salt = line[2];
byte[] derivedKey = DatatypeConverter.parseBase64Binary(line[3]);
byte[] derivedKey = Base64.getDecoder().decode(line[3]);
PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), iterations, derivedKey);
PBKDF2Engine engine = new PBKDF2Engine(params);
return engine.verifyKey(password);

View File

@ -4,7 +4,6 @@ import ch.jalu.configme.resource.PropertyResource;
import ch.jalu.injector.Injector;
import ch.jalu.injector.InjectorBuilder;
import com.google.common.io.Files;
import fr.xephi.authme.api.NewAPI;
import fr.xephi.authme.api.v3.AuthMeApi;
import fr.xephi.authme.command.CommandHandler;
import fr.xephi.authme.datasource.DataSource;
@ -76,7 +75,7 @@ public class AuthMeInitializationTest {
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "config.test.yml"), settingsFile);
// Mock / wire various Bukkit components
given(server.getLogger()).willReturn(mock(Logger.class));
given(server.getLogger()).willReturn(Logger.getAnonymousLogger());
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
given(server.getPluginManager()).willReturn(pluginManager);

View File

@ -1,5 +1,6 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
@ -8,6 +9,7 @@ import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.PasswordRecoveryService;
import fr.xephi.authme.service.ValidationService;
import org.bukkit.entity.Player;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@ -45,6 +47,11 @@ public class SetPasswordCommandTest {
@Mock
private ValidationService validationService;
@BeforeClass
public static void setUpLogger() {
TestHelper.setupLogger();
}
@Test
public void shouldChangePassword() {
// given

View File

@ -125,7 +125,7 @@ public class RecoveryCodeServiceTest {
return ReflectionTestUtils.getFieldValue(RecoveryCodeService.class, recoveryCodeService, "recoveryCodes");
}
private ExpiringMap<String, String> getTriesCounter() {
private ExpiringMap<String, Integer> getTriesCounter() {
return ReflectionTestUtils.getFieldValue(RecoveryCodeService.class, recoveryCodeService, "playerTries");
}
}