2004-10-23 11:28:42 +00:00
|
|
|
/**
|
2006-10-12 05:45:32 +00:00
|
|
|
* Copyright (C) 2004-2006 Brad Hards <bradh@frogmouth.net>
|
2004-10-23 11:28:42 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2006-10-12 05:45:32 +00:00
|
|
|
|
|
|
|
#include <QtCrypto>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
|
|
|
class StaticUnitTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase();
|
|
|
|
void hexConversions();
|
|
|
|
void providers();
|
|
|
|
void capabilities();
|
|
|
|
void secureMemory();
|
|
|
|
private:
|
|
|
|
QCA::Initializer* m_init;
|
|
|
|
};
|
2004-10-23 11:28:42 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::initTestCase()
|
2004-10-23 11:28:42 +00:00
|
|
|
{
|
2005-11-06 09:25:56 +00:00
|
|
|
m_init = new QCA::Initializer;
|
|
|
|
#include "../fixpaths.include"
|
2004-10-23 11:28:42 +00:00
|
|
|
}
|
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::cleanupTestCase()
|
2004-10-23 11:28:42 +00:00
|
|
|
{
|
2005-11-06 09:25:56 +00:00
|
|
|
delete m_init;
|
|
|
|
}
|
2004-10-23 11:28:42 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::hexConversions()
|
|
|
|
{
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
QByteArray test(10, 'a');
|
2004-10-23 11:28:42 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex(test), QString("61616161616161616161") );
|
2004-10-23 11:28:42 +00:00
|
|
|
|
|
|
|
test.fill('b');
|
|
|
|
test[7] = 0x00;
|
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( test == QCA::hexToArray(QString("62626262626262006262")), true );
|
2004-10-23 11:28:42 +00:00
|
|
|
|
2007-04-13 19:19:18 +00:00
|
|
|
QCA::SecureArray testArray(10);
|
2004-11-05 09:39:08 +00:00
|
|
|
//testArray.fill( 'a' );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < testArray.size(); i++) {
|
2004-11-05 09:39:08 +00:00
|
|
|
testArray[ i ] = 0x61;
|
|
|
|
}
|
2007-06-13 02:30:43 +00:00
|
|
|
QCOMPARE( QCA::arrayToHex( testArray.toByteArray() ), QString( "61616161616161616161" ) );
|
2004-11-05 09:39:08 +00:00
|
|
|
//testArray.fill( 'b' );
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < testArray.size(); i++) {
|
2004-11-05 09:39:08 +00:00
|
|
|
testArray[ i ] = 0x62;
|
|
|
|
}
|
|
|
|
testArray[6] = 0x00;
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( testArray == QCA::hexToArray(QString("62626262626200626262")), true );
|
2004-11-06 08:52:30 +00:00
|
|
|
|
2007-06-13 02:30:43 +00:00
|
|
|
QCOMPARE( testArray == QCA::hexToArray( QCA::arrayToHex( testArray.toByteArray() ) ), true );
|
2005-04-02 11:42:04 +00:00
|
|
|
|
|
|
|
testArray[9] = 0x00;
|
2007-06-13 02:30:43 +00:00
|
|
|
QCOMPARE( testArray == QCA::hexToArray( QCA::arrayToHex( testArray.toByteArray() ) ), true );
|
2005-11-06 09:25:56 +00:00
|
|
|
}
|
|
|
|
|
2004-11-06 08:52:30 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::capabilities()
|
|
|
|
{
|
|
|
|
// capabilities are reported as a list - that is a problem for
|
2004-11-06 08:52:30 +00:00
|
|
|
// doing a direct comparison, since they change
|
|
|
|
// We try to work around that using contains()
|
|
|
|
QStringList supportedCapabilities = QCA::supportedFeatures();
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( supportedCapabilities.contains("random"), (QBool)true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("sha1"), (QBool)true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("sha0"), (QBool)true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("md2"),(QBool) true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("md4"), (QBool)true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("md5"), (QBool)true );
|
|
|
|
QCOMPARE( supportedCapabilities.contains("ripemd160"), (QBool)true );
|
2004-11-06 08:52:30 +00:00
|
|
|
|
|
|
|
QStringList defaultCapabilities = QCA::defaultFeatures();
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( defaultCapabilities.contains("random"), (QBool)true );
|
2004-11-06 08:52:30 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::isSupported("random"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("sha0"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("sha0,sha1"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("md2,md4,md5"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("md5"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("ripemd160"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("sha256,sha384,sha512"), true );
|
|
|
|
QCOMPARE( QCA::isSupported("nosuchfeature"), false );
|
2004-11-06 08:52:30 +00:00
|
|
|
|
|
|
|
QString caps( "random,sha1,md5,ripemd160");
|
|
|
|
QStringList capList;
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
capList = caps.split( "," );
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::isSupported(capList), true );
|
2004-11-06 08:52:30 +00:00
|
|
|
capList.append("noSuch");
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::isSupported(capList), false );
|
2004-11-06 23:29:02 +00:00
|
|
|
capList.clear();
|
|
|
|
capList.append("noSuch");
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::isSupported(capList), false );
|
|
|
|
}
|
2004-11-09 09:00:22 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::secureMemory()
|
|
|
|
{
|
2004-11-09 09:00:22 +00:00
|
|
|
// this should be reliably true
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::haveSecureMemory(), true );
|
|
|
|
}
|
2004-11-21 00:16:07 +00:00
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
void StaticUnitTest::providers()
|
|
|
|
{
|
2004-11-21 00:16:07 +00:00
|
|
|
// providers are obviously variable, this might be a bit brittle
|
|
|
|
QStringList providerNames;
|
2005-11-06 09:25:56 +00:00
|
|
|
QCA::scanForPlugins();
|
2004-11-21 00:16:07 +00:00
|
|
|
QCA::ProviderList qcaProviders = QCA::providers();
|
Big fixup of the unit test harness, and each unit test case, to match
the new Qt4 stuff, and the removal of QCString from the API
When I run this, I get:
# Running normal tests... #
Base64UnitTest - 22 tests passed, 0 tests failed
BigIntUnitTest - 252 tests passed, 0 tests failed
CertUnitTest - 0 tests passed, 1 test failed
Unexpected failure:
certunittest.cpp[40]: failed on "QCA::haveSystemStore()"
result = '0', expected = '1'
CipherUnitTest - 2740 tests passed, 0 tests failed
HashUnitTest - 186 tests passed, 0 tests failed
HexUnitTest - 17 tests passed, 0 tests failed
KDFUnitTest - 0 tests passed, 0 tests failed; also 2 skipped
Skipped tests:
kdfunittest.cpp[80]: "PBKDF version 1 with SHA1 not supported"
kdfunittest.cpp[98]: "PBKDF version 2 with SHA1 not supported"
KeyLengthUnitTest - 9 tests passed, 0 tests failed
MACUnitTest - 33 tests passed, 0 tests failed
RandomUnitTest - 67 tests passed, 0 tests failed
SecureArrayUnitTest - 32 tests passed, 0 tests failed
StaticUnitTest - 31 tests passed, 0 tests failed
SymmetricKeyUnitTest - 13 tests passed, 0 tests failed
# Done with normal tests:
Total test cases: 13
Total test steps : 3405
Total passed test steps (including unexpected) : 3402
Total unexpected passed test steps : 0
Total failed test steps (including expected) : 1
Total expected failed test steps : 0
Total skipped test steps : 2
CCMAIL: delta-affinix.com@lists.affinix.com
svn path=/trunk/kdesupport/qca/; revision=394072
2005-03-01 11:15:25 +00:00
|
|
|
for (int i = 0; i < qcaProviders.size(); ++i) {
|
|
|
|
providerNames.append( qcaProviders[i]->name() );
|
2004-11-21 00:16:07 +00:00
|
|
|
}
|
2007-06-29 21:30:22 +00:00
|
|
|
QCOMPARE( providerNames.contains("qca-ossl"), (QBool)true );
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( providerNames.contains("qca-gcrypt"), (QBool)true );
|
2006-12-17 07:22:35 +00:00
|
|
|
QCOMPARE( providerNames.contains("qca-nss"), (QBool)true );
|
|
|
|
QCOMPARE( providerNames.contains("qca-pkcs11"), (QBool)true );
|
|
|
|
QCOMPARE( providerNames.contains("qca-gnupg"), (QBool)true );
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( providerNames.contains("qca-botan"), (QBool)true );
|
2004-12-30 09:22:20 +00:00
|
|
|
|
2007-06-29 21:30:22 +00:00
|
|
|
QCA::setProviderPriority("qca-ossl", 4);
|
2004-12-30 09:22:20 +00:00
|
|
|
QCA::setProviderPriority("qca-botan", 2);
|
2007-06-29 21:30:22 +00:00
|
|
|
QCOMPARE( QCA::providerPriority( "qca-ossl"), 4 );
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::providerPriority( "qca-gcrypt"), 0 );
|
|
|
|
QCOMPARE( QCA::providerPriority( "qca-botan"), 2 );
|
2007-06-29 21:30:22 +00:00
|
|
|
QCA::setProviderPriority("qca-ossl", 3);
|
2004-12-30 09:22:20 +00:00
|
|
|
// reuse last
|
|
|
|
QCA::setProviderPriority("qca-botan", -1);
|
2005-11-06 09:25:56 +00:00
|
|
|
QCOMPARE( QCA::providerPriority( "qca-botan"), 3 );
|
2004-12-30 09:22:20 +00:00
|
|
|
|
|
|
|
QCA::unloadAllPlugins();
|
2004-10-23 11:28:42 +00:00
|
|
|
}
|
|
|
|
|
2005-11-06 09:25:56 +00:00
|
|
|
QTEST_MAIN(StaticUnitTest)
|
2006-10-12 05:45:32 +00:00
|
|
|
|
|
|
|
#include "staticunittest.moc"
|
|
|
|
|