Skip to content

fix: Storing Nextcloud credentials on Windows does not work #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/components/nextcloud/done_login_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ class DoneLoginStep extends StatefulWidget {
class _DoneLoginStepState extends State<DoneLoginStep> {
static const width = 400.0;

void _logout() {
void _logout() async {
Prefs.url.value = '';
await Prefs.url.waitUntilSaved(); // wait for write value is finished
Prefs.username.value = '';
await Prefs.username.waitUntilSaved(); // wait for write value is finished
Prefs.ncPassword.value = '';
await Prefs.ncPassword.waitUntilSaved(); // wait for write value is finished
Prefs.ncPasswordIsAnAppPassword.value = false;
await Prefs.ncPasswordIsAnAppPassword.waitUntilSaved(); // wait for write value is finished
Prefs.encPassword.value = '';
await Prefs.encPassword.waitUntilSaved(); // wait for write value is finished
Prefs.pfp.value = null;
Prefs.lastStorageQuota.value = null;
Prefs.key.value = '';
await Prefs.key.waitUntilSaved(); // wait for write value is finished
Prefs.iv.value = '';
await Prefs.iv.waitUntilSaved(); // wait for write value is finished
widget.recheckCurrentStep();
}

Expand Down
10 changes: 9 additions & 1 deletion lib/components/nextcloud/enc_login_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ class _EncLoginStepState extends State<EncLoginStep> {
text: text,
style: TextStyle(color: colorScheme.link),
recognizer: TapGestureRecognizer()
..onTap = () {
..onTap = () async {
Prefs.url.value = '';
await Prefs.url.waitUntilSaved();
Prefs.username.value = '';
await Prefs.username.waitUntilSaved();
Prefs.ncPassword.value = '';
await Prefs.ncPassword.waitUntilSaved();
widget.recheckCurrentStep();
},
),
Expand Down Expand Up @@ -140,16 +143,21 @@ class _EncLoginStepState extends State<EncLoginStep> {

try {
Prefs.encPassword.value = encPassword;
await Prefs.encPassword.waitUntilSaved();

final client = NextcloudClientExtension.withSavedDetails()!;
_isChecking.value = true;
await client.loadEncryptionKey();
widget.recheckCurrentStep();
} on EncLoginFailure {
Prefs.encPassword.value = '';
await Prefs.encPassword.waitUntilSaved();


_errorMessage.value = t.login.encLoginStep.wrongEncPassword;
} catch (e) {
Prefs.encPassword.value = '';
await Prefs.encPassword.waitUntilSaved();
log.severe('Failed to load encryption key: $e', e);

_errorMessage.value = '${t.login.encLoginStep.connectionFailed}\n\n$e';
Expand Down
11 changes: 9 additions & 2 deletions lib/components/nextcloud/nc_login_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ class _NcLoginStepState extends State<NcLoginStep> {
);
final username = await client.getUsername();

Prefs.url.value = credentials.server ==
NextcloudClientExtension.defaultNextcloudUri.toString()
Prefs.url.value= credentials.server ==
NextcloudClientExtension.defaultNextcloudUri.toString()
? ''
: credentials.server;
await Prefs.url.waitUntilSaved(); // wait until properly saved

Prefs.username.value = username;
await Prefs.username.waitUntilSaved();

Prefs.ncPassword.value = credentials.appPassword;
await Prefs.ncPassword.waitUntilSaved();
Prefs.ncPasswordIsAnAppPassword.value = true;

Prefs.encPassword.value = '';
await Prefs.encPassword.waitUntilSaved();

Prefs.pfp.value = null;
client.core.avatar
Expand Down
2 changes: 2 additions & 0 deletions lib/components/settings/nextcloud_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class _NextcloudProfileState extends State<NextcloudProfile> {
@override
void initState() {
Prefs.username.addListener(_usernameChanged);
Prefs.url.addListener(_usernameChanged);
Prefs.encPassword.addListener(_usernameChanged);
Prefs.key.addListener(_usernameChanged);
Prefs.iv.addListener(_usernameChanged);
Expand All @@ -40,6 +41,7 @@ class _NextcloudProfileState extends State<NextcloudProfile> {
@override
void dispose() {
Prefs.username.removeListener(_usernameChanged);
Prefs.url.removeListener(_usernameChanged);
Prefs.encPassword.removeListener(_usernameChanged);
Prefs.key.removeListener(_usernameChanged);
Prefs.iv.removeListener(_usernameChanged);
Expand Down
5 changes: 4 additions & 1 deletion lib/data/nextcloud/nextcloud_client_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ extension NextcloudClientExtension on NextcloudClient {
try {
final String key = encrypter.decrypt64(encryptedKey, iv: iv);
Prefs.key.value = key;
await Prefs.key.waitUntilSaved();
Prefs.iv.value = iv.base64;
await Prefs.iv.waitUntilSaved();
return key;
} catch (e) {
// can't decrypt, so we need to get the previous encryption key (user's password)
Expand All @@ -142,8 +144,9 @@ extension NextcloudClientExtension on NextcloudClient {
await setConfig(config);

Prefs.key.value = key.base64;
await Prefs.key.waitUntilSaved();
Prefs.iv.value = iv.base64;

await Prefs.iv.waitUntilSaved();
return key.base64;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/data/nextcloud/saber_syncer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ class SaberSyncInterface
} on EncLoginFailure {
// enc password has changed since the user last logged in, so log out
Prefs.encPassword.value = '';
await Prefs.encPassword.waitUntilSaved();
Prefs.key.value = '';
await Prefs.key.waitUntilSaved();
Prefs.iv.value = '';
await Prefs.iv.waitUntilSaved();
}
return Uint8List(0);
} else if (file.remoteFile?.size == 0) {
Expand Down
Loading