* @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
* @version 1.0
*/
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <cstdlib>
#include <string>
#include <fstream>
#include <sys/smack.h>
#include <fcntl.h>
#include <unistd.h>
#include <unordered_map>
+#include <tzplatform_config.h>
const std::string SMACK_USER_APP_PREFIX = "User::Pkg::";
const char *SYSTEM_LABEL = ckmc_owner_id_system;
RUNNER_ASSERT_MSG(expected == actual, "Actual list of aliases differ from expected list.");
}
-void check_alias_info_list_helper(const CKM::AliasPwdVector& expected, const CKM::AliasPwdVector& actual,
- const std::string &userSmackLabel)
+void check_alias_info_list_helper(const InfoVector& expected,
+ const InfoMap& actual,
+ const std::string &userSmackLabel)
{
std::string errorLogMsg;
- std::unordered_map<std::string, bool> aliasPwdMap;
RUNNER_ASSERT_MSG(expected.size() == actual.size(), "Aliases item count differs, expected: " <<
expected.size() << " actual: " << actual.size());
- for (const auto &it : actual)
- {
- aliasPwdMap[std::get<0>(it)] = std::get<1>(it);
- }
-
-
- for (const auto &it : expected)
+ for (const auto &expectedIt : expected)
{
- auto aliasPwd = aliasPwdMap.find(userSmackLabel + std::get<0>(it));
- if (aliasPwd != aliasPwdMap.end()) {
- if (aliasPwd->second != std::get<1>(it)) {
- errorLogMsg += "Alias: " + std::get<0>(it) + " has wrong encryption status: "
- + std::to_string(std::get<1>(it)) + "\n";
+ auto actualIt = actual.find(userSmackLabel + expectedIt.alias);
+ if (actualIt != actual.end()) {
+ if (actualIt->second.passwordProtected != expectedIt.passwordProtected) {
+ errorLogMsg += "Alias: " + actualIt->second.alias + " has wrong encryption status: "
+ + std::to_string(actualIt->second.passwordProtected) + "\n";
+ }
+ if (actualIt->second.backend != expectedIt.backend) {
+ errorLogMsg += "Alias: " + actualIt->second.alias + " belongs to wrong backend: "
+ + std::to_string(static_cast<int>(actualIt->second.backend)) + "\n";
}
}
else {
- errorLogMsg += "Expected alias: " + std::get<0>(it) + " not found.\n";
+ errorLogMsg += "Expected alias: " + actualIt->second.alias + " not found.\n";
}
}
if (!errorLogMsg.empty()) {
- for (const auto &it : actual)
+ for (const auto& [alias, info] : actual)
{
- errorLogMsg += "Actual alias: " + std::get<0>(it) + " status: "
- + std::to_string(std::get<1>(it)) + "\n";
+ errorLogMsg += "Actual alias: " + alias +
+ " status: " + std::to_string(info.passwordProtected) +
+ " backend: " + std::to_string(static_cast<int>(info.backend)) + "\n";
}
RUNNER_FAIL_MSG("Actual list of aliases differ from expected list.\n" + errorLogMsg);
}
}
-void check_alias_info_list(const CKM::AliasPwdVector& expected)
+CKM::BackendId backend()
+{
+#ifdef TZ_BACKEND
+ return CKM::BackendId::TZ;
+#else
+ return CKM::BackendId::SW;
+#endif
+}
+
+void check_alias_info_list(const InfoVector& expected)
{
ckmc_alias_info_list_s *aliasInfoList = NULL;
int ret = ckmc_get_data_alias_info_list(&aliasInfoList);
RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get the list of data aliases. " << ret << " / "
<< CKMCErrorToString(ret));
- CKM::AliasPwdVector actual;
+ InfoMap actual;
ckmc_alias_info_list_s *plist = aliasInfoList;
- char* alias;
+ char* alias = nullptr;
bool isPasswordProtected;
unsigned int it = 0;
while (plist)
ret = ckmc_alias_info_get_alias(plist->info, &alias);
RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get alias. " << ret << " / "
<< CKMCErrorToString(ret));
+ RUNNER_ASSERT_MSG(alias != nullptr, "Got null alias. Iterator: " << it);
+
ret = ckmc_alias_info_is_password_protected(plist->info, &isPasswordProtected);
RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get password protection status" << ret << " / "
<< CKMCErrorToString(ret));
- RUNNER_ASSERT_MSG(alias != nullptr, "Got null alias. Iterator: " << it);
- actual.push_back(std::make_pair(alias, isPasswordProtected));
+
+ ckmc_backend_id_e backend;
+ ret = ckmc_alias_info_get_backend(plist->info, &backend);
+ RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE, "Failed to get backend" << ret << " / "
+ << CKMCErrorToString(ret));
+
+ actual.try_emplace(alias, alias, isPasswordProtected, static_cast<CKM::BackendId>(backend));
plist = plist->next;
it++;
}
return ParamListPtr(list, ckmc_param_list_free);
}
-void assert_buffers_equal(const ckmc_raw_buffer_s b1, const ckmc_raw_buffer_s b2, bool equal)
+void setParam(ParamListPtr& params, ckmc_param_name_e name, ckmc_raw_buffer_s* buffer)
+{
+ int ret = ckmc_param_list_set_buffer(params.get(), name, buffer);
+ RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE,
+ "Failed to set param " << name << " error: " << CKMCErrorToString(ret));
+}
+
+void setParam(ParamListPtr& params, ckmc_param_name_e name, uint64_t integer)
+{
+ int ret = ckmc_param_list_set_integer(params.get(), name, integer);
+ RUNNER_ASSERT_MSG(ret == CKMC_ERROR_NONE,
+ "Failed to set param " << name << " error: " << CKMCErrorToString(ret));
+}
+
+void assert_buffers_equal(const ckmc_raw_buffer_s* b1, const ckmc_raw_buffer_s* b2, bool equal)
{
if(equal) {
- RUNNER_ASSERT_MSG(b1.size == b2.size, "Buffer size differs: " << b1.size << "!=" << b2.size);
- RUNNER_ASSERT_MSG(0 == memcmp(b1.data, b2.data, b1.size), "Buffer contents differ");
+ RUNNER_ASSERT_MSG(b1->size == b2->size,
+ "Buffer size differs: " << b1->size << "!=" << b2->size);
+ RUNNER_ASSERT_MSG(0 == memcmp(b1->data, b2->data, b1->size), "Buffer contents differ");
} else {
- RUNNER_ASSERT_MSG(b1.size != b2.size || 0 != memcmp(b1.data, b2.data, b1.size),
+ RUNNER_ASSERT_MSG(b1->size != b2->size || 0 != memcmp(b1->data, b2->data, b1->size),
"Buffers should be different");
}
}
return RawBufferPtr(buffer, ckmc_buffer_free);
}
+CipherCtxPtr create_cipher_ctx(ckmc_cipher_ctx_h ctx)
+{
+ return CipherCtxPtr(ctx, ckmc_cipher_free);
+}
+
CKM::Policy generate_ckm_policy(int iterator_nr) {
if (iterator_nr % 2) { // policy with password and with / without extractable flag
return CKM::Policy(CKM::Password("test_pwd"), iterator_nr % 4);
}
return CKM::Policy();
}
+
+void require_default_user(char *argv[])
+{
+ uid_t expected_uid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+ if (expected_uid != geteuid()) {
+ std::string userStr("owner");
+ const char* user = tzplatform_getenv(TZ_SYS_DEFAULT_USER);
+ if (user)
+ userStr = user;
+
+ std::cerr << argv[0] << " should be executed as " << userStr << ". Aborting" << std::endl;
+ exit(-1);
+ }
+}