fix: treat steam host same as totp with 5 digits
This commit is contained in:
parent
a6ee7ac2bd
commit
1418741229
2 changed files with 14 additions and 8 deletions
|
@ -2,6 +2,7 @@ import 'package:ente_auth/utils/totp_util.dart';
|
|||
|
||||
class Code {
|
||||
static const defaultDigits = 6;
|
||||
static const steamDigits = 5;
|
||||
static const defaultPeriod = 30;
|
||||
|
||||
int? generatedID;
|
||||
|
@ -67,10 +68,12 @@ class Code {
|
|||
String issuer,
|
||||
String secret,
|
||||
) {
|
||||
final digits =
|
||||
issuer.toLowerCase() == "steam" ? steamDigits : defaultDigits;
|
||||
return Code(
|
||||
account,
|
||||
issuer,
|
||||
defaultDigits,
|
||||
digits,
|
||||
defaultPeriod,
|
||||
secret,
|
||||
Algorithm.sha1,
|
||||
|
@ -82,10 +85,13 @@ class Code {
|
|||
|
||||
static Code fromRawData(String rawData) {
|
||||
Uri uri = Uri.parse(rawData);
|
||||
final issuer = _getIssuer(uri);
|
||||
final digits = issuer.toLowerCase() == "stream" ? 5 : _getDigits(uri);
|
||||
|
||||
try {
|
||||
return Code(
|
||||
_getAccount(uri),
|
||||
_getIssuer(uri),
|
||||
issuer,
|
||||
_getDigits(uri),
|
||||
_getPeriod(uri),
|
||||
getSanitizedSecret(uri.queryParameters['secret']!),
|
||||
|
@ -184,7 +190,7 @@ class Code {
|
|||
}
|
||||
|
||||
static Type _getType(Uri uri) {
|
||||
if (uri.host == "totp") {
|
||||
if (uri.host == "totp" || uri.host == "steam") {
|
||||
return Type.totp;
|
||||
} else if (uri.host == "hotp") {
|
||||
return Type.hotp;
|
||||
|
|
|
@ -3,13 +3,13 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:otp/otp.dart' as otp;
|
||||
|
||||
String getOTP(Code code) {
|
||||
if(code.type == Type.hotp) {
|
||||
if (code.type == Type.hotp) {
|
||||
return _getHOTPCode(code);
|
||||
}
|
||||
return otp.OTP.generateTOTPCodeString(
|
||||
getSanitizedSecret(code.secret),
|
||||
DateTime.now().millisecondsSinceEpoch,
|
||||
length: code.digits,
|
||||
length: code.issuer.toLowerCase() == "steam" ? 5 : code.digits,
|
||||
interval: code.period,
|
||||
algorithm: _getAlgorithm(code),
|
||||
isGoogle: true,
|
||||
|
@ -20,7 +20,7 @@ String _getHOTPCode(Code code) {
|
|||
return otp.OTP.generateHOTPCodeString(
|
||||
getSanitizedSecret(code.secret),
|
||||
code.counter,
|
||||
length: code.digits,
|
||||
length: code.issuer.toLowerCase() == "steam" ? 5 : code.digits,
|
||||
algorithm: _getAlgorithm(code),
|
||||
isGoogle: true,
|
||||
);
|
||||
|
@ -30,7 +30,7 @@ String getNextTotp(Code code) {
|
|||
return otp.OTP.generateTOTPCodeString(
|
||||
getSanitizedSecret(code.secret),
|
||||
DateTime.now().millisecondsSinceEpoch + code.period * 1000,
|
||||
length: code.digits,
|
||||
length: code.issuer.toLowerCase() == "stream" ? 5 : code.digits,
|
||||
interval: code.period,
|
||||
algorithm: _getAlgorithm(code),
|
||||
isGoogle: true,
|
||||
|
@ -60,4 +60,4 @@ String safeDecode(String value) {
|
|||
debugPrint("Failed to decode $e");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue