#1141 Fix review remarks by @games647

- Use SHA512 to generate keys instead of default SHA1
- Declare google authenticator dependency as optional and add relocation rule
This commit is contained in:
ljacqu
2018-04-03 00:12:25 +02:00
parent 2bf78dd186
commit 9326094d9c
4 changed files with 34 additions and 19 deletions
@@ -197,7 +197,7 @@ public enum MessageKey {
/** Your secret code is %code. You can scan it from here %url */
TWO_FACTOR_CREATE("two_factor.code_created", "%code", "%url"),
/** Please submit your two-factor authentication code with /2fa code &ltcode>. */
/** Please submit your two-factor authentication code with /2fa code <code>. */
TWO_FACTOR_CODE_REQUIRED("two_factor.code_required"),
/** Two-factor authentication is already enabled for your account! */
@@ -1,9 +1,11 @@
package fr.xephi.authme.security.totp;
import com.google.common.annotations.VisibleForTesting;
import com.warrenstrange.googleauth.GoogleAuthenticator;
import com.warrenstrange.googleauth.GoogleAuthenticatorConfig;
import com.warrenstrange.googleauth.GoogleAuthenticatorConfig.GoogleAuthenticatorConfigBuilder;
import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator;
import com.warrenstrange.googleauth.HmacHashFunction;
import com.warrenstrange.googleauth.IGoogleAuthenticator;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.entity.Player;
@@ -18,16 +20,20 @@ public class TotpAuthenticator {
private final IGoogleAuthenticator authenticator;
private final BukkitService bukkitService;
@Inject
TotpAuthenticator(BukkitService bukkitService) {
this(new GoogleAuthenticator(), bukkitService);
this.authenticator = createGoogleAuthenticator();
this.bukkitService = bukkitService;
}
@VisibleForTesting
TotpAuthenticator(IGoogleAuthenticator authenticator, BukkitService bukkitService) {
this.authenticator = authenticator;
this.bukkitService = bukkitService;
/**
* @return new Google Authenticator instance
*/
protected IGoogleAuthenticator createGoogleAuthenticator() {
GoogleAuthenticatorConfig config = new GoogleAuthenticatorConfigBuilder()
.setHmacHashFunction(HmacHashFunction.HmacSHA512)
.build();
return new GoogleAuthenticator(config);
}
/**