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 extern bool isLibInitialized;
18 BOOST_AUTO_TEST_SUITE(KEY_PROVIDER_TEST)
19 BOOST_AUTO_TEST_CASE(KeyDomainKEK){
20 BOOST_REQUIRE_MESSAGE(isLibInitialized,
21 "Library is not initialized!");
22 CKM::KeyProvider keyProvider;
23 CKM::RawBuffer rb_test;
24 BOOST_REQUIRE_NO_THROW(rb_test =
25 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
26 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
27 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
28 "KeyProvider created, but uninitialized");
31 BOOST_AUTO_TEST_CASE(KeyDomainKekInvalidPassword){
32 BOOST_REQUIRE_MESSAGE(isLibInitialized,
33 "Library is not initialized!");
34 CKM::KeyProvider keyProvider;
35 CKM::RawBuffer rb_test;
36 BOOST_REQUIRE_NO_THROW(rb_test =
37 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
38 BOOST_REQUIRE_THROW(keyProvider = CKM::KeyProvider(rb_test, INCORRECT_PASSWORD),
39 CKM::KeyProvider::Exception::PassWordError);
40 BOOST_REQUIRE_MESSAGE(!keyProvider.isInitialized(),
41 "KeyProvider not created, but initialized");
44 BOOST_AUTO_TEST_CASE(KeygetPureDomainKEK){
45 BOOST_REQUIRE_MESSAGE(isLibInitialized,
46 "Library is not initialized!");
47 CKM::KeyProvider keyProvider;
48 CKM::RawBuffer rb_test;
49 BOOST_REQUIRE_NO_THROW(rb_test =
50 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
51 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
52 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
53 "KeyProvider created, but uninitialized");
54 BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getPureDomainKEK());
57 BOOST_AUTO_TEST_CASE(KeyGetWrappedDomainKEK){
58 BOOST_REQUIRE_MESSAGE(isLibInitialized,
59 "Library is not initialized!");
60 CKM::KeyProvider keyProvider;
61 CKM::RawBuffer rb_test;
62 BOOST_REQUIRE_NO_THROW(rb_test =
63 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
64 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
65 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
66 "KeyProvider created, but uninitialized");
67 BOOST_REQUIRE_NO_THROW(rb_test = keyProvider.getWrappedDomainKEK(PASSWORD));
70 BOOST_AUTO_TEST_CASE(KeyGenerateDEK){
71 BOOST_REQUIRE_MESSAGE(isLibInitialized,
72 "Library is not initialized!");
73 CKM::KeyProvider keyProvider;
74 CKM::RawBuffer rb_test;
75 CKM::RawBuffer rb_DEK1;
76 BOOST_REQUIRE_NO_THROW(rb_test =
77 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
78 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
79 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
80 "KeyProvider created, but uninitialized");
81 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
84 BOOST_AUTO_TEST_CASE(KeyGetPureDEK){
85 BOOST_REQUIRE_MESSAGE(isLibInitialized,
86 "Library is not initialized!");
87 CKM::KeyProvider keyProvider;
88 CKM::RawBuffer rb_pureDEK1;
89 CKM::RawBuffer rb_DEK1;
90 CKM::RawBuffer rb_test;
91 BOOST_REQUIRE_NO_THROW(rb_test =
92 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
93 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
94 BOOST_REQUIRE_MESSAGE(keyProvider.isInitialized(),
95 "KeyProvider created, but uninitialized");
96 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
97 BOOST_REQUIRE_NO_THROW(rb_pureDEK1 = keyProvider.getPureDEK(rb_DEK1));
100 BOOST_AUTO_TEST_CASE(KeyReencrypt){
101 BOOST_REQUIRE_MESSAGE(isLibInitialized,
102 "Library is not initialized!");
103 CKM::RawBuffer rb_test;
104 BOOST_REQUIRE_NO_THROW(rb_test =
105 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
106 BOOST_REQUIRE_NO_THROW(CKM::KeyProvider::reencrypt(rb_test, PASSWORD,
110 BOOST_AUTO_TEST_CASE(KeyReencrypt_incorrect_password){
111 BOOST_REQUIRE_MESSAGE(isLibInitialized,
112 "Library is not initialized!");
113 CKM::RawBuffer rb_test;
114 BOOST_REQUIRE_NO_THROW(rb_test =
115 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
116 BOOST_REQUIRE_THROW((rb_test = CKM::KeyProvider::reencrypt(rb_test, INCORRECT_PASSWORD,
117 NEW_PASSWORD)), CKM::KeyProvider::Exception::PassWordError);
120 BOOST_AUTO_TEST_CASE(KeyGetPureDEK_after_reencrypt){
121 BOOST_REQUIRE_MESSAGE(isLibInitialized,
122 "Library is not initialized!");
123 CKM::KeyProvider keyProvider;
124 CKM::RawBuffer rb_DEK1;
125 CKM::RawBuffer rb_test;
126 BOOST_REQUIRE_NO_THROW(rb_test =
127 CKM::KeyProvider::generateDomainKEK(USERNAME_LONG, PASSWORD));
128 BOOST_REQUIRE_NO_THROW(keyProvider = CKM::KeyProvider(rb_test, PASSWORD));
129 BOOST_REQUIRE_NO_THROW(rb_DEK1 = keyProvider.generateDEK(SMACK_LABEL_1));
130 BOOST_REQUIRE_NO_THROW(keyProvider.getPureDEK(rb_DEK1));
133 BOOST_AUTO_TEST_SUITE_END()