From: Tomasz Iwanek Date: Mon, 26 Sep 2016 09:12:48 +0000 (+0200) Subject: Fix checking privilege level for hybrid apps X-Git-Tag: accepted/tizen/common/20161011.154148^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae4180600470832d977354a5bc350031817a1a4c;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Fix checking privilege level for hybrid apps There are two facts: - we need to store all privileges into pkgmgr database, - we need to check privilege level for native and web privileges separatelly in case of hybrid application. Therefore, merging of native and web privilege is delayed till checking privilege level. Installing of hybrid app will involve customized step for checking privilege level. Requires: - https://review.tizen.org/gerrit/89685 Change-Id: I7bb044e4ddb6de488e959b8433105bc22c82f0c1 --- diff --git a/src/hybrid/CMakeLists.txt b/src/hybrid/CMakeLists.txt index ccc7f4a..bc950d5 100644 --- a/src/hybrid/CMakeLists.txt +++ b/src/hybrid/CMakeLists.txt @@ -1,7 +1,9 @@ SET(SRCS step/configuration/step_merge_tpk_config.cc + step/configuration/step_merge_tpk_privileges.cc step/configuration/step_stash_tpk_config.cc step/encryption/step_encrypt_resources.cc + step/security/step_hybrid_check_signature.cc hybrid_installer.cc ) ADD_LIBRARY(${TARGET_LIBNAME_HYBRID} STATIC ${SRCS}) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 7a5e12e..eac41e6 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -57,7 +57,6 @@ #include #include #include -#include #include #include #include @@ -74,8 +73,10 @@ #include "hybrid/hybrid_backend_data.h" #include "hybrid/step/configuration/step_merge_tpk_config.h" +#include "hybrid/step/configuration/step_merge_tpk_privileges.h" #include "hybrid/step/configuration/step_stash_tpk_config.h" #include "hybrid/step/encryption/step_encrypt_resources.h" +#include "hybrid/step/security/step_hybrid_check_signature.h" #include "wgt/step/configuration/step_parse.h" #include "wgt/step/encryption/step_remove_encryption_data.h" #include "wgt/step/filesystem/step_copy_preview_icons.h" @@ -110,7 +111,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -151,7 +153,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -231,7 +234,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -301,7 +305,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -342,7 +347,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -387,7 +393,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -414,7 +421,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); diff --git a/src/hybrid/step/configuration/step_merge_tpk_config.cc b/src/hybrid/step/configuration/step_merge_tpk_config.cc index 913ad98..15d59c3 100644 --- a/src/hybrid/step/configuration/step_merge_tpk_config.cc +++ b/src/hybrid/step/configuration/step_merge_tpk_config.cc @@ -21,10 +21,6 @@ common_installer::Step::Status StepMergeTpkConfig::process() { g_list_concat(wgt_data->application, tpk_data->application); tpk_data->application = nullptr; - wgt_data->privileges = - g_list_concat(wgt_data->privileges, tpk_data->privileges); - tpk_data->privileges = nullptr; - return Status::OK; } diff --git a/src/hybrid/step/configuration/step_merge_tpk_config.h b/src/hybrid/step/configuration/step_merge_tpk_config.h index 2171d59..623eba5 100644 --- a/src/hybrid/step/configuration/step_merge_tpk_config.h +++ b/src/hybrid/step/configuration/step_merge_tpk_config.h @@ -15,6 +15,9 @@ namespace configuration { * \brief MergeTpkConfig * Merges information from tpk manifest into information from widget * configuration for hybrid package. + * + * Expection is the information about native privileges. These are merged in + * \see StepMergeTpkPrivileges */ class StepMergeTpkConfig : public common_installer::Step { public: diff --git a/src/hybrid/step/configuration/step_merge_tpk_privileges.cc b/src/hybrid/step/configuration/step_merge_tpk_privileges.cc new file mode 100644 index 0000000..ef763d6 --- /dev/null +++ b/src/hybrid/step/configuration/step_merge_tpk_privileges.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache 2.0 license that can be +// found in the LICENSE file. + +#include "hybrid/step/configuration/step_merge_tpk_privileges.h" + +#include "hybrid/hybrid_backend_data.h" + +namespace ci = common_installer; + +namespace hybrid { +namespace configuration { + +ci::Step::Status StepMergeTpkPrivileges::process() { + // merge privilege list for insertion into database + HybridBackendData* data = + static_cast(context_->backend_data.get()); + manifest_x* tpk_data = data->tpk_manifest_data.get(); + manifest_x* wgt_data = context_->manifest_data.get(); + wgt_data->privileges = + g_list_concat(wgt_data->privileges, tpk_data->privileges); + tpk_data->privileges = nullptr; + return Status::OK; +} + +} // namespace configuration +} // namespace hybrid diff --git a/src/hybrid/step/configuration/step_merge_tpk_privileges.h b/src/hybrid/step/configuration/step_merge_tpk_privileges.h new file mode 100644 index 0000000..0afe851 --- /dev/null +++ b/src/hybrid/step/configuration/step_merge_tpk_privileges.h @@ -0,0 +1,34 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef HYBRID_STEP_CONFIGURATION_STEP_MERGE_TPK_PRIVILEGES_H_ +#define HYBRID_STEP_CONFIGURATION_STEP_MERGE_TPK_PRIVILEGES_H_ + +#include +#include + +namespace hybrid { +namespace configuration { + +/** + * @brief The StepMergeTpkPrivileges class + * Merges native privileges into web applicaiton privileges when + * installing hybrid app. + */ +class StepMergeTpkPrivileges : public common_installer::Step { + public: + using Step::Step; + + Status process() override; + Status undo() override { return Status::OK; } + Status clean() override { return Status::OK; } + Status precheck() override { return Status::OK; } + + STEP_NAME(MergeTpkPrivileges) +}; + +} // namespace configuration +} // namespace hybrid + +#endif // HYBRID_STEP_CONFIGURATION_STEP_MERGE_TPK_PRIVILEGES_H_ diff --git a/src/hybrid/step/security/step_hybrid_check_signature.cc b/src/hybrid/step/security/step_hybrid_check_signature.cc new file mode 100644 index 0000000..b71717f --- /dev/null +++ b/src/hybrid/step/security/step_hybrid_check_signature.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache 2.0 license that can be +// found in the LICENSE file. + +#include "hybrid/step/security/step_hybrid_check_signature.h" + +#include + +#include + +#include "hybrid/hybrid_backend_data.h" + +namespace ci = common_installer; + +namespace { + +const char kNativePackageType[] = "tpk"; + +} // namespace + +namespace hybrid { +namespace security { + +ci::Step::Status StepHybridCheckSignature::CheckPrivilegeLevel( + ci::PrivilegeLevel level) { + auto status = StepCheckSignature::CheckPrivilegeLevel(level); + if (status != Status::OK) + return status; + + HybridBackendData* data = + static_cast(context_->backend_data.get()); + manifest_x* tpk_data = data->tpk_manifest_data.get(); + if (tpk_data->privileges) { + std::string error_message; + if (!context_->is_preload_request.get()) { + if (!ci::ValidatePrivilegeLevel(level, kNativePackageType, + tpk_data->api_version, tpk_data->privileges, &error_message)) { + if (!error_message.empty()) { + LOG(ERROR) << "error_message: " << error_message; + on_error(Status::SIGNATURE_ERROR, error_message); + } + return Status::SIGNATURE_ERROR; + } + } + } + + return Status::OK; +} + +} // namespace security +} // namespace hybrid diff --git a/src/hybrid/step/security/step_hybrid_check_signature.h b/src/hybrid/step/security/step_hybrid_check_signature.h new file mode 100644 index 0000000..d867700 --- /dev/null +++ b/src/hybrid/step/security/step_hybrid_check_signature.h @@ -0,0 +1,27 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef HYBRID_STEP_SECURITY_STEP_HYBRID_CHECK_SIGNATURE_H_ +#define HYBRID_STEP_SECURITY_STEP_HYBRID_CHECK_SIGNATURE_H_ + +#include +#include + +namespace hybrid { +namespace security { + +class StepHybridCheckSignature + : public common_installer::security::StepCheckSignature { + public: + using StepCheckSignature::StepCheckSignature; + + Status CheckPrivilegeLevel(common_installer::PrivilegeLevel level) override; + + STEP_NAME(HybridCheckSignature) +}; + +} // namespace security +} // namespace hybrid + +#endif // HYBRID_STEP_SECURITY_STEP_HYBRID_CHECK_SIGNATURE_H_