Set pkg type and privilege level while installation 36/240836/4
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 12 Aug 2020 04:47:56 +0000 (13:47 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 21 Aug 2020 06:43:28 +0000 (15:43 +0900)
Change-Id: I2df40379d48d33acf96c99c799a9338fdc2a65ea
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/security_registration.cc
src/common/security_registration.h
src/common/step/security/step_recover_security.cc
src/common/step/security/step_register_security.cc
src/common/step/security/step_rollback_deinstallation_security.cc
src/common/step/security/step_update_security.cc

index 91b93da4109b70e35f3b0d87aa25ef70a1b77465..4d894237111db9305533e1d29aa8d5c01db6cd7b 100644 (file)
@@ -88,9 +88,10 @@ class SecurityContextRequest {
   bool IsValid() const {
     return req_ != NULL;
   }
-  bool PrepareBasic(const std::string& pkg_id, uid_t uid) {
-    if (pkg_id.empty()) {
-      LOG(ERROR) << "Pkgid is empty";
+  bool PrepareBasic(const std::string& pkg_id, uid_t uid,
+      const std::string& type = "" ) {
+    if (pkg_id.empty() || type.empty()) {
+      LOG(ERROR) << "Invalid parameter";
       return false;
     }
     int error = security_manager_app_inst_req_set_pkg_id(req_, pkg_id.c_str());
@@ -103,6 +104,18 @@ class SecurityContextRequest {
       SetErrorMessage(&error_message_, error);
       return false;
     }
+
+    pkg_type pkgtype = SM_PKG_TYPE_NONE;
+    if (type == "tpk")
+      pkgtype = SM_PKG_TYPE_CORE;
+    else if (type == "wgt")
+      pkgtype = SM_PKG_TYPE_WRT;
+
+    error = security_manager_app_inst_req_set_pkg_type(req_, pkgtype);
+    if (error != SECURITY_MANAGER_SUCCESS) {
+      SetErrorMessage(&error_message_, error);
+      return false;
+    }
     return true;
   }
 
@@ -157,6 +170,17 @@ class SecurityContextRequest {
     return true;
   }
 
+  bool PreparePrivilegeLevel(ci::PrivilegeLevel priv_level) {
+    pkg_privilege_level level = (pkg_privilege_level)priv_level;
+    int error = security_manager_app_inst_req_set_pkg_privilege_level(
+        req_, level);
+    if (error != SECURITY_MANAGER_SUCCESS) {
+      SetErrorMessage(&error_message_, error);
+      return false;
+    }
+    return true;
+  }
+
   bool PrepareAppWithPrivileges(const std::string& app_id,
       const std::vector<std::string>& privileges,
       const AppDefinedPrivInfo& appdef_privileges,
@@ -397,10 +421,16 @@ void PrepareAppDefinedPrivilegeData(GList *privileges,
   }
 }
 
-bool RegisterSecurityContextForManifest(
-    const std::string& pkg_id, const boost::filesystem::path& path, uid_t uid,
-    common_installer::CertificateInfo* cert_info, manifest_x* manifest,
-    bool cross_app_rules, std::string* error_message) {
+bool RegisterSecurityContextForManifest(const ci::InstallerContext* context,
+    std::string* error_message) {
+  std::string pkg_id = context->pkgid.get();
+  std::string pkg_type = context->pkg_type.get();
+  bf::path path = context->GetPkgPath();
+  uid_t uid = context->uid.get();
+  const ci::CertificateInfo* cert_info = &(context->certificate_info.get());
+  manifest_x* manifest = context->manifest_data.get();
+  bool cross_app_rules = context->cross_app_rules.get();
+
   // Although application framework hold list of privilege per package, there
   // is situation where we need to filter privileges. This data model doesn't
   // cover hybrid apps well where native privileges should be granted only to
@@ -426,7 +456,7 @@ bool RegisterSecurityContextForManifest(
     *error_message = req.ErrorMessage();
     return false;
   }
-  if (!req.PrepareBasic(pkg_id, uid)) {
+  if (!req.PrepareBasic(pkg_id, uid, pkg_type)) {
     *error_message = req.ErrorMessage();
     return false;
   }
@@ -436,6 +466,11 @@ bool RegisterSecurityContextForManifest(
     return false;
   }
 
+  if (!req.PreparePrivilegeLevel(context->privilege_level.get())) {
+    *error_message = req.ErrorMessage();
+    return false;
+  }
+
   for (application_x* app : GListRange<application_x*>(manifest->application)) {
     if (!app->appid) {
       return false;
index 064c9903797644312ca5a62ff6e3471151196300..751dca06f6a300fd37352d464482b51229f138ac 100644 (file)
@@ -22,21 +22,14 @@ namespace common_installer {
  * Adapter interface for external Security module used for registering
  * package to security context
  *
- * \param pkg_id pkgid of given package
- * \param path path of installed package
- * \param uid uid
- * \param cert_info pointer to certificate info
- * \param manifest pointer to manifest structure
- * \param cross_app_rules true if n-to-n smack rules should be generated
- *                        apps (should be set for hybrid applications).
+ * \param context installer context contains necessary information
  * \param error_message extra/detailed error message
  *
  * \return true if success
  */
-bool RegisterSecurityContextForManifest(const std::string& pkg_id,
-    const boost::filesystem::path& path, uid_t uid,
-    common_installer::CertificateInfo* cert_info, manifest_x* manifest,
-    bool cross_app_rules, std::string* error_message);
+bool RegisterSecurityContextForManifest(
+        const common_installer::InstallerContext* context,
+        std::string* error_message);
 
 /**
  * Adapter interface for external Security module.
index 3ba113fce38349c78b20f963fc527f183406d575..21a5b1ad0eb98dc0a4170e0e8a2b12c9364d3573 100644 (file)
@@ -55,10 +55,7 @@ Step::Status StepRecoverSecurity::RecoveryUpdate() {
     return Status::INVALID_VALUE;
   }
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
@@ -84,10 +81,7 @@ Step::Status StepRecoverSecurity::RecoveryReadonlyUpdateInstall() {
     return Status::INVALID_VALUE;
   }
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Unsuccessful update";
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
index 83cd55ba3cbc560a60fde73e0b6c25492d7e17e9..917be13df5090b9e115bdc7359eea2e65df31399 100644 (file)
@@ -40,10 +40,7 @@ Step::Status StepRegisterSecurity::precheck() {
 Step::Status StepRegisterSecurity::process() {
   std::string error_message;
   if (context_->request_type.get() != RequestType::Move &&
-      !RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+      !RegisterSecurityContextForManifest(context_, &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
       on_error(Status::SECURITY_ERROR, error_message);
index fbe4487c6896952e6292ae454e2e2969cc6dccac..7e1614d570ce3c849023d2c021b5e53b23714154 100644 (file)
@@ -27,10 +27,7 @@ Step::Status StepRollbackDeinstallationSecurity::precheck() {
 
 Step::Status StepRollbackDeinstallationSecurity::undo() {
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     LOG(ERROR) << "Failure on re-installing security context for app "
                << context_->pkgid.get();
     if (!error_message.empty()) {
index b7969851228b0556a4556b89d6fa2466a3a62f27..f00f4b2027af90180a88a32478acc368dc40b1b3 100644 (file)
@@ -13,10 +13,7 @@ namespace security {
 
 Step::Status StepUpdateSecurity::process() {
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
       on_error(Status::SECURITY_ERROR, error_message);
@@ -40,10 +37,7 @@ Step::Status StepUpdateSecurity::process() {
 
 Step::Status StepUpdateSecurity::undo() {
   std::string error_message;
-  if (!RegisterSecurityContextForManifest(
-      context_->pkgid.get(), context_->GetPkgPath(), context_->uid.get(),
-      &context_->certificate_info.get(), context_->old_manifest_data.get(),
-      context_->cross_app_rules.get(), &error_message)) {
+  if (!RegisterSecurityContextForManifest(context_, &error_message)) {
     if (!error_message.empty()) {
       LOG(ERROR) << "error_message: " << error_message;
     }