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

Add methods isHardwareKeySupported and refreshHardwareKeys to DBus #8055

Merged
Merged
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
37 changes: 37 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,43 @@ void MainWindow::appExit()
close();
}

/**
* Returns if application was built with hardware key support.
* Intented to be used by 3rd-party applications using DBus.
*
* @return True if built with hardware key support, false otherwise
*/
bool MainWindow::isHardwareKeySupported()
{
#ifdef WITH_XC_YUBIKEY
return true;
#else
return false;
#endif
}

/**
* Refreshes list of hardware keys known.
* Triggers the DatabaseOpenWidget to automatically select the key last used for a database if found.
* Intented to be used by 3rd-party applications using DBus.
*
* @return True if any key was found, false otherwise or if application lacks hardware key support
*/
bool MainWindow::refreshHardwareKeys()
{
#ifdef WITH_XC_YUBIKEY
auto yk = YubiKey::instance();
// find keys sync to allow returning if any key was found
bool found = yk->findValidKeys();
// emit signal so DatabaseOpenWidget can select last used key
// emit here manually because sync findValidKeys() cannot do that properly
emit yk->detectComplete(found);
return found;
#else
return false;
#endif
}

void MainWindow::updateLastDatabasesMenu()
{
m_ui->menuRecentDatabases->clear();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class MainWindow : public QMainWindow
public slots:
void openDatabase(const QString& filePath, const QString& password = {}, const QString& keyfile = {});
void appExit();
bool isHardwareKeySupported();
bool refreshHardwareKeys();
void displayGlobalMessage(const QString& text,
MessageWidget::MessageType type,
bool showClosebutton = true,
Expand Down
6 changes: 6 additions & 0 deletions src/gui/org.keepassxc.KeePassXC.MainWindow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
</method>
<method name="appExit">
</method>
<method name="isHardwareKeySupported">
<arg name="hardwareKeySupported" type="b" direction="out"/>
</method>
<method name="refreshHardwareKeys">
<arg name="found" type="b" direction="out"/>
</method>
<method name="lockAllDatabases">
</method>
<method name="closeAllDatabases">
Expand Down