Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Nov 1, 2023
1 parent 7a0ee58 commit ba4a76c
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 125 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ android {
defaultConfig {
applicationId "com.keevault.keevault"
applicationIdSuffix idSuffix
minSdkVersion 26
minSdkVersion 29
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.8.0'
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
Expand Down
31 changes: 17 additions & 14 deletions lib/logging/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import 'package:logger/logger.dart';
import 'package:logger_flutter/logger_flutter.dart';
import 'package:logging/logging.dart' as logging;

class KeeVaultLogOutput extends LogOutput {
@override
void output(OutputEvent event) {
assert(() {
// ignore: avoid_print
event.lines.forEach(print);
return true;
}());
LogConsole.add(event, bufferSize: 1000);
}
}
// class KeeVaultLogOutput extends LogOutput {
// @override
// void output(OutputEvent event) {
// assert(() {
// // ignore: avoid_print
// event.lines.forEach(print);
// return true;
// }());
// LogConsole.add(event, bufferSize: 1000);
// }
// }

Logger getLogger() {
return Logger(
printer: SimplePrinter(printTime: false, colors: false),
output: KeeVaultLogOutput(),
final lg = Logger(
printer: SimplePrinter(printTime: true, colors: false),
//output: KeeVaultLogOutput(),
output: ConsoleOutput(),
filter: ProductionFilter(),
);
LogConsole.init(bufferSize: 1000);
return lg;
}

final l = getLogger();
Expand Down
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ void main() async {
},
(dynamic error, StackTrace stackTrace) {
if (error is KeeLoginFailedMITMException) {
l.wtf('MITM attack detected!', error, stackTrace);
l.wtf('MITM attack detected!', error: error, stackTrace: stackTrace);
navigatorKey.currentState?.overlay?.context.let((context) {
var message =
'Sign in failed because the response we received from the server indicates that it may be compromised. The most likely explanation is that someone near you or at your internet service provider is attempting to interfere with the secure connection and connect you to a malicious server (A Miscreant In The Middle attack). Find a different internet connection immediately, shut down the Kee Vault app and then try again. If it keeps happening, your local device may be compromised. The security of your Kee Vault remains intact so you need not panic. More information about the error is available at https://forum.kee.pm/';
try {
message = S.of(context).serverMITMWarning;
} catch (e, stackTrace) {
l.w('Error while localising error message', e, stackTrace);
l.w('Error while localising error message', error: e, stackTrace: stackTrace);
}
DialogUtils.showErrorDialog(context, null, message);
MatomoTracker.instance.trackEvent(eventInfo: EventInfo(category: 'main', action: 'error', name: 'mitm'));
Expand All @@ -57,13 +57,13 @@ void main() async {
error.message.startsWith('Scaffold.geometryOf() must only be accessed during the paint phase.')) {
l.w("Known Flutter bug ignored: 'Scaffold.geometryOf() must only be accessed during the paint phase.' This is known to be caused by tap interactions while the animations package is actively animating from an entrylistitem to an entry for editing. Other potential causes should be investigated if this is unlikely to have been the cause in this specific situation.");
} else {
l.wtf('Unhandled error in app.', error, stackTrace);
l.wtf('Unhandled error in app.', error: error, stackTrace: stackTrace);
navigatorKey.currentState?.overlay?.context.let((context) {
var message = 'Unexpected error: $error';
try {
message = S.of(context).unexpected_error('$error');
} catch (e, stackTrace) {
l.w('Error while localising error message', e, stackTrace);
l.w('Error while localising error message', error: e, stackTrace: stackTrace);
}
DialogUtils.showErrorDialog(context, null, '$message : $stackTrace');
MatomoTracker.instance.trackEvent(eventInfo: EventInfo(category: 'main', action: 'error', name: 'wtf'));
Expand Down
6 changes: 3 additions & 3 deletions lib/model/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class EntryViewModel {
digits: data['size']?.toInt() ?? OtpAuth.DEFAULT_DIGITS,
).toUri().toString();
} on FormatException catch (e, stackTrace) {
l.d('Error parsing data while normalising OTP value', e, stackTrace);
l.d('Error parsing data while normalising OTP value', error: e, stackTrace: stackTrace);
rethrow;
}
}
Expand All @@ -283,10 +283,10 @@ class EntryViewModel {
).toUri().toString();
} on FormatException catch (e, stackTrace) {
// ignore format exception from base32 decoding.
l.w('Error decoding base32 secret', e, stackTrace);
l.w('Error decoding base32 secret', error: e, stackTrace: stackTrace);
return null;
} catch (e, stackTrace) {
l.w('Error while parsing OTP format', e, stackTrace);
l.w('Error while parsing OTP format', error: e, stackTrace: stackTrace);
throw FormatException('Error parsing Tray OTP Format $e');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/vault_backend/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class JWT {
final signature = Signature(base64Url.decode(base64Url.normalize(sigParts[2])));
isValid = verifier.verify(Uint8List.fromList(data), signature);
} catch (e, stacktrace) {
l.e('Cryptography error during JWT verification', e, stacktrace);
l.e('Cryptography error during JWT verification', error: e, stackTrace: stacktrace);
throw KeeInvalidJWTException();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/account_create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class _AccountCreateWidgetState extends State<AccountCreateWidget> {
return PaymentService.instance.finishTransaction(item);
} on Exception catch (e) {
l.w('Exception while finishing the payment transaction. Ignoring but an app restart and/or a fresh sign-in or registration attempt may be required for everything to catch up. May also require a few minutes for server-side operations to complete.',
e);
error: e);
}
});
if (retry) {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/binaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class BinaryCardWidget extends StatelessWidget {
duration: Duration(seconds: 3),
));
} on Exception catch (e, st) {
l.e('Export failed: $e', st);
l.e('Export failed', error: e, stackTrace: st);
if (e is PlatformException) {
if (e.code == 'read_external_storage_denied' && context.mounted) {
alertUserToPermissionsProblem(context, 'export');
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/dialog_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DialogUtils {
TextButton(
child: Text(S.of(context).openLogConsole),
onPressed: () async {
await LogConsole.open(context);
LogConsole.open(context);
},
),
TextButton(
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class EntryWidget extends StatelessWidget {
l.d('Got totp secret with ${value.lengthInBytes} bytes.');
return OtpAuth(secret: value);
} catch (e, stackTrace) {
l.w('Invalid base32 code?', e, stackTrace);
l.w('Invalid base32 code?', error: e, stackTrace: stackTrace);
return null;
}
}
Expand Down Expand Up @@ -237,12 +237,14 @@ class EntryWidget extends StatelessWidget {
if (e.code == barcode.BarcodeScanner.cameraAccessDenied) {
// We already tried to get the user to grant permission so if they really don't want to
// by this point, they'll have to enter the code manually.
l.i('User denied camera permission.. Automatically continuing to manual code entry.', e);
l.i('User denied camera permission.. Automatically continuing to manual code entry.', error: e);
} else {
l.e('Unknown PlatformException. Automatically continuing to manual code entry.', e, stackTrace);
l.e('Unknown PlatformException. Automatically continuing to manual code entry.',
error: e, stackTrace: stackTrace);
}
} catch (e, stackTrace) {
l.w('Error during barcode scanning. Automatically continuing to manual code entry.', e, stackTrace);
l.w('Error during barcode scanning. Automatically continuing to manual code entry.',
error: e, stackTrace: stackTrace);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/entry_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class _OtpEntryFieldState extends _EntryTextFieldState {
_errorMessage = null;
});
} on FormatException catch (e, stackTrace) {
l.e('Error while decoding otpauth url.', e, stackTrace);
l.e('Error while decoding otpauth url.', error: e, stackTrace: stackTrace);
setState(() {
_currentOtp = '';
_errorMessage = 'Error generating token $e';
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/help.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class _HelpWidgetState extends State<HelpWidget> with TraceableClientMixin {
Padding(
padding: const EdgeInsets.all(16.0),
child: OutlinedButton(
onPressed: () async => await LogConsole.open(context), child: Text('Show log console')),
onPressed: () async => LogConsole.open(context), child: Text('Show log console')),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/import_export.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class _ImportExportWidgetState extends State<ImportExportWidget> {
duration: Duration(seconds: 3),
));
} on Exception catch (e, st) {
l.e('Export failed: $e', st);
l.e('Export failed', error: e, stackTrace: st);
if (e is PlatformException) {
if (e.code == 'read_external_storage_denied' && context.mounted) {
alertUserToPermissionsProblem(context, 'export');
Expand Down Expand Up @@ -401,7 +401,7 @@ class _ImportExportWidgetState extends State<ImportExportWidget> {
duration: Duration(seconds: 3),
));
} on Exception catch (e, st) {
l.e('Export failed: $e', st);
l.e('Export failed', error: e, stackTrace: st);
if (e is PlatformException) {
if (e.code == 'read_external_storage_denied' && context.mounted) {
alertUserToPermissionsProblem(context, 'export');
Expand Down
Loading

0 comments on commit ba4a76c

Please sign in to comment.