Skip to content

Commit

Permalink
Merge branch 'develop' into uuid-matching
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde authored May 20, 2020
2 parents 2aea58a + a1b4a3f commit d7cc6f4
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 93 deletions.
26 changes: 18 additions & 8 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ BrowserService::BrowserService()
: QObject()
, m_browserHost(new BrowserHost)
, m_dialogActive(false)
, m_bringToFrontRequested(false)
, m_prevWindowState(WindowState::Normal)
, m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224"))
{
Expand Down Expand Up @@ -110,8 +109,7 @@ bool BrowserService::openDatabase(bool triggerUnlock)
}

if (triggerUnlock) {
m_bringToFrontRequested = true;
raiseWindow(true);
emit requestUnlock();
}

return false;
Expand Down Expand Up @@ -1231,6 +1229,23 @@ void BrowserService::raiseWindow(const bool force)
#endif
}

void BrowserService::updateWindowState()
{
m_prevWindowState = WindowState::Normal;
if (getMainWindow()->isMinimized()) {
m_prevWindowState = WindowState::Minimized;
}
#ifdef Q_OS_MACOS
if (macUtils()->isHidden()) {
m_prevWindowState = WindowState::Hidden;
}
#else
if (getMainWindow()->isHidden()) {
m_prevWindowState = WindowState::Hidden;
}
#endif
}

void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
{
if (dbWidget) {
Expand All @@ -1243,11 +1258,6 @@ void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget)
{
if (dbWidget) {
if (m_bringToFrontRequested) {
hideWindow();
m_bringToFrontRequested = false;
}

QJsonObject msg;
msg["action"] = QString("database-unlocked");
m_browserHost->sendClientMessage(msg);
Expand Down
5 changes: 4 additions & 1 deletion src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class BrowserService : public QObject
static const QString OPTION_ONLY_HTTP_AUTH;
static const QString ADDITIONAL_URL;

signals:
void requestUnlock();

public slots:
void databaseLocked(DatabaseWidget* dbWidget);
void databaseUnlocked(DatabaseWidget* dbWidget);
Expand Down Expand Up @@ -143,6 +146,7 @@ private slots:

void hideWindow() const;
void raiseWindow(const bool force = false);
void updateWindowState();

static bool moveSettingsToCustomData(Entry* entry, const QString& name);
static int moveKeysToCustomData(Entry* entry, QSharedPointer<Database> db);
Expand All @@ -151,7 +155,6 @@ private slots:
QHash<QString, QSharedPointer<BrowserAction>> m_browserClients;

bool m_dialogActive;
bool m_bringToFrontRequested;
WindowState m_prevWindowState;
QUuid m_keepassBrowserUUID;

Expand Down
10 changes: 6 additions & 4 deletions src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::GUI_MinimizeOnStartup, {QS("GUI/MinimizeOnStartup"), Roaming, false}},
{Config::GUI_MinimizeOnClose, {QS("GUI/MinimizeOnClose"), Roaming, false}},
{Config::GUI_HideUsernames, {QS("GUI/HideUsernames"), Roaming, false}},
{Config::GUI_HidePasswords, {QS("GUI/HidePasswords"), Roaming, true}},
{Config::GUI_AdvancedSettings, {QS("GUI/AdvancedSettings"), Roaming, false}},
{Config::GUI_MonospaceNotes, {QS("GUI/MonospaceNotes"), Roaming, false}},
{Config::GUI_ApplicationTheme, {QS("GUI/ApplicationTheme"), Roaming, QS("auto")}},
Expand Down Expand Up @@ -202,7 +201,8 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {

// Messages
{Config::Messages_NoLegacyKeyFileWarning, {QS("Messages/NoLegacyKeyFileWarning"), Roaming, false}},
{Config::Messages_Qt55CompatibilityWarning, {QS("Messages/Messages_Qt55CompatibilityWarning"), Local, false}}};
{Config::Messages_Qt55CompatibilityWarning, {QS("Messages/Qt55CompatibilityWarning"), Local, false}},
{Config::Messages_HidePreReleaseWarning, {QS("Messages/HidePreReleaseWarning"), Local, {}}}};

// clang-format on

Expand Down Expand Up @@ -341,7 +341,8 @@ static const QHash<QString, Config::ConfigKey> deprecationMap = {
{QS("generator/WordList"), Config::PasswordGenerator_WordList},
{QS("generator/WordCase"), Config::PasswordGenerator_WordCase},
{QS("generator/Type"), Config::PasswordGenerator_Type},
{QS("QtErrorMessageShown"), Config::Messages_Qt55CompatibilityWarning}};
{QS("QtErrorMessageShown"), Config::Messages_Qt55CompatibilityWarning},
{QS("GUI/HidePasswords"), Config::Deleted}};

/**
* Migrate settings from previous versions.
Expand Down Expand Up @@ -380,13 +381,14 @@ void Config::migrate()
}

// Move local settings to separate file
if (m_localSettings)
if (m_localSettings) {
for (const auto& setting : asConst(configStrings)) {
if (setting.type == Local && m_settings->contains(setting.name)) {
m_localSettings->setValue(setting.name, m_settings->value(setting.name));
m_settings->remove(setting.name);
}
}
}

// Detailed version migrations

Expand Down
2 changes: 1 addition & 1 deletion src/core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class Config : public QObject
GUI_MinimizeOnStartup,
GUI_MinimizeOnClose,
GUI_HideUsernames,
GUI_HidePasswords,
GUI_AdvancedSettings,
GUI_MonospaceNotes,
GUI_ApplicationTheme,
Expand Down Expand Up @@ -179,6 +178,7 @@ class Config : public QObject

Messages_NoLegacyKeyFileWarning,
Messages_Qt55CompatibilityWarning,
Messages_HidePreReleaseWarning,

// Special internal value
Deleted
Expand Down
8 changes: 8 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,3 +755,11 @@ void DatabaseTabWidget::performGlobalAutoType()
unlockDatabaseInDialog(currentDatabaseWidget(), DatabaseOpenDialog::Intent::AutoType);
}
}

void DatabaseTabWidget::performBrowserUnlock()
{
auto dbWidget = currentDatabaseWidget();
if (dbWidget && dbWidget->isLocked()) {
unlockDatabaseInDialog(dbWidget, DatabaseOpenDialog::Intent::Browser);
}
}
1 change: 1 addition & 0 deletions src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public slots:
void changeReports();
void changeDatabaseSettings();
void performGlobalAutoType();
void performBrowserUnlock();

signals:
void databaseOpened(DatabaseWidget* dbWidget);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> db, QWidget* parent)

#ifdef WITH_XC_SSHAGENT
if (sshAgent()->isEnabled()) {
connect(this, SIGNAL(databaseLocked()), sshAgent(), SLOT(databaseModeChanged()));
connect(this, SIGNAL(databaseUnlocked()), sshAgent(), SLOT(databaseModeChanged()));
connect(this, SIGNAL(databaseLockRequested()), sshAgent(), SLOT(databaseLocked()));
connect(this, SIGNAL(databaseUnlocked()), sshAgent(), SLOT(databaseUnlocked()));
}
#endif

Expand Down Expand Up @@ -739,7 +739,7 @@ void DatabaseWidget::addToAgent()

OpenSSHKey key;
if (settings.toOpenSSHKey(currentEntry, key, true)) {
SSHAgent::instance()->addIdentity(key, settings);
SSHAgent::instance()->addIdentity(key, settings, database()->uuid());
} else {
m_messageWidget->showMessage(key.errorString(), MessageWidget::Error);
}
Expand Down
3 changes: 1 addition & 2 deletions src/gui/DatabaseWidgetStateSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DatabaseWidgetStateSync::DatabaseWidgetStateSync(QObject* parent)
m_mainSplitterSizes = variantToIntList(config()->get(Config::GUI_SplitterState));
m_previewSplitterSizes = variantToIntList(config()->get(Config::GUI_PreviewSplitterState));
m_hideUsernames = config()->get(Config::GUI_HideUsernames).toBool();
m_hidePasswords = config()->get(Config::GUI_HidePasswords).toBool();
m_hidePasswords = true;
m_listViewState = config()->get(Config::GUI_ListViewState).toByteArray();
m_searchViewState = config()->get(Config::GUI_SearchViewState).toByteArray();

Expand All @@ -49,7 +49,6 @@ void DatabaseWidgetStateSync::sync()
config()->set(Config::GUI_SplitterState, intListToVariant(m_mainSplitterSizes));
config()->set(Config::GUI_PreviewSplitterState, intListToVariant(m_previewSplitterSizes));
config()->set(Config::GUI_HideUsernames, m_hideUsernames);
config()->set(Config::GUI_HidePasswords, m_hidePasswords);
config()->set(Config::GUI_ListViewState, m_listViewState);
config()->set(Config::GUI_SearchViewState, m_searchViewState);
config()->sync();
Expand Down
48 changes: 32 additions & 16 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ MainWindow::MainWindow()
&DatabaseTabWidget::activateDatabaseChanged,
browserService(),
&BrowserService::activeDatabaseChanged);
connect(
browserService(), &BrowserService::requestUnlock, m_ui->tabWidget, &DatabaseTabWidget::performBrowserUnlock);
#endif

#ifdef WITH_XC_SSHAGENT
Expand Down Expand Up @@ -185,12 +187,8 @@ MainWindow::MainWindow()
#endif

setWindowIcon(resources()->applicationIcon());
m_ui->globalMessageWidget->setHidden(true);
// clang-format off
m_ui->globalMessageWidget->hideMessage();
connect(m_ui->globalMessageWidget, &MessageWidget::linkActivated, &MessageWidget::openHttpUrl);
connect(m_ui->globalMessageWidget, SIGNAL(showAnimationStarted()), m_ui->globalMessageWidgetContainer, SLOT(show()));
connect(m_ui->globalMessageWidget, SIGNAL(hideAnimationFinished()), m_ui->globalMessageWidgetContainer, SLOT(hide()));
// clang-format on

m_clearHistoryAction = new QAction(tr("Clear history"), m_ui->menuFile);
m_lastDatabasesActions = new QActionGroup(m_ui->menuRecentDatabases);
Expand Down Expand Up @@ -508,19 +506,37 @@ MainWindow::MainWindow()
MessageWidget::Error);
}

#if defined(KEEPASSXC_BUILD_TYPE_SNAPSHOT) || defined(KEEPASSXC_BUILD_TYPE_PRE_RELEASE)
auto* hidePreRelWarn = new QAction(tr("Don't show again for this version"), m_ui->globalMessageWidget);
m_ui->globalMessageWidget->addAction(hidePreRelWarn);
auto hidePreRelWarnConn = QSharedPointer<QMetaObject::Connection>::create();
*hidePreRelWarnConn = connect(m_ui->globalMessageWidget, &KMessageWidget::hideAnimationFinished, [=] {
m_ui->globalMessageWidget->removeAction(hidePreRelWarn);
disconnect(*hidePreRelWarnConn);
hidePreRelWarn->deleteLater();
});
connect(hidePreRelWarn, &QAction::triggered, [=] {
m_ui->globalMessageWidget->animatedHide();
config()->set(Config::Messages_HidePreReleaseWarning, KEEPASSXC_VERSION);
});
#endif
#if defined(KEEPASSXC_BUILD_TYPE_SNAPSHOT)
m_ui->globalMessageWidget->showMessage(
tr("WARNING: You are using an unstable build of KeePassXC!\n"
"There is a high risk of corruption, maintain a backup of your databases.\n"
"This version is not meant for production use."),
MessageWidget::Warning,
-1);
if (config()->get(Config::Messages_HidePreReleaseWarning) != KEEPASSXC_VERSION) {
m_ui->globalMessageWidget->showMessage(
tr("WARNING: You are using an unstable build of KeePassXC!\n"
"There is a high risk of corruption, maintain a backup of your databases.\n"
"This version is not meant for production use."),
MessageWidget::Warning,
-1);
}
#elif defined(KEEPASSXC_BUILD_TYPE_PRE_RELEASE)
m_ui->globalMessageWidget->showMessage(
tr("NOTE: You are using a pre-release version of KeePassXC!\n"
"Expect some bugs and minor issues, this version is not meant for production use."),
MessageWidget::Information,
15000);
if (config()->get(Config::Messages_HidePreReleaseWarning) != KEEPASSXC_VERSION) {
m_ui->globalMessageWidget->showMessage(
tr("NOTE: You are using a pre-release version of KeePassXC!\n"
"Expect some bugs and minor issues, this version is not meant for production use."),
MessageWidget::Information,
-1);
}
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) && QT_VERSION < QT_VERSION_CHECK(5, 6, 0))
if (!config()->get(Config::Messages_Qt55CompatibilityWarning).toBool()) {
m_ui->globalMessageWidget->showMessage(
Expand Down
29 changes: 7 additions & 22 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,13 @@
<number>0</number>
</property>
<item>
<widget class="QWidget" name="globalMessageWidgetContainer" native="true">
<layout class="QVBoxLayout" name="globalMessageWidgetLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="MessageWidget" name="globalMessageWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">MessageWidget {margin: 90px}</string>
</property>
</widget>
</item>
</layout>
<widget class="MessageWidget" name="globalMessageWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
Expand Down
8 changes: 6 additions & 2 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,11 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt)
return false;
}

if (!settings.toOpenSSHKey(m_entry, key, decrypt)) {
if (!settings.toOpenSSHKey(m_mainUi->usernameComboBox->lineEdit()->text(),
m_mainUi->passwordEdit->text(),
m_advancedUi->attachmentsWidget->entryAttachments(),
key,
decrypt)) {
showMessage(settings.errorString(), MessageWidget::Error);
return false;
}
Expand All @@ -695,7 +699,7 @@ void EditEntryWidget::addKeyToAgent()
KeeAgentSettings settings;
toKeeAgentSettings(settings);

if (!sshAgent()->addIdentity(key, settings)) {
if (!sshAgent()->addIdentity(key, settings, m_db->uuid())) {
showMessage(sshAgent()->errorString(), MessageWidget::Error);
return;
}
Expand Down
33 changes: 30 additions & 3 deletions src/sshagent/KeeAgentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,40 @@ bool KeeAgentSettings::keyConfigured() const
* @return true if key was properly opened
*/
bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool decrypt)
{
return toOpenSSHKey(entry->username(), entry->password(), entry->attachments(), key, decrypt);
}

