Fix removing encrypted ASN.1 keys from ssh-agent (#6804)

Contents of id_rsa-encrypted-asn1 are from
TestOpenSSHKey::testDecryptRSAAES128CBC().

Closes #6788
This commit is contained in:
Chih-Hsuan Yen 2021-08-08 21:36:06 +08:00 committed by GitHub
parent 0921bf2d61
commit bc5d0df19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 1 deletions

View File

@ -478,7 +478,7 @@ bool KeeAgentSettings::toOpenSSHKey(const QString& username,
return false;
}
if (key.encrypted() && decrypt) {
if (key.encrypted() && (decrypt || key.publicKey().isEmpty())) {
if (!key.openKey(password)) {
m_error = key.errorString();
return false;

View File

@ -16,6 +16,7 @@
*/
#include "TestSSHAgent.h"
#include "config-keepassx-tests.h"
#include "core/Config.h"
#include "crypto/Crypto.h"
#include "sshagent/KeeAgentSettings.h"
@ -211,6 +212,18 @@ void TestSSHAgent::testConfirmConstraint()
QVERIFY(agent.checkIdentity(m_key, keyInAgent) && !keyInAgent);
}
void TestSSHAgent::testToOpenSSHKey()
{
KeeAgentSettings settings;
settings.setSelectedType("file");
settings.setFileName(QString("%1/id_rsa-encrypted-asn1").arg(QString(KEEPASSX_TEST_DATA_DIR)));
OpenSSHKey key;
settings.toOpenSSHKey("username", "correctpassphrase", QString(), nullptr, key, false);
QVERIFY(!key.publicKey().isEmpty());
}
void TestSSHAgent::cleanupTestCase()
{
if (m_agentProcess.state() != QProcess::NotRunning) {

View File

@ -34,6 +34,7 @@ private slots:
void testRemoveOnClose();
void testLifetimeConstraint();
void testConfirmConstraint();
void testToOpenSSHKey();
void cleanupTestCase();
private:

View File

@ -0,0 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,804E4D214D1263FF94E3743FE799DBB4
lM9TDfOTbiRhaGGDh7Hn+rqw8CCWcYBZYu7smyYLdnWKXKPmbne8CQFZBAS1FJwZ
6Mj6n075yFGyzN9/OfeqKiUA4adlbwLbGw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