#1141 2FA implementation fixes

- Merge TotpService into TotpAuthenticator
- Add missing tests
- Migrate old 2fa enabled key to new one
This commit is contained in:
ljacqu
2018-05-01 22:49:07 +02:00
parent 29ac3a7022
commit 1e3ed795c1
13 changed files with 356 additions and 79 deletions
@@ -4,13 +4,14 @@ import com.warrenstrange.googleauth.GoogleAuthenticator;
import com.warrenstrange.googleauth.GoogleAuthenticatorKey;
import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator;
import com.warrenstrange.googleauth.IGoogleAuthenticator;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.entity.Player;
import javax.inject.Inject;
/**
* Provides rudimentary TOTP functions (wraps third-party TOTP implementation).
* Provides TOTP functions (wrapping a third-party TOTP implementation).
*/
public class TotpAuthenticator {
@@ -30,6 +31,10 @@ public class TotpAuthenticator {
return new GoogleAuthenticator();
}
public boolean checkCode(PlayerAuth auth, String totpCode) {
return checkCode(auth.getTotpKey(), totpCode);
}
/**
* Returns whether the given input code matches for the provided TOTP key.
*
@@ -58,7 +63,7 @@ public class TotpAuthenticator {
private final String totpKey;
private final String authenticatorQrCodeUrl;
TotpGenerationResult(String totpKey, String authenticatorQrCodeUrl) {
public TotpGenerationResult(String totpKey, String authenticatorQrCodeUrl) {
this.totpKey = totpKey;
this.authenticatorQrCodeUrl = authenticatorQrCodeUrl;
}
@@ -1,18 +0,0 @@
package fr.xephi.authme.security.totp;
import fr.xephi.authme.data.auth.PlayerAuth;
import javax.inject.Inject;
/**
* Service for TOTP actions.
*/
public class TotpService {
@Inject
private TotpAuthenticator totpAuthenticator;
public boolean verifyCode(PlayerAuth auth, String totpCode) {
return totpAuthenticator.checkCode(auth.getTotpKey(), totpCode);
}
}