From d77f4af04b8c2b37b5efea695d2b8064bbc1357b Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 13 Sep 2024 09:17:49 +0530 Subject: [PATCH] [auth][mob] Allow sharing of codes --- auth/lib/ui/code_widget.dart | 2 -- auth/lib/ui/share/code_share.dart | 17 +++++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/auth/lib/ui/code_widget.dart b/auth/lib/ui/code_widget.dart index bb5b3dc221..ffdcdbfb80 100644 --- a/auth/lib/ui/code_widget.dart +++ b/auth/lib/ui/code_widget.dart @@ -1,7 +1,5 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; -import 'dart:math'; import 'dart:ui' as ui; import 'package:auto_size_text/auto_size_text.dart'; diff --git a/auth/lib/ui/share/code_share.dart b/auth/lib/ui/share/code_share.dart index 3d3b8e7f65..2e6875b0cd 100644 --- a/auth/lib/ui/share/code_share.dart +++ b/auth/lib/ui/share/code_share.dart @@ -88,7 +88,6 @@ class _ShareCodeDialogState extends State { onTap: () async { try { await shareCode(); - Navigator.of(context).pop(); } catch (e) { logger.warning('Failed to share code: ${e.toString()}'); @@ -111,32 +110,30 @@ class _ShareCodeDialogState extends State { Future shareCode() async { final result = generateFutureTotpCodes(widget.code, 30); - // show toast with total time taken Map data = { 'startTime': result.$1, 'step': widget.code.period, 'codes': result.$2.join(","), }; try { - // generated 128 bit crypto secure random key - final Uint8List key = generate256BitKey(); + final Uint8List key = _generate256BitKey(); Uint8List input = utf8.encode(jsonEncode(data)); - final encResult = CryptoUtil.encryptSync(input, key); + final encResult = await CryptoUtil.encryptData(input, key); String url = - 'https://auth.io/share?data=${uint8ListToUrlSafeBase64(encResult.encryptedData!)}&nonce=${uint8ListToUrlSafeBase64(encResult.nonce!)}#key=${uint8ListToUrlSafeBase64(key)}'; - logger.info('url: $url'); + 'https://auth.ente.io/share?data=${_uint8ListToUrlSafeBase64(encResult.encryptedData!)}&header=${_uint8ListToUrlSafeBase64(encResult.header!)}#${_uint8ListToUrlSafeBase64(key)}'; shareText(url, context: context).ignore(); } catch (e) { - logger.warning('Failed to encrypt data: ${e.toString()}'); + logger.severe('Failed to encrypt data: ${e.toString()}'); + await showGenericErrorDialog(context: context, error: e); } } - String uint8ListToUrlSafeBase64(Uint8List data) { + String _uint8ListToUrlSafeBase64(Uint8List data) { String base64Str = base64UrlEncode(data); return base64Str.replaceAll('=', ''); } - Uint8List generate256BitKey() { + Uint8List _generate256BitKey() { final random = Random.secure(); final bytes = Uint8List(32); // 32 bytes = 32 * 8 bits = 256 bits for (int i = 0; i < bytes.length; i++) {