Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Jan 25, 2025
1 parent 904bf54 commit ef2b708
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions lib/cubit/vault_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ class VaultCubit extends Cubit<VaultState> {
/// Our understanding of which situation we need to recover from can change as we proceed through the various attempts to recover.
Future<void> refresh(User user,
{String? overridePasswordRemote,
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.None}) async {
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.none}) async {
VaultState s = state;

if (s is VaultLoaded) {
Expand All @@ -569,11 +569,11 @@ class VaultCubit extends Cubit<VaultState> {
l.i('refresh called during an ongoing refresh operation. Will not start a new refresh now.');
return;
}
if (s is VaultRefreshCredentialsRequired && recovery == PasswordMismatchRecoverySituation.None) {
if (s is VaultRefreshCredentialsRequired && recovery == PasswordMismatchRecoverySituation.none) {
l.i('refresh called during an ongoing refresh credentials repair operation. Will not refresh now.');
return;
}
if (s is VaultUploadCredentialsRequired && recovery == PasswordMismatchRecoverySituation.None) {
if (s is VaultUploadCredentialsRequired && recovery == PasswordMismatchRecoverySituation.none) {
l.i('refresh called during an ongoing upload credentials repair operation. Will not refresh now.');
return;
}
Expand All @@ -586,17 +586,17 @@ class VaultCubit extends Cubit<VaultState> {
Credentials credsRemote = credsLocal;
StrengthAssessedCredentials? credentialsOverrideWithStrength;

if (recovery != PasswordMismatchRecoverySituation.None && overridePasswordRemote != null) {
if (recovery != PasswordMismatchRecoverySituation.none && overridePasswordRemote != null) {
l.d('we will attempt a recovery from a mismatched password');
final protectedValue = ProtectedValue.fromString(overridePasswordRemote);
credentialsOverrideWithStrength = StrengthAssessedCredentials(protectedValue, user.emailParts);
if (recovery == PasswordMismatchRecoverySituation.RemoteUserDiffers) {
if (recovery == PasswordMismatchRecoverySituation.remoteUserDiffers) {
l.d('we have a service password explicitly supplied');

final key = protectedValue.hash;
await user.attachKey(key);
}
if (recovery == PasswordMismatchRecoverySituation.RemoteFileDiffers) {
if (recovery == PasswordMismatchRecoverySituation.remoteFileDiffers) {
l.d('we have a KDBX password explicitly supplied');
credsRemote = credentialsOverrideWithStrength.credentials;
}
Expand Down Expand Up @@ -642,7 +642,7 @@ class VaultCubit extends Cubit<VaultState> {
l.d('lastRemoteEtag: $lastRemoteEtag');
final tempLockedFile = await _remoteVaultRepo.download(user, credsRemote, lastRemoteEtag);

if (recovery == PasswordMismatchRecoverySituation.RemoteUserDiffers) {
if (recovery == PasswordMismatchRecoverySituation.remoteUserDiffers) {
// If we're in state 3 (or 4) this should get us into 2; User may need to enter the other password again when the next refresh operation happens (assuming we found no change to the kdbx to download this time) but they'll get the problem resolved eventually.
l.d('Updating QU with newly successful service password');
await _qu.saveQuickUnlockUserPassKey(user.passKey);
Expand Down Expand Up @@ -694,10 +694,10 @@ class VaultCubit extends Cubit<VaultState> {
lockedFile = tempLockedFile;
} on KdbxInvalidKeyException {
// Pretty sure this can't happen - download doesn't actually attempt to unlock the downloaded file and autofillMerge handles the exception itself.
handleRefreshAuthError(s.vault, recovery: PasswordMismatchRecoverySituation.RemoteFileDiffers);
handleRefreshAuthError(s.vault, recovery: PasswordMismatchRecoverySituation.remoteFileDiffers);
return;
} on KeeLoginRequiredException {
handleRefreshAuthError(s.vault, recovery: PasswordMismatchRecoverySituation.RemoteUserDiffers);
handleRefreshAuthError(s.vault, recovery: PasswordMismatchRecoverySituation.remoteUserDiffers);
return;
} on KeeSubscriptionExpiredException {
emitError(
Expand Down Expand Up @@ -753,7 +753,7 @@ class VaultCubit extends Cubit<VaultState> {

// RemoteFileDiffers only time and safe time to save the credentials? we are saying whatever creds worked to open the remote file is what we will save as the credentials needed to open the local file.
// updatedLocalFile must be null if we are in remotefilediffers mode
if (recovery == PasswordMismatchRecoverySituation.RemoteFileDiffers && successfulCredentials != null) {
if (recovery == PasswordMismatchRecoverySituation.remoteFileDiffers && successfulCredentials != null) {
l.d('Updating QU with newly successful KDBX password');
final requireFullPasswordPeriod =
int.tryParse(Settings.getValue<String>('requireFullPasswordPeriod') ?? '60') ?? 60;
Expand Down Expand Up @@ -781,7 +781,7 @@ class VaultCubit extends Cubit<VaultState> {
// etag during the next refresh or upload operation, we will re-download the update
// and perform a merge. This should be a NOOP but is inefficient.
handleRefreshAuthError(updatedLocalFile ?? s.vault,
recovery: PasswordMismatchRecoverySituation.RemoteFileDiffers);
recovery: PasswordMismatchRecoverySituation.remoteFileDiffers);
} on Exception catch (e, stack) {
l.e("Kee Vault failed to apply a change to your local vault for some unexpected reason or hardware fault. Please Share these application logs with us so that we can discuss and advise what to do next. If you have your Kee Vault on other devices, we recommend disconnecting them from the internet and exporting your vault to a KDBX file now, especially if you do not have a recent backup. We are likely to be able to restore all or most of your data but this may take a significant amount of time so the sooner you contact us to explain the details of what may have triggered the problem and share the error logs with us, the sooner we'll get you back up and running. Background refresh error: $e \n\n stack: $stack");
emitError(
Expand Down Expand Up @@ -1132,7 +1132,7 @@ class VaultCubit extends Cubit<VaultState> {
//TODO:f: check history after upload and warn user or attempt reconciliation in case that they uploaded a newer version from a different device in between our check for the latest version and the network upload completing.
Future<void> upload(User user, LocalVaultFile vault,
{String? overridePasswordRemote,
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.None}) async {
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.none}) async {
l.d('uploading vault with recovery mode $recovery');
VaultState s = state;
if (s is VaultLoaded) {
Expand All @@ -1157,17 +1157,17 @@ class VaultCubit extends Cubit<VaultState> {
'Cannot upload when we do not know the credentials required to perform merge operation or update KDBX password. Please tell us about this error so we can resolve it for you.');
}

if (recovery != PasswordMismatchRecoverySituation.None && overridePasswordRemote != null) {
if (recovery != PasswordMismatchRecoverySituation.none && overridePasswordRemote != null) {
l.d('we will attempt a recovery from a mismatched password');
final protectedValue = ProtectedValue.fromString(overridePasswordRemote);
credentialsOverrideWithStrength = StrengthAssessedCredentials(protectedValue, user.emailParts);
if (recovery == PasswordMismatchRecoverySituation.RemoteUserDiffers) {
if (recovery == PasswordMismatchRecoverySituation.remoteUserDiffers) {
l.d('we have a service password explicitly supplied');

final key = protectedValue.hash;
await user.attachKey(key);
}
if (recovery == PasswordMismatchRecoverySituation.RemoteFileDiffers) {
if (recovery == PasswordMismatchRecoverySituation.remoteFileDiffers) {
l.d('we have a KDBX password explicitly supplied');
credsRemote = credentialsOverrideWithStrength.credentials;
}
Expand All @@ -1191,7 +1191,7 @@ class VaultCubit extends Cubit<VaultState> {
} on KeeLoginRequiredException {
l.w('Unable to determine latest remote file etag due to authentication error. User recently changed password elsewhere?');
handleUploadAuthError(updatedLocalFile, state is VaultSaving ? (state as VaultSaving).locally : false,
PasswordMismatchRecoverySituation.RemoteUserDiffers);
PasswordMismatchRecoverySituation.remoteUserDiffers);
return;
} on KeeServiceTransportException catch (e) {
final message = e.handle('Error establishing current remote file version');
Expand Down Expand Up @@ -1230,7 +1230,7 @@ class VaultCubit extends Cubit<VaultState> {
// This should be rare because we've recently retrieved or checked our download auth token but can happen sometimes, maybe on very slow networks when the user is changing their master password elsewhere concurrently.
l.w('Unable to download latest remote file for local merging due to authentication error. User recently changed password elsewhere?');
handleUploadAuthError(updatedLocalFile, state is VaultSaving ? (state as VaultSaving).locally : false,
PasswordMismatchRecoverySituation.RemoteUserDiffers);
PasswordMismatchRecoverySituation.remoteUserDiffers);
return;
} on KeeServiceTransportException catch (e) {
final message = e.handle('Error while downloading more recent changes from remote');
Expand Down Expand Up @@ -1348,7 +1348,7 @@ class VaultCubit extends Cubit<VaultState> {
_generatorProfilesCubit, updatedLocalFile.files.current.body.meta.keeVaultSettings);
} on KeeLoginRequiredException {
handleUploadAuthError(updatedLocalFile, state is VaultSaving ? (state as VaultSaving).locally : false,
PasswordMismatchRecoverySituation.RemoteUserDiffers);
PasswordMismatchRecoverySituation.remoteUserDiffers);
return;
} on KeeMissingPrimaryDBException {
emitKeeMissingPrimaryDBExceptionError();
Expand Down
6 changes: 3 additions & 3 deletions lib/password_mismatch_recovery_situation.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enum PasswordMismatchRecoverySituation {
None,
RemoteUserDiffers,
RemoteFileDiffers,
none,
remoteUserDiffers,
remoteFileDiffers,

//TODO: Probably can never know that these are the situation - can't tell the difference between user typing the wrong password and can't try the remote file password anyway until the service password is correct. Maybe delete these enum values?
//RemoteUserAndFileDiffers,
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/vault.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _VaultWidgetState extends State<VaultWidget> with WidgetsBindingObserver {
Future<void> _refreshAuthenticate(String password) async {
final user = BlocProvider.of<AccountCubit>(context).currentUser;
final VaultState vaultState = BlocProvider.of<VaultCubit>(context).state;
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.None;
PasswordMismatchRecoverySituation recovery = PasswordMismatchRecoverySituation.none;
if (vaultState is VaultRefreshCredentialsRequired) {
recovery = vaultState.recovery;
}
Expand Down

0 comments on commit ef2b708

Please sign in to comment.