Skip to content

Commit

Permalink
[AegisImport] Fix Steam code import & parse groups and fav flag (#1972)
Browse files Browse the repository at this point in the history
## Description

## Tests
Tested locally
  • Loading branch information
ua741 authored Jun 3, 2024
2 parents 81c2a5c + d6b6e69 commit 493153d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions auth/lib/ui/settings/data/import/aegis_import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/models/code.dart';
import 'package:ente_auth/models/code_display.dart';
import 'package:ente_auth/services/authenticator_service.dart';
import 'package:ente_auth/store/code_store.dart';
import 'package:ente_auth/ui/common/progress_dialog.dart';
Expand Down Expand Up @@ -126,8 +127,19 @@ Future<int?> _processAegisExportFile(
} else {
aegisDB = decodedJson['db'];
}
final Map<String, String> groupIDToName = {};
try {
for (var item in aegisDB?['groups']) {
groupIDToName[item['uuid']] = item['name'];
}
} catch (e) {
Logger("AegisImport").warning("Failed to parse groups", e);
}

final parsedCodes = [];
for (var item in aegisDB?['entries']) {
bool isFavorite = item['favorite'] ?? false;
List<String> tags = [];
var kind = item['type'];
var account = item['name'];
var issuer = item['issuer'];
Expand All @@ -137,11 +149,15 @@ Future<int?> _processAegisExportFile(
var digits = item['info']['digits'];

var counter = item['info']['counter'];

for (var group in item['groups']) {
if (groupIDToName.containsKey(group)) {
tags.add(groupIDToName[group]!);
}
}
// Build the OTP URL
String otpUrl;

if (kind.toLowerCase() == 'totp') {
if (kind.toLowerCase() == 'totp' || kind.toLowerCase() == 'steam') {
otpUrl =
'otpauth://$kind/$issuer:$account?secret=$secret&issuer=$issuer&algorithm=$algorithm&digits=$digits&period=$timer';
} else if (kind.toLowerCase() == 'hotp') {
Expand All @@ -150,7 +166,10 @@ Future<int?> _processAegisExportFile(
} else {
throw Exception('Invalid OTP type: $kind');
}
parsedCodes.add(Code.fromOTPAuthUrl(otpUrl));

Code code = Code.fromOTPAuthUrl(otpUrl);
code = code.copyWith(display: CodeDisplay(pinned: isFavorite, tags: tags));
parsedCodes.add(code);
}

for (final code in parsedCodes) {
Expand Down
2 changes: 1 addition & 1 deletion auth/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ente_auth
description: ente two-factor authenticator
version: 3.0.5+305
version: 3.0.6+306
publish_to: none

environment:
Expand Down

0 comments on commit 493153d

Please sign in to comment.