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

Refactor browser settings and TOTP #2284

Merged
merged 4 commits into from
Sep 16, 2018
Merged

Conversation

droidmonkey
Copy link
Member

@droidmonkey droidmonkey commented Sep 11, 2018

Description

This is a pretty hefty refactor, but well needed (especially TOTP). This aligns BrowserSettings to be similar in design and function to Config and other settings classes. It is now dynamically initialized and accessed using an inline function. Some other static methods/vars were made dynamic due to them being private to their class and only initialized once.

TOTP was completely overhauled, every single function was changed and cleaned up. It was also placed into a namespace instead of a class since all its members are static (desired convention). The previous implementation was extremely brittle and required state to be stored across several different classes. Users of the previous TOTP class were required to know how it worked and when to supply proper variables (BAD!!). The new implementation is completely plug-and-play, no manual required!

Closes #2132

Motivation and context

Clean code == happy maintainers

How has this been tested?

Manually and with written tests

Screenshots (if appropriate):

No GUI layouts were harmed in this refactor. The SetupTotpDialog.ui only changes to using SettingsGroups to control radio buttons.

Types of changes

  • ✅ Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • ✅ I have read the CONTRIBUTING document. [REQUIRED]
  • ✅ My code follows the code style of this project. [REQUIRED]
  • ✅ All new and existing tests passed. [REQUIRED]
  • ✅ I have compiled and verified my code with -DWITH_ASAN=ON. [REQUIRED]
  • ✅ I have added tests to cover my changes.

@droidmonkey droidmonkey added this to the v2.4.0 milestone Sep 11, 2018
@droidmonkey droidmonkey force-pushed the refactor/static-init branch 2 times, most recently from 5399b23 to 46fe646 Compare September 11, 2018 23:51
Copy link
Member

@varjolintu varjolintu left a comment

Choose a reason for hiding this comment

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

Everything worked great. Good job!

}
m_attributes->set("TOTP Settings", data);
m_attributes->set("TOTP Seed", m_data.totpSettings->key, true);
m_attributes->set("TOTP Settings", text);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could make this translatable somehow. But I think you should at least use a static symbol for this instead of repeating the raw string everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would not translate an attribute key. That would also break compat with the KeePass2 plugins.

private Q_SLOTS:
void toggleDefault(bool status);
void toggleSteam(bool status);
explicit SetupTotpDialog(QWidget *parent = nullptr, Entry* entry = nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

QWidget*

This class should also be called TotpSetupDialog.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with the name, I did consider that change

m_ui->progressBar->update();
uCounter++;
m_counter++;
Copy link
Member

Choose a reason for hiding this comment

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

++m_counter

src/totp/totp.h Outdated
static const QString STEAM_SHORTNAME = "S";

QSharedPointer<Totp::Settings> parseSettings(const QString& rawSettings, const QString& key=QString());
QSharedPointer<Totp::Settings> createSettings(const QString& key, const uint digits, const uint step,
Copy link
Member

Choose a reason for hiding this comment

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

Spaces around operators and use {} instead of QString().

@droidmonkey
Copy link
Member Author

All requested changes were made @phoerious

Copy link
Contributor

@weslly weslly left a comment

Choose a reason for hiding this comment

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

For some reason all my TOTP codes stopped working, but the tests still pass. I'll try to debug it

@droidmonkey
Copy link
Member Author

droidmonkey commented Sep 15, 2018

Ok good test, I agree the tests passed and was worried about this exact scenario. Check your system time.


quint64 current;
if (time == 0) {
current = qToBigEndian(QDateTime::currentDateTime().toTime_t() / step);
Copy link
Contributor

@weslly weslly Sep 15, 2018

Choose a reason for hiding this comment

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

Found the bug!

toTime_t() returns a 32bit uint, but it worked with the old code because it was stored in a quint64 variable before being passed to qToBigEndian.

toTime_t() is also obsolete since qt 5.8 and we should eventually replace it with toSecsSinceEpoch(), which already returns a qint64.

Copy link
Member Author

@droidmonkey droidmonkey Sep 15, 2018

Choose a reason for hiding this comment

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

I'll use the new function, seems the old one is way overdue for deletion. The tests don't pick this up since it requires "real time" to work.

Copy link
Contributor

Choose a reason for hiding this comment

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

toSecsSinceEpoch() was introduced in 5.8 so we would need to increase the minimum Qt version requirement at https://github.com/keepassxreboot/keepassxc/blob/develop/INSTALL.md too

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh...

* Convert BrowserSettings into instanced class
* Moved HostInstaller init into class constructor
* CSV Import and Entry Model
* Eliminate TOTP logic from GUI elements
* Consolidate TOTP functionality under the Totp namespace
* Eliminate guessing about state and encoders
* Increased test cases
* Add entry view column for TOTP [#2132]
* General code cleanup, reduction of unnecessary steps, separation of concerns
* Rename SetupTotpDialog to TotpSetupDialog for consistency
@droidmonkey
Copy link
Member Author

Fixed the TOTP fail and cleaned up the commit list, this is ready for merge once approvals are granted.

@droidmonkey droidmonkey merged commit c0aa1ef into develop Sep 16, 2018
@droidmonkey droidmonkey deleted the refactor/static-init branch September 16, 2018 12:29
droidmonkey added a commit that referenced this pull request Mar 19, 2019
- New Database Wizard [#1952]
- Advanced Search [#1797]
- Automatic update checker [#2648]
- KeeShare database synchronization [#2109, #1992, #2738, #2742, #2746, #2739]
- Improve favicon fetching; transition to Duck-Duck-Go [#2795, #2011, #2439]
- Remove KeePassHttp support [#1752]
- CLI: output info to stderr for easier scripting [#2558]
- CLI: Add --quiet option [#2507]
- CLI: Add create command [#2540]
- CLI: Add recursive listing of entries [#2345]
- CLI: Fix stdin/stdout encoding on Windows [#2425]
- SSH Agent: Support OpenSSH for Windows [#1994]
- macOS: TouchID Quick Unlock [#1851]
- macOS: Multiple improvements; include CLI in DMG [#2165, #2331, #2583]
- Linux: Prevent Klipper from storing secrets in clipboard [#1969]
- Linux: Use polling based file watching for NFS [#2171]
- Linux: Enable use of browser plugin in Snap build [#2802]
- TOTP QR Code Generator [#1167]
- High-DPI Scaling for 4k screens [#2404]
- Make keyboard shortcuts more consistent [#2431]
- Warn user if deleting referenced entries [#1744]
- Allow toolbar to be hidden and repositioned [#1819, #2357]
- Increase max allowed database timeout to 12 hours [#2173]
- Password generator uses existing password length by default [#2318]
- Improve alert message box button labels [#2376]
- Show message when a database merge makes no changes [#2551]
- Browser Integration Enhancements [#1497, #2253, #1904, #2232, #1850, #2218, #2391, #2396, #2542, #2622, #2637, #2790]
- Overall Code Improvements [#2316, #2284, #2351, #2402, #2410, #2419, #2422, #2443, #2491, #2506, #2610, #2667, #2709, #2731]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Totp to the general panel for double click to copy
4 participants