1 #define BOOST_TEST_MODULE KEY_MANAGER_TEST
2 #include <boost/test/unit_test.hpp>
3 #include <key-provider.h>
4 #include <test_common.h>
7 const CKM::Password PASSWORD = "12345TIZEN12345AAAAAAAAA";
8 const CKM::Password INCORRECT_PASSWORD = "AAAAAAAAAAAAAAAAAAAAA";
9 const CKM::Password NEW_PASSWORD = "NEW12345TIZEN12345NEW";
11 const std::string USERNAME_SHORT = "AB";
12 const std::string USERNAME_LONG = "SOFTWARE_CENTER_SYSTEM_SW_LAB_SECURITY_PART";
13 const std::string SMACK_LABEL_1 = "SAMPLE_SMACK_LABEL_1";
14 const std::string SMACK_LABEL_2 = "SAMPLE_SMACK_LABEL_2";
16 static bool isLibInitialized = false;
18 struct KeyProviderLib {
21 CKM::KeyProvider::initializeLibrary();
22 isLibInitialized = true;
24 Catch (CKM::Exception) {
25 std::cout << "Library initialization failed!" << std::endl;
29 Try { CKM::KeyProvider::closeLibrary(); }
30 Catch (CKM::Exception) {
31 std::cout << "Library deinitialization failed!" << std::endl;
36 BOOST_GLOBAL_FIXTURE(TestConfig)
37 BOOST_GLOBAL_FIXTURE(KeyProviderLib)
39 BOOST_AUTO_TEST_SUITE(KEY_PROVIDER_TEST)
40 BOOST_AUTO_TEST_CASE(KeyDomainKEK){
41 BOOST_REQUIRE_MESSAGE(isLibInitialized,
42 "Library is not initialized!");
43 CKM::KeyProvider keyProvider;
44 CKM::RawBuffer rb_test;
45 BOOST_REQUIRE_NO_THROW(rb_test =
46 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
47 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
48 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
49 "KeyProvider created, but uninitialized");
52 BOOST_AUTO_TEST_CASE(KeyDomainKekInvalidPassword){
53 BOOST_REQUIRE_MESSAGE(isLibInitialized,
54 "Library is not initialized!");
55 CKM::KeyProvider keyProvider;
56 CKM::RawBuffer rb_test;
57 BOOST_REQUIRE_NO_THROW(rb_test =
58 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
59 BOOST_REQUIRE_THROW(keyProvider = CKM::KeyProvider(rb_test, INCORRECT_PASSWORD),
60 CKM::KeyProvider::Exception::PassWordError);
61 BOOST_REQUIRE_MESSAGE(!keyProvider.isInitialized(),
62 "KeyProvider not created, but initialized");
65 BOOST_AUTO_TEST_CASE(KeygetPureDomainKEK){
66 BOOST_REQUIRE_MESSAGE(isLibInitialized,
67 "Library is not initialized!");
68 CKM::KeyProvider keyProvider;
69 CKM::RawBuffer rb_test;
70 BOOST_REQUIRE_NO_THROW(rb_test =
71 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
72 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
73 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
74 "KeyProvider created, but uninitialized");
75 BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getPureDomainKEK());
78 BOOST_AUTO_TEST_CASE(KeyGetWrappedDomainKEK){
79 BOOST_REQUIRE_MESSAGE(isLibInitialized,
80 "Library is not initialized!");
81 CKM::KeyProvider keyProvider;
82 CKM::RawBuffer rb_test;
83 BOOST_REQUIRE_NO_THROW(rb_test =
84 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
85 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
86 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
87 "KeyProvider created, but uninitialized");
88 BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getWrappedDomainKEK(PASSWORD));
91 BOOST_AUTO_TEST_CASE(KeyGenerateDEK){
92 BOOST_REQUIRE_MESSAGE(isLibInitialized,
93 "Library is not initialized!");
94 CKM::KeyProvider keyProvider;
95 CKM::RawBuffer rb_test;
96 CKM::RawBuffer rb_DEK1;
97 BOOST_REQUIRE_NO_THROW(rb_test =
98 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
99 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
100 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
101 "KeyProvider created, but uninitialized");
102 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
105 BOOST_AUTO_TEST_CASE(KeyGetPureDEK){
106 BOOST_REQUIRE_MESSAGE(isLibInitialized,
107 "Library is not initialized!");
108 CKM::KeyProvider keyProvider;
109 CKM::RawBuffer rb_pureDEK1;
110 CKM::RawBuffer rb_DEK1;
111 CKM::RawBuffer rb_test;
112 BOOST_REQUIRE_NO_THROW(rb_test =
113 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
114 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
115 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
116 "KeyProvider created, but uninitialized");
117 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
118 BOOST_REQUIRE_NO_THROW(rb_pureDEK1 = keyProvider.getPureDEK(rb_DEK1));
121 BOOST_AUTO_TEST_CASE(KeyReencrypt){
122 BOOST_REQUIRE_MESSAGE(isLibInitialized,
123 "Library is not initialized!");
124 CKM::RawBuffer rb_test;
125 BOOST_REQUIRE_NO_THROW(rb_test =
126 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
127 BOOST_REQUIRE_NO_THROW(CKM::KeyProvider::reencrypt(rb_test, PASSWORD,
131 BOOST_AUTO_TEST_CASE(KeyReencrypt_incorrect_password){
132 BOOST_REQUIRE_MESSAGE(isLibInitialized,
133 "Library is not initialized!");
134 CKM::RawBuffer rb_test;
135 BOOST_REQUIRE_NO_THROW(rb_test =
136 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
137 BOOST_REQUIRE_THROW((rb_test = CKM::KeyProvider::reencrypt(rb_test, INCORRECT_PASSWORD,
138 NEW_PASSWORD)), CKM::KeyProvider::Exception::PassWordError);
141 BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt){
142 BOOST_REQUIRE_MESSAGE(isLibInitialized,
143 "Library is not initialized!");
144 CKM::KeyProvider keyProvider;
145 CKM::RawBuffer rb_DEK1;
146 CKM::RawBuffer rb_test;
147 BOOST_REQUIRE_NO_THROW(rb_test =
148 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
149 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
150 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
151 BOOST_REQUIRE_NO_THROW(keyProvider.getPureDEK(rb_DEK1));
154 BOOST_AUTO_TEST_SUITE_END()