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>
178 lines
5.3 KiB
Dart
178 lines
5.3 KiB
Dart
part of '../settings_page.dart';
|
|
|
|
class _ConnectionSection extends ConsumerWidget {
|
|
const _ConnectionSection({required this.identityRecoveryPageBuilder});
|
|
|
|
final WidgetBuilder identityRecoveryPageBuilder;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final config = ref.watch(relayConfigProvider);
|
|
final authState = ref.watch(authProvider).value;
|
|
final nsec = config.nsec;
|
|
final community = authState?.community;
|
|
|
|
return AppListCard(
|
|
label: 'Connection',
|
|
children: [
|
|
AppListRow(
|
|
icon: LucideIcons.server,
|
|
title: 'Connected to',
|
|
subtitle: config.baseUrl,
|
|
),
|
|
if (nsec != null && nsec.isNotEmpty && community != null) ...[
|
|
_IdentityRow(nsec: nsec),
|
|
AppListRow(
|
|
icon: LucideIcons.scanQrCode,
|
|
title: 'Send identity to desktop',
|
|
subtitle: 'Scan a recovery code shown by Buzz Desktop',
|
|
trailing: const _RowChevron(),
|
|
onTap: () async {
|
|
final pairing = ref.read(pairingProvider.notifier);
|
|
final authorized = await pairing.authorizeIdentityExport(
|
|
community: community,
|
|
);
|
|
if (!authorized) {
|
|
if (!context.mounted) return;
|
|
final message = ref.read(pairingProvider).errorMessage;
|
|
if (message != null) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text(message)));
|
|
}
|
|
return;
|
|
}
|
|
|
|
try {
|
|
if (!context.mounted) return;
|
|
final resumed = await _waitForResumedFrame();
|
|
if (!resumed) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text(
|
|
'Buzz did not return to the foreground. Try again.',
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
if (!context.mounted) return;
|
|
await Navigator.of(context).push(
|
|
MaterialPageRoute<void>(builder: identityRecoveryPageBuilder),
|
|
);
|
|
} finally {
|
|
pairing.reset();
|
|
}
|
|
},
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
const _resumeWaitTimeout = Duration(seconds: 5);
|
|
|
|
Future<bool> _waitForResumedFrame() async {
|
|
final binding = WidgetsBinding.instance;
|
|
if (binding.lifecycleState != AppLifecycleState.resumed) {
|
|
final resumed = Completer<void>();
|
|
final listener = AppLifecycleListener(
|
|
onResume: () {
|
|
if (!resumed.isCompleted) resumed.complete();
|
|
},
|
|
);
|
|
try {
|
|
await resumed.future.timeout(_resumeWaitTimeout);
|
|
} on TimeoutException {
|
|
return false;
|
|
} finally {
|
|
listener.dispose();
|
|
}
|
|
}
|
|
await binding.endOfFrame;
|
|
return true;
|
|
}
|
|
|
|
/// Destructive, so it gets a container of its own rather than sitting at the
|
|
/// bottom of the connection group.
|
|
class _RemoveCommunitySection extends ConsumerWidget {
|
|
const _RemoveCommunitySection();
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
return AppListCard(
|
|
children: [
|
|
AppListRow(
|
|
icon: LucideIcons.logOut,
|
|
title: 'Remove community',
|
|
titleColor: context.colors.error,
|
|
onTap: () => _confirmRemoveCommunity(context, ref),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _IdentityRow extends StatelessWidget {
|
|
const _IdentityRow({required this.nsec});
|
|
|
|
final String nsec;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final privHex = nostr.Nip19.decode(payload: nsec).data;
|
|
final pubkey = privHex.isNotEmpty ? nostr.Keys(privHex).public : 'unknown';
|
|
|
|
return AppListRow(
|
|
icon: LucideIcons.key,
|
|
title: 'Identity (pubkey)',
|
|
subtitle: pubkey,
|
|
subtitleStyle: context.textTheme.bodySmall?.copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
fontFamily: 'GeistMono',
|
|
fontSize: 11,
|
|
),
|
|
subtitleMaxLines: 2,
|
|
trailing: IconButton(
|
|
icon: const Icon(LucideIcons.copy, size: 16),
|
|
onPressed: () async {
|
|
await copyToClipboard(context, pubkey, message: 'Pubkey copied');
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
void _confirmRemoveCommunity(BuildContext context, WidgetRef ref) {
|
|
showBuzzDialog<void>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Remove Community'),
|
|
content: const Text(
|
|
'This will disconnect this community. You will need '
|
|
'to scan a new pairing code to reconnect.',
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(ctx).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop(); // close dialog
|
|
// Pop all pushed routes back to root so MaterialApp.home rebuilds
|
|
// to PairingPage when auth state changes.
|
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
|
ref.read(authProvider.notifier).signOut();
|
|
},
|
|
style: FilledButton.styleFrom(backgroundColor: ctx.colors.error),
|
|
child: const Text('Remove'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|