Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix(auth): support stream codes completely

Prateek Sunald104fc67882e
diff --git a/auth/lib/utils/totp_util.dart b/auth/lib/utils/totp_util.dart
index 0d6a8bd68f..d0076ed41f 100644
--- a/auth/lib/utils/totp_util.dart
+++ b/auth/lib/utils/totp_util.dart
@@ -1,8 +1,12 @@
import 'package:ente_auth/models/code.dart';
import 'package:flutter/foundation.dart';
import 'package:otp/otp.dart' as otp;
+import 'package:steam_totp/steam_totp.dart';
String getOTP(Code code) {
+ if (code.issuer.toLowerCase() == 'steam') {
+ return _getSteamCode(code);
+ }
if (code.type == Type.hotp) {
return _getHOTPCode(code);
}
@@ -26,7 +30,18 @@ String _getHOTPCode(Code code) {
);
}
+String _getSteamCode(Code code, [bool isNext = false]) {
+ final SteamTOTP steamtotp = SteamTOTP(secret: code.secret);
+
+ return steamtotp.generate(
+ DateTime.now().millisecondsSinceEpoch ~/ 1000 + (isNext ? code.period : 0),
+ );
+}
+
String getNextTotp(Code code) {
+ if (code.issuer.toLowerCase() == 'steam') {
+ return _getSteamCode(code, true);
+ }
return otp.OTP.generateTOTPCodeString(
getSanitizedSecret(code.secret),
DateTime.now().millisecondsSinceEpoch + code.period * 1000,
diff --git a/auth/pubspec.lock b/auth/pubspec.lock
index a47858d533..b3a643b0be 100644
--- a/auth/pubspec.lock
+++ b/auth/pubspec.lock
@@ -745,6 +745,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
+ hashlib:
+ dependency: transitive
+ description:
+ name: hashlib
+ sha256: "67e640e19cc33070113acab3125cd48ebe480a0300e15554dec089b8878a729f"
+ url: "https://pub.dev"
+ source: hosted
+ version: "1.16.0"
+ hashlib_codecs:
+ dependency: transitive
+ description:
+ name: hashlib_codecs
+ sha256: "49e2a471f74b15f1854263e58c2ac11f2b631b5b12c836f9708a35397d36d626"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.2.0"
hex:
dependency: transitive
description:
@@ -1439,6 +1455,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.1"
+ steam_totp:
+ dependency: "direct main"
+ description:
+ name: steam_totp
+ sha256: "3c09143c983f6bb05bb53e9232f9d40bbcc01c596ba0273c3e6bb246729abfa1"
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.0.1"
step_progress_indicator:
dependency: "direct main"
description:
diff --git a/auth/pubspec.yaml b/auth/pubspec.yaml
index d58648b7fd..0941b60711 100644
--- a/auth/pubspec.yaml
+++ b/auth/pubspec.yaml
@@ -94,6 +94,7 @@ dependencies:
sqflite_common_ffi: ^2.3.0+4
sqlite3: ^2.1.0
sqlite3_flutter_libs: ^0.5.19+1
+ steam_totp: ^0.0.1
step_progress_indicator: ^1.0.2
styled_text: ^8.1.0
tray_manager: ^0.2.1