Return DENY when application has no policy for given privacy privilege 01/169401/3
authorZofia Grzelewska <z.abramowska@samsung.com>
Tue, 6 Feb 2018 09:01:04 +0000 (10:01 +0100)
committerZofia Grzelewska <z.abramowska@samsung.com>
Tue, 6 Feb 2018 11:29:27 +0000 (12:29 +0100)
When application has no policy set in privacy bucket, return
DENY inside checkPermission. This will be also returned in case
of privileges declared in application manifests, because currently
askuser cannot differentiate these two cases.

Change-Id: I9a177bdd9cc2e107dff973c5328263f23c31a0a4

src/client/impl/ApiInterfaceImpl.cpp
src/common/policy/Policy.cpp
src/notification-daemon/Logic.cpp

index 4dc209405e2677d8c81f8474f5eb7307e6144770..a1833e8a2682ccd58a2bd459044a113228b8c1ea 100644 (file)
@@ -100,6 +100,10 @@ askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privile
 
     auto policyLevel = getPrivilegeMappedPolicy(appId, privilege);
 
+    if (policyLevel.empty()) {
+        ALOGD("Privilege " << privilege << " is not a privacy privilege for app " << appId);
+        return ASKUSER_CHECK_RESULT_DENY;
+    }
     if (policyLevel == "Allow") {
         return ASKUSER_CHECK_RESULT_ALLOW;
     }
@@ -112,6 +116,8 @@ askuser_check_result ApiInterfaceImpl::checkPrivilege(const std::string &privile
         return ASKUSER_CHECK_RESULT_ASK;
     }
 
+    ALOGE("Unknown policy level set : " << policyLevel <<
+          " for app " << appId << " and privilege " << privilege);
     return ASKUSER_CHECK_RESULT_DENY;
 }
 
index 501464c2a9934d808f9eebb90169a48393451c7c..0d48c08473ce6c4e121c02bf9883bb7e5942ddbd 100644 (file)
@@ -71,6 +71,9 @@ PolicyEntryCopy::PolicyEntryCopy(policy_entry *entry) {
 }
 
 Policy getMinimumPolicy(const std::vector<Policy> &policies) {
+    if (policies.empty())
+        return "";
+
     Policy minimumPolicy = "Allow";
 
     for (auto &policy : policies) {
@@ -127,7 +130,10 @@ Policy getPrivilegePolicy(const std::string &appId, const Privilege &privilege)
 Policy getPrivaciesPolicy(const std::string &appId, const std::vector<Privacy> &privacies) {
     std::vector<Policy> policies;
     for (auto &privacy : privacies) {
-        policies.push_back(calculatePolicyForPrivacy(appId, privacy));
+        Policy privacyPolicy = calculatePolicyForPrivacy(appId, privacy);
+        if (privacyPolicy.empty())
+            continue;
+        policies.push_back(privacyPolicy);
     }
     return getMinimumPolicy(policies);
 }
index 57197cf8193c515683c6e6ebca0f2c82143f09e5..1f7b8460a7dd354f45ddda2deaf1faf88bd00db0 100644 (file)
@@ -231,8 +231,18 @@ void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::
             // Remove privacies which are already allowed - we don't need to spam user more with popups
             privacy = removePrivacy;
         }
+        if (policy.empty()) {
+            ALOGD("Application doesn't use privacy " << privacy);
+            continue;
+        }
         policies.push_back(policy);
     }
+
+    if (policies.empty()) {
+        ALOGD("Privilege " << privilege << " is not privacy for app : " << conn.appId);
+        m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_FOREVER);
+        return;
+    }
     std::string policyLevel = getMinimumPolicy(policies);
 
     ALOGD("Privilege policy level calculated to : " << policyLevel);