ssl: add a test for 3DES encrypted keys
This adds a test for 3DES encrypted keys in addition to the current DES encrypted keys. Change-Id: I229e3ef710e9ee23efa2a3275b89d958491de4a2 Reviewed-by: Richard J. Moore <rich@kde.org>bb10
parent
74a7f13ac1
commit
2fd0afc1f8
|
|
@ -0,0 +1,18 @@
|
|||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,8963B71DA5F406B2
|
||||
|
||||
95nMwjY/6wRlQU/F09WlGniwxkqct0Kr4/75stXAYJU/i56dyWHN22xJFB2SGaRO
|
||||
Bi2g+hQnczyQ9qCpdxIzHvTo9Z1yRRdSZxtsdw57ZDYo9xtoRXQdNFCb1gbsSrlf
|
||||
yZNRKueRCr/TFcxYcrZveUWwEssuZbztNW+deF/NSz35XJrI2C6MwTdm+lDTN6lS
|
||||
AI/F7bGB0k+9nlIHNVgXPLnGOStIWhbTBbYtGryh0j/y913dtZX1djUHHmGCdEP6
|
||||
7WnfoD4v+5ux1YFb051xJJP+3lRE4evXJe0vzZAs5Lqy3qta/uwc3nV2oERursCM
|
||||
roWkjZkP6TPAMFmkgQu1eHViL1u5CD+mYD/wDj2YwCIh8U2A5BN8KqM0N4bLEoPI
|
||||
dcW2Pu60VEpMyeSKOSIyJsvT7F9M9/FpyNg5QW4BfrZNkVb/d7NROu/Lg5Oy4uf9
|
||||
a38tTgrQFQXcZFHbnTKD6VabCsZnVK0mFsEloUaTYalLTB6+C+jh7q3D08Re2OAB
|
||||
g9yQshBx5DreOL4Y6rb1N6DqUqem4FqKbPP+x6URSf4SrXvH4jkBkk2AiQjc0oWl
|
||||
5qvUt11LQOEMdvajlRicjlMm9KtV6+jRuSIeKgZqLpyja/4l+mX+G2X4pCbOiHFV
|
||||
I5mRLLb3Cn7JEv6XlAZ1sjRZX7iS7sWFi3pzj6/i5JiH6RiQPHRmygrEUPdtD6J7
|
||||
d1W+fEh/osK+lB5Faa82oWrwxbdtgrNhKdQp1dkGezHe6WpBv8iMbTqXMBJHH/Pj
|
||||
/hFc4FkZMYEZwKEVQ2Cyjq9kzKLnAS9s6x6PchagmNL20b5liB7V/w==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
|
@ -87,7 +87,9 @@ private slots:
|
|||
void toEncryptedPemOrDer_data();
|
||||
void toEncryptedPemOrDer();
|
||||
|
||||
void passphraseChecks_data();
|
||||
void passphraseChecks();
|
||||
void noPassphraseChecks();
|
||||
#endif
|
||||
private:
|
||||
QString testDataDir;
|
||||
|
|
@ -347,77 +349,88 @@ void tst_QSslKey::toEncryptedPemOrDer()
|
|||
// ### add a test to verify that public keys are _decrypted_ correctly (by the ctor)
|
||||
}
|
||||
|
||||
void tst_QSslKey::passphraseChecks_data()
|
||||
{
|
||||
QTest::addColumn<QString>("fileName");
|
||||
|
||||
QTest::newRow("DES") << QString(testDataDir + "/rsa-with-passphrase-des.pem");
|
||||
QTest::newRow("3DES") << QString(testDataDir + "/rsa-with-passphrase-3des.pem");
|
||||
}
|
||||
|
||||
void tst_QSslKey::passphraseChecks()
|
||||
{
|
||||
{
|
||||
QString fileName(testDataDir + "/rsa-with-passphrase.pem");
|
||||
QFile keyFile(fileName);
|
||||
QVERIFY(keyFile.exists());
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey);
|
||||
QVERIFY(key.isNull()); // null passphrase => should not be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "");
|
||||
QVERIFY(key.isNull()); // empty passphrase => should not be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "WRONG!");
|
||||
QVERIFY(key.isNull()); // wrong passphrase => should not be able to decode key
|
||||
}
|
||||
#ifdef QT_NO_OPENSSL
|
||||
QEXPECT_FAIL("", "Encrypted keys require support from the SSL backend", Abort);
|
||||
#endif
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "123");
|
||||
QVERIFY(!key.isNull()); // correct passphrase
|
||||
}
|
||||
}
|
||||
QFETCH(QString, fileName);
|
||||
|
||||
QFile keyFile(fileName);
|
||||
QVERIFY(keyFile.exists());
|
||||
{
|
||||
// be sure and check a key without passphrase too
|
||||
QString fileName(testDataDir + "/rsa-without-passphrase.pem");
|
||||
QFile keyFile(fileName);
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey);
|
||||
QVERIFY(!key.isNull()); // null passphrase => should be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "");
|
||||
QVERIFY(!key.isNull()); // empty passphrase => should be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "xxx");
|
||||
QVERIFY(!key.isNull()); // passphrase given but key is not encrypted anyway => should work
|
||||
}
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey);
|
||||
QVERIFY(key.isNull()); // null passphrase => should not be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "");
|
||||
QVERIFY(key.isNull()); // empty passphrase => should not be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "WRONG!");
|
||||
QVERIFY(key.isNull()); // wrong passphrase => should not be able to decode key
|
||||
}
|
||||
#ifdef QT_NO_OPENSSL
|
||||
QEXPECT_FAIL("", "Encrypted keys require support from the SSL backend", Abort);
|
||||
#endif
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "123");
|
||||
QVERIFY(!key.isNull()); // correct passphrase
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSslKey::noPassphraseChecks()
|
||||
{
|
||||
// be sure and check a key without passphrase too
|
||||
QString fileName(testDataDir + "/rsa-without-passphrase.pem");
|
||||
QFile keyFile(fileName);
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey);
|
||||
QVERIFY(!key.isNull()); // null passphrase => should be able to decode key
|
||||
}
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "");
|
||||
QVERIFY(!key.isNull()); // empty passphrase => should be able to decode key
|
||||
}
|
||||
#ifdef QT_NO_OPENSSL
|
||||
QEXPECT_FAIL("", "Encrypted keys require support from the SSL backend", Abort);
|
||||
#endif
|
||||
{
|
||||
if (!keyFile.isOpen())
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
else
|
||||
keyFile.reset();
|
||||
QSslKey key(&keyFile,QSsl::Rsa,QSsl::Pem, QSsl::PrivateKey, "xxx");
|
||||
QVERIFY(!key.isNull()); // passphrase given but key is not encrypted anyway => should work
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue