diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test-key-provider.cpp | 26 | ||||
-rw-r--r-- | tests/test_common.cpp | 17 | ||||
-rw-r--r-- | tests/test_common.h | 16 | ||||
-rw-r--r-- | tests/test_db_crypto.cpp | 6 | ||||
-rw-r--r-- | tests/test_sql.cpp | 8 |
5 files changed, 36 insertions, 37 deletions
diff --git a/tests/test-key-provider.cpp b/tests/test-key-provider.cpp index 04c0d9c8..590907d5 100644 --- a/tests/test-key-provider.cpp +++ b/tests/test-key-provider.cpp @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(KeyDomainKEK){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD)); @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(KeyDomainKekInvalidPassword){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_THROW(keyProvider = CKM::KeyProvider(rb_test, INCORRECT_PASSWORD), @@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(KeygetPureDomainKEK){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, std::string(PASSWORD))); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(KeyGetWrappedDomainKEK){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD)); @@ -92,8 +92,8 @@ BOOST_AUTO_TEST_CASE(KeyGenerateDEK){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_test; - CKM::RawBuffer rb_DEK1; + CKM::SafeBuffer rb_test; + CKM::SafeBuffer rb_DEK1; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD)); @@ -106,9 +106,9 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_pureDEK1; - CKM::RawBuffer rb_DEK1; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_pureDEK1; + CKM::SafeBuffer rb_DEK1; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD)); @@ -121,7 +121,7 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK){ BOOST_AUTO_TEST_CASE(KeyReencrypt){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(CKM::KeyProvider::reencrypt(rb_test, PASSWORD, @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(KeyReencrypt){ BOOST_AUTO_TEST_CASE(KeyReencrypt_incorrect_password){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_THROW((rb_test = CKM::KeyProvider::reencrypt(rb_test, INCORRECT_PASSWORD, @@ -142,8 +142,8 @@ BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt){ BOOST_REQUIRE_MESSAGE(isLibInitialized, "Library is not initialized!"); CKM::KeyProvider keyProvider; - CKM::RawBuffer rb_DEK1; - CKM::RawBuffer rb_test; + CKM::SafeBuffer rb_DEK1; + CKM::SafeBuffer rb_test; BOOST_REQUIRE_NO_THROW(rb_test = CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD)); BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD)); diff --git a/tests/test_common.cpp b/tests/test_common.cpp index 55feab35..999f6089 100644 --- a/tests/test_common.cpp +++ b/tests/test_common.cpp @@ -3,27 +3,18 @@ using namespace CKM; -RawBuffer createDefaultPass() { - RawBuffer raw; +SafeBuffer createDefaultPass() { + SafeBuffer raw; for(unsigned char i =0; i < RAW_PASS_SIZE; i++) raw.push_back(i); return raw; } -RawBuffer createBigBlob(std::size_t size) { - RawBuffer raw; +SafeBuffer createBigBlob(std::size_t size) { + SafeBuffer raw; for(std::size_t i = 0; i < size; i++) { raw.push_back(static_cast<unsigned char>(i)); } return raw; } -//raw to hex string conversion from SqlConnection -std::string rawToHexString(const std::vector<unsigned char> &raw) { - std::string dump(raw.size()*2, '0'); - for(std::size_t i = 0; i < raw.size(); i++){ - sprintf(&dump[2*i], "%02x", raw[i]); - } - return dump; -} - diff --git a/tests/test_common.h b/tests/test_common.h index c4a5865c..8f2b33e3 100644 --- a/tests/test_common.h +++ b/tests/test_common.h @@ -1,5 +1,6 @@ #pragma once #include <string> +#include <safe-buffer.h> #include <ckm/ckm-type.h> #include <boost/test/unit_test_log.hpp> #include <boost/test/results_reporter.hpp> @@ -16,15 +17,22 @@ struct TestConfig { private: }; -CKM::RawBuffer createDefaultPass(); -CKM::RawBuffer createBigBlob(std::size_t size); +CKM::SafeBuffer createDefaultPass(); +CKM::SafeBuffer createBigBlob(std::size_t size); -const CKM::RawBuffer defaultPass = createDefaultPass(); +const CKM::SafeBuffer defaultPass = createDefaultPass(); const std::string pattern = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; const std::size_t RAW_PASS_SIZE = 32; const std::size_t HEX_PASS_SIZE = RAW_PASS_SIZE * 2; +template <class T> +std::string rawToHexString(const T &raw) { + std::string dump(raw.size()*2, '0'); + for(std::size_t i = 0; i < raw.size(); i++) { + sprintf(&dump[2*i], "%02x", static_cast<int>(raw[i])); + } + return dump; +} -std::string rawToHexString(const std::vector<unsigned char> &raw); diff --git a/tests/test_db_crypto.cpp b/tests/test_db_crypto.cpp index 4933e6a5..215e6917 100644 --- a/tests/test_db_crypto.cpp +++ b/tests/test_db_crypto.cpp @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(DBtestSimple) { BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass)); DBRow rowPattern = createDefaultRow(); - rowPattern.data = RawBuffer(32, 1); + rowPattern.data = SafeBuffer(32, 1); rowPattern.dataSize = rowPattern.data.size(); checkDBIntegrity(rowPattern, db); @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(DBtestGlobal) { BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass)); DBRow rowPattern = createDefaultRow(restricted_global); - rowPattern.data = RawBuffer(1024, 2); + rowPattern.data = SafeBuffer(1024, 2); rowPattern.dataSize = rowPattern.data.size(); BOOST_REQUIRE_NO_THROW(db.saveDBRow(rowPattern)); @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE(DBtestTransaction) { BOOST_REQUIRE_NO_THROW(db = DBCrypto(crypto_db, defaultPass)); DBRow rowPattern = createDefaultRow(0); - rowPattern.data = RawBuffer(100, 20); + rowPattern.data = SafeBuffer(100, 20); rowPattern.dataSize = rowPattern.data.size(); DBCrypto::Transaction transaction(&db); diff --git a/tests/test_sql.cpp b/tests/test_sql.cpp index 984504ca..d1f5f12b 100644 --- a/tests/test_sql.cpp +++ b/tests/test_sql.cpp @@ -25,7 +25,7 @@ const char *insert_table = "INSERT INTO t1(a,b) VALUES (" " 'two for the show');"; const char *select_table = "SELECT * FROM t1"; -CKM::RawBuffer raw_password = createDefaultPass(); +CKM::SafeBuffer raw_password = createDefaultPass(); BOOST_AUTO_TEST_SUITE(SQL_TEST) BOOST_AUTO_TEST_CASE(sqlTestConversion){ @@ -43,7 +43,7 @@ BOOST_AUTO_TEST_CASE(sqlTestSetKeyTooShort) { BOOST_CHECK(unlink(encrypt_me_not) == 0 || errno == ENOENT); SqlConnection connection(encrypt_me_not, SqlConnection::Flag::CRW); - CKM::RawBuffer wrong_key(RAW_PASS_SIZE - 1, 1); + CKM::SafeBuffer wrong_key(RAW_PASS_SIZE - 1, 1); BOOST_REQUIRE_THROW(connection.SetKey(wrong_key), SqlConnection::Exception::InvalidArguments); } @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(sqlTestSetKeyTooLong) { BOOST_CHECK(unlink(encrypt_me_not) == 0 || errno == ENOENT); SqlConnection connection(encrypt_me_not, SqlConnection::Flag::CRW); - CKM::RawBuffer wrong_key(RAW_PASS_SIZE + 1, 1); + CKM::SafeBuffer wrong_key(RAW_PASS_SIZE + 1, 1); BOOST_REQUIRE_THROW(connection.SetKey(wrong_key), SqlConnection::Exception::InvalidArguments); } @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(sqlTestConnectionEncryptedNegative) { { SqlConnection encrypting_you(encrypt_me, SqlConnection::Flag::RW); - CKM::RawBuffer wrong_password; + CKM::SafeBuffer wrong_password; for(std::size_t i = 0; i < RAW_PASS_SIZE; i++) { wrong_password.push_back(raw_password[i] + 1); } |