Hide UI elements when KeePassXC was compiled without -DWITH_XC_YUBIKEY

This commit is contained in:
Janek Bevendorff 2017-02-21 01:06:32 +01:00
parent 8d3e0687a0
commit b2650c5a96
No known key found for this signature in database
GPG Key ID: CFEC2F6850BFFA53
5 changed files with 50 additions and 30 deletions

View File

@ -195,13 +195,12 @@ if(NOT ZLIB_SUPPORTS_GZIP)
endif()
# Optional
find_package(YubiKey)
if(WITH_XC_YUBIKEY)
find_package(YubiKey REQUIRED)
if(YUBIKEY_FOUND)
include_directories(SYSTEM ${YUBIKEY_INCLUDE_DIRS})
endif()
if(UNIX)
check_cxx_source_compiles("#include <sys/prctl.h>
int main() { prctl(PR_SET_DUMPABLE, 0); return 0; }"

View File

@ -179,7 +179,7 @@ if(MINGW)
${CMAKE_SOURCE_DIR}/share/windows/icon.rc)
endif()
if(YUBIKEY_FOUND)
if(WITH_XC_YUBIKEY)
set(keepassx_SOURCES ${keepassx_SOURCES} keys/drivers/YubiKey.cpp)
else()
set(keepassx_SOURCES ${keepassx_SOURCES} keys/drivers/YubiKeyStub.cpp)
@ -209,7 +209,8 @@ target_link_libraries(keepassx_core
Qt5::Network
${GCRYPT_LIBRARIES}
${GPGERROR_LIBRARIES}
${ZLIB_LIBRARIES})
${ZLIB_LIBRARIES}
${YUBIKEY_LIBRARIES})
if (UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus)
endif()
@ -234,10 +235,6 @@ endif()
add_executable(${PROGNAME} WIN32 MACOSX_BUNDLE ${keepassx_SOURCES_MAINEXE} ${WIN32_ProductVersionFiles})
target_link_libraries(${PROGNAME} keepassx_core)
if(YUBIKEY_FOUND)
target_link_libraries(keepassx_core ${YUBIKEY_LIBRARIES})
endif()
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON)
if(APPLE)

View File

