SSH Agent: Fix invalid iqmp output for RSA keys

This fixes loading RSA keys to Pageant.
This commit is contained in:
Toni Spets 2018-05-20 09:49:47 +03:00 committed by Jonathan White
parent 9805f2331d
commit 8c70856a82
3 changed files with 87 additions and 3 deletions

View File

@ -102,14 +102,14 @@ namespace {
mpi_invm(u, q, p);
iqmp_hex.resize((bap.length() + 1) * 2);
gcry_mpi_print(GCRYMPI_FMT_HEX, reinterpret_cast<unsigned char*>(iqmp_hex.data()), iqmp_hex.length(), nullptr, u);
iqmp_hex.resize(bap.length() * 2);
gcry_mpi_print(GCRYMPI_FMT_HEX, reinterpret_cast<unsigned char*>(iqmp_hex.data()), iqmp_hex.size(), nullptr, u);
gcry_mpi_release(u);
gcry_mpi_release(p);
gcry_mpi_release(q);
return QByteArray::fromHex(iqmp_hex);
return QByteArray::fromHex(QString(iqmp_hex).toLatin1());
}
}

View File

@ -181,6 +181,89 @@ void TestOpenSSHKey::testParseRSA()
QCOMPARE(key.fingerprint(), QString("SHA256:DYdaZciYNxCejr+/8x+OKYxeTU1D5UsuIFUG4PWRFkk"));
}
void TestOpenSSHKey::testParseRSACompare()
{
const QString oldKeyString = QString(
"-----BEGIN RSA PRIVATE KEY-----\n"
"MIIEpAIBAAKCAQEAsCHtJicDPWnvHSIKbnTZaJkIB9vgE0pmLdK580JUqBuonVbB\n"
"y1QTy0ZQ7/TtqvLPgwPK88TR46OLO/QGCzo2+XxgJ85uy0xfuyUYRmSuw0drsErN\n"
"mH8vU91lSBxsGDp9LtBbgHKoR23vMWZ34IxFRc55XphrIH48ijsMaL6bXBwF/3tD\n"
"9T3lm2MpP1huyVNnIY9+GRRWCy4f9LMj/UGu/n4RtwwfpOZBBRwYkq5QkzA9lPm/\n"
"VzF3MP1rKTMkvAw+Nfb383mkmc6MRnsa6uh6iDa9aVB7naegM13UJQX/PY1Ks6pO\n"
"XDpy/MQ7iCh+HmYNq5dRmARyaNl9xIXJNhz1cQIDAQABAoIBAQCnEUc1LUQxeM5K\n"
"wANN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Y-----\n"
);
const QByteArray oldKeyData = oldKeyString.toLatin1();
const QByteArray newKeyData = newKeyString.toLatin1();
OpenSSHKey newKey, oldKey;
QByteArray oldPrivateKey, newPrivateKey;
BinaryStream oldPrivateStream(&oldPrivateKey), newPrivateStream(&newPrivateKey);
QVERIFY(oldKey.parse(oldKeyData));
QVERIFY(newKey.parse(newKeyData));
// comment is not part of the old format and writePrivate() includes it
oldKey.setComment("id_rsa");
QVERIFY(oldKey.writePrivate(oldPrivateStream));
QVERIFY(newKey.writePrivate(newPrivateStream));
QCOMPARE(oldKey.type(), newKey.type());
QCOMPARE(oldKey.fingerprint(), newKey.fingerprint());
QCOMPARE(oldPrivateKey, newPrivateKey);
}
void TestOpenSSHKey::testDecryptOpenSSHAES256CBC()
{
const QString keyString = QString(

View File

@ -31,6 +31,7 @@ private slots:
void testParse();
void testParseDSA();
void testParseRSA();
void testParseRSACompare();
void testDecryptRSAAES128CBC();
void testDecryptOpenSSHAES256CBC();
void testDecryptRSAAES256CBC();