#define BOOST_TEST_MODULE KEY_MANAGER_TEST
#include <boost/test/unit_test.hpp>
+#include <exception.h>
#include <key-provider.h>
#include <test_common.h>
#include <iostream>
-const std::string PASSWORD = "12345TIZEN12345AAAAAAAAA";
-const std::string INCORRECT_PASSWORD = "AAAAAAAAAAAAAAAAAAAAA";
-const std::string NEW_PASSWORD = "NEW12345TIZEN12345NEW";
+const CKM::Password PASSWORD = "12345TIZEN12345AAAAAAAAA";
+const CKM::Password INCORRECT_PASSWORD = "AAAAAAAAAAAAAAAAAAAAA";
+const CKM::Password NEW_PASSWORD = "NEW12345TIZEN12345NEW";
const std::string USERNAME_SHORT = "AB";
const std::string USERNAME_LONG = "SOFTWARE_CENTER_SYSTEM_SW_LAB_SECURITY_PART";
const std::string SMACK_LABEL_1 = "SAMPLE_SMACK_LABEL_1";
const std::string SMACK_LABEL_2 = "SAMPLE_SMACK_LABEL_2";
-static bool isLibInitialized = false;
-
-struct KeyProviderLib {
- KeyProviderLib() {
- Try {
- CKM::KeyProvider::initializeLibrary();
- isLibInitialized = true;
- }
- Catch (CKM::Exception) {
- std::cout << "Library initialization failed!" << std::endl;
- }
- }
- ~KeyProviderLib() {
- Try { CKM::KeyProvider::closeLibrary(); }
- Catch (CKM::Exception) {
- std::cout << "Library deinitialization failed!" << std::endl;
- }
- }
-};
-
-BOOST_GLOBAL_FIXTURE(TestConfig)
-BOOST_GLOBAL_FIXTURE(KeyProviderLib)
+extern bool isLibInitialized;
BOOST_AUTO_TEST_SUITE(KEY_PROVIDER_TEST)
BOOST_AUTO_TEST_CASE(KeyDomainKEK){
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_THROW(keyProvider = CKM::KeyProvider(rb_test, INCORRECT_PASSWORD),
- CKM::KeyProvider::Exception::UnwrapFailed);
+ CKM::Exc::AuthenticationFailed);
BOOST_REQUIRE_MESSAGE(!keyProvider.isInitialized(),
"KeyProvider not created, but initialized");
}
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer 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)));
+ BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
"KeyProvider created, but uninitialized");
BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getPureDomainKEK());
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_test;
- CKM::SafeBuffer rb_DEK1;
+ CKM::RawBuffer rb_test;
+ CKM::RawBuffer rb_DEK1;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_pureDEK1;
- CKM::SafeBuffer rb_DEK1;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_pureDEK1;
+ CKM::RawBuffer rb_DEK1;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
BOOST_AUTO_TEST_CASE(KeyReencrypt){
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(CKM::KeyProvider::reencrypt(rb_test, PASSWORD,
BOOST_AUTO_TEST_CASE(KeyReencrypt_incorrect_password){
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer 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,
- NEW_PASSWORD)), CKM::KeyProvider::Exception::UnwrapFailed);
+ NEW_PASSWORD)), CKM::Exc::AuthenticationFailed);
}
BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt){
BOOST_REQUIRE_MESSAGE(isLibInitialized,
"Library is not initialized!");
CKM::KeyProvider keyProvider;
- CKM::SafeBuffer rb_DEK1;
- CKM::SafeBuffer rb_test;
+ CKM::RawBuffer rb_DEK1;
+ CKM::RawBuffer rb_test;
BOOST_REQUIRE_NO_THROW(rb_test =
CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));