Skip to content
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

Fix multi-account password saving #6290

Merged
merged 1 commit into from
Nov 13, 2021
Merged

Conversation

vgaming
Copy link
Member

@vgaming vgaming commented Nov 12, 2021

Fixes GH-6288, and hopefully makes the code
more readable / easier to understand.

@vgaming
Copy link
Member Author

vgaming commented Nov 12, 2021

I tested the new code locally, it works both for single-account use case and for storing/loading multiple accounts

@vgaming
Copy link
Member Author

vgaming commented Nov 12, 2021

I also hate to admit, but I cannot pinpoint where exactly the old code was broken. In my perception that was just messy code that is really hard to understand, with unneeded additional variable offset, triple resizes that adjust for escaped and not escaped keys... A lot of unnecessary complexity. In the issue GH-6288 itself, however, it was observed that credentials file is not split correctly, with the CREDENTIAL_SEPARATOR obviously broken. I can copy more of the relevant IRC discussions here if there's a question

@Wedge009 Wedge009 added the Backport A reminder of a bugfix that was added to master that needs to be duplicated on the stable branch. label Nov 12, 2021
@Wedge009
Copy link
Member

Wedge009 commented Nov 12, 2021

As discussed in #wesnoth-dev, it is indeed strange that it didn't expose the issue for multi-account credential saving for you in 1.14. But it does look like replacing manual std::copy and offset tracking is a good thing if it solves the bug for you and @Hejnewar.

It looks like only @CelticMinstrel has done any meaningful work on this code, so I'll suggest he review this before merging.

@vgaming
Copy link
Member Author

vgaming commented Nov 12, 2021

UPD: When using this branch on an old corrupted credentials file from wesnoth-1.16.1, the passwords have still to be entered once, but they're saved successfully and for the user it works as expected. (This PR doesn't really change reading of the credentials file.) What remains however is that the credentials file will keep those extra broken/unneeded entries, even with the new PR. They'll just stay as garbage around, without use.

@vgaming
Copy link
Member Author

vgaming commented Nov 12, 2021

To provide a bit of context for people who weren't today in IRC. Without this PR, for single-account credentials file, the entry in credentials file looks like: server: server.wesnoth.org:15000, login: vasili. For multi-account credentials file, without the PR, corrupted entries will be created upon save, such as: server: server.wesnoth.org:15000, login: login: vasili@server.wesnoth.org:15000=�����;sa��vasya2 (the login spans much further than it should, including the server and probably password of the previous/next entries)

Copy link
Member

@CelticMinstrel CelticMinstrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one minor change to make.

@@ -230,21 +233,15 @@ namespace preferences
filesystem::delete_file(filesystem::get_credentials_file());
return;
}
secure_buffer credentials_data(1, CREDENTIAL_SEPARATOR);
std::size_t offset = 1;
secure_buffer credentials_data(0, CREDENTIAL_SEPARATOR);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(0, CREDENTIAL_SEPARATOR) does nothing - just remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! Addressed the comment

Fixes GH-6288, and hopefully makes the code
more readable / easier to understand.
@vgaming vgaming force-pushed the fix-multi-account-password-saving branch from ed58d05 to 701bb5a Compare November 13, 2021 17:14
@vgaming vgaming merged commit f0c9f1e into master Nov 13, 2021
@vgaming vgaming deleted the fix-multi-account-password-saving branch November 13, 2021 17:16
@AI0867
Copy link
Member

AI0867 commented Nov 15, 2021

The only potential bug I see in the old code is that the second resize (for the difference in size between escaped and non-escaped keys) doesn't pad the buffer with CREDENTIAL_SEPARATOR.

The new code looks like a definite improvement. It might be a bit slower due to not pre-allocating the buffer, but this is hardly a performance-critical path.

@vgaming
Copy link
Member Author

vgaming commented Nov 15, 2021

@AI0867 totally agree. Also, for this code path, I'd indeed prefer readability, maintainability and less bugs, over performance optimization %insert-donald-knuth-quote-here%

@AI0867
Copy link
Member

AI0867 commented Nov 15, 2021

Mostly unrelated, but I'm unsure if I should open a new issue for this: I noticed a TODO to do key stretching on the autogenerated key. This seems like a good idea, but unfortunately, it comes with a whole host of backwards-compatibility issues, especially if we want to be able to allow older versions of wesnoth to keep using the same credentials file.

Should we open a new issue for that to think about what a good design would even look like?

@vgaming
Copy link
Member Author

vgaming commented Nov 19, 2021

@AI0867 I don't know, I can't really say. Normally I always try to prioritize fixing bugs, and only then doing new features. But that is subjective of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport A reminder of a bugfix that was added to master that needs to be duplicated on the stable branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wesnoth fails to remember multiple account passwords
4 participants