tpk/wgt backend will run as system session 99/81099/13 accepted/tizen/common/20160812.140745 accepted/tizen/ivi/20160815.233251 accepted/tizen/mobile/20160815.233131 accepted/tizen/tv/20160815.233209 accepted/tizen/wearable/20160815.233230 submit/tizen/20160811.013634 submit/tizen/20160811.062803 submit/tizen/20160812.053402
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 22 Jul 2016 05:07:34 +0000 (14:07 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 11 Aug 2016 02:19:49 +0000 (19:19 -0700)
Related changes
[slp-pkgmgr] https://review.tizen.org/gerrit/#/c/80764/
[pkgmgr-server] https://review.tizen.org/gerrit/#/c/78205/
[app-installers] https://review.tizen.org/gerrit/#/c/78206/
[tpk-backend] https://review.tizen.org/gerrit/#/c/80787/

Change-Id: Ia44020806701b668feaf7e1f5c5048dfc6643951
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
packaging/wgt-backend.manifest
src/unit_tests/manifest_test.cc
src/unit_tests/smoke_test.cc
src/wgt/step/encryption/step_encrypt_resources.cc
src/wgt/step/encryption/step_remove_encryption_data.cc
src/wgt/wgt_app_query_interface.cc

index 18893ce..85f79f1 100644 (file)
@@ -3,6 +3,6 @@
                 <domain name="_" />
         </request>
         <assign>
-                <filesystem path="/usr/bin/wgt-backend" label="System" exec_label="User" />
+                <filesystem path="/usr/bin/wgt-backend" label="System" exec_label="none" />
         </assign>
 </manifest>
index ab26141..46a8e36 100644 (file)
@@ -65,7 +65,7 @@ class StepParseRunner {
  private:
   void PrepareContext() {
     context_.reset(new ci::InstallerContext());
-    context_->root_application_path.set(ci::GetRootAppPath(false));
+    context_->root_application_path.set(ci::GetRootAppPath(false, getuid()));
     context_->unpacked_dir_path.set(
         bf::path(kManifestTestcaseData) / dir_suffix_);
     context_->backend_data.set(new wgt::WgtBackendData());
index 97a8d22..3e80354 100644 (file)
@@ -55,7 +55,8 @@ enum class RequestResult {
 class ScopedTzipInterface {
  public:
   explicit ScopedTzipInterface(const std::string& pkgid)
-      : pkg_path_(bf::path(ci::GetRootAppPath(false)) / pkgid),
+      : pkg_path_(bf::path(ci::GetRootAppPath(false,
+            tzplatform_getuid(TZ_SYS_DEFAULT_USER))) / pkgid),
         interface_(ci::GetMountLocation(pkg_path_)) {
     interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
   }
@@ -99,7 +100,8 @@ bool TouchFile(const bf::path& path) {
 }
 
 void RemoveAllRecoveryFiles() {
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   if (!bf::exists(root_path))
     return;
   for (auto& dir_entry : boost::make_iterator_range(
@@ -114,7 +116,8 @@ void RemoveAllRecoveryFiles() {
 }
 
 bf::path FindRecoveryFile() {
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   for (auto& dir_entry : boost::make_iterator_range(
          bf::directory_iterator(root_path), bf::directory_iterator())) {
     if (bf::is_regular_file(dir_entry)) {
@@ -129,7 +132,8 @@ bf::path FindRecoveryFile() {
 bool ValidateFileContentInPackage(const std::string& pkgid,
                                   const std::string& relative,
                                   const std::string& expected) {
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   bf::path file_path = root_path / pkgid / relative;
   if (!bf::exists(file_path)) {
     LOG(ERROR) << file_path << " doesn't exist";
@@ -151,7 +155,8 @@ bool ValidateFileContentInPackage(const std::string& pkgid,
 
 void ValidatePackageFS(const std::string& pkgid,
                        const std::vector<std::string>& appids) {
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   bf::path package_path = root_path / pkgid;
   bf::path data_path = package_path / "data";
   bf::path shared_path = package_path / "shared";
@@ -163,7 +168,8 @@ void ValidatePackageFS(const std::string& pkgid,
   ASSERT_TRUE(bf::exists(cache_path));
 
   bf::path manifest_path =
-      bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
+      bf::path(getUserManifestPath(
+          tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
   ASSERT_TRUE(bf::exists(manifest_path));
 
   for (auto& appid : appids) {
@@ -188,12 +194,14 @@ void ValidatePackageFS(const std::string& pkgid,
 
 void PackageCheckCleanup(const std::string& pkgid,
                          const std::vector<std::string>&) {
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(
+      false, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   bf::path package_path = root_path / pkgid;
   ASSERT_FALSE(bf::exists(package_path));
 
   bf::path manifest_path =
-      bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
+      bf::path(getUserManifestPath(
+          tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
   ASSERT_FALSE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -205,13 +213,17 @@ void PackageCheckCleanup(const std::string& pkgid,
 
 void ValidatePackage(const std::string& pkgid,
                      const std::vector<std::string>& appids) {
-  ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ASSERT_TRUE(ci::QueryIsPackageInstalled(
+      pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
   ValidatePackageFS(pkgid, appids);
 }
 
 void CheckPackageNonExistance(const std::string& pkgid,
                               const std::vector<std::string>& appids) {
-  ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ASSERT_FALSE(ci::QueryIsPackageInstalled(
+      pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
   PackageCheckCleanup(pkgid, appids);
 }
 
@@ -470,7 +482,8 @@ TEST_F(SmokeTest, RDSMode) {
   ValidatePackage(pkgid, {appid});
 
   // Check delta modifications
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
@@ -486,7 +499,9 @@ TEST_F(SmokeTest, EnablePkg) {
   ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
             ci::AppInstaller::Result::OK);
 
-  ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
+      ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
 }
 
 TEST_F(SmokeTest, DisablePkg) {
@@ -497,7 +512,9 @@ TEST_F(SmokeTest, DisablePkg) {
             ci::AppInstaller::Result::OK);
   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid,
+      ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
   ValidatePackageFS(pkgid, {appid});
 }
 
@@ -507,7 +524,8 @@ TEST_F(SmokeTest, ClearMode) {
   std::string appid = "smokeapp20.ClearMode";
   ASSERT_EQ(Install(path, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   bs::error_code error;
   bf::create_directory(root_path / pkgid / "data" / "dir", error);
   ASSERT_FALSE(error);
@@ -529,7 +547,8 @@ TEST_F(SmokeTest, DeltaMode) {
   ValidatePackage(pkgid, {appid});
 
   // Check delta modifications
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
@@ -651,7 +670,8 @@ TEST_F(SmokeTest, DeltaMode_Hybrid) {
   ValidatePackage(pkgid, {appid1, appid2});
 
   // Check delta modifications
-  bf::path root_path = ci::GetRootAppPath(false);
+  bf::path root_path = ci::GetRootAppPath(false,
+      tzplatform_getuid(TZ_SYS_DEFAULT_USER));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
index 8528ca9..c5e8d7a 100644 (file)
@@ -135,18 +135,24 @@ bool StepEncryptResources::EncryptFile(const bf::path &src) {
   unsigned char* encrypted_data = nullptr;
   size_t enc_data_len = 0;
   // TODO(p.sikorski) check if it is Preloaded
-  wae_app_type_e enc_type =
-      context_->request_mode.get() == common_installer::RequestMode::GLOBAL ?
-          WAE_DOWNLOADED_GLOBAL_APP : WAE_DOWNLOADED_NORMAL_APP;
-
-
-  int ret = wae_encrypt_web_application(
-              context_->pkgid.get().c_str(),
-              enc_type,
-              reinterpret_cast<const unsigned char*>(input_buffer),
-              length,
-              &encrypted_data,
-              &enc_data_len);
+  int ret;
+  if (context_->request_mode.get() == common_installer::RequestMode::GLOBAL)
+    ret = wae_encrypt_global_web_application(
+            context_->pkgid.get().c_str(),
+            context_->is_preload_request.get() ?
+            true : false,
+            reinterpret_cast<const unsigned char*>(input_buffer),
+            length,
+            &encrypted_data,
+            &enc_data_len);
+  else
+    ret = wae_encrypt_web_application(
+            context_->uid.get(),
+            context_->pkgid.get().c_str(),
+            reinterpret_cast<const unsigned char*>(input_buffer),
+            length,
+            &encrypted_data,
+            &enc_data_len);
   delete []input_buffer;
   if (WAE_ERROR_NONE != ret) {
     switch (ret) {
index 4baa502..e398b23 100644 (file)
@@ -12,14 +12,17 @@ namespace wgt {
 namespace encryption {
 
 common_installer::Step::Status StepRemoveEncryptionData::process() {
-  wae_app_type_e enc_type =
-      context_->request_mode.get() == common_installer::RequestMode::GLOBAL ?
-          WAE_DOWNLOADED_GLOBAL_APP : WAE_DOWNLOADED_NORMAL_APP;
-
   // There is no check, if application was encrypted or not
   // (it is not saved anywhere in tizen manifest)
   // so, if WAE_ERROR_NO_KEY error, then application was not encrypted
-  int ret = wae_remove_app_dek(context_->pkgid.get().c_str(), enc_type);
+  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() ?
+                true : false);
+  else
+    ret = wae_remove_app_dek(context_->uid.get(),
+                context_->pkgid.get().c_str());
   if (WAE_ERROR_NONE == ret || WAE_ERROR_NO_KEY == ret) {
     LOG(DEBUG) << "Encryption data removed (if existed)";
     return common_installer::Step::Status::OK;
index 912c861..90adc45 100644 (file)
@@ -36,6 +36,20 @@ 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) {
@@ -106,23 +120,26 @@ bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) {
   if (arg.empty())
     return false;
 
+  uid_t uid = GetUid(argc, argv);
   // argument from commandline is package id
-  if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode()))
+  if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode(uid), uid))
     return true;
 
   // argument from commandline is path to file
   std::string pkg_id = GetPkgIdFromPath(arg);
   if (pkg_id.empty())
     return false;
-  return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode());
+  return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode(uid), uid);
 }
 
 bool WgtAppQueryInterface::IsHybridApplication(int argc, char** argv) {
   std::string arg = GetInstallationRequestInfo(argc, argv);
   if (arg.find("apps_rw/recovery-") != std::string::npos)
     arg = ReadPkgidFromRecovery(arg);
-  if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode())) {
-    bf::path package_directory(ci::GetRootAppPath(false));
+
+  uid_t uid = GetUid(argc, argv);
+  if (ci::QueryIsPackageInstalled(arg, 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))
       return true;