From ae4180600470832d977354a5bc350031817a1a4c Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Mon, 26 Sep 2016 11:12:48 +0200 Subject: [PATCH 01/16] 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 --- src/hybrid/CMakeLists.txt | 2 + src/hybrid/hybrid_installer.cc | 24 ++++++---- .../step/configuration/step_merge_tpk_config.cc | 4 -- .../step/configuration/step_merge_tpk_config.h | 3 ++ .../configuration/step_merge_tpk_privileges.cc | 27 ++++++++++++ .../step/configuration/step_merge_tpk_privileges.h | 34 +++++++++++++++ .../step/security/step_hybrid_check_signature.cc | 51 ++++++++++++++++++++++ .../step/security/step_hybrid_check_signature.h | 27 ++++++++++++ 8 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 src/hybrid/step/configuration/step_merge_tpk_privileges.cc create mode 100644 src/hybrid/step/configuration/step_merge_tpk_privileges.h create mode 100644 src/hybrid/step/security/step_hybrid_check_signature.cc create mode 100644 src/hybrid/step/security/step_hybrid_check_signature.h 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_ -- 2.7.4 From 88bac074ab0094c74a426de47e8a4a2b33200ef1 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Tue, 4 Oct 2016 17:49:40 +0900 Subject: [PATCH 02/16] Fix WgtAppQueryInterface Don't parse again argv, argc. They are already parsed by PkgMgrInterface. Requires: - https://review.tizen.org/gerrit/90478 Change-Id: I2ab9f8ad291f97070d38617e1fd4cb15bb9e986a Signed-off-by: Sangyoon Jang --- src/wgt/wgt_app_query_interface.cc | 57 +++++++++----------------------------- src/wgt/wgt_app_query_interface.h | 14 ++++------ src/wgt_backend/wgt_backend.cc | 3 +- 3 files changed, 21 insertions(+), 53 deletions(-) diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index 90adc45..be08ae1 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -36,35 +37,6 @@ namespace { const char kHybridConfigLocation[] = "res/wgt/config.xml"; const char kTizenManifestLocation[] = "tizen-manifest.xml"; -uid_t GetUid(int argc, char** argv) { - uid_t uid = 0; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-u")) { - if (i + 1 < argc) { - uid = atoi(argv[i + 1]); - break; - } - } - } - - return uid; -} - -std::string GetInstallationRequestInfo(int argc, char** argv) { - std::string path; - for (int i = 0; i < argc; ++i) { - if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "-r") || - !strcmp(argv[i], "-d") || !strcmp(argv[i], "-b") || - !strcmp(argv[i], "-w") || !strcmp(argv[i], "-y")) { - if (i + 1 < argc) { - path = argv[i + 1]; - break; - } - } - } - return path; -} - std::string GetPkgIdFromPath(const std::string& path) { if (!bf::exists(path)) return {}; @@ -115,12 +87,7 @@ std::string ReadPkgidFromRecovery(const std::string& recovery_path) { namespace wgt { -bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { - std::string arg = GetInstallationRequestInfo(argc, argv); - if (arg.empty()) - return false; - - uid_t uid = GetUid(argc, argv); +bool WgtAppQueryInterface::IsPkgInstalled(const std::string& arg, uid_t uid) { // argument from commandline is package id if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode(uid), uid)) return true; @@ -132,24 +99,26 @@ bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid); } -bool WgtAppQueryInterface::IsHybridApplication(int argc, char** argv) { - std::string arg = GetInstallationRequestInfo(argc, argv); +bool WgtAppQueryInterface::IsHybridApplication(const std::string& arg, + uid_t uid) { + std::string info; if (arg.find("apps_rw/recovery-") != std::string::npos) - arg = ReadPkgidFromRecovery(arg); + info = ReadPkgidFromRecovery(arg); + else + info = arg; - uid_t uid = GetUid(argc, argv); - if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode(uid), uid)) { + if (ci::QueryIsPackageInstalled(info, ci::GetRequestMode(uid), uid)) { bf::path package_directory(ci::GetRootAppPath(false, uid)); - if (bf::exists(package_directory / arg / kTizenManifestLocation) && - bf::exists(package_directory / arg / kHybridConfigLocation)) + if (bf::exists(package_directory / info / kTizenManifestLocation) && + bf::exists(package_directory / info / kHybridConfigLocation)) return true; } else { bool tizen_manifest_found = false; bool config_xml_found = false; - if (!ci::CheckPathInZipArchive(arg.c_str(), kTizenManifestLocation, + if (!ci::CheckPathInZipArchive(info.c_str(), kTizenManifestLocation, &tizen_manifest_found)) return false; - if (!ci::CheckPathInZipArchive(arg.c_str(), kHybridConfigLocation, + if (!ci::CheckPathInZipArchive(info.c_str(), kHybridConfigLocation, &config_xml_found)) return false; if (tizen_manifest_found && config_xml_found) diff --git a/src/wgt/wgt_app_query_interface.h b/src/wgt/wgt_app_query_interface.h index 8c3776a..fe075fe 100644 --- a/src/wgt/wgt_app_query_interface.h +++ b/src/wgt/wgt_app_query_interface.h @@ -5,6 +5,10 @@ #ifndef WGT_WGT_APP_QUERY_INTERFACE_H_ #define WGT_WGT_APP_QUERY_INTERFACE_H_ +#include + +#include + #include namespace wgt { @@ -20,23 +24,17 @@ class WgtAppQueryInterface : public common_installer::AppQueryInterface { * \brief method for checking if package is installed based * on argv * - * \param argc main() argc argument passed to the backend - * \param argv main() argv argument passed to the backend - * * \return true if package is installed */ - bool IsAppInstalledByArgv(int argc, char** argv) override; + bool IsPkgInstalled(const std::string& arg, uid_t uid) override; /** * \brief This method is workaround for detecting installation of hybrid * application. * - * \param argc main() argc argument passed to the backend - * \param argv main() argv argument passed to the backend - * * \return true if package is hybrid */ - bool IsHybridApplication(int argc, char** argv); + bool IsHybridApplication(const std::string& arg, uid_t uid); }; } // namespace wgt diff --git a/src/wgt_backend/wgt_backend.cc b/src/wgt_backend/wgt_backend.cc index 14639c6..f0633b4 100644 --- a/src/wgt_backend/wgt_backend.cc +++ b/src/wgt_backend/wgt_backend.cc @@ -24,7 +24,8 @@ int main(int argc, char** argv) { // This is workaround for hybrid apps as they requires much different flow // but installer does not branch at all in current design - if (query_interface.IsHybridApplication(argc, argv)) { + if (query_interface.IsHybridApplication( + pkgmgr->GetRequestInfo(), pkgmgr->GetUid())) { LOG(INFO) << "Hybrid package detected"; hybrid::HybridInstaller installer(pkgmgr); return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1; -- 2.7.4 From a93be446c8cb36cff18a0ad5b7337ff512f5f6fd Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 7 Oct 2016 10:56:10 +0200 Subject: [PATCH 03/16] Patch reinstall/RDS according to SDK behaviour Commit changes reinstall request argument. Now pkgid is expected instead of path to directory. What is more, if package manifest is not in the directory supplied by reinstall/RDS then it will be copied from install location. Application installer expects that SDK will put files into: - local installation: /home/$USERNAME/apps_rw/tmp/$PKGID/ - global installation: /opt/apps/tmp/$PKGID/ Requires: - https://review.tizen.org/gerrit/91412 Submit together: - https://review.tizen.org/gerrit/91430 - https://review.tizen.org/gerrit/91431 - https://review.tizen.org/gerrit/91432 Verification: - run smoke tests, - run reinstall from SDK, - run RDS from SDK. Change-Id: I7a5008c6a5d9d28f4181a0be92d42dc9c8e57e28 --- src/unit_tests/smoke_test.cc | 19 ++++++--- .../test_samples/smoke/delta_dir/.rds_delta | 6 +-- .../smoke/delta_dir/{ => res/wgt}/ADDED | 0 .../smoke/delta_dir/{ => res/wgt}/MODIFIED | 0 .../smoke/delta_dir/{ => res/wgt}/config.xml | 0 src/wgt/CMakeLists.txt | 2 +- .../step/configuration/step_check_rds_manifest.cc | 49 ++++++++++++++++++++++ .../step/configuration/step_check_rds_manifest.h | 31 ++++++++++++++ src/wgt/step/rds/step_wgt_rds_modify.cc | 23 ---------- src/wgt/step/rds/step_wgt_rds_modify.h | 41 ------------------ src/wgt/wgt_installer.cc | 11 ++--- 11 files changed, 104 insertions(+), 78 deletions(-) rename src/unit_tests/test_samples/smoke/delta_dir/{ => res/wgt}/ADDED (100%) rename src/unit_tests/test_samples/smoke/delta_dir/{ => res/wgt}/MODIFIED (100%) rename src/unit_tests/test_samples/smoke/delta_dir/{ => res/wgt}/config.xml (100%) create mode 100644 src/wgt/step/configuration/step_check_rds_manifest.cc create mode 100644 src/wgt/step/configuration/step_check_rds_manifest.h delete mode 100644 src/wgt/step/rds/step_wgt_rds_modify.cc delete mode 100644 src/wgt/step/rds/step_wgt_rds_modify.h diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 48c6045..ec1ab9d 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -6,13 +6,16 @@ #include #include #include + #include #include #include #include #include #include +#include #include + #include #include #include @@ -334,15 +337,15 @@ ci::AppInstaller::Result Uninstall(const std::string& pkgid, return CallBackend(SIZEOFARRAY(argv), argv, type, mode); } -ci::AppInstaller::Result Reinstall(const bf::path& path, - const bf::path& delta_dir, +ci::AppInstaller::Result RDSUpdate(const bf::path& path, + const std::string& pkgid, PackageType type, RequestResult mode = RequestResult::NORMAL) { if (Install(path, type) != ci::AppInstaller::Result::OK) { LOG(ERROR) << "Failed to install application. Cannot perform RDS"; return ci::AppInstaller::Result::UNKNOWN; } - const char* argv[] = {"", "-r", delta_dir.c_str(), "-u", + const char* argv[] = {"", "-r", pkgid.c_str(), "-u", kTestUserIdStr.c_str()}; return CallBackend(SIZEOFARRAY(argv), argv, type, mode); } @@ -493,10 +496,16 @@ TEST_F(SmokeTest, DeinstallationMode) { TEST_F(SmokeTest, RDSMode) { bf::path path = kSmokePackagesDirectory / "RDSMode.wgt"; - bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/"; std::string pkgid = "smokeapp11"; std::string appid = "smokeapp11.RDSMode"; - ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT), + bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/"; + bf::path sdk_expected_directory = + bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid; + bs::error_code error; + bf::create_directories(sdk_expected_directory.parent_path(), error); + ASSERT_FALSE(error); + ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory)); + ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT), ci::AppInstaller::Result::OK); ValidatePackage(pkgid, {appid}); diff --git a/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta b/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta index fb08dcc..7467bbe 100644 --- a/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta +++ b/src/unit_tests/test_samples/smoke/delta_dir/.rds_delta @@ -1,6 +1,6 @@ #add -ADDED +res/wgt/ADDED #modify -MODIFIED +res/wgt/MODIFIED #delete -DELETED +res/wgt/DELETED diff --git a/src/unit_tests/test_samples/smoke/delta_dir/ADDED b/src/unit_tests/test_samples/smoke/delta_dir/res/wgt/ADDED similarity index 100% rename from src/unit_tests/test_samples/smoke/delta_dir/ADDED rename to src/unit_tests/test_samples/smoke/delta_dir/res/wgt/ADDED diff --git a/src/unit_tests/test_samples/smoke/delta_dir/MODIFIED b/src/unit_tests/test_samples/smoke/delta_dir/res/wgt/MODIFIED similarity index 100% rename from src/unit_tests/test_samples/smoke/delta_dir/MODIFIED rename to src/unit_tests/test_samples/smoke/delta_dir/res/wgt/MODIFIED diff --git a/src/unit_tests/test_samples/smoke/delta_dir/config.xml b/src/unit_tests/test_samples/smoke/delta_dir/res/wgt/config.xml similarity index 100% rename from src/unit_tests/test_samples/smoke/delta_dir/config.xml rename to src/unit_tests/test_samples/smoke/delta_dir/res/wgt/config.xml diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 3124963..678dc70 100755 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -1,5 +1,6 @@ # Target - sources SET(SRCS + step/configuration/step_check_rds_manifest.cc step/configuration/step_check_start_files.cc step/configuration/step_parse.cc step/encryption/step_encrypt_resources.cc @@ -12,7 +13,6 @@ SET(SRCS step/filesystem/step_wgt_resource_directory.cc step/filesystem/step_wgt_update_package_directory.cc step/pkgmgr/step_generate_xml.cc - step/rds/step_wgt_rds_modify.cc step/security/step_add_default_privileges.cc step/security/step_check_settings_level.cc step/security/step_check_wgt_background_category.cc diff --git a/src/wgt/step/configuration/step_check_rds_manifest.cc b/src/wgt/step/configuration/step_check_rds_manifest.cc new file mode 100644 index 0000000..560f015 --- /dev/null +++ b/src/wgt/step/configuration/step_check_rds_manifest.cc @@ -0,0 +1,49 @@ +// 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 "wgt/step/configuration/step_check_rds_manifest.h" + +#include +#include +#include + +namespace bf = boost::filesystem; +namespace bs = boost::system; + +namespace { + +const char kConfigInstalled[] = "res/wgt/config.xml"; +const char kConfigDeltaDir[] = "res/wgt/config.xml"; + +} // namespace + +namespace wgt { +namespace configuration { + +common_installer::Step::Status StepCheckRDSManifest::process() { + bf::path target = context_->unpacked_dir_path.get() / kConfigDeltaDir; + if (!bf::exists(target)) { + bf::path source = context_->root_application_path.get() / + context_->pkgid.get() / kConfigInstalled; + if (!bf::exists(source)) { + LOG(ERROR) << "Cannot find old manifest file"; + return Status::APP_DIR_ERROR; + } + bs::error_code error; + bf::create_directories(source.parent_path(), error); + if (error) { + LOG(ERROR) << "Failed to create directories for manifest file"; + return Status::APP_DIR_ERROR; + } + bf::copy_file(source, target, error); + if (error) { + LOG(ERROR) << "Failed to copy old manifest file"; + return Status::APP_DIR_ERROR; + } + } + return Status::OK; +} + +} // namespace configuration +} // namespace wgt diff --git a/src/wgt/step/configuration/step_check_rds_manifest.h b/src/wgt/step/configuration/step_check_rds_manifest.h new file mode 100644 index 0000000..ff5e06f --- /dev/null +++ b/src/wgt/step/configuration/step_check_rds_manifest.h @@ -0,0 +1,31 @@ +// 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 WGT_STEP_CONFIGURATION_STEP_CHECK_RDS_MANIFEST_H_ +#define WGT_STEP_CONFIGURATION_STEP_CHECK_RDS_MANIFEST_H_ + +#include + +#include +#include + +namespace wgt { +namespace configuration { + +class StepCheckRDSManifest : public common_installer::Step { + public: + using Step::Step; + + Status process() override; + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } + Status precheck() override { return Status::OK; } + + STEP_NAME(CheckRDSManifest) +}; + +} // namespace configuration +} // namespace wgt + +#endif // WGT_STEP_CONFIGURATION_STEP_CHECK_RDS_MANIFEST_H_ diff --git a/src/wgt/step/rds/step_wgt_rds_modify.cc b/src/wgt/step/rds/step_wgt_rds_modify.cc deleted file mode 100644 index aa293e9..0000000 --- a/src/wgt/step/rds/step_wgt_rds_modify.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#include "wgt/step/rds/step_wgt_rds_modify.h" - -#include -#include - -#include -#include -#include - -namespace wgt { -namespace rds { - -std::string StepWgtRDSModify::GetAppPath() { - boost::filesystem::path p = context_->pkg_path.get() / "res" / "wgt"; - return p.string(); -} - -} // namespace rds -} // namespace wgt diff --git a/src/wgt/step/rds/step_wgt_rds_modify.h b/src/wgt/step/rds/step_wgt_rds_modify.h deleted file mode 100644 index 2812b5a..0000000 --- a/src/wgt/step/rds/step_wgt_rds_modify.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved -// Use of this source code is governed by a apache 2.0 license that can be -// found in the LICENSE file. - -#ifndef WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ -#define WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ - -#include -#include -#include - -#include -#include -#include - -#include "common/installer_context.h" - -namespace wgt { -namespace rds { - -/** - * \brief Step that apply RDS modification during reinstallation process - */ -class StepWgtRDSModify : public common_installer::rds::StepRDSModify { - public: - using StepRDSModify::StepRDSModify; - - /** - * \brief return app path - * - * \return std::string - */ - std::string GetAppPath() override; - - STEP_NAME(WgtRDSModify) -}; - -} // namespace rds -} // namespace wgt - -#endif // WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 29e1d7e..4905e55 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -59,6 +59,8 @@ #include #include #include +#include +#include #include #include #include @@ -71,9 +73,8 @@ #include #include -#include -#include +#include "wgt/step/configuration/step_check_rds_manifest.h" #include "wgt/step/configuration/step_check_start_files.h" #include "wgt/step/configuration/step_parse.h" #include "wgt/step/encryption/step_encrypt_resources.h" @@ -86,7 +87,6 @@ #include "wgt/step/filesystem/step_wgt_resource_directory.h" #include "wgt/step/filesystem/step_wgt_update_package_directory.h" #include "wgt/step/pkgmgr/step_generate_xml.h" -#include "wgt/step/rds/step_wgt_rds_modify.h" #include "wgt/step/security/step_add_default_privileges.h" #include "wgt/step/security/step_check_settings_level.h" #include "wgt/step/security/step_check_wgt_background_category.h" @@ -214,8 +214,9 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) } case ci::RequestType::Reinstall: { AddStep(pkgmgr_); + AddStep(); AddStep( - wgt::configuration::StepParse::ConfigLocation::PACKAGE, false); + wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false); AddStep(); AddStep(); AddStep(); @@ -226,7 +227,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4 From fdd6a8bba4cfb4f25a3a40f197b6ab0a31090eae Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 17 Oct 2016 20:00:32 +0900 Subject: [PATCH 04/16] Fix step order of hybrid installer Parser plugins should be run after pakcage registration. Change-Id: I0635000604e28c28e88a7e3d56b69a972fec533a Signed-off-by: Sangyoon Jang --- src/hybrid/hybrid_installer.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index eac41e6..e98f992 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -133,10 +133,10 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep( - ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep( + ci::Plugin::ActionType::Install); AddStep(); AddStep(); AddStep(); @@ -327,10 +327,10 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep( - ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep( + ci::Plugin::ActionType::Install); AddStep(); AddStep(); AddStep(); @@ -401,10 +401,10 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep( - ci::Plugin::ActionType::Install); AddStep(); AddStep(); + AddStep( + ci::Plugin::ActionType::Install); AddStep(); AddStep(); AddStep(); -- 2.7.4 From 8c6fc81fabd0d348c8ab57af6ac6f7fd376e8cd1 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 17 Oct 2016 20:02:15 +0900 Subject: [PATCH 05/16] Temporary fix for hybrid pkg installation Submit together: - https://review.tizen.org/gerrit/92583 - https://review.tizen.org/gerrit/92584 - https://review.tizen.org/gerrit/92585 Change-Id: If9ab9d27126568e12efadcaea50988ab57cd4c5f Signed-off-by: Sangyoon Jang --- src/wgt/step/pkgmgr/step_generate_xml.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index d3e9aad..669bb26 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -94,6 +94,16 @@ bool WriteWidgetApplicationAttributesAndElements( if (app->multiple) xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple", BAD_CAST app->multiple); + // FIXME: For hotfix, must be removed + if (app->support_sizes) { + for (auto& ss : GListRange(app->support_sizes)) { + xmlTextWriterStartElement(writer, BAD_CAST "support-size"); + xmlTextWriterWriteAttribute(writer, BAD_CAST "preview", + BAD_CAST ss->preview); + xmlTextWriterWriteString(writer, BAD_CAST ss->size); + xmlTextWriterEndElement(writer); + } + } auto& appwidgets = widget_info.app_widgets(); const auto& appwidget = std::find_if(appwidgets.begin(), appwidgets.end(), -- 2.7.4 From 58317277b6f3775ee6fc3d56e83b81be220f7848 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 30 Sep 2016 10:48:38 +0200 Subject: [PATCH 06/16] Revert "Fix checking privilege level for hybrid apps" Following commit will reimplement this bug fix. This reverts commit 3002913a84371529abcb09bc7f51857bd3a3899a. Change-Id: I6334d50351fe49daedf543322738b102de2444f5 --- src/hybrid/CMakeLists.txt | 2 - src/hybrid/hybrid_installer.cc | 24 ++++------ .../step/configuration/step_merge_tpk_config.cc | 4 ++ .../step/configuration/step_merge_tpk_config.h | 3 -- .../configuration/step_merge_tpk_privileges.cc | 27 ------------ .../step/configuration/step_merge_tpk_privileges.h | 34 --------------- .../step/security/step_hybrid_check_signature.cc | 51 ---------------------- .../step/security/step_hybrid_check_signature.h | 27 ------------ 8 files changed, 12 insertions(+), 160 deletions(-) delete mode 100644 src/hybrid/step/configuration/step_merge_tpk_privileges.cc delete mode 100644 src/hybrid/step/configuration/step_merge_tpk_privileges.h delete mode 100644 src/hybrid/step/security/step_hybrid_check_signature.cc delete mode 100644 src/hybrid/step/security/step_hybrid_check_signature.h diff --git a/src/hybrid/CMakeLists.txt b/src/hybrid/CMakeLists.txt index bc950d5..ccc7f4a 100644 --- a/src/hybrid/CMakeLists.txt +++ b/src/hybrid/CMakeLists.txt @@ -1,9 +1,7 @@ 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 e98f992..1a0e76f 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -73,10 +74,8 @@ #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" @@ -111,8 +110,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -153,8 +151,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -234,8 +231,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -305,8 +301,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -347,8 +342,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -393,8 +387,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -421,8 +414,7 @@ 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 15d59c3..913ad98 100644 --- a/src/hybrid/step/configuration/step_merge_tpk_config.cc +++ b/src/hybrid/step/configuration/step_merge_tpk_config.cc @@ -21,6 +21,10 @@ 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 623eba5..2171d59 100644 --- a/src/hybrid/step/configuration/step_merge_tpk_config.h +++ b/src/hybrid/step/configuration/step_merge_tpk_config.h @@ -15,9 +15,6 @@ 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 deleted file mode 100644 index ef763d6..0000000 --- a/src/hybrid/step/configuration/step_merge_tpk_privileges.cc +++ /dev/null @@ -1,27 +0,0 @@ -// 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 deleted file mode 100644 index 0afe851..0000000 --- a/src/hybrid/step/configuration/step_merge_tpk_privileges.h +++ /dev/null @@ -1,34 +0,0 @@ -// 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 deleted file mode 100644 index b71717f..0000000 --- a/src/hybrid/step/security/step_hybrid_check_signature.cc +++ /dev/null @@ -1,51 +0,0 @@ -// 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 deleted file mode 100644 index d867700..0000000 --- a/src/hybrid/step/security/step_hybrid_check_signature.h +++ /dev/null @@ -1,27 +0,0 @@ -// 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_ -- 2.7.4 From 0ef8a4fec09d222efd16fd595a57f2e71a1ab264 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 30 Sep 2016 10:07:13 +0200 Subject: [PATCH 07/16] 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: I4ec7c8714a55917dbda665bf2a1c08ca30ce3f97 --- src/hybrid/hybrid_installer.cc | 23 +++++++--- src/unit_tests/manifest_test.cc | 8 ++-- src/wgt/step/configuration/step_parse.cc | 8 +++- src/wgt/step/pkgmgr/step_generate_xml.cc | 13 +++--- .../step/security/step_add_default_privileges.cc | 7 ++- .../security/step_check_extension_privileges.cc | 51 ++++++++++++---------- .../security/step_check_extension_privileges.h | 3 +- .../step/security/step_check_wgt_ime_privilege.cc | 16 ++++--- src/wgt/wgt_installer.cc | 22 +++++++--- 9 files changed, 94 insertions(+), 57 deletions(-) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 1a0e76f..ee59c63 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -4,6 +4,7 @@ #include "hybrid/hybrid_installer.h" +#include #include #include #include @@ -94,6 +95,7 @@ namespace hybrid { HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) : AppInstaller("wgt", pkgmgr) { + context_->cross_app_rules.set(true); context_->backend_data.set(new HybridBackendData()); switch (pkgmgr_->GetRequestType()) { @@ -111,7 +113,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -152,7 +155,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -232,7 +236,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -302,7 +307,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -343,7 +349,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -388,7 +395,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); @@ -415,7 +423,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); AddStep(); diff --git a/src/unit_tests/manifest_test.cc b/src/unit_tests/manifest_test.cc index 46a8e36..52f9a81 100644 --- a/src/unit_tests/manifest_test.cc +++ b/src/unit_tests/manifest_test.cc @@ -184,8 +184,8 @@ TEST_F(ManifestTest, PrivilegeElement_ValidName) { manifest_x* m = runner.GetManifest(); ASSERT_NE(m, nullptr); std::vector priv_vec; - for (const char* priv : GListRange(m->privileges)) { - priv_vec.push_back(priv); + for (privilege_x* priv : GListRange(m->privileges)) { + priv_vec.push_back(priv->value); } ASSERT_FALSE(priv_vec.empty()); const char* expected_name = "http://tizen.org/privilege/application.launch"; @@ -198,8 +198,8 @@ TEST_F(ManifestTest, PrivilegeElement_ManyElements) { manifest_x* m = runner.GetManifest(); ASSERT_NE(m, nullptr); std::vector priv_vec; - for (const char* priv : GListRange(m->privileges)) { - priv_vec.push_back(priv); + for (privilege_x* priv : GListRange(m->privileges)) { + priv_vec.push_back(priv->value); } ASSERT_EQ(priv_vec.size(), 2); const char* first_priv = "http://tizen.org/privilege/application.close"; diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index c15d8af..cf349e8 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -518,8 +519,11 @@ bool StepParse::FillPrivileges(manifest_x* manifest) { privileges = ExtractPrivileges(perm_info); 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->type = strdup(common_installer::kWebPrivilegeType); + privilege->value = strdup(priv.c_str()); + manifest->privileges = g_list_append(manifest->privileges, privilege); } return true; } diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 669bb26..a20a3a3 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -499,12 +499,15 @@ common_installer::Step::Status StepGenerateXml::GenerateApplications( } void StepGenerateXml::GeneratePrivilege(xmlTextWriterPtr writer) { - if (context_->manifest_data.get()->privileges) { + if (context_->manifest_data.get()->privileges) { xmlTextWriterStartElement(writer, BAD_CAST "privileges"); - for (const char* priv : - GListRange(context_->manifest_data.get()->privileges)) { - xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege", - "%s", BAD_CAST priv); + for (privilege_x* priv : + GListRange(context_->manifest_data.get()->privileges)) { + xmlTextWriterStartElement(writer, BAD_CAST "privilege"); + xmlTextWriterWriteAttribute(writer, BAD_CAST "type", + BAD_CAST priv->type); + xmlTextWriterWriteString(writer, BAD_CAST priv->value); + xmlTextWriterEndElement(writer); } xmlTextWriterEndElement(writer); diff --git a/src/wgt/step/security/step_add_default_privileges.cc b/src/wgt/step/security/step_add_default_privileges.cc index e5e0288..47098d3 100644 --- a/src/wgt/step/security/step_add_default_privileges.cc +++ b/src/wgt/step/security/step_add_default_privileges.cc @@ -24,8 +24,11 @@ common_installer::Step::Status StepAddDefaultPrivileges::precheck() { common_installer::Step::Status StepAddDefaultPrivileges::process() { manifest_x* m = context_->manifest_data.get(); - m->privileges = g_list_append(m->privileges, - strdup(common::privileges::kPrivForWebApp)); + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(common_installer::kWebPrivilegeType); + privilege->value = strdup(common_installer::privileges::kPrivForWebApp); + m->privileges = g_list_append(m->privileges, privilege); return Status::OK; } diff --git a/src/wgt/step/security/step_check_extension_privileges.cc b/src/wgt/step/security/step_check_extension_privileges.cc index c28071a..990ba97 100755 --- a/src/wgt/step/security/step_check_extension_privileges.cc +++ b/src/wgt/step/security/step_check_extension_privileges.cc @@ -3,7 +3,16 @@ // found in the LICENSE file. #include "wgt/step/security/step_check_extension_privileges.h" + +#include + +#include +#include +#include +#include + #include +#include #include #include @@ -14,9 +23,6 @@ #include #include "wgt/extension_config_parser.h" -#include "manifest_parser/values.h" -#include "common/certificate_validation.h" -#include "common/utils/glist_range.h" namespace { const char kPluginsDirectory[] = "/res/wgt/plugin/"; @@ -40,8 +46,9 @@ common_installer::Step::Status StepCheckExtensionPrivileges::process() { manifest_x* m = context_->manifest_data.get(); std::set current_privileges; - for (const char* priv : GListRange(m->privileges)) { - current_privileges.insert(priv); + for (privilege_x* priv : GListRange(m->privileges)) { + if (strcmp(priv->type, common_installer::kWebPrivilegeType) == 0) + current_privileges.insert(priv->value); } std::set xmlFiles; @@ -52,27 +59,32 @@ common_installer::Step::Status StepCheckExtensionPrivileges::process() { xmlFiles.insert(glob_result.gl_pathv[i]); } } - std::set privileges; + GList* privileges = nullptr; + BOOST_SCOPE_EXIT_ALL(&) { + g_list_free_full(privileges, &common_installer::FreePrivilegeX); + }; for (auto it = xmlFiles.begin(); it != xmlFiles.end(); ++it) { LOG(DEBUG) << "start to parse extension xml : " << *it; ExtensionConfigParser extensionParser(*it); std::vector list = extensionParser.GetExtensionPrivilegeList(); - for (std::string priv : list) { + for (const std::string& priv : list) { if (current_privileges.find(priv) == current_privileges.end()) { - privileges.emplace(priv); + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(common_installer::kWebPrivilegeType); + privilege->value = strdup(priv.c_str()); + privileges = g_list_append(privileges, privilege); } } } - if (!privileges.empty()) { + if (privileges) { if (!CheckPrivilegeLevel(privileges)) { LOG(DEBUG) << "Fail to validation of privilege"; return Status::ERROR; } - for (auto it = privileges.begin(); it != privileges.end(); ++it) { - LOG(DEBUG) << "set list privilege : " << *it; - m->privileges = g_list_append(m->privileges, strdup((*it).c_str())); - } + m->privileges = g_list_concat(m->privileges, privileges); + privileges = nullptr; } return Status::OK; } @@ -104,28 +116,21 @@ std::string StepCheckExtensionPrivileges::GetExtensionPath() { } bool StepCheckExtensionPrivileges::CheckPrivilegeLevel( - std::set priv_set) { - GList* privileges = nullptr; - for (auto it = priv_set.begin(); it != priv_set.end(); ++it) { - privileges = g_list_append(privileges, strdup((*it).c_str())); - } - guint size = g_list_length(privileges); - if (size == 0) return true; + GList* privileges) { + if (g_list_length(privileges) == 0) + return true; std::string error_message; if (!common_installer::ValidatePrivilegeLevel( context_->privilege_level.get(), - context_->pkg_type.get(), context_->manifest_data.get()->api_version, privileges, &error_message)) { - g_list_free_full(privileges, free); if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; } return false; } - g_list_free_full(privileges, free); return true; } diff --git a/src/wgt/step/security/step_check_extension_privileges.h b/src/wgt/step/security/step_check_extension_privileges.h index 837f564..c390d3c 100755 --- a/src/wgt/step/security/step_check_extension_privileges.h +++ b/src/wgt/step/security/step_check_extension_privileges.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -45,7 +46,7 @@ class StepCheckExtensionPrivileges : public common_installer::Step { Status precheck() override; private: std::string GetExtensionPath(); - bool CheckPrivilegeLevel(std::set priv_set); + bool CheckPrivilegeLevel(GList* privileges); STEP_NAME(CheckExtensionPrivileges) }; diff --git a/src/wgt/step/security/step_check_wgt_ime_privilege.cc b/src/wgt/step/security/step_check_wgt_ime_privilege.cc index 9976852..aedbbaf 100644 --- a/src/wgt/step/security/step_check_wgt_ime_privilege.cc +++ b/src/wgt/step/security/step_check_wgt_ime_privilege.cc @@ -47,9 +47,12 @@ common_installer::Step::Status StepCheckWgtImePrivilege::process() { context_->manifest_plugins_data.get().ime_info.get().setUuid(std::string()); } else if (version23) { // be sure there's a privilege in manifest - context_->manifest_data.get()->privileges - = g_list_append(context_->manifest_data.get()->privileges, - strdup(common::privileges::kImePrivilegeName)); + privilege_x* privilege = + reinterpret_cast(calloc(1, sizeof(privilege_x))); + privilege->type = strdup(common_installer::kWebPrivilegeType); + privilege->value = strdup(common_installer::privileges::kImePrivilegeName); + context_->manifest_data.get()->privileges = + g_list_append(context_->manifest_data.get()->privileges, privilege); } return Status::OK; @@ -73,9 +76,10 @@ common_installer::Step::Status StepCheckWgtImePrivilege::Check24Api() const { common_installer::Step::Status StepCheckWgtImePrivilege::CheckImePrivilege() const { - for (const auto privilege : - GListRange(context_->manifest_data.get()->privileges)) { - if (!strcmp(privilege, common::privileges::kImePrivilegeName)) + for (privilege_x* privilege : + GListRange(context_->manifest_data.get()->privileges)) { + if (!strcmp(privilege->value, + common_installer::privileges::kImePrivilegeName)) return Status::OK; } diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 4905e55..e1140e2 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -115,7 +116,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -152,7 +154,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -248,7 +251,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -316,7 +320,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -352,7 +357,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -391,7 +397,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); @@ -414,7 +421,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep( + ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); AddStep(); -- 2.7.4 From bcc1a4118edf8664b8500531e70f53889a03a78f Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 15 Sep 2016 12:25:48 +0200 Subject: [PATCH 08/16] Fixing rollback This patch should fix: 1) Situation when backup files are not fully restored when file that has been backed up wasn't removed yet -> file is not restored (new flag: FS_MERGE_OVERWRITE) 2) Situation when backup file was not fully copied and we restore broken copy (new flag: FS_COMMIT_COPY_FILE) Submit together: - https://review.tizen.org/gerrit/88235 - https://review.tizen.org/gerrit/88236 Change-Id: I49baa0c194b6247d33f40cc804610eb32aafe490 --- src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc b/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc index fbb8519..b14c333 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc +++ b/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc @@ -58,7 +58,7 @@ bool StepWgtPatchStorageDirectories::ShareDirFor3x() { } bf::path dst = context_->pkg_path.get() / kSharedResLocation; if (!common_installer::MoveDir(src, dst, - common_installer::FS_MERGE_DIRECTORIES)) { + common_installer::FS_MERGE_SKIP)) { LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; return false; } -- 2.7.4 From 89b66c02fd032842fd8366a2ec0650b9bb8232d0 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Wed, 16 Nov 2016 16:37:34 +0100 Subject: [PATCH 09/16] Fix manifest preload location This patch sets manifest location for preload request to TZ_SYS_RO_PACKAGES. Change-Id: I678e78981fdcb8698d1cda8f1b5eba7bf6173e49 --- src/wgt/step/pkgmgr/step_generate_xml.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index a20a3a3..3e63560 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -340,7 +340,8 @@ common_installer::Step::Status StepGenerateXml::precheck() { common_installer::Step::Status StepGenerateXml::process() { bf::path xml_path = - bf::path(getUserManifestPath(context_->uid.get(), false)) + bf::path(getUserManifestPath(context_->uid.get(), + context_->is_preload_request.get())) / bf::path(context_->pkgid.get()); xml_path += ".xml"; context_->xml_path.set(xml_path.string()); -- 2.7.4 From f0222f78e3f0e056c697b68ea94d9da7e54aa1cb Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 17 Nov 2016 19:36:31 +0900 Subject: [PATCH 10/16] Add StepCheckInstallable Requires: - https://review.tizen.org/gerrit/98476 Change-Id: I13c733301b6b57f92533a7a451ccb920b1c86635 Signed-off-by: Sangyoon Jang --- src/hybrid/hybrid_installer.cc | 4 ++++ src/wgt/wgt_installer.cc | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index ee59c63..2b416e3 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); @@ -299,6 +301,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); @@ -388,6 +391,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index e1140e2..a9b0473 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -112,6 +113,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -316,6 +318,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::PACKAGE, true); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -394,6 +397,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(pkgmgr_); AddStep( wgt::configuration::StepParse::ConfigLocation::INSTALLED, true); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4 From 749c566211473c2fa4d6a8c9952147cbb673c330 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Tue, 15 Nov 2016 09:02:01 +0100 Subject: [PATCH 11/16] Fix StepCreateStorageDirectores This patch provides proper handling for following test case: 1. Crash installation before StepGenerateXML 2. Install again 3. The installation should be successful Change-Id: Ic55d86d5164ecb1f596f7ddc7d51cf16a0f6268e --- src/wgt/step/filesystem/step_create_symbolic_link.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wgt/step/filesystem/step_create_symbolic_link.cc b/src/wgt/step/filesystem/step_create_symbolic_link.cc index cbdbb7f..a814f04 100644 --- a/src/wgt/step/filesystem/step_create_symbolic_link.cc +++ b/src/wgt/step/filesystem/step_create_symbolic_link.cc @@ -42,6 +42,8 @@ bool StepCreateSymbolicLink::CreateSymlinksForApps() { common_installer::CreateDir(exec_path); exec_path /= bf::path(app->appid); + if (bf::exists(exec_path)) + bf::remove_all(exec_path); if (strcmp(app->component_type, "uiapp") == 0) { bf::create_symlink(bf::path(WRT_LAUNCHER), exec_path, error); -- 2.7.4 From 18be8ca9cadfd4fe6f13c69202d7b3eb756336ba Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Tue, 15 Nov 2016 10:35:47 +0100 Subject: [PATCH 12/16] [Coding style] Wgt step reorder as tpk This commit reoders step RegisterApplication with RegisterSecurity as it is done in Tpk installer. It could be done because that steps do not depend of each other. Change-Id: Ia30152f749f0b5a360bdabcfad032142e84cdd5f --- src/wgt/wgt_installer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index a9b0473..43fc80c 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -139,10 +139,10 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); AddStep( ci::Plugin::ActionType::Install); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4 From f877886dd2baf5f15fc2c4cca80a7cafe4bae39a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 17 Nov 2016 19:34:46 +0900 Subject: [PATCH 13/16] Adjust to privilege verification API change Requires: - https://review.tizen.org/gerrit/98384 - https://review.tizen.org/gerrit/98161 Change-Id: Idf6d33b3216466f23efbcb0ad2d1c25ea131936a Signed-off-by: Sangyoon Jang --- src/wgt/step/security/step_check_extension_privileges.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wgt/step/security/step_check_extension_privileges.cc b/src/wgt/step/security/step_check_extension_privileges.cc index 990ba97..2e8d2a2 100755 --- a/src/wgt/step/security/step_check_extension_privileges.cc +++ b/src/wgt/step/security/step_check_extension_privileges.cc @@ -123,6 +123,7 @@ bool StepCheckExtensionPrivileges::CheckPrivilegeLevel( std::string error_message; if (!common_installer::ValidatePrivilegeLevel( context_->privilege_level.get(), + context_->uid.get(), context_->manifest_data.get()->api_version, privileges, &error_message)) { -- 2.7.4 From 6a4cf6791a12ed4a4371fd0cd3e251bdbbf75ca9 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 21 Nov 2016 16:00:25 +0900 Subject: [PATCH 14/16] Implement wgt backend library This backend library is for getting package information from file. The functions are called by dlsym from pkgmgr_client api. (Refer to: https://review.tizen.org/gerrit/73286) Change-Id: I547fae4bf0a431a28826ef8c4f6e83768c4acc18 Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 3 + packaging/wgt-backend.spec | 3 + src/CMakeLists.txt | 1 + src/lib/CMakeLists.txt | 15 ++++ src/lib/wgt_archive_info.cc | 214 ++++++++++++++++++++++++++++++++++++++++++++ src/lib/wgt_archive_info.h | 23 +++++ src/lib/wgt_pkgmgr.cc | 34 +++++++ 7 files changed, 293 insertions(+) create mode 100644 src/lib/CMakeLists.txt create mode 100644 src/lib/wgt_archive_info.cc create mode 100644 src/lib/wgt_archive_info.h create mode 100644 src/lib/wgt_pkgmgr.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index f39937d..77ad385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINKER_FLAGS}") # Targets SET(TARGET_LIBNAME_WGT "wgt-installer") +SET(TARGET_LIBNAME_WGT_ARCHIVE_INFO "wgt") SET(TARGET_WGT_BACKEND "wgt-backend") SET(TARGET_LIBNAME_HYBRID "hybrid-installer") @@ -46,8 +47,10 @@ PKG_CHECK_MODULES(APP_INSTALLERS_DEPS REQUIRED app-installers) PKG_CHECK_MODULES(WGT_MANIFEST_HANDLERS_DEPS REQUIRED wgt-manifest-handlers) PKG_CHECK_MODULES(MANIFEST_PARSER_DEPS REQUIRED manifest-parser) PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer) +PKG_CHECK_MODULES(PKGMGR_TYPES_DEPS REQUIRED pkgmgr-types) PKG_CHECK_MODULES(ENCRYPTION_DEPS REQUIRED libwebappenc) PKG_CHECK_MODULES(TPK_INSTALLER_DEPS REQUIRED tpk-installer) +PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf) FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options) FIND_PACKAGE(GTest REQUIRED) diff --git a/packaging/wgt-backend.spec b/packaging/wgt-backend.spec index dbc504c..998fc24 100644 --- a/packaging/wgt-backend.spec +++ b/packaging/wgt-backend.spec @@ -16,8 +16,10 @@ BuildRequires: pkgconfig(app-installers) BuildRequires: pkgconfig(manifest-parser) BuildRequires: pkgconfig(wgt-manifest-handlers) BuildRequires: pkgconfig(pkgmgr-installer) +BuildRequires: pkgconfig(pkgmgr-types) BuildRequires: pkgconfig(libwebappenc) BuildRequires: pkgconfig(tpk-installer) +BuildRequires: pkgconfig(vconf) %description This is a package that installs the WGT backend of pkgmgr. @@ -57,6 +59,7 @@ ln -s %{_bindir}/wgt-backend %{buildroot}%{_sysconfdir}/package-manager/backend/ %manifest wgt-backend.manifest %license LICENSE %{_sysconfdir}/package-manager/backend/wgt +%{_sysconfdir}/package-manager/backendlib/libwgt.so %{_bindir}/wgt-backend %{_datadir}/wgt-backend/default.png diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0136fd6..5384753 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ ADD_SUBDIRECTORY(hybrid) +ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(wgt) ADD_SUBDIRECTORY(wgt_backend) ADD_SUBDIRECTORY(unit_tests) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..a14aaae --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,15 @@ +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} LIB_SRCS) +ADD_LIBRARY(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} SHARED ${LIB_SRCS}) + +TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../") + +APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT_ARCHIVE_INFO} PUBLIC + APP_INSTALLERS_DEPS + PKGMGR_TYPES_DEPS + MANIFEST_PARSER_DEPS + WGT_MANIFEST_HANDLERS_DEPS + VCONF_DEPS + Boost +) + +INSTALL(TARGETS ${TARGET_LIBNAME_WGT_ARCHIVE_INFO} DESTINATION ${SYSCONF_INSTALL_DIR}/package-manager/backendlib) diff --git a/src/lib/wgt_archive_info.cc b/src/lib/wgt_archive_info.cc new file mode 100644 index 0000000..bcaa43b --- /dev/null +++ b/src/lib/wgt_archive_info.cc @@ -0,0 +1,214 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include "lib/wgt_archive_info.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace bf = boost::filesystem; +namespace ci = common_installer; + +namespace { + +const char kVconfLanguageKey[] = "db/menu_widget/language"; + +bool ExtractPackageArchive(const char* file_path, const bf::path& tmp_dir) { + if (!ci::ExtractToTmpDir(file_path, tmp_dir)) { + LOG(ERROR) << "Failed to extract"; + return false; + } + return true; +} + +bool GetPackageInfo(wgt::parse::WidgetConfigParser& parser, + package_manager_pkg_detail_info_t* info) { + auto widget_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::WidgetInfo::Key())); + auto app_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::TizenApplicationInfo::Key())); + if (!widget_info || !app_info) { + LOG(ERROR) << "WidgetInfo / TizenApplicationInfo not found"; + return false; + } + + snprintf(info->pkg_type, sizeof(info->pkg_type), "wgt"); + snprintf(info->version, sizeof(info->version), "%s", + widget_info->version().c_str()); + snprintf(info->author, sizeof(info->version), "%s", + widget_info->author().c_str()); + + snprintf(info->pkg_name, sizeof(info->pkg_name), "%s", + app_info->package().c_str()); + snprintf(info->pkgid, sizeof(info->pkgid), "%s", app_info->package().c_str()); + snprintf(info->api_version, sizeof(info->api_version), "%s", + app_info->required_version().c_str()); + + return true; +} + +bool GetPrivilegesInfo(wgt::parse::WidgetConfigParser& parser, + package_manager_pkg_detail_info_t* info) { + auto privileges_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::PermissionsInfo::Key())); + if (!privileges_info) + return false; + + const auto& privileges = privileges_info->GetAPIPermissions(); + for (auto& priv : privileges) { + info->privilege_list = g_list_append(info->privilege_list, + strdup(priv.c_str())); + } + + return true; +} + +bool GetLabelInfo(wgt::parse::WidgetConfigParser& parser, const char* locale, + package_manager_pkg_detail_info_t* info) { + auto widget_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::WidgetInfo::Key())); + if (!widget_info) + return false; + + std::string name; + const auto& labels = widget_info->name_set(); + if (labels.find(locale) != labels.end()) { + name = labels.find(locale)->second; + snprintf(info->label, sizeof(info->label), "%s", name.c_str()); + return true; + } else if (labels.find("") != labels.end()) { + name = labels.find("")->second; + snprintf(info->label, sizeof(info->label), "%s", name.c_str()); + return true; + } + + return false; +} + +bool GetDescriptionInfo(wgt::parse::WidgetConfigParser& parser, + const char* locale, package_manager_pkg_detail_info_t* info) { + auto widget_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::WidgetInfo::Key())); + if (!widget_info) + return false; + + std::string desc; + const auto& descriptions = widget_info->description_set(); + if (descriptions.find(locale) != descriptions.end()) { + desc = descriptions.find(locale)->second; + snprintf(info->pkg_description, sizeof(info->pkg_description), "%s", + desc.c_str()); + return true; + } else if (descriptions.find("") != descriptions.end()) { + desc = descriptions.find("")->second; + snprintf(info->pkg_description, sizeof(info->pkg_description), "%s", + desc.c_str()); + return true; + } + + return false; +} + +bool ReadIcon(const bf::path& icon, const bf::path& tmp_dir, + package_manager_pkg_detail_info_t* info) { + bf::path icon_path; + if (icon.is_absolute()) + icon_path = icon; + else + icon_path = tmp_dir / icon; + + LOG(INFO) << "Icon file path: " << icon_path; + + std::ifstream ifs(icon_path.c_str(), + std::ifstream::in | std::ifstream::binary); + ifs.seekg(0, ifs.end); + int len = ifs.tellg(); + ifs.seekg(0, ifs.beg); + + if (len <= 0) + return false; + + char* buf = static_cast(malloc(sizeof(char) * len)); + + LOG(INFO) << "Reading icon file, " << len << " bytes"; + ifs.read(buf, len); + + info->icon_buf = buf; + info->icon_size = len; + + return true; +} + +bool GetIconInfo(wgt::parse::WidgetConfigParser& parser, + bf::path& tmp_dir, package_manager_pkg_detail_info_t* info) { + auto icons_info = + std::static_pointer_cast( + parser.GetManifestData(wgt::parse::ApplicationIconsInfo::Key())); + if (!icons_info) + return false; + + return ReadIcon(icons_info->icons().front().path(), tmp_dir, info); +} + +} // namespace + +bool WgtArchiveInfo::GetArchiveInfo(const char* file_path, + package_manager_pkg_detail_info_t* info) { + bf::path tmp_dir = ci::GenerateTmpDir("/tmp"); + if (!ci::CreateDir(tmp_dir)) + return false; + LOG(DEBUG) << "Unpack at temporary dir: " << tmp_dir; + if (!ExtractPackageArchive(file_path, tmp_dir)) + return false; + + wgt::parse::WidgetConfigParser parser; + bf::path manifest_path = tmp_dir / "config.xml"; + if (!parser.ParseManifest(manifest_path)) { + LOG(ERROR) << "Failed to parse"; + bf::remove_all(tmp_dir); + return false; + } + + if (!GetPackageInfo(parser, info)) { + LOG(ERROR) << "Failed to get package info"; + bf::remove_all(tmp_dir); + return false; + } + if (!GetPrivilegesInfo(parser, info)) + LOG(WARNING) << "Failed to get privileges info"; + if (!GetIconInfo(parser, tmp_dir, info)) + LOG(WARNING) << "Failed to get icon info"; + + char* locale = vconf_get_str(kVconfLanguageKey); + if (!GetLabelInfo(parser, locale, info)) + LOG(WARNING) << "Failed to get label info"; + if (!GetDescriptionInfo(parser, locale, info)) + LOG(WARNING) << "Failed to get description info"; + + free(locale); + bf::remove_all(tmp_dir); + + return true; +} diff --git a/src/lib/wgt_archive_info.h b/src/lib/wgt_archive_info.h new file mode 100644 index 0000000..3882f78 --- /dev/null +++ b/src/lib/wgt_archive_info.h @@ -0,0 +1,23 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef LIB_WGT_ARCHIVE_INFO_H_ +#define LIB_WGT_ARCHIVE_INFO_H_ + +#include + +#include + +#include + +class WgtArchiveInfo : public common_installer::Singleton { + CRTP_DECLARE_DEFAULT_CONSTRUCTOR_CLASS(WgtArchiveInfo) + public: + bool GetArchiveInfo(const char* file_path, + package_manager_pkg_detail_info_t* info); + + SCOPE_LOG_TAG(WgtArchiveInfo) +}; + +#endif // LIB_WGT_ARCHIVE_INFO diff --git a/src/lib/wgt_pkgmgr.cc b/src/lib/wgt_pkgmgr.cc new file mode 100644 index 0000000..129c185 --- /dev/null +++ b/src/lib/wgt_pkgmgr.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include + +#include "lib/wgt_archive_info.h" + +#define EXPORT_API __attribute__((visibility("default"))) + +namespace { + +int GetPackageArchiveInfo(const char* path, + package_manager_pkg_detail_info_t* info) { + if (!WgtArchiveInfo::Instance().GetArchiveInfo(path, info)) + return -1; + return 0; +} + +void PluginOnUnload() { +} + +} // namespace + +extern "C" EXPORT_API int pkg_plugin_on_load(pkg_plugin_set* set) { + if (set == nullptr) + return -1; + set->plugin_on_unload = PluginOnUnload; + set->pkg_is_installed = nullptr; + set->get_installed_pkg_list = nullptr; + set->get_pkg_detail_info = nullptr; + set->get_pkg_detail_info_from_package = GetPackageArchiveInfo; + return 0; +} -- 2.7.4 From da4c4d58e52f8df826f5643fdeed5e07161b5da9 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Tue, 22 Nov 2016 16:43:12 +0900 Subject: [PATCH 15/16] apply extended concept of package's attribute. Requires : https://review.tizen.org/gerrit/#/c/99039/ Change-Id: I3da722ec30cd00554b9fe9e00b001bb6922a8cbf Signed-off-by: jongmyeongko --- src/hybrid/hybrid_installer.cc | 1 + src/wgt/step/configuration/step_parse.cc | 4 ---- src/wgt/step/encryption/step_encrypt_resources.cc | 2 +- src/wgt/step/encryption/step_remove_encryption_data.cc | 2 +- src/wgt/step/pkgmgr/step_generate_xml.cc | 2 +- src/wgt/wgt_installer.cc | 2 ++ 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 2b416e3..324c771 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -236,6 +236,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, true); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index cf349e8..8fcbcec 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -230,10 +230,6 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { manifest->type = strdup("wgt"); manifest->appsetting = strdup("false"); manifest->nodisplay_setting = strdup("false"); - if (context_->is_preload_request.get()) - manifest->preload = strdup("true"); - else - manifest->preload = strdup("false"); manifest->installed_storage = strdup("installed_internal"); // For wgt package use the long name diff --git a/src/wgt/step/encryption/step_encrypt_resources.cc b/src/wgt/step/encryption/step_encrypt_resources.cc index d7d2e9a..9c6b9d8 100644 --- a/src/wgt/step/encryption/step_encrypt_resources.cc +++ b/src/wgt/step/encryption/step_encrypt_resources.cc @@ -195,7 +195,7 @@ bool StepEncryptResources::EncryptFile(const bf::path &src) { == common_installer::RequestMode::GLOBAL) { ret = wae_encrypt_global_web_application( context_->pkgid.get().c_str(), - context_->is_preload_request.get() ? + context_->is_readonly_package.get() ? true : false, inChunk.get(), (size_t)bytesRead, diff --git a/src/wgt/step/encryption/step_remove_encryption_data.cc b/src/wgt/step/encryption/step_remove_encryption_data.cc index e398b23..7b3e9ac 100644 --- a/src/wgt/step/encryption/step_remove_encryption_data.cc +++ b/src/wgt/step/encryption/step_remove_encryption_data.cc @@ -18,7 +18,7 @@ common_installer::Step::Status StepRemoveEncryptionData::process() { int ret; if (context_->request_mode.get() == common_installer::RequestMode::GLOBAL) ret = wae_remove_global_app_dek(context_->pkgid.get().c_str(), - context_->is_preload_request.get() ? + context_->is_readonly_package.get() ? true : false); else ret = wae_remove_app_dek(context_->uid.get(), diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 3e63560..d1d1e6f 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -341,7 +341,7 @@ common_installer::Step::Status StepGenerateXml::precheck() { common_installer::Step::Status StepGenerateXml::process() { bf::path xml_path = bf::path(getUserManifestPath(context_->uid.get(), - context_->is_preload_request.get())) + context_->is_readonly_package.get())) / bf::path(context_->pkgid.get()); xml_path += ".xml"; context_->xml_path.set(xml_path.string()); diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 43fc80c..e87ec01 100755 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -222,6 +222,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep( wgt::configuration::StepParse::ConfigLocation::RESOURCE_WGT, false); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -247,6 +248,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep("res/wgt/"); -- 2.7.4 From 6d35edbd8c01d948ae06abbe4f2d76cc92adc2ff Mon Sep 17 00:00:00 2001 From: Bartlomiej Kunikowski Date: Mon, 17 Oct 2016 12:53:12 +0200 Subject: [PATCH 16/16] Fix smoke tests for hybrid packages Change-Id: I0d475b40ad6251184fcbef992e1cf5008c7fe2b6 --- src/unit_tests/smoke_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index ec1ab9d..4dab080 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -750,7 +750,8 @@ TEST_F(SmokeTest, DeinstallationMode_Hybrid) { std::string appid2 = "smokehyb03.Native"; ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK); + ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID), + ci::AppInstaller::Result::OK); CheckPackageNonExistance(pkgid, {appid1, appid2}); } @@ -795,10 +796,10 @@ TEST_F(SmokeTest, MountUpdateMode_Hybrid) { std::string pkgid = "smokehyb06"; std::string appid1 = "smokehyb06.web"; std::string appid2 = "smokehyb06.service"; - ASSERT_EQ(MountInstall(path_old, PackageType::WGT), + ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID), ci::AppInstaller::Result::OK); AddDataFiles(pkgid); - ASSERT_EQ(MountInstall(path_new, PackageType::WGT), + ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID), ci::AppInstaller::Result::OK); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid1, appid2}); -- 2.7.4