π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: treat steam host same as totp with 5 digits
Prateek Sunal1418741229c6
diff --git a/auth/lib/models/code.dart b/auth/lib/models/code.dartindex 7853eb19d0..ab50c2ddd7 100644--- a/auth/lib/models/code.dart+++ b/auth/lib/models/code.dart@@ -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;diff --git a/auth/lib/utils/totp_util.dart b/auth/lib/utils/totp_util.dartindex a494485249..eded634837 100644--- a/auth/lib/utils/totp_util.dart+++ b/auth/lib/utils/totp_util.dart@@ -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;}-}\ No newline at end of file+}