From 0d7aea8b9ce763198225f1dc33eec9b487a823f6 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 29 Sep 2016 16:25:57 +0200 Subject: [PATCH] Reworking handling privileges for hybrid application This patch keeps single list of privileges (stored in manifest_x) and filters privileges when registring security rules of applications. Following changed: - generated platform manifest xml contains tags with 'type' atttibute set to 'tpk' or 'wgt', - in case of absence of attribute, its default value is 'tpk', - manifest_x changes privilege type from GList of char* to GList of privilege_x. Structure named 'privilege_x' contain parsed privilege type, - although there is one privilege list, given the fact that privilege now have type, native and web privileges should be registered in native or web apps only. Verification: - no regression in tpk/wgt smoke tests, - install hybrid app with native and web privileges and check generated manifest file for privileges, - install web app with privileges and check generated manifest file, - install web app without privileges and check generated manifest file -> default privileges should be added. Submit together: - https://review.tizen.org/gerrit/#/c/90540/ - https://review.tizen.org/gerrit/#/c/90543/ - https://review.tizen.org/gerrit/#/c/90544/ - https://review.tizen.org/gerrit/#/c/90546/ - https://review.tizen.org/gerrit/#/c/90561/ Change-Id: I16a0ec57d48c615f58aa8bada27073fb26208298 --- src/common/certificate_validation.cc | 56 ++++++--- src/common/certificate_validation.h | 4 +- src/common/installer_context.cc | 3 +- src/common/installer_context.h | 7 ++ src/common/privileges.cc | 44 ++++++- src/common/privileges.h | 40 ++++++- src/common/security_registration.cc | 32 +++-- src/common/security_registration.h | 8 +- .../step/configuration/step_parse_manifest.cc | 10 +- .../step_create_per_user_storage_directories.cc | 4 +- .../filesystem/step_create_storage_directories.cc | 4 +- src/common/step/security/step_check_signature.cc | 2 +- .../step/security/step_privilege_compatibility.cc | 129 ++++++++++++++------- .../step/security/step_privilege_compatibility.h | 17 ++- src/common/step/security/step_recover_security.cc | 2 +- src/common/step/security/step_register_security.cc | 2 +- src/common/step/security/step_revoke_security.cc | 3 +- .../step_rollback_deinstallation_security.cc | 2 +- src/common/step/security/step_update_security.cc | 4 +- 19 files changed, 281 insertions(+), 92 deletions(-) diff --git a/src/common/certificate_validation.cc b/src/common/certificate_validation.cc index 9e1864a..2e97b2b 100644 --- a/src/common/certificate_validation.cc +++ b/src/common/certificate_validation.cc @@ -5,11 +5,14 @@ #include "common/certificate_validation.h" #include +#include #include #include #include +#include +#include "common/privileges.h" #include "common/utils/base64.h" namespace bf = boost::filesystem; @@ -227,9 +230,8 @@ bool ValidateSignatures(const bf::path& base_path, } bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level, - const std::string& app_type, const char* api_version, GList* privileges, + const char* api_version, GList* privileges, std::string* error_message) { - bool is_web_app = app_type == "wgt"; if (level == common_installer::PrivilegeLevel::UNTRUSTED) { if (privileges) { LOG(ERROR) << "Untrusted application cannot declare privileges"; @@ -239,23 +241,39 @@ bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level, } } - char* error = nullptr; - int status = PRVMGR_ERR_NONE; - // Do the privilege check only if the package has privileges - if (privileges) { - status = privilege_manager_verify_privilege(api_version, - is_web_app ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, - privileges, PrivilegeLevelToVisibility(level), &error); - } - if (status != PRVMGR_ERR_NONE) { - std::string errnum = - boost::str(boost::format("%d") % status); - LOG(ERROR) << "Error while verifing privilege level: " - << error << " <" << errnum << ">"; - *error_message = error; - *error_message += ":<" + errnum + ">"; - free(error); - return false; + GList* native_privileges = + ci::PrivilegeXToPrivilege(privileges, ci::kNativePrivilegeType); + BOOST_SCOPE_EXIT_ALL(&) { + g_list_free_full(native_privileges, free); + }; + GList* web_privileges = + ci::PrivilegeXToPrivilege(privileges, ci::kWebPrivilegeType); + BOOST_SCOPE_EXIT_ALL(&) { + g_list_free_full(web_privileges, free); + }; + + for (const std::pair& pair : + std::initializer_list>{ + {native_privileges, false}, + {web_privileges, true} + }) { + char* error = nullptr; + int status = PRVMGR_ERR_NONE; + // Do the privilege check only if the package has privileges + if (pair.first) { + status = privilege_manager_verify_privilege(api_version, + pair.second ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, + pair.first, PrivilegeLevelToVisibility(level), &error); + } + if (status != PRVMGR_ERR_NONE) { + std::string errnum = boost::str(boost::format("%d") % status); + LOG(ERROR) << "Error while verifing privilege level: " + << error << " <" << errnum << ">"; + *error_message = error; + *error_message += ":<" + errnum + ">"; + free(error); + return false; + } } LOG(INFO) << "Privilege level checked"; return true; diff --git a/src/common/certificate_validation.h b/src/common/certificate_validation.h index e257aa3..e1670d8 100644 --- a/src/common/certificate_validation.h +++ b/src/common/certificate_validation.h @@ -37,8 +37,8 @@ bool ValidateSignatures(const boost::filesystem::path& base_path, bool check_reference, std::string* error_message); bool ValidatePrivilegeLevel(common_installer::PrivilegeLevel level, - const std::string& app_type, const char* api_version, GList* privileges, - std::string* error_message); + const char* api_version, GList* privileges, + std::string* error_message); } // namespace common_installer diff --git a/src/common/installer_context.cc b/src/common/installer_context.cc index 340196b..73f9f75 100644 --- a/src/common/installer_context.cc +++ b/src/common/installer_context.cc @@ -36,7 +36,8 @@ InstallerContext::InstallerContext() uid(getuid()), backend_data(nullptr), privilege_level(PrivilegeLevel::UNTRUSTED), - is_preload_request(false) {} + is_preload_request(false), + cross_app_rules(false) {} InstallerContext::~InstallerContext() { if (manifest_data.get()) diff --git a/src/common/installer_context.h b/src/common/installer_context.h index b71bae3..bdfbae5 100644 --- a/src/common/installer_context.h +++ b/src/common/installer_context.h @@ -296,6 +296,13 @@ class InstallerContext { Property force_remove; /** + * \brief Describes behaviour for security manager. It set to true, this will + * force to generates n-to-n rules for package's apps. + * This will be used for hybrid apps. + */ + Property cross_app_rules; + + /** * \brief Property of vector of files to add */ Property> files_to_add; diff --git a/src/common/privileges.cc b/src/common/privileges.cc index 9505488..1f47941 100644 --- a/src/common/privileges.cc +++ b/src/common/privileges.cc @@ -4,7 +4,12 @@ #include "common/privileges.h" -namespace common { +#include +#include + +#include "common/utils/glist_range.h" + +namespace common_installer { namespace privileges { const char kImePrivilegeName[] = "http://tizen.org/privilege/ime"; const char kPrivForWebApp[] = @@ -20,4 +25,39 @@ const char kPrivForExternalAppData[] = const char kPrivForSharedData[] = "http://tizen.org/privilege/appdir.shareddata"; } // namespace privileges -} // namespace common + +const char kNativePrivilegeType[] = "tpk"; +const char kWebPrivilegeType[] = "wgt"; + +GList* PrivilegeXToPrivilege(GList* privileges, const std::string& type) { + GList* result = nullptr; + for (auto& r : GListRange(privileges)) { + if (type == r->type) { + result = g_list_append(result, strdup(r->value)); + } + } + return result; +} + +GList* PrivilegeToPrivilegeX(GList* privileges, const std::string& type) { + GList* result = nullptr; + for (auto& r : GListRange(privileges)) { + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(type.c_str()); + privilege->value = strdup(r); + result = g_list_append(result, privilege); + } + return result; +} + +void FreePrivilegeX(gpointer data) { + privilege_x* privilege = reinterpret_cast(data); + if (privilege->type) + free(privilege->type); + if (privilege->value) + free(privilege->value); + free(privilege); +} + +} // namespace common_installer diff --git a/src/common/privileges.h b/src/common/privileges.h index 23cdd18..34be41b 100644 --- a/src/common/privileges.h +++ b/src/common/privileges.h @@ -5,7 +5,12 @@ #ifndef COMMON_PRIVILEGES_H_ #define COMMON_PRIVILEGES_H_ -namespace common { +#include +#include + +#include + +namespace common_installer { namespace privileges { extern const char kImePrivilegeName[]; extern const char kPrivForWebApp[]; @@ -15,6 +20,37 @@ extern const char kPrivForPlatform[]; extern const char kPrivForExternalAppData[]; extern const char kPrivForSharedData[]; } // namespace privileges -} // namespace common + +extern const char kNativePrivilegeType[]; +extern const char kWebPrivilegeType[]; + +/** + * @brief PrivilegeByType + * Converts glist of privilege_x to glist of char* filtering by type + * + * @param privileges glist of privilege_x + * @param type type for filter + * @return glist of char* + */ +GList* PrivilegeXToPrivilege(GList* privileges, const std::string& type); + +/** + * @brief PrivilegeAppendType + * Converts glist of char* to glist of privilege_x of given type + * + * @param privileges glist of char* + * @param type type to be added + * @return glist of privilege_x + */ +GList* PrivilegeToPrivilegeX(GList* privileges, const std::string& type); + +/** + * @brief FreePrivilegeX + * free function for glist_free_full to free privilege_x + * @param data + */ +void FreePrivilegeX(gpointer data); + +} // namespace common_installer #endif // COMMON_PRIVILEGES_H_ diff --git a/src/common/security_registration.cc b/src/common/security_registration.cc index a90bc5e..335265e 100644 --- a/src/common/security_registration.cc +++ b/src/common/security_registration.cc @@ -18,6 +18,7 @@ #include #include "common/pkgmgr_query.h" +#include "common/privileges.h" #include "common/utils/file_util.h" #include "common/utils/glist_range.h" @@ -55,7 +56,7 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id, const std::string& author_id, const std::string& api_version, const boost::filesystem::path& path, uid_t uid, const std::vector& privileges, - app_inst_req* req, std::string* error_message) { + app_inst_req* req, bool /*cross_app_rules*/, std::string* error_message) { if (app_id.empty() || pkg_id.empty()) { LOG(ERROR) << "Appid or pkgid is empty. Both values must be set"; return false; @@ -79,6 +80,8 @@ bool PrepareRequest(const std::string& app_id, const std::string& pkg_id, return false; } + // TODO(t.iwanek): set is_hybrid in request according to cross_app_rules var + error = security_manager_app_inst_req_set_uid(req, uid); if (error != SECURITY_MANAGER_SUCCESS) { std::string errnum = boost::str(boost::format("%d") % error); @@ -221,7 +224,7 @@ bool RegisterSecurityContext(const std::string& app_id, const std::string& pkg_id, const std::string& author_id, const std::string& api_version, const boost::filesystem::path& path, uid_t uid, const std::vector& privileges, - std::string* error_message) { + bool cross_app_rules, std::string* error_message) { app_inst_req* req; int error = security_manager_app_inst_req_new(&req); @@ -236,7 +239,7 @@ bool RegisterSecurityContext(const std::string& app_id, } if (!PrepareRequest(app_id, pkg_id, author_id, api_version, path, uid, - privileges, req, error_message)) { + privileges, req, cross_app_rules, error_message)) { LOG(ERROR) << "Failed while preparing security_manager_app_inst_req"; security_manager_app_inst_req_free(req); return false; @@ -272,7 +275,7 @@ bool UnregisterSecurityContext(const std::string& app_id, } if (!PrepareRequest(app_id, pkg_id, std::string(), std::string(), - bf::path(), uid, {}, req, error_message)) { + bf::path(), uid, {}, req, false, error_message)) { LOG(ERROR) << "Failed while preparing security_manager_app_inst_req"; security_manager_app_inst_req_free(req); return false; @@ -296,18 +299,29 @@ bool UnregisterSecurityContext(const std::string& app_id, bool RegisterSecurityContextForManifest( const std::string& pkg_id, const boost::filesystem::path& path, uid_t uid, common_installer::CertificateInfo* cert_info, manifest_x* manifest, - std::string* error_message) { - std::vector priv_vec; - for (const char* priv : GListRange(manifest->privileges)) { - priv_vec.emplace_back(priv); + bool cross_app_rules, std::string* error_message) { + // Although application framework hold list of privilege per package, there + // is situation where we need to filter privileges. This data model doesn't + // cover hybrid apps well where native privileges should be granted only to + // native app and web privileges should be granted only to web applications. + std::vector tpk_priv_vec; + std::vector wgt_priv_vec; + for (auto& priv : GListRange(manifest->privileges)) { + if (strcmp(priv->type, kWebPrivilegeType) == 0) + wgt_priv_vec.emplace_back(priv->value); + else + tpk_priv_vec.emplace_back(priv->value); } for (application_x* app : GListRange(manifest->application)) { if (!app->appid) { return false; } + bool is_web_priv = strcmp(app->type, "webapp") == 0; if (!RegisterSecurityContext(app->appid, pkg_id, cert_info->author_id.get(), - manifest->api_version, path, uid, priv_vec, error_message)) { + manifest->api_version, path, uid, + is_web_priv ? wgt_priv_vec : tpk_priv_vec, + cross_app_rules, error_message)) { return false; } } diff --git a/src/common/security_registration.h b/src/common/security_registration.h index b8a60e2..c0b42b9 100644 --- a/src/common/security_registration.h +++ b/src/common/security_registration.h @@ -29,6 +29,8 @@ namespace common_installer { * \param path path of installed package * \param uid uid * \param privileges pointer to manifest structure + * \param cross_app_rules true if n-to-n smack rules should be generated + * apps (should be set for hybrid applications). * \param error_message extra/detailed error message * * \return true if success @@ -37,7 +39,7 @@ bool RegisterSecurityContext(const std::string& app_id, const std::string& pkg_id, const std::string& author_id, const std::string& api_version, const boost::filesystem::path& path, uid_t uid, const std::vector& privileges, - std::string* error_message); + bool cross_app_rules, std::string* error_message); /** * Adapter interface for external Security module. @@ -66,6 +68,8 @@ bool UnregisterSecurityContext(const std::string& app_id, * \param uid uid * \param cert_info pointer to certificate info * \param manifest pointer to manifest structure + * \param cross_app_rules true if n-to-n smack rules should be generated + * apps (should be set for hybrid applications). * \param error_message extra/detailed error message * * \return true if success @@ -73,7 +77,7 @@ bool UnregisterSecurityContext(const std::string& app_id, bool RegisterSecurityContextForManifest(const std::string& pkg_id, const boost::filesystem::path& path, uid_t uid, common_installer::CertificateInfo* cert_info, manifest_x* manifest, - std::string* error_message); + bool cross_app_rules, std::string* error_message); /** * Adapter interface for external Security module. diff --git a/src/common/step/configuration/step_parse_manifest.cc b/src/common/step/configuration/step_parse_manifest.cc index be9abdd..f54436b 100644 --- a/src/common/step/configuration/step_parse_manifest.cc +++ b/src/common/step/configuration/step_parse_manifest.cc @@ -35,6 +35,7 @@ #include "common/feature_validator.h" #include "common/installer_context.h" #include "common/paths.h" +#include "common/privileges.h" #include "common/pkgmgr_registration.h" #include "common/pkgmgr_query.h" #include "common/step/step.h" @@ -306,10 +307,13 @@ bool StepParseManifest::FillPrivileges(manifest_x* manifest) { if (!perm_info) return true; - std::set privileges = perm_info->GetPrivileges(); + const auto& privileges = perm_info->GetPrivileges(); for (auto& priv : privileges) { - manifest->privileges = g_list_append(manifest->privileges, - strdup(priv.c_str())); + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->value = strdup(priv.first.c_str()); + privilege->type = strdup(priv.second.c_str()); + manifest->privileges = g_list_append(manifest->privileges, privilege); } return true; } diff --git a/src/common/step/filesystem/step_create_per_user_storage_directories.cc b/src/common/step/filesystem/step_create_per_user_storage_directories.cc index 3c9ebeb..83d4177 100644 --- a/src/common/step/filesystem/step_create_per_user_storage_directories.cc +++ b/src/common/step/filesystem/step_create_per_user_storage_directories.cc @@ -31,8 +31,8 @@ common_installer::Step::Status StepCreatePerUserStorageDirectories::process() { trusted = true; bool shareddata = false; - for (char* priv : GListRange(manifest->privileges)) { - if (!strcmp(priv, common::privileges::kPrivForSharedData)) { + for (auto& priv : GListRange(manifest->privileges)) { + if (!strcmp(priv->value, privileges::kPrivForSharedData)) { shareddata = true; break; } diff --git a/src/common/step/filesystem/step_create_storage_directories.cc b/src/common/step/filesystem/step_create_storage_directories.cc index cc81b8a..e13c5ee 100644 --- a/src/common/step/filesystem/step_create_storage_directories.cc +++ b/src/common/step/filesystem/step_create_storage_directories.cc @@ -93,8 +93,8 @@ bool StepCreateStorageDirectories::SubShareDir() { return false; } bool has_priv = false; - for (char* priv : GListRange(manifest->privileges)) { - if (!strcmp(priv, common::privileges::kPrivForSharedData)) { + for (auto& priv : GListRange(manifest->privileges)) { + if (!strcmp(priv->value, privileges::kPrivForSharedData)) { has_priv = true; break; } diff --git a/src/common/step/security/step_check_signature.cc b/src/common/step/security/step_check_signature.cc index ecd9c83..3723237 100644 --- a/src/common/step/security/step_check_signature.cc +++ b/src/common/step/security/step_check_signature.cc @@ -87,7 +87,7 @@ Step::Status StepCheckSignature::CheckSignatureMismatch() { Step::Status StepCheckSignature::CheckPrivilegeLevel(PrivilegeLevel level) { std::string error_message; if (!context_->is_preload_request.get()) { - if (!ValidatePrivilegeLevel(level, context_->pkg_type.get(), + if (!ValidatePrivilegeLevel(level, context_->manifest_data.get()->api_version, context_->manifest_data.get()->privileges, &error_message)) { if (!error_message.empty()) { diff --git a/src/common/step/security/step_privilege_compatibility.cc b/src/common/step/security/step_privilege_compatibility.cc index ca9cfe1..f24dcbb 100644 --- a/src/common/step/security/step_privilege_compatibility.cc +++ b/src/common/step/security/step_privilege_compatibility.cc @@ -4,9 +4,12 @@ #include "common/step/security/step_privilege_compatibility.h" +#include + #include #include +#include #include #include #include @@ -15,8 +18,39 @@ #include "common/privileges.h" #include "common/utils/glist_range.h" +namespace ci = common_installer; + namespace { +std::string GetInternalPrivilegeForLevel(ci::PrivilegeLevel level) { + switch (level) { + case common_installer::PrivilegeLevel::PUBLIC: + return ci::privileges::kPrivForPublic; + case common_installer::PrivilegeLevel::PARTNER: + return ci::privileges::kPrivForPartner; + case common_installer::PrivilegeLevel::PLATFORM: + return ci::privileges::kPrivForPlatform; + default: + assert(false && "This shouldn't be reached"); + } +} + +bool MapPrivileges(GList* priv, GList** out, bool is_web, + const char* api_version) { + if (!priv) + return true; + + if (privilege_manager_get_mapped_privilege_list(api_version, + is_web ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, + priv, out) != PRVMGR_ERR_NONE) { + LOG(ERROR) << "privilege_manager_get_mapped_privilege_list failed for " + << (is_web ? "web privileges" : "native privileges"); + return false; + } + + return true; +} + bool TranslatePrivilegesForCompatibility(manifest_x* m) { if (!m->api_version) { LOG(WARNING) << "Skipping privileges mapping because api-version " @@ -29,26 +63,44 @@ bool TranslatePrivilegesForCompatibility(manifest_x* m) { return true; } - // get mapping - GList* mapped_privilege_list; - bool is_webapp = (strncmp(m->type, "wgt", strlen("wgt")) == 0) ? true : false; - LOG(DEBUG) << "type = " << m->type; - if (privilege_manager_get_mapped_privilege_list(m->api_version, - is_webapp ? PRVMGR_PACKAGE_TYPE_WRT : PRVMGR_PACKAGE_TYPE_CORE, - m->privileges, &mapped_privilege_list) != PRVMGR_ERR_NONE) { - LOG(ERROR) << "privilege_manager_get_mapped_privilege_list failed"; + GList* native_privileges = + ci::PrivilegeXToPrivilege(m->privileges, ci::kNativePrivilegeType); + GList* web_privileges = + ci::PrivilegeXToPrivilege(m->privileges, ci::kWebPrivilegeType); + GList* mapped_native_privileges = nullptr; + GList* mapped_web_privileges = nullptr; + GList* converted_native_privileges = nullptr; + GList* converted_web_privileges = nullptr; + BOOST_SCOPE_EXIT_ALL(&) { + g_list_free_full(native_privileges, free); + g_list_free_full(web_privileges, free); + g_list_free_full(mapped_native_privileges, free); + g_list_free_full(mapped_web_privileges, free); + g_list_free_full(converted_native_privileges, &ci::FreePrivilegeX); + g_list_free_full(converted_web_privileges, &ci::FreePrivilegeX); + }; + if (!MapPrivileges(native_privileges, &mapped_native_privileges, false, + m->api_version)) + return false; + if (!MapPrivileges(web_privileges, &mapped_web_privileges, true, + m->api_version)) return false; - } - // set pkgmgr new list - g_list_free_full(m->privileges, free); - m->privileges = nullptr; - for (GList* l = mapped_privilege_list; l != nullptr; l = l->next) { - m->privileges = g_list_append(m->privileges, - strdup(reinterpret_cast(l->data))); - } + converted_native_privileges = + ci::PrivilegeToPrivilegeX(mapped_native_privileges, + ci::kNativePrivilegeType); + converted_web_privileges = + ci::PrivilegeToPrivilegeX(mapped_web_privileges, + ci::kWebPrivilegeType); + + converted_native_privileges = + g_list_concat(converted_native_privileges, converted_web_privileges); + converted_web_privileges = nullptr; + + g_list_free_full(m->privileges, &ci::FreePrivilegeX); + m->privileges = converted_native_privileges; + converted_native_privileges = nullptr; - g_list_free_full(mapped_privilege_list, free); return true; } @@ -67,30 +119,27 @@ Step::Status StepPrivilegeCompatibility::precheck() { Step::Status StepPrivilegeCompatibility::process() { // Add default privileges for each certificates level. - bool ret = true; - switch (context_->privilege_level.get()) { - case common_installer::PrivilegeLevel::PUBLIC: - context_->manifest_data.get()->privileges = - g_list_append(context_->manifest_data.get()->privileges, - strdup(common::privileges::kPrivForPublic)); - break; - case common_installer::PrivilegeLevel::PARTNER: - context_->manifest_data.get()->privileges = - g_list_append(context_->manifest_data.get()->privileges, - strdup(common::privileges::kPrivForPartner)); - break; - case common_installer::PrivilegeLevel::PLATFORM: - context_->manifest_data.get()->privileges = - g_list_append(context_->manifest_data.get()->privileges, - strdup(common::privileges::kPrivForPlatform)); - break; - default: - LOG(ERROR) << "Untrusted package are not suppored anymore"; - return Status::PRIVILEGE_ERROR; + auto internal_priv = + GetInternalPrivilegeForLevel(context_->privilege_level.get()); + + if (internal_priv_type_ == InternalPrivType::TPK || + internal_priv_type_ == InternalPrivType::BOTH) { + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(kNativePrivilegeType); + privilege->value = strdup(internal_priv.c_str()); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, privilege); } - if (!ret) { - LOG(ERROR) << "Error during adding default privileges for certificates."; - return Status::PRIVILEGE_ERROR; + + if (internal_priv_type_ == InternalPrivType::WGT || + internal_priv_type_ == InternalPrivType::BOTH) { + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(kWebPrivilegeType); + privilege->value = strdup(internal_priv.c_str()); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, privilege); } return TranslatePrivilegesForCompatibility(context_->manifest_data.get()) ? diff --git a/src/common/step/security/step_privilege_compatibility.h b/src/common/step/security/step_privilege_compatibility.h index 83da70e..1f50043 100644 --- a/src/common/step/security/step_privilege_compatibility.h +++ b/src/common/step/security/step_privilege_compatibility.h @@ -7,6 +7,8 @@ #include +#include + #include "common/installer_context.h" #include "common/step/step.h" @@ -19,7 +21,17 @@ namespace security { */ class StepPrivilegeCompatibility : public Step { public: - using Step::Step; + enum class InternalPrivType { + TPK, + WGT, + BOTH, + }; + + StepPrivilegeCompatibility(InstallerContext* context, + InternalPrivType internal_priv_type) + : Step(context), + internal_priv_type_(internal_priv_type) { + } Status process() override; Status clean() override { return Status::OK; } @@ -27,6 +39,9 @@ class StepPrivilegeCompatibility : public Step { Status undo() override { return Status::OK; } Status precheck() override; + private: + InternalPrivType internal_priv_type_; + STEP_NAME(PrivilegeCompatibility) }; diff --git a/src/common/step/security/step_recover_security.cc b/src/common/step/security/step_recover_security.cc index b0c4e93..566575f 100644 --- a/src/common/step/security/step_recover_security.cc +++ b/src/common/step/security/step_recover_security.cc @@ -50,7 +50,7 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() { if (!RegisterSecurityContextForManifest( context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(), &context_->certificate_info.get(), context_->manifest_data.get(), - &error_message)) { + context_->cross_app_rules.get(), &error_message)) { LOG(ERROR) << "Unsuccessful update"; if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; diff --git a/src/common/step/security/step_register_security.cc b/src/common/step/security/step_register_security.cc index 9ec62c6..61e6e85 100644 --- a/src/common/step/security/step_register_security.cc +++ b/src/common/step/security/step_register_security.cc @@ -42,7 +42,7 @@ Step::Status StepRegisterSecurity::process() { if (!RegisterSecurityContextForManifest( context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(), &context_->certificate_info.get(), context_->manifest_data.get(), - &error_message)) { + context_->cross_app_rules.get(), &error_message)) { if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; on_error(Status::SECURITY_ERROR, error_message); diff --git a/src/common/step/security/step_revoke_security.cc b/src/common/step/security/step_revoke_security.cc index b8187ee..0868030 100644 --- a/src/common/step/security/step_revoke_security.cc +++ b/src/common/step/security/step_revoke_security.cc @@ -29,7 +29,8 @@ Step::Status StepRevokeSecurity::clean() { std::string error_message; if (!UnregisterSecurityContextForManifest( context_->pkgid.get(), context_->uid.get(), - context_->manifest_data.get(), &error_message)) { + context_->manifest_data.get(), + &error_message)) { LOG(ERROR) << "Failure on unregistering security context for app " << context_->pkgid.get(); if (!error_message.empty()) { diff --git a/src/common/step/security/step_rollback_deinstallation_security.cc b/src/common/step/security/step_rollback_deinstallation_security.cc index dcf2553..b7c0a4c 100644 --- a/src/common/step/security/step_rollback_deinstallation_security.cc +++ b/src/common/step/security/step_rollback_deinstallation_security.cc @@ -30,7 +30,7 @@ Step::Status StepRollbackDeinstallationSecurity::undo() { if (!RegisterSecurityContextForManifest( context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(), &context_->certificate_info.get(), context_->manifest_data.get(), - &error_message)) { + context_->cross_app_rules.get(), &error_message)) { LOG(ERROR) << "Failure on re-installing security context for app " << context_->pkgid.get(); if (!error_message.empty()) { diff --git a/src/common/step/security/step_update_security.cc b/src/common/step/security/step_update_security.cc index b954c79..361d7d4 100644 --- a/src/common/step/security/step_update_security.cc +++ b/src/common/step/security/step_update_security.cc @@ -16,7 +16,7 @@ Step::Status StepUpdateSecurity::process() { if (!RegisterSecurityContextForManifest( context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(), &context_->certificate_info.get(), context_->manifest_data.get(), - &error_message)) { + context_->cross_app_rules.get(), &error_message)) { if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; on_error(Status::SECURITY_ERROR, error_message); @@ -41,7 +41,7 @@ Step::Status StepUpdateSecurity::undo() { if (!RegisterSecurityContextForManifest( context_->pkgid.get(), context_->pkg_path.get(), context_->uid.get(), &context_->certificate_info.get(), context_->old_manifest_data.get(), - &error_message)) { + context_->cross_app_rules.get(), &error_message)) { if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; } -- 2.7.4