mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
KeeShare: Remove checking signed container
* Remove QuaZip dependency in favor of minizip * Remove signature checks, but maintain signatures for backwards compatibility * Remove UI components related to certificates except for personal certificate for backwards compatibility * Default to unsigned containers (*.kdbx)
This commit is contained in:
@@ -125,11 +125,6 @@ add_unit_test(NAME testcryptohash SOURCES TestCryptoHash.cpp
|
||||
add_unit_test(NAME testsymmetriccipher SOURCES TestSymmetricCipher.cpp
|
||||
LIBS ${TEST_LIBRARIES})
|
||||
|
||||
if(WITH_XC_KEESHARE)
|
||||
add_unit_test(NAME testsignature SOURCES TestSignature.cpp
|
||||
LIBS ${TEST_LIBRARIES})
|
||||
endif()
|
||||
|
||||
add_unit_test(NAME testhashedblockstream SOURCES TestHashedBlockStream.cpp
|
||||
LIBS testsupport ${TEST_LIBRARIES})
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ QTEST_GUILESS_MAIN(TestSharing)
|
||||
Q_DECLARE_METATYPE(KeeShareSettings::Type)
|
||||
Q_DECLARE_METATYPE(KeeShareSettings::Key)
|
||||
Q_DECLARE_METATYPE(KeeShareSettings::Certificate)
|
||||
Q_DECLARE_METATYPE(KeeShareSettings::Trust)
|
||||
Q_DECLARE_METATYPE(KeeShareSettings::ScopedCertificate)
|
||||
Q_DECLARE_METATYPE(QList<KeeShareSettings::ScopedCertificate>)
|
||||
|
||||
void TestSharing::initTestCase()
|
||||
{
|
||||
@@ -65,55 +62,12 @@ void TestSharing::testNullObjects()
|
||||
const auto xmlActive = KeeShareSettings::Active::deserialize(empty);
|
||||
QVERIFY(xmlActive.isNull());
|
||||
|
||||
const auto foreign = KeeShareSettings::Foreign();
|
||||
QVERIFY(foreign.certificates.isEmpty());
|
||||
const auto xmlForeign = KeeShareSettings::Foreign::deserialize(empty);
|
||||
QVERIFY(xmlForeign.certificates.isEmpty());
|
||||
|
||||
const auto reference = KeeShareSettings::Reference();
|
||||
QVERIFY(reference.isNull());
|
||||
const auto xmlReference = KeeShareSettings::Reference::deserialize(empty);
|
||||
QVERIFY(xmlReference.isNull());
|
||||
}
|
||||
|
||||
void TestSharing::testCertificateSerialization()
|
||||
{
|
||||
QFETCH(KeeShareSettings::Trust, trusted);
|
||||
auto key = stubkey();
|
||||
KeeShareSettings::ScopedCertificate original;
|
||||
original.path = "/path";
|
||||
original.certificate = KeeShareSettings::Certificate{key, "Some <!> &#_\"\" weird string"};
|
||||
original.trust = trusted;
|
||||
|
||||
QString buffer;
|
||||
QXmlStreamWriter writer(&buffer);
|
||||
writer.writeStartDocument();
|
||||
writer.writeStartElement("Certificate");
|
||||
KeeShareSettings::ScopedCertificate::serialize(writer, original);
|
||||
writer.writeEndElement();
|
||||
writer.writeEndDocument();
|
||||
|
||||
QXmlStreamReader reader(buffer);
|
||||
reader.readNextStartElement();
|
||||
QVERIFY(reader.name() == "Certificate");
|
||||
KeeShareSettings::ScopedCertificate restored = KeeShareSettings::ScopedCertificate::deserialize(reader);
|
||||
|
||||
QCOMPARE(restored.certificate.key->private_key_bits(), original.certificate.key->private_key_bits());
|
||||
QCOMPARE(restored.certificate.signer, original.certificate.signer);
|
||||
QCOMPARE(restored.trust, original.trust);
|
||||
QCOMPARE(restored.path, original.path);
|
||||
|
||||
QCOMPARE(restored.certificate.key->public_key_bits(), key->public_key_bits());
|
||||
}
|
||||
|
||||
void TestSharing::testCertificateSerialization_data()
|
||||
{
|
||||
QTest::addColumn<KeeShareSettings::Trust>("trusted");
|
||||
QTest::newRow("Ask") << KeeShareSettings::Trust::Ask;
|
||||
QTest::newRow("Trusted") << KeeShareSettings::Trust::Trusted;
|
||||
QTest::newRow("Untrusted") << KeeShareSettings::Trust::Untrusted;
|
||||
}
|
||||
|
||||
void TestSharing::testKeySerialization()
|
||||
{
|
||||
auto key = stubkey();
|
||||
@@ -177,16 +131,13 @@ void TestSharing::testSettingsSerialization()
|
||||
QFETCH(bool, exporting);
|
||||
QFETCH(KeeShareSettings::Certificate, ownCertificate);
|
||||
QFETCH(KeeShareSettings::Key, ownKey);
|
||||
QFETCH(QList<KeeShareSettings::ScopedCertificate>, foreignCertificates);
|
||||
|
||||
KeeShareSettings::Own originalOwn;
|
||||
KeeShareSettings::Foreign originalForeign;
|
||||
KeeShareSettings::Active originalActive;
|
||||
originalActive.in = importing;
|
||||
originalActive.out = exporting;
|
||||
originalOwn.certificate = ownCertificate;
|
||||
originalOwn.key = ownKey;
|
||||
originalForeign.certificates = foreignCertificates;
|
||||
|
||||
const QString serializedActive = KeeShareSettings::Active::serialize(originalActive);
|
||||
KeeShareSettings::Active restoredActive = KeeShareSettings::Active::deserialize(serializedActive);
|
||||
@@ -194,9 +145,6 @@ void TestSharing::testSettingsSerialization()
|
||||
const QString serializedOwn = KeeShareSettings::Own::serialize(originalOwn);
|
||||
KeeShareSettings::Own restoredOwn = KeeShareSettings::Own::deserialize(serializedOwn);
|
||||
|
||||
const QString serializedForeign = KeeShareSettings::Foreign::serialize(originalForeign);
|
||||
KeeShareSettings::Foreign restoredForeign = KeeShareSettings::Foreign::deserialize(serializedForeign);
|
||||
|
||||
QCOMPARE(restoredActive.in, importing);
|
||||
QCOMPARE(restoredActive.out, exporting);
|
||||
if (ownCertificate.key) {
|
||||
@@ -205,44 +153,29 @@ void TestSharing::testSettingsSerialization()
|
||||
if (ownKey.key) {
|
||||
QCOMPARE(restoredOwn.key, ownKey);
|
||||
}
|
||||
QCOMPARE(restoredForeign.certificates.count(), foreignCertificates.count());
|
||||
for (int i = 0; i < foreignCertificates.count(); ++i) {
|
||||
QCOMPARE(restoredForeign.certificates[i].certificate, foreignCertificates[i].certificate);
|
||||
}
|
||||
}
|
||||
|
||||
void TestSharing::testSettingsSerialization_data()
|
||||
{
|
||||
auto sshKey0 = stubkey(0);
|
||||
KeeShareSettings::ScopedCertificate certificate0;
|
||||
certificate0.path = "/path/0";
|
||||
certificate0.certificate = KeeShareSettings::Certificate{sshKey0, "Some <!> &#_\"\" weird string"};
|
||||
certificate0.trust = KeeShareSettings::Trust::Trusted;
|
||||
|
||||
KeeShareSettings::Certificate certificate0;
|
||||
certificate0.key = sshKey0;
|
||||
certificate0.signer = "signer";
|
||||
|
||||
KeeShareSettings::Key key0;
|
||||
key0.key = sshKey0;
|
||||
|
||||
auto sshKey1 = stubkey(1);
|
||||
KeeShareSettings::ScopedCertificate certificate1;
|
||||
certificate1.path = "/path/1";
|
||||
certificate1.certificate = KeeShareSettings::Certificate{sshKey1, "Another "};
|
||||
certificate1.trust = KeeShareSettings::Trust::Untrusted;
|
||||
|
||||
QTest::addColumn<bool>("importing");
|
||||
QTest::addColumn<bool>("exporting");
|
||||
QTest::addColumn<KeeShareSettings::Certificate>("ownCertificate");
|
||||
QTest::addColumn<KeeShareSettings::Key>("ownKey");
|
||||
QTest::addColumn<QList<KeeShareSettings::ScopedCertificate>>("foreignCertificates");
|
||||
QTest::newRow("1") << false << false << KeeShareSettings::Certificate() << KeeShareSettings::Key()
|
||||
<< QList<KeeShareSettings::ScopedCertificate>();
|
||||
QTest::newRow("2") << true << false << KeeShareSettings::Certificate() << KeeShareSettings::Key()
|
||||
<< QList<KeeShareSettings::ScopedCertificate>();
|
||||
QTest::newRow("3") << true << true << KeeShareSettings::Certificate() << KeeShareSettings::Key()
|
||||
<< QList<KeeShareSettings::ScopedCertificate>({certificate0, certificate1});
|
||||
QTest::newRow("4") << false << true << certificate0.certificate << key0
|
||||
<< QList<KeeShareSettings::ScopedCertificate>();
|
||||
QTest::newRow("5") << false << false << certificate0.certificate << key0
|
||||
<< QList<KeeShareSettings::ScopedCertificate>({certificate1});
|
||||
|
||||
QTest::newRow("1") << false << false << KeeShareSettings::Certificate() << KeeShareSettings::Key();
|
||||
QTest::newRow("2") << true << false << KeeShareSettings::Certificate() << KeeShareSettings::Key();
|
||||
QTest::newRow("3") << true << true << KeeShareSettings::Certificate() << KeeShareSettings::Key();
|
||||
QTest::newRow("4") << false << true << certificate0 << key0;
|
||||
QTest::newRow("5") << false << false << certificate0 << key0;
|
||||
}
|
||||
|
||||
const QSharedPointer<Botan::RSA_PrivateKey> TestSharing::stubkey(int index)
|
||||
|
||||
@@ -31,8 +31,6 @@ class TestSharing : public QObject
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testNullObjects();
|
||||
void testCertificateSerialization();
|
||||
void testCertificateSerialization_data();
|
||||
void testKeySerialization();
|
||||
void testReferenceSerialization();
|
||||
void testReferenceSerialization_data();
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TestSignature.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include "crypto/Crypto.h"
|
||||
#include "crypto/Random.h"
|
||||
#include "keeshare/Signature.h"
|
||||
|
||||
#include <botan/pem.h>
|
||||
#include <botan/rsa.h>
|
||||
|
||||
QTEST_GUILESS_MAIN(TestSignature)
|
||||
static const char* rsa_2_private = "-----BEGIN RSA PRIVATE KEY-----\n"
|
||||
"MIIEowIBAAKCAQEAwGdladnqFfcDy02Gubx4sdBT8NYEg2YKXfcKLSwca5gV4X7I\n"
|
||||
"z/+QR51LAfPCkj+QjWpj3DD1/6P7s6jOJ4BNd6CSDukv18DOsIsFn2D+zLmVoir2\n"
|
||||
"lki3sTsmiEz65KvHE8EnQ8IzZCqZDC40tZOcz2bnkZrmcsEibK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JLpDGE3iYy7AINSskI6dyhXL8rl7UxWYroqJSKq0knGrCT1eRdM0zqAfH4QKOJ\n"
|
||||
"BD4EfK7ff1EeGgNh1CR+dRJ6GXlXxdRPPrwattDaqsW8Xsvl30UA69DRT7KOQqXv\n"
|
||||
"nxRu74P3KCP+OuKEfVOcnQKBgQC+/2r1Zj/5huBhW9BbQ/ABBSOuueMeGEfDeIUu\n"
|
||||
"FQG6PGKqbA2TQp9pnuMGECGGH5UuJ+epeMN36Y/ZW7iKoJGuFg7EGoHlTZMYj6Yb\n"
|
||||
"xJoRhDwuZy1eiATkicOyxUHf6hHme9dz6YA1+i+O4knWxuR5ZrVhUiRPrrQBO4JI\n"
|
||||
"oSwiqQKBgHblgOVfOJrG3HDg6bo+qmxQsGFRCD0mehsg9YpokuZVX0UJtGx/RJHU\n"
|
||||
"vIBL00An6YcNfPTSlNJeG83APtk/tdgsXvQd3pmIkeY78x6xWKSieZXv4lyDv7lX\n"
|
||||
"r28lCTj2Ez2gEzEohZgf4V1uzBvTdJefarpQ00ep34UZ9FsNfUwD\n"
|
||||
"-----END RSA PRIVATE KEY-----\n";
|
||||
static const char* rsa_2_public = "-----BEGIN RSA PUBLIC KEY-----\n"
|
||||
"MIIBCgKCAQEAwGdladnqFfcDy02Gubx4sdBT8NYEg2YKXfcKLSwca5gV4X7Iz/+Q\n"
|
||||
"R51LAfPCkj+QjWpj3DD1/6P7s6jOJ4BNd6CSDukv18DOsIsFn2D+zLmVoir2lki3\n"
|
||||
"sTsmiEz65KvHE8EnQ8IzZCqZDC40tZOcz2bnkZrmcsEibKoxYsmQJk95NwdRteFy\n"
|
||||
"mp1qH3zq85xdNWw2u6c5CKzLgI5BjInttO98iSxL0KuY/JmzMx0gTbRiqc0x22EO\n"
|
||||
"DtdVsBoNL/pt8v6Q+WLpRg4/Yq7YurAngxk4h38NWvufj2vJvbcRqX4cupcu92T9\n"
|
||||
"SWwSwZmd4Xy3bt+AUlq4XRMa1MlKfPvXmwIDAQAB\n"
|
||||
"-----END RSA PUBLIC KEY-----\n";
|
||||
static const char* rsa_2_sign = "4fda1b39f93f174cdc79ac2bd6118155359830c90e2c39b60a1a548852f2c87a"
|
||||
"cd61b2a378259a38befad35dbf208a2c1332ab74faf2cee2ff2e8be49c4c5f41"
|
||||
"dc10e5a5fafb53d3c54e2b7640d7bfee6bb0f24c5a1fb934150a144c2b465fe4"
|
||||
"8a1579e666a097fb1609ae9abc5760f6e6d6e73acb610fb11dd1c409ca284a72"
|
||||
"0be64dd56a28ab257e8721f5bade58816382581ac08d932098dd200d836fe897"
|
||||
"f78a5f02095ac3b21cca2a47b2afd282ce075c6450cba8c85b08b58c5bacb75d"
|
||||
"e1a73bdec4321193d4a3ce653d8e3aa8a4f2beac6a44497328f8855f7e28e15d"
|
||||
"f63b21f8bc7204bf6e202c9cb08be050379be5ad88d8e695a38440a50e75dfdf";
|
||||
static const char* rsa_1_private = "-----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"
|
||||
"wANNCqE+SgoIClPdeHC7fmrLh1ttqe6ib6ybBUFRS31yXs0hnfefunVEDKlaV8K2\n"
|
||||
"N52UAMAsngFHQNRvGh6kEWeZPd9Xc+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fDH2s8CgYAXC/lWWHQ//PGP0pH4oiEXisx1K0X1u0xMGgrChxBRGRiKZUwNMIvJ\n"
|
||||
"TqUu7IKizK19cLHF/NBvxHYHFw+m7puNjn6T1RtRCUjRZT7Dx1VHfVosL9ih5DA8\n"
|
||||
"tpbZA5KGKcvHtB5DDgT0MHwzBZnb4Q//Rhovzn+HXZPsJTTgHHy3NQ==\n"
|
||||
"-----END RSA PRIVATE KEY-----\n";
|
||||
static const char* rsa_1_public = "-----BEGIN RSA PUBLIC KEY-----\n"
|
||||
"MIIBCgKCAQEAsCHtJicDPWnvHSIKbnTZaJkIB9vgE0pmLdK580JUqBuonVbBy1QT\n"
|
||||
"y0ZQ7/TtqvLPgwPK88TR46OLO/QGCzo2+XxgJ85uy0xfuyUYRmSuw0drsErNmH8v\n"
|
||||
"U91lSBxsGDp9LtBbgHKoR23vMWZ34IxFRc55XphrIH48ijsMaL6bXBwF/3tD9T3l\n"
|
||||
"m2MpP1huyVNnIY9+GRRWCy4f9LMj/UGu/n4RtwwfpOZBBRwYkq5QkzA9lPm/VzF3\n"
|
||||
"MP1rKTMkvAw+Nfb383mkmc6MRnsa6uh6iDa9aVB7naegM13UJQX/PY1Ks6pOXDpy\n"
|
||||
"/MQ7iCh+HmYNq5dRmARyaNl9xIXJNhz1cQIDAQAB\n"
|
||||
"-----END RSA PUBLIC KEY-----\n";
|
||||
|
||||
static QByteArray data("Some trivial test with a longer .... ................................. longer text");
|
||||
|
||||
QSharedPointer<Botan::Private_Key> loadPrivateKey(const QString& pem)
|
||||
{
|
||||
try {
|
||||
std::string label;
|
||||
auto der = Botan::PEM_Code::decode(pem.toStdString(), label);
|
||||
auto key = new Botan::RSA_PrivateKey(
|
||||
Botan::AlgorithmIdentifier("RSA", Botan::AlgorithmIdentifier::USE_NULL_PARAM), der);
|
||||
return QSharedPointer<Botan::Private_Key>(key);
|
||||
} catch (std::exception& e) {
|
||||
qWarning("Failed to load key: %s", e.what());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
QSharedPointer<Botan::Public_Key> loadPublicKey(const QString& pem)
|
||||
{
|
||||
try {
|
||||
std::string label;
|
||||
auto der = Botan::PEM_Code::decode(pem.toStdString(), label);
|
||||
auto key =
|
||||
new Botan::RSA_PublicKey(Botan::AlgorithmIdentifier("RSA", Botan::AlgorithmIdentifier::USE_NULL_PARAM),
|
||||
std::vector<uint8_t>(der.begin(), der.end()));
|
||||
return QSharedPointer<Botan::Public_Key>(key);
|
||||
} catch (std::exception& e) {
|
||||
qWarning("Failed to load key: %s", e.what());
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void TestSignature::initTestCase()
|
||||
{
|
||||
QVERIFY(Crypto::init());
|
||||
}
|
||||
|
||||
void TestSignature::testSigningOpenSSH_RSA_PrivateOnly()
|
||||
{
|
||||
auto rsaKey = loadPrivateKey(rsa_2_private);
|
||||
QVERIFY(rsaKey);
|
||||
|
||||
QString sign;
|
||||
Signature::create(data, rsaKey, sign);
|
||||
QCOMPARE(sign, QString("rsa|%1").arg(QString::fromLatin1(rsa_2_sign)));
|
||||
|
||||
const bool verified = Signature::verify(data, rsaKey, sign);
|
||||
QCOMPARE(verified, true);
|
||||
}
|
||||
|
||||
void TestSignature::testSigningOpenSSH_RSA()
|
||||
{
|
||||
auto privateKey = loadPrivateKey(rsa_2_private);
|
||||
QVERIFY(privateKey);
|
||||
|
||||
QString sign;
|
||||
Signature::create(data, privateKey, sign);
|
||||
QVERIFY(!sign.isEmpty());
|
||||
|
||||
auto publicKey = loadPublicKey(rsa_2_public);
|
||||
QVERIFY(publicKey);
|
||||
|
||||
const bool verified = Signature::verify(data, publicKey, sign);
|
||||
QCOMPARE(verified, true);
|
||||
}
|
||||
|
||||
void TestSignature::testSigningGenerated_RSA_PrivateOnly()
|
||||
{
|
||||
QSharedPointer<Botan::Private_Key> key(new Botan::RSA_PrivateKey(*randomGen()->getRng(), 2048));
|
||||
|
||||
QString sign;
|
||||
Signature::create(data, key, sign);
|
||||
QVERIFY(!sign.isEmpty());
|
||||
|
||||
const bool verified = Signature::verify(data, key, sign);
|
||||
QCOMPARE(verified, true);
|
||||
}
|
||||
|
||||
void TestSignature::testSigningTest_RSA_PrivateOnly()
|
||||
{
|
||||
auto rsaKey = loadPrivateKey(rsa_2_private);
|
||||
QVERIFY(rsaKey);
|
||||
|
||||
QString sign;
|
||||
Signature::create(data, rsaKey, sign);
|
||||
QVERIFY(!sign.isEmpty());
|
||||
|
||||
const bool verified = Signature::verify(data, rsaKey, sign);
|
||||
QCOMPARE(verified, true);
|
||||
}
|
||||
|
||||
void TestSignature::testSigningTest_RSA()
|
||||
{
|
||||
auto privateKey = loadPrivateKey(rsa_1_private);
|
||||
QVERIFY(privateKey);
|
||||
|
||||
QString sign;
|
||||
Signature::create(data, privateKey, sign);
|
||||
QVERIFY(!sign.isEmpty());
|
||||
|
||||
auto publicKey = loadPublicKey(rsa_1_public);
|
||||
QVERIFY(publicKey);
|
||||
|
||||
const bool verified = Signature::verify(data, publicKey, sign);
|
||||
QCOMPARE(verified, true);
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
||||
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 or (at your option)
|
||||
* version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSXC_TESTSIGNATURE_H
|
||||
#define KEEPASSXC_TESTSIGNATURE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TestSignature : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
|
||||
void testSigningOpenSSH_RSA_PrivateOnly();
|
||||
void testSigningOpenSSH_RSA();
|
||||
|
||||
void testSigningGenerated_RSA_PrivateOnly();
|
||||
|
||||
void testSigningTest_RSA_PrivateOnly();
|
||||
void testSigningTest_RSA();
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_TESTSIGNATURE_H
|
||||
Reference in New Issue
Block a user