From dc1aead2a2f36d0cbffea2e1194474bf8d5a43b0 Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Wed, 7 Mar 2018 20:43:26 -0800 Subject: [PATCH] OpenSSHKey: when writing to agent, ensure comment string is at least one byte This unbreaks adding keys to gpg-agent. Signed-off-by: Steven Noonan --- src/gui/entry/EditEntryWidget.cpp | 10 +++++++++- src/sshagent/SSHAgent.cpp | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 4d12dd16b..079f81056 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -420,12 +420,16 @@ void EditEntryWidget::browsePrivateKey() bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt) { + QString fileName; QByteArray privateKeyData; if (m_sshAgentUi->attachmentRadioButton->isChecked()) { - privateKeyData = m_advancedUi->attachmentsWidget->getAttachment(m_sshAgentUi->attachmentComboBox->currentText()); + fileName = m_sshAgentUi->attachmentComboBox->currentText(); + privateKeyData = m_advancedUi->attachmentsWidget->getAttachment(fileName); } else { QFile localFile(m_sshAgentUi->externalFileEdit->text()); + QFileInfo localFileInfo(localFile); + fileName = localFileInfo.fileName(); if (localFile.fileName().isEmpty()) { return false; @@ -464,6 +468,10 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt) key.setComment(m_entry->username()); } + if (key.comment().isEmpty()) { + key.setComment(fileName); + } + return true; } diff --git a/src/sshagent/SSHAgent.cpp b/src/sshagent/SSHAgent.cpp index 45d774aab..36a16b20b 100644 --- a/src/sshagent/SSHAgent.cpp +++ b/src/sshagent/SSHAgent.cpp @@ -268,10 +268,15 @@ void SSHAgent::databaseModeChanged(DatabaseWidget::Mode mode) } QByteArray keyData; + QString fileName; if (settings.selectedType() == "attachment") { - keyData = e->attachments()->value(settings.attachmentName()); + fileName = settings.attachmentName(); + keyData = e->attachments()->value(fileName); } else if (!settings.fileName().isEmpty()) { QFile file(settings.fileName()); + QFileInfo fileInfo(file); + + fileName = fileInfo.fileName(); if (file.size() > 1024 * 1024) { continue; @@ -302,6 +307,10 @@ void SSHAgent::databaseModeChanged(DatabaseWidget::Mode mode) key.setComment(e->username()); } + if (key.comment().isEmpty()) { + key.setComment(fileName); + } + if (settings.removeAtDatabaseClose()) { removeIdentityAtLock(key, uuid); }