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

OpenSSHKey: when writing to agent, ensure comment string is at least one byte #1681

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
10 changes: 9 additions & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 10 additions & 1 deletion src/sshagent/SSHAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down