@ -28,6 +28,8 @@
#include "gui/MessageBox.h"
#include "crypto/Random.h"
#include "config-keepassx.h"
ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent)
: DialogyWidget(parent)
, m_ui(new Ui::ChangeMasterKeyWidget())
@ -50,11 +52,15 @@ ChangeMasterKeyWidget::ChangeMasterKeyWidget(QWidget* parent)
connect(m_ui->createKeyFileButton, SIGNAL(clicked()), SLOT(createKeyFile()));
connect(m_ui->browseKeyFileButton, SIGNAL(clicked()), SLOT(browseKeyFile()));
#ifdef WITH_XC_YUBIKEY
connect(m_ui->challengeResponseGroup, SIGNAL(clicked(bool)), SLOT(challengeResponseGroupToggled(bool)));
connect(m_ui->buttonRedetectYubikey, SIGNAL(clicked()), SLOT(pollYubikey()));
connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection);
connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection);
#else
m_ui->challengeResponseGroup->setVisible(false);
#endif
}
ChangeMasterKeyWidget::~ChangeMasterKeyWidget()
@ -98,8 +104,10 @@ void ChangeMasterKeyWidget::clearForms()
m_ui->keyFileGroup->setChecked(false);
m_ui->togglePasswordButton->setChecked(false);
#ifdef WITH_XC_YUBIKEY
m_ui->challengeResponseGroup->setChecked(false);
m_ui->comboChallengeResponse->clear();
#endif
m_ui->enterPasswordEdit->setFocus();
}
@ -118,9 +126,10 @@ void ChangeMasterKeyWidget::generateKey()
{
m_key.clear();
bool anyChecked = m_ui->passwordGroup->isChecked();
anyChecked |= m_ui->keyFileGroup->isChecked();
anyChecked |= m_ui->challengeResponseGroup->isChecked();
bool anyChecked = m_ui->passwordGroup->isChecked() | m_ui->keyFileGroup->isChecked();
#ifdef WITH_XC_YUBIKEY
anyChecked |= m_ui->challengeResponseGroup->isChecked();
#endif
if (!anyChecked) {
if (MessageBox::warning(this, tr("No authentication factor chosen"),
@ -160,6 +169,7 @@ void ChangeMasterKeyWidget::generateKey()
m_key.addKey(fileKey);
}
#ifdef WITH_XC_YUBIKEY
if (m_ui->challengeResponseGroup->isChecked()) {
int i = m_ui->comboChallengeResponse->currentIndex();
i = m_ui->comboChallengeResponse->itemData(i).toInt();
@ -174,6 +184,7 @@ void ChangeMasterKeyWidget::generateKey()
m_key.addChallengeResponseKey(key);
}
#endif
m_ui->messageWidget->hideMessage();
emit editFinished(true);

View File

@ -29,14 +29,16 @@
#include "format/KeePass2Reader.h"
#include "keys/FileKey.h"
#include "keys/PasswordKey.h"
#include "keys/YkChallengeResponseKey.h"
#include "crypto/Random.h"
#include "keys/YkChallengeResponseKey.h"
#include "config-keepassx.h"
DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
: DialogyWidget(parent)
, m_ui(new Ui::DatabaseOpenWidget())
, m_db(nullptr)
: DialogyWidget(parent),
m_ui(new Ui::DatabaseOpenWidget()),
m_db(nullptr)
{
m_ui->setupUi(this);
@ -49,11 +51,6 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
m_ui->yubikeyProgress->setVisible(false);
QSizePolicy sp = m_ui->yubikeyProgress->sizePolicy();
sp.setRetainSizeWhenHidden(true);
m_ui->yubikeyProgress->setSizePolicy(sp);
m_ui->buttonTogglePassword->setIcon(filePath()->onOffIcon("actions", "password-show"));
connect(m_ui->buttonTogglePassword, SIGNAL(toggled(bool)),
m_ui->editPassword, SLOT(setShowPassword(bool)));
@ -61,21 +58,33 @@ DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent)
connect(m_ui->editPassword, SIGNAL(textChanged(QString)), SLOT(activatePassword()));
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(activateKeyFile()));
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(activateChallengeResponse()));
connect(m_ui->checkPassword, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
connect(m_ui->checkKeyFile, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(setOkButtonEnabled()));
connect(m_ui->checkChallengeResponse, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(setOkButtonEnabled()));
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(openDatabase()));
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
#ifdef WITH_XC_YUBIKEY
m_ui->yubikeyProgress->setVisible(false);
QSizePolicy sp = m_ui->yubikeyProgress->sizePolicy();
sp.setRetainSizeWhenHidden(true);
m_ui->yubikeyProgress->setSizePolicy(sp);
connect(m_ui->buttonRedetectYubikey, SIGNAL(clicked()), SLOT(pollYubikey()));
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(activateChallengeResponse()));
connect(m_ui->checkChallengeResponse, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled()));
connect(m_ui->comboChallengeResponse, SIGNAL(activated(int)), SLOT(setOkButtonEnabled()));
connect(YubiKey::instance(), SIGNAL(detected(int,bool)), SLOT(yubikeyDetected(int,bool)), Qt::QueuedConnection);
connect(YubiKey::instance(), SIGNAL(notFound()), SLOT(noYubikeyFound()), Qt::QueuedConnection);
#else
m_ui->checkChallengeResponse->setVisible(false);
m_ui->buttonRedetectYubikey->setVisible(false);
m_ui->comboChallengeResponse->setVisible(false);
m_ui->yubikeyProgress->setVisible(false);
#endif
#ifdef Q_OS_MACOS
// add random padding to layouts to align widgets properly
@ -109,10 +118,12 @@ void DatabaseOpenWidget::load(const QString& filename)
}
}
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
#ifdef WITH_XC_YUBIKEY
m_ui->comboChallengeResponse->clear();
pollYubikey();
#endif
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
m_ui->editPassword->setFocus();
}
@ -199,9 +210,12 @@ CompositeKey DatabaseOpenWidget::databaseKey()
if (config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastKeyFiles", lastKeyFiles);
config()->set("LastChallengeResponse", lastChallengeResponse);
}
#ifdef WITH_XC_YUBIKEY
if (config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastChallengeResponse", lastChallengeResponse);
}
if (m_ui->checkChallengeResponse->isChecked()) {
int i = m_ui->comboChallengeResponse->currentIndex();
@ -210,6 +224,7 @@ CompositeKey DatabaseOpenWidget::databaseKey()
masterKey.addChallengeResponseKey(key);
}
#endif
return masterKey;
}

View File

@ -58,9 +58,7 @@ bool YubiKey::getSerial(unsigned int& serial) const
return false;
}
YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock,
const QByteArray& chal,
QByteArray& resp) const
YubiKey::ChallengeResult YubiKey::challenge(int slot, bool mayBlock, const QByteArray& chal, QByteArray& resp) const
{
Q_UNUSED(slot);
Q_UNUSED(mayBlock);