/**
* Read a SSH key based on settings to key.
*
* Sets error string on error.
*
* @param username username to set on key if empty
* @param password password to decrypt key if needed
* @param attachments attachments to read an attachment key from
* @param key output key object
* @param decrypt avoid private key decryption if possible (old RSA keys are always decrypted)
* @return true if key was properly opened
*/
bool KeeAgentSettings::toOpenSSHKey(const QString& username,
const QString& password,
const EntryAttachments* attachments,
OpenSSHKey& key,
bool decrypt)
{
QString fileName;
QByteArray privateKeyData;

if (m_selectedType == "attachment") {
if (!attachments) {
m_error = QCoreApplication::translate("KeeAgentSettings",
"Private key is an attachment but no attachments provided.");
return false;
}

fileName = m_attachmentName;
privateKeyData = entry->attachments()->value(fileName);
privateKeyData = attachments->value(fileName);
} else {
QFile localFile(fileNameEnvSubst());
QFileInfo localFileInfo(localFile);
Expand Down Expand Up @@ -405,14 +432,14 @@ bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool de
}

if (key.encrypted() && (decrypt || key.publicParts().isEmpty())) {
if (!key.openKey(entry->password())) {
if (!key.openKey(password)) {
m_error = key.errorString();
return false;
}
}

if (key.comment().isEmpty()) {
key.setComment(entry->username());
key.setComment(username);
}

if (key.comment().isEmpty()) {
Expand Down
Loading

0 comments on commit d7cc6f4

Please sign in to comment.