mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
**Category:** new-feature **User Impact:** Mobile users must confirm with Face ID, biometrics, or their device passcode before sending their Buzz identity to Desktop. **Problem:** A signed-in phone could send its full identity, including the `nsec`, to a desktop without fresh local verification. **Solution:** Require OS device authentication before opening the identity-recovery scanner, retain that authorization only for the active pairing session and short pairing window, and require fresh authentication again if it expires before the identity payload is sent. Normal app opening, identity import, and community removal remain unchanged. ## Screencasts | Enable Face ID | Use Face ID | | --- | --- | |  |  | <details> <summary>File changes</summary> **Android and iOS integration** - `mobile/android/app/build.gradle.kts` declares the AppCompat dependency required by the biometric activity theme. - `mobile/android/app/src/main/kotlin/xyz/block/buzz/mobile/MainActivity.kt` uses the activity type required by the system authentication prompt. - `mobile/android/app/src/main/res/values/styles.xml` and `mobile/android/app/src/main/res/values-night/styles.xml` use the compatible launch theme. - `mobile/ios/Podfile.lock` records the native local-authentication dependency. - `mobile/ios/Runner/Info.plist` explains why Buzz requests Face ID access. **Identity policy and pairing flow** - `mobile/lib/shared/security/sensitive_action_authorizer.dart` wraps OS authentication and maps platform errors to stable app-level outcomes. - `mobile/lib/shared/community/community.dart` and `mobile/lib/shared/community/community_storage.dart` persist the sensitive-action policy. - `mobile/lib/features/invites/invite_join_provider.dart` assigns the explicit policy for invite-created communities. - `mobile/lib/features/pairing/pairing_provider.dart` gates export, binds grants to the active community/session, reauthenticates expired grants, and clears grants on every terminal path. - `mobile/lib/features/pairing/pairing_page.dart` lets users choose biometric protection while importing an identity. - `mobile/lib/features/settings/settings_page.dart` wires pairing into settings. - `mobile/lib/features/settings/settings_page/connection_section.dart` authenticates before opening export recovery and bounds the foreground-resume wait. - `mobile/pubspec.yaml` and `mobile/pubspec.lock` add and lock `local_auth`. **Coverage** - `mobile/test/shared/security/sensitive_action_authorizer_test.dart` covers native result mapping, unsupported devices, and single-flight behavior. - `mobile/test/shared/community/community_test.dart` and `mobile/test/shared/community/community_storage_test.dart` cover policy defaults and persistence. - `mobile/test/features/invites/invite_join_provider_test.dart` covers the invite policy. - `mobile/test/features/pairing/pairing_page_test.dart` covers import protection controls. - `mobile/test/features/pairing/pairing_provider_test.dart` covers export/import authorization, stale/reset/concurrent guards, malformed payload cleanup, and no-export failure paths. - `mobile/test/features/settings/connection_section_test.dart` covers the tap gate, lifecycle resume, and timeout behavior. </details> ## Reproduction steps 1. Pair an identity into the mobile app. 2. Open Settings and choose “Send identity to desktop.” 3. Verify Face ID, biometrics, or the device passcode is required before the recovery scanner opens. 4. Cancel device authentication and verify the scanner does not open and no identity transfer begins. 5. Authenticate, scan a Desktop recovery code, confirm the SAS, and verify the identity transfer completes. ## Validation At `be5620f5f10aa6cc16e86a4f01f102f3d9aeef9b`: - `cd mobile && ../bin/flutter analyze` — no issues - `cd mobile && ../bin/flutter test` — 1,368 tests passed - `cd mobile/android && JAVA_HOME=$(/usr/libexec/java_home -v 21) ./gradlew app:assembleDebug` — debug APK assembled successfully --------- Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
113 lines
3.5 KiB
Dart
113 lines
3.5 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
import 'community.dart';
|
|
|
|
class CommunityStorage {
|
|
static const _keyCommunities = 'buzz_communities';
|
|
static const _keyActiveId = 'buzz_active_community_id';
|
|
|
|
// Legacy keys for migration.
|
|
static const _legacyCommunities = 'buzz_workspaces';
|
|
static const _legacyActiveId = 'buzz_active_workspace_id';
|
|
static const _legacyRelayUrl = 'buzz_relay_url';
|
|
static const _legacyToken = 'buzz_token';
|
|
static const _legacyPubkey = 'buzz_pubkey';
|
|
static const _legacyNsec = 'buzz_nsec';
|
|
|
|
final FlutterSecureStorage _secure;
|
|
|
|
CommunityStorage({FlutterSecureStorage? secure})
|
|
: _secure = secure ?? const FlutterSecureStorage();
|
|
|
|
/// Load all communities. On first call, migrates legacy single-community
|
|
/// credentials if present.
|
|
Future<List<Community>> loadAll() async {
|
|
final raw = await _secure.read(key: _keyCommunities);
|
|
if (raw != null) return _decodeList(raw);
|
|
|
|
final legacyCommunities = await _secure.read(key: _legacyCommunities);
|
|
if (legacyCommunities != null) {
|
|
final communities = _decodeList(legacyCommunities);
|
|
await _saveList(communities);
|
|
final legacyActiveId = await _secure.read(key: _legacyActiveId);
|
|
if (legacyActiveId != null) await saveActiveId(legacyActiveId);
|
|
await _secure.delete(key: _legacyCommunities);
|
|
await _secure.delete(key: _legacyActiveId);
|
|
return communities;
|
|
}
|
|
|
|
// Migration: check for legacy single-community keys.
|
|
final legacyUrl = await _secure.read(key: _legacyRelayUrl);
|
|
final legacyToken = await _secure.read(key: _legacyToken);
|
|
if (legacyUrl != null && legacyToken != null) {
|
|
final legacyPubkey = await _secure.read(key: _legacyPubkey);
|
|
final legacyNsec = await _secure.read(key: _legacyNsec);
|
|
|
|
final name = Community.nameFromUrl(legacyUrl);
|
|
final community = Community.create(
|
|
name: name,
|
|
relayUrl: legacyUrl,
|
|
pubkey: legacyPubkey,
|
|
nsec: legacyNsec,
|
|
sensitiveActionPolicy: SensitiveActionPolicy.disabledByUser,
|
|
);
|
|
|
|
await _saveList([community]);
|
|
await saveActiveId(community.id);
|
|
|
|
// Delete legacy keys.
|
|
await _secure.delete(key: _legacyRelayUrl);
|
|
await _secure.delete(key: _legacyToken);
|
|
await _secure.delete(key: _legacyPubkey);
|
|
await _secure.delete(key: _legacyNsec);
|
|
|
|
return [community];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
Future<void> save(Community community) async {
|
|
final all = await loadAll();
|
|
final index = all.indexWhere((w) => w.id == community.id);
|
|
if (index >= 0) {
|
|
all[index] = community;
|
|
} else {
|
|
all.add(community);
|
|
}
|
|
await _saveList(all);
|
|
}
|
|
|
|
Future<void> remove(String id) async {
|
|
final all = await loadAll();
|
|
all.removeWhere((w) => w.id == id);
|
|
await _saveList(all);
|
|
}
|
|
|
|
Future<String?> loadActiveId() async {
|
|
return _secure.read(key: _keyActiveId);
|
|
}
|
|
|
|
Future<void> saveActiveId(String id) async {
|
|
await _secure.write(key: _keyActiveId, value: id);
|
|
}
|
|
|
|
Future<void> clearActiveId() async {
|
|
await _secure.delete(key: _keyActiveId);
|
|
}
|
|
|
|
List<Community> _decodeList(String raw) {
|
|
final list = jsonDecode(raw) as List<dynamic>;
|
|
return list
|
|
.map((entry) => Community.fromJson(entry as Map<String, dynamic>))
|
|
.toList();
|
|
}
|
|
|
|
Future<void> _saveList(List<Community> communities) async {
|
|
final json = jsonEncode(communities.map((item) => item.toJson()).toList());
|
|
await _secure.write(key: _keyCommunities, value: json);
|
|
}
|
|
}
|