From d6252206ef65d199b5d034b3dd7359af436dd5aa Mon Sep 17 00:00:00 2001 From: Zofia Grzelewska Date: Tue, 6 Feb 2018 10:01:04 +0100 Subject: [PATCH] Return DENY when application has no policy for given privacy privilege 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 | 6 ++++++ src/common/policy/Policy.cpp | 8 +++++++- src/notification-daemon/Logic.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/client/impl/ApiInterfaceImpl.cpp b/src/client/impl/ApiInterfaceImpl.cpp index 4dc2094..a1833e8 100644 --- a/src/client/impl/ApiInterfaceImpl.cpp +++ b/src/client/impl/ApiInterfaceImpl.cpp @@ -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; } diff --git a/src/common/policy/Policy.cpp b/src/common/policy/Policy.cpp index 501464c..0d48c08 100644 --- a/src/common/policy/Policy.cpp +++ b/src/common/policy/Policy.cpp @@ -71,6 +71,9 @@ PolicyEntryCopy::PolicyEntryCopy(policy_entry *entry) { } Policy getMinimumPolicy(const std::vector &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 &privacies) { std::vector 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); } diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index 57197cf..1f7b846 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -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); -- 2.7.4