From: Rafal Walczyna Date: Wed, 8 Aug 2018 11:45:24 +0000 (+0200) Subject: [KeyManager] Add possibility to check whether alias is password protected X-Git-Tag: submit/tizen/20190328.074934~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a3d6687fa0171c671d0d81d58714b5c01087de77;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [KeyManager] Add possibility to check whether alias is password protected [ACR] TWDAPI-194 [Verification] TCT KeyManager tests on 5.5 TM1 - 100% pass New features was tested manually in Chrome Dev Tools Change-Id: I7ace3984746b56d186dd05d99f836d65116a741a Signed-off-by: Rafal Walczyna --- diff --git a/src/keymanager/keymanager_instance.cc b/src/keymanager/keymanager_instance.cc index 2676dc1f..e87c8c2a 100644 --- a/src/keymanager/keymanager_instance.cc +++ b/src/keymanager/keymanager_instance.cc @@ -40,51 +40,8 @@ namespace { typedef std::vector RawBuffer; -typedef int (*AliasListFunction)(ckmc_alias_list_s**); +const std::string kSpace = ckmc_owner_id_separator; -const std::string kSpace = " "; - -void GetGenericAliasList(AliasListFunction func, picojson::object* out) { - ScopeLogger(); - - ckmc_alias_list_s* alias_list = nullptr; - int ret = func(&alias_list); - - picojson::value result{picojson::array{}}; - - if (CKMC_ERROR_NONE == ret) { - auto& aliases = result.get(); - - picojson::value resultElem = picojson::value(picojson::object()); - picojson::object& obj = resultElem.get(); - ckmc_alias_list_s* head = alias_list; - - while (head) { - // aliases.push_back(picojson::value(head->alias ? head->alias : "")); - if (head->alias) { - char* saveptr = nullptr; - char* tokenized = strtok_r(head->alias, kSpace.c_str(), &saveptr); - if (nullptr != tokenized) { - obj["packageId"] = picojson::value(tokenized); - } - tokenized = strtok_r(nullptr, kSpace.c_str(), &saveptr); - if (nullptr != tokenized) { - obj["name"] = picojson::value(tokenized); - } - - aliases.push_back(resultElem); - } - - head = head->next; - } - - if (alias_list) { - ckmc_alias_list_all_free(alias_list); - } - } - - common::tools::ReportSuccess(result, *out); -} } // namespace KeyManagerInstance::KeyManagerInstance() { @@ -110,7 +67,77 @@ KeyManagerInstance::KeyManagerInstance() { void KeyManagerInstance::GetDataAliasList(const picojson::value& args, picojson::object& out) { ScopeLogger(); - GetGenericAliasList(ckmc_get_data_alias_list, &out); + picojson::value result = picojson::value(picojson::array()); + auto& aliases = result.get(); + + ckmc_alias_info_list_s* alias_info_list = nullptr; + SCOPE_EXIT { + ckmc_alias_info_list_all_free(alias_info_list); + }; + + int ret = ckmc_get_data_alias_info_list(&alias_info_list); + + // It is stated in key-manager documantation that this error means empty list + // I have also checked native implementation. It does not look good, but it was + // reported to native team and they decided not to change it. + if (CKMC_ERROR_DB_ALIAS_UNKNOWN == ret) { + LoggerD("Alias list is empty"); + ReportSuccess(result, out); + return; + } + + if (CKMC_ERROR_NONE != ret) { + LoggerD("Failed to get alias list: %d", ret); + PlatformResult error = GetError(ret); + ReportError(error, &out); + return; + } + + picojson::value result_element = picojson::value(picojson::object()); + picojson::object& obj = result_element.get(); + ckmc_alias_info_list_s* current_item = alias_info_list; + + while (current_item) { + if (current_item->info) { + char* name = nullptr; + + ret = ckmc_alias_info_get_alias(current_item->info, &name); + + if (CKMC_ERROR_NONE != ret) { + LoggerD("Failed to get alias name information: %d", ret); + PlatformResult error = GetError(ret); + ReportError(error, &out); + return; + } + LoggerD("Alias name: %s", name); + char* saveptr = nullptr; + char* tokenized = strtok_r(name, kSpace.c_str(), &saveptr); + + if (nullptr != tokenized) { + obj["packageId"] = picojson::value(tokenized); + } + + tokenized = strtok_r(nullptr, kSpace.c_str(), &saveptr); + if (nullptr != tokenized) { + obj["name"] = picojson::value(tokenized); + } + + bool is_password_protected = false; + ret = ckmc_alias_info_is_password_protected(current_item->info, &is_password_protected); + + if (CKMC_ERROR_NONE != ret) { + LoggerE("Failed to get alias password information: %d", ret); + PlatformResult error = GetError(ret); + ReportError(error, &out); + return; + } + obj["isProtected"] = picojson::value(is_password_protected); + aliases.push_back(result_element); + } + current_item = current_item->next; + } + + ReportSuccess(result, out); } PlatformResult KeyManagerInstance::GetError(int ret) { @@ -145,7 +172,6 @@ void KeyManagerInstance::SaveData(const picojson::value& args, picojson::object& if (password_value.is()) { password = password_value.get(); - LoggerE("password %s ", password.c_str()); } auto save_data = [data_raw, password, alias](const std::shared_ptr& result) {