2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file test_encryption-scheme.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
25 #include <boost/test/unit_test.hpp>
26 #include <boost/test/results_reporter.hpp>
28 #include <scheme-test.h>
33 // this is done to limit the amount of code included in binary
34 const int OLD_ENC_SCHEME = 0;
35 const int NEW_ENC_SCHEME = 1;
37 const char* const ONLYCAP = "/sys/fs/smackfs/onlycap";
39 class OnlycapFixture {
42 std::fstream file(ONLYCAP);
54 std::ofstream file(ONLYCAP);
59 std::string m_oldOnlycap;
62 } // namespace anonymous
64 BOOST_FIXTURE_TEST_SUITE(ENCRYPTION_SCHEME_TEST, OnlycapFixture)
66 // Test database should have the old scheme
67 BOOST_AUTO_TEST_CASE(T010_Check_old_scheme)
73 test.CheckSchemeVersion(filter, OLD_ENC_SCHEME);
76 // Newly written data should use the new scheme
77 BOOST_AUTO_TEST_CASE(T020_Check_new_scheme)
80 test.RemoveUserData();
84 test.CheckSchemeVersion(filter, NEW_ENC_SCHEME);
87 BOOST_AUTO_TEST_CASE(T030_Remove_old_scheme)
93 size_t aliases = test.CountObjects();
94 BOOST_REQUIRE_MESSAGE(aliases == 0, "All aliases should be removed");
97 BOOST_AUTO_TEST_CASE(T040_Remove_new_scheme)
100 test.RemoveUserData();
104 size_t aliases = test.CountObjects();
105 BOOST_REQUIRE_MESSAGE(aliases == 0, "All aliases should be removed");
108 // Reading old db should reencrypt objects with new scheme
109 BOOST_AUTO_TEST_CASE(T100_Read)
116 filter.exportableOnly = true;
117 test.CheckSchemeVersion(filter, NEW_ENC_SCHEME);
120 BOOST_AUTO_TEST_CASE(T110_Count_objects_after_read)
124 size_t orig = test.CountObjects();
125 BOOST_REQUIRE_MESSAGE(orig > 0, "No objects in db");
129 size_t current = test.CountObjects();
130 BOOST_REQUIRE_MESSAGE(current == orig,
131 "Original number of objects: " << orig << " Current: " << current);
134 // Reading old db with incorrect passwords should leave the scheme unchanged
135 BOOST_AUTO_TEST_CASE(T120_Read_wrong_pass)
142 test.CheckSchemeVersion(filter, OLD_ENC_SCHEME);
145 // Signing/verification should reencrypt objects with new scheme
146 BOOST_AUTO_TEST_CASE(T200_SignVerify)
152 ItemFilter filter(DataType::KEY_RSA_PUBLIC, DataType::KEY_RSA_PRIVATE);
153 test.CheckSchemeVersion(filter, NEW_ENC_SCHEME);
156 // Encryption/decryption should reencrypt objects with new scheme
157 BOOST_AUTO_TEST_CASE(T210_EncryptDecrypt)
161 test.EncryptDecrypt();
163 ItemFilter filter1(DataType::KEY_RSA_PUBLIC, DataType::KEY_RSA_PRIVATE);
164 test.CheckSchemeVersion(filter1, NEW_ENC_SCHEME);
166 ItemFilter filter2(DataType::KEY_AES);
167 test.CheckSchemeVersion(filter2, NEW_ENC_SCHEME);
170 // Chain creation should reencrypt objects with new scheme
171 BOOST_AUTO_TEST_CASE(T220_CreateChain)
177 // non exportable certificates and certificates protected with passwords can't be used for chain
179 ItemFilter filter1(DataType::CERTIFICATE);
180 filter1.exportableOnly = true;
181 filter1.noPassword = true;
182 test.CheckSchemeVersion(filter1, NEW_ENC_SCHEME);
184 ItemFilter filter2(DataType::CHAIN_CERT_0, DataType::CHAIN_CERT_15);
185 filter2.exportableOnly = true;
186 filter2.noPassword = true;
187 test.CheckSchemeVersion(filter2, NEW_ENC_SCHEME);
190 BOOST_AUTO_TEST_SUITE_END()