Add new arguments for installation requests 95/229895/10
authorTomasz Swierczek <t.swierczek@samsung.com>
Mon, 6 Apr 2020 09:03:47 +0000 (11:03 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 14 May 2020 08:38:05 +0000 (08:38 +0000)
Added arguments are:
* pkg_type (none, wrt, core, metadata)
* pkg_privilege_level (none, public, platform, partner)

This change is adjusting usage of privilege-checker functions
to its API changes.

Before this patch, privilege-checker used pkgmgr to check these data
about newly installed app. Because security-manager calls
privilege-checker at app install time, this required the pkgmgr db to be
filled before calling security-manager in app installer.
However, installer is currently changing its order of operation
and we can't rely on its data being available at this time.

Since this data is known explicitly by installer, its easy to add this
information to the installation request (per pkg).

If not set ("none" values), privilege-checker consults pkgmgr
like it used to.

Adding this API will also ease the situation in security-tests, where
pkgmgr DB had to be filled manually before each *fake* app installation
done only for purpose of security-manager API tests.
Now, the installation request in security-tests can be filled with
other-than-none values for both variables, which will result
in pkgmgr DB not being checked at app install time.

Change-Id: I518eb4524c9c1f3ff2e6d68ea25c037591f6634b

src/client/client-security-manager.cpp
src/common/cynara.cpp
src/common/include/cynara.h
src/common/include/privilege-info.h
src/common/include/protocols.h
src/common/privilege-info.cpp
src/common/service_impl.cpp
src/include/app-manager.h
src/include/security-manager-types.h

index 325e13877ee20aedfe13159b68fa8c07d69e1a1c..bdd456d31f0cd4135222c43816a2e4a718f848c8 100644 (file)
@@ -183,6 +183,30 @@ int security_manager_app_inst_req_set_pkg_id(app_inst_req *p_req, const char *pk
     return SECURITY_MANAGER_SUCCESS;
 }
 
+SECURITY_MANAGER_API
+int security_manager_app_inst_req_set_pkg_privilege_level(app_inst_req *p_req,
+        pkg_privilege_level privilege_level)
+{
+    if (!p_req)
+        return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+
+    p_req->privLevel = privilege_level;
+
+    return SECURITY_MANAGER_SUCCESS;
+}
+
+SECURITY_MANAGER_API
+int security_manager_app_inst_req_set_pkg_type(app_inst_req *p_req, pkg_type pkg_type)
+{
+    if (!p_req)
+        return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+
+    p_req->pkgType = pkg_type;
+
+    return SECURITY_MANAGER_SUCCESS;
+}
+
+
 SECURITY_MANAGER_API
 int security_manager_app_inst_req_add_privilege(app_inst_req *p_req, const char *privilege)
 {
index e8e392dc5397ec941de69e22241e665d84791564..0b34e56be8bfdeee52985ce72cc0b605ef490905 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Rafal Krypa <r.krypa@samsung.com>
  *
@@ -340,10 +340,13 @@ void CynaraAdmin::updateAppPolicy(
     const std::string &label,
     bool global,
     uid_t uid,
+    int pkg_type,
+    int pkg_privilege_level,
     const std::vector<std::string> &privileges,
     bool policyRemove)
 {
-    updateAppPolicy(label, label, global, uid, privileges, policyRemove);
+    updateAppPolicy(label, label, global, uid, pkg_type,
+                    pkg_privilege_level, privileges, policyRemove);
 }
 
 void CynaraAdmin::updateAppPolicy(
@@ -351,6 +354,8 @@ void CynaraAdmin::updateAppPolicy(
     const std::string &newLabel,
     bool global,
     uid_t uid,
+    int pkg_type,
+    int pkg_privilege_level,
     const std::vector<std::string> &privileges,
     bool policyRemove)
 {
@@ -417,7 +422,7 @@ void CynaraAdmin::updateAppPolicy(
         std::vector<std::string> blacklistPrivileges;
         std::vector<std::string> privacyPrivileges;
         for (auto &p : privileges) {
-            PrivilegeInfo priv(id, oldLabel, p);
+            PrivilegeInfo priv(id, oldLabel, p, pkg_type, pkg_privilege_level);
             if (askUserEnabled && priv.hasAttribute(PrivilegeInfo::PrivilegeAttr::PRIVACY))
                 privacyPrivileges.push_back(p);
             if (priv.hasAttribute(PrivilegeInfo::PrivilegeAttr::BLACKLIST))
index b99424064e1dbbe2f71df3734221fd6807161eb7..3e4427c6451cdbdcc272811a2845f8e9a48d0998 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2014-2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2014-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Rafal Krypa <r.krypa@samsung.com>
  *
@@ -134,10 +134,13 @@ public:
      * @param label application Smack label
      * @param global true if it's a global or preloaded installation
      * @param uid user identifier
+     * @param pkg_type package type
+     * @param pkg_privilege_level package privilege level
      * @param privileges currently enabled privileges
      * @param policyRemove true while application deinstallation
      */
     void updateAppPolicy(const std::string &label, bool global, uid_t uid,
+        int pkg_type, int pkg_privilege_level,
         const std::vector<std::string> &privileges,
         bool policyRemove = false);
 
@@ -153,10 +156,13 @@ public:
      * @param newLabel application Smack new label
      * @param global true if it's a global or preloaded installation
      * @param uid user identifier
+     * @param pkg_type package type passed from installation request
+     * @param pkg_privilege_level package privilege level passed from installation request
      * @param privileges currently enabled privileges
      * @param policyRemove true while application deinstallation
      */
     void updateAppPolicy(const std::string &oldLabel, const std::string &newLabel, bool global, uid_t uid,
+        int pkg_type, int pkg_privilege_level,
         const std::vector<std::string> &privileges,
         bool policyRemove = false);
 
index 64a3f5952bac0dc0a04793ba46932712d316a36e..bda157c5763eb646fc2252e5d73bf9e259e39e7d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 
 #pragma once
 
+#include <privilege_info.h> // external privilege-info header
 #include <string>
 #include <functional>
 
 #include <dpl/exception.h>
+#include <security-manager-types.h>
 
 namespace SecurityManager {
 
@@ -43,7 +45,9 @@ public:
         BLACKLIST
     };
 
-    PrivilegeInfo(uid_t uid, const std::string &label, const std::string &privilege);
+    PrivilegeInfo(uid_t uid, const std::string &label, const std::string &privilege,
+                  int pkg_type = SM_PKG_TYPE_NONE,
+                  int pkg_privilege_level = SM_PKG_PRIVILEGE_LEVEL_NONE);
 
     bool hasAttribute(PrivilegeAttr attr);
 
@@ -52,6 +56,8 @@ private:
     std::string m_appId;
     std::string m_pkgId;
     std::string m_privilege;
+    privilege_manager_package_type_e m_packageType;
+    privilege_manager_visibility_e m_privilegeLevel;
 };
 
 } // namespace SecurityManager
index 0f75c8409091064baea3074416a5460de7859c06..67aa4eadd50d01324fcc4b0060b0ff1055f7327b 100644 (file)
@@ -61,6 +61,8 @@ struct app_inst_req : ISerializable {
     std::string tizenVersion;
     std::string authorName;
     int installationType = SM_APP_INSTALL_NONE;
+    int pkgType = SM_PKG_TYPE_NONE;
+    int privLevel = SM_PKG_PRIVILEGE_LEVEL_NONE;
     bool isHybrid = false;
 
     app_inst_req() : apps(1) {}
@@ -69,14 +71,14 @@ struct app_inst_req : ISerializable {
     {
         Deserialization::Deserialize(stream,
             apps, pkgName, pkgPaths, uid, tizenVersion, authorName,
-            installationType, isHybrid);
+            installationType, pkgType, privLevel, isHybrid);
     }
 
     virtual void Serialize(IStream &stream) const
     {
         Serialization::Serialize(stream,
             apps, pkgName, pkgPaths, uid, tizenVersion, authorName,
-            installationType, isHybrid);
+            installationType, pkgType, privLevel, isHybrid);
     }
 };
 
index 8df2c3d845fbffe12e73cb37afeba9adcab30f16..d547a47b19b286efb6b412a0019aa99a3c05f936 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2017 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -19,8 +19,6 @@
  * @version    1.0
  */
 
-#include <privilege_info.h> // external privilege-info header
-
 #include "privilege-info.h" // header for this file
 
 #include <dpl/log/log.h>
 
 namespace SecurityManager {
 
-PrivilegeInfo::PrivilegeInfo(uid_t uid, const std::string &label, const std::string &privilege) :
+PrivilegeInfo::PrivilegeInfo(uid_t uid, const std::string &label, const std::string &privilege,
+                             int pkg_type, int pkg_privilege_level) :
     m_uid(uid),
     m_privilege(privilege)
 {
+    switch(pkg_type) {
+        case SM_PKG_TYPE_NONE:
+            m_packageType = PRVMGR_PACKAGE_TYPE_NONE;
+            break;
+        case SM_PKG_TYPE_WRT:
+            m_packageType = PRVMGR_PACKAGE_TYPE_WRT;
+            break;
+        case SM_PKG_TYPE_CORE:
+            m_packageType = PRVMGR_PACKAGE_TYPE_CORE;
+            break;
+        case SM_PKG_TYPE_METADATA:
+            m_packageType = PRVMGR_PACKAGE_TYPE_METADATA;
+            break;
+        default:
+            ThrowMsg(Exception::UnknownError,
+                "Error in PrivilegeInfo::PrivilegeInfo(), invalid pkg_type" << pkg_type);
+    }
+
+    switch(pkg_privilege_level) {
+        case SM_PKG_PRIVILEGE_LEVEL_NONE:
+            m_privilegeLevel = PRVMGR_PACKAGE_VISIBILITY_NONE;
+            break;
+        case SM_PKG_PRIVILEGE_LEVEL_PUBLIC:
+            m_privilegeLevel = PRVMGR_PACKAGE_VISIBILITY_PUBLIC;
+            break;
+        case SM_PKG_PRIVILEGE_LEVEL_PARTNER:
+            m_privilegeLevel = PRVMGR_PACKAGE_VISIBILITY_PARTNER;
+            break;
+        case SM_PKG_PRIVILEGE_LEVEL_PLATFORM:
+            m_privilegeLevel = PRVMGR_PACKAGE_VISIBILITY_PLATFORM;
+            break;
+        default:
+            ThrowMsg(Exception::UnknownError,
+                "Error in PrivilegeInfo::PrivilegeInfo(), invalid pkg_privilege_level" << pkg_privilege_level);
+    }
+
     try {
         SmackLabels::generateAppPkgNameFromLabel(label, m_appId, m_pkgId);
     } catch(const SmackException::InvalidLabel&) {
@@ -43,7 +78,8 @@ PrivilegeInfo::PrivilegeInfo(uid_t uid, const std::string &label, const std::str
 bool PrivilegeInfo::hasAttribute(PrivilegeAttr attr)
 {
     privilege_manager_privilege_type_e type;
-    int ret = privilege_info_get_privilege_type(m_uid, m_pkgId.c_str(), m_privilege.c_str(), &type);
+    int ret = privilege_info_get_privilege_type(m_uid, m_pkgId.c_str(),
+            m_packageType, m_privilegeLevel, m_privilege.c_str(), &type);
     if (ret != PRVMGR_ERR_NONE)
         ThrowMsg(Exception::UnknownError, "Error while getting privilege type " << ret);
 
index c9763138f364c5dee3ac2aece0ed1d2437b25aa1..e6319a6974f65deef2214b1b591459819437feea 100644 (file)
@@ -501,7 +501,8 @@ void ServiceImpl::appInstallCynaraPolicies(app_inst_req::app& app, app_inst_req&
     Smack::Label oldAppLabel = SmackLabels::generateProcessLabel(
             app.appName, req.pkgName, ih.isOldPkgHybrid);
 
-    m_cynaraAdmin.updateAppPolicy(oldAppLabel, appLabel, global, req.uid, privileges);
+    m_cynaraAdmin.updateAppPolicy(oldAppLabel, appLabel, global,
+        req.uid, req.pkgType, req.privLevel, privileges);
     m_cynaraAdmin.updateAppDefinedPolicy(global, req.uid,
         ih.oldAppDefinedPrivileges, app.appDefinedPrivileges);
 }
@@ -850,7 +851,8 @@ void ServiceImpl::appUninstallCynaraPolicies(const std::string &processLabel, ap
     // policy for entire package, as all apps in non-hybrid package have
     // the same Smack label.
     // This bug exists in security-manager since version 1.2.1 (Sep 2016).
-    m_cynaraAdmin.updateAppPolicy(processLabel, global, req.uid, std::vector<std::string>(), true);
+    m_cynaraAdmin.updateAppPolicy(processLabel, global,
+        req.uid, req.pkgType, req.privLevel, std::vector<std::string>(), true);
     m_cynaraAdmin.updateAppDefinedPolicy(global, req.uid,
         ui.oldAppDefinedPrivileges, AppDefinedPrivilegesVector());
 }
index c681cf0c033290ea876542467d0f4c1f517843e2..413bd949045d89e170d873da4c845d599e8fd17d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2000 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Rafal Krypa <r.krypa@samsung.com>
  *
@@ -51,6 +51,33 @@ void security_manager_app_inst_req_free(app_inst_req *p_req);
  */
 int security_manager_app_inst_req_set_target_version(app_inst_req *p_req, const char *tizen_ver);
 
+/**
+ * This function is used to set package privilege level. If not set in the installation request,
+ * defaults to SM_PKG_PRIVILEGE_LEVEL_NONE (value will be checked in package manager in such case).
+ *
+ * This API can be called only once for installation request
+ * (like security_manager_app_inst_req_set_pkg_id).
+ *
+ * \param[in] p_req             Pointer handling app_inst_req structure
+ * \param[in] privilege_level   Package privilege level
+ * \return API return code or error code
+ */
+int security_manager_app_inst_req_set_pkg_privilege_level(app_inst_req *p_req,
+        pkg_privilege_level privilege_level);
+
+/**
+ * This function is used to set package type. If not set in the installation request,
+ * defaults to SM_PKG_TYPE_NONE (value will be checked in package manager in such case).
+ *
+ * This API can be called only once for installation request
+ * (like security_manager_app_inst_req_set_pkg_id).
+ *
+ * \param[in] p_req             Pointer handling app_inst_req structure
+ * \param[in] privilege_level   Package type
+ * \return API return code or error code
+ */
+int security_manager_app_inst_req_set_pkg_type(app_inst_req *p_req, pkg_type pkg_type);
+
 /**
  * This function is used to set up application identifier in app_inst_req structure
  *
index f7fa2eb2ee1076f26e7f3c7f48305a8fa68b1b78..645bfe6aabd642075b78d6b2de1d3e3bbb289db8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Rafal Krypa <r.krypa@samsung.com>
  *
@@ -81,6 +81,32 @@ enum app_install_type {
 };
 typedef enum app_install_type app_install_type;
 
+/**
+ * This enum is used to set the level of trust for privileges
+ * that can be requested by the application in its manifest in given package.
+ * This information is used by underlying privilege-checker
+ * database module.
+ */
+enum pkg_privilege_level {
+    SM_PKG_PRIVILEGE_LEVEL_NONE = 0,
+    SM_PKG_PRIVILEGE_LEVEL_PUBLIC,
+    SM_PKG_PRIVILEGE_LEVEL_PARTNER,
+    SM_PKG_PRIVILEGE_LEVEL_PLATFORM
+};
+typedef enum pkg_privilege_level pkg_privilege_level;
+
+/**
+ * This enum defines the package type as recognized
+ * by underlying privilege-checker database module.
+ */
+ enum pkg_type {
+    SM_PKG_TYPE_NONE = 0,
+    SM_PKG_TYPE_WRT,
+    SM_PKG_TYPE_CORE,
+    SM_PKG_TYPE_METADATA
+ };
+typedef enum pkg_type pkg_type;
+
 /**
  * This enum has values equivalent to gumd user type.
  * The gum-utils help states that