From 46f6d211d0f1b26727a68ee433ec1ab1740ebbe6 Mon Sep 17 00:00:00 2001 From: Maksym Ked Date: Thu, 23 May 2019 22:45:57 +0300 Subject: Added storage of encryption required rpcs --- .../application_manager/policies/policy_handler.h | 2 + .../application_manager/rpc_protection_manager.h | 16 +-- .../rpc_protection_manager_impl.h | 45 +++++-- .../rc_get_interior_vehicle_data_consent_test.cc | 2 +- .../src/application_manager_impl.cc | 16 ++- .../src/policies/policy_handler.cc | 15 ++- .../src/rpc_protection_manager_impl.cc | 145 +++++++++++++-------- .../application_manager/src/rpc_service_impl.cc | 12 +- .../mock_rpc_protection_manager.h | 3 +- .../policies/policy_encryption_flag_getter.h | 5 + .../policies/policy_handler_interface.h | 2 + .../policies/policy_handler_observer.h | 2 + .../include/protocol_handler/protocol_handler.h | 1 + .../policies/mock_policy_handler_interface.h | 1 + .../policy_external/policy/mock_cache_manager.h | 1 + .../policy_external/policy/mock_policy_manager.h | 1 + .../policy_regular/policy/mock_cache_manager.h | 1 + .../policy_regular/policy/mock_policy_manager.h | 1 + .../policy_external/include/policy/cache_manager.h | 6 + .../include/policy/cache_manager_interface.h | 6 + .../include/policy/policy_manager_impl.h | 2 + .../include/policy/policy_table/types.h | 1 - .../policy/policy_external/src/cache_manager.cc | 14 ++ .../policy_external/src/policy_manager_impl.cc | 14 ++ .../policy_regular/include/policy/cache_manager.h | 6 + .../include/policy/cache_manager_interface.h | 6 + .../include/policy/policy_manager_impl.h | 3 + .../policy/policy_regular/src/cache_manager.cc | 14 ++ .../policy_regular/src/policy_manager_impl.cc | 14 ++ 29 files changed, 256 insertions(+), 101 deletions(-) diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 196cb9a61e..dddd1b333d 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -676,6 +676,8 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void OnPTUFinished(const bool ptu_result) OVERRIDE; + virtual void OnPTInited() OVERRIDE; + /** * @brief OnDeviceSwitching Notifies policy manager on device switch event so * policy permissions should be processed accordingly diff --git a/src/components/application_manager/include/application_manager/rpc_protection_manager.h b/src/components/application_manager/include/application_manager/rpc_protection_manager.h index 0a272117ea..fcd2cd64db 100644 --- a/src/components/application_manager/include/application_manager/rpc_protection_manager.h +++ b/src/components/application_manager/include/application_manager/rpc_protection_manager.h @@ -37,6 +37,7 @@ #include #include "application_manager/application.h" +#include "application_manager/policies/policy_handler_observer.h" #include "smart_objects/smart_object.h" namespace ns_smart_device_link { @@ -60,7 +61,7 @@ namespace application_manager { * PolicyEncryptionFlagGetterInterface which is implemented by PolicyManager, * providing adequate level of abstraction. */ -class RPCProtectionManager { +class RPCProtectionManager : public policy::PolicyHandlerObserver { public: /* * @brief virtual destructor RPCProtectionManager @@ -77,7 +78,6 @@ class RPCProtectionManager { virtual bool CheckPolicyEncryptionFlag( const uint32_t function_id, const ApplicationSharedPtr app, - const uint32_t conrrelation_id, const bool is_rpc_service_secure) const = 0; /* * @brief check whether given rpc is saved to internal cache and needs to be @@ -89,18 +89,6 @@ class RPCProtectionManager { */ virtual bool IsInEncryptionNeededCache( const uint32_t app_id, const uint32_t conrrelation_id) const = 0; - /* - * @brief create encryption needed response in case when received unencrypted - * rpc that requires encryption - * @param connection_key connection key - * @param function_id function id - * @param conrrelation_id conrrelation id - * @return response with error code ENCRYPTION_NEEDED - */ - virtual smart_objects::SmartObjectSPtr CreateEncryptionNeededResponse( - const uint32_t connection_key, - const uint32_t function_id, - const uint32_t conrrelation_id) = 0; /* * @brief Adds app id and correlation id of a message to internal cache diff --git a/src/components/application_manager/include/application_manager/rpc_protection_manager_impl.h b/src/components/application_manager/include/application_manager/rpc_protection_manager_impl.h index 35217f1591..ca7b010d49 100644 --- a/src/components/application_manager/include/application_manager/rpc_protection_manager_impl.h +++ b/src/components/application_manager/include/application_manager/rpc_protection_manager_impl.h @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_PROTOCOL_HANDLER_RPC_PROTECTION_MANAGER_IMPL_H_ #include +#include #include "application_manager/rpc_protection_manager.h" #include "application_manager/policies/policy_handler.h" @@ -43,6 +44,10 @@ namespace application_manager { */ class RPCProtectionManagerImpl : public RPCProtectionManager { public: + typedef std::pair AppIdCorrIdPair; + typedef std::set FunctionNames; + typedef std::map AppEncryptedRpcMap; + RPCProtectionManagerImpl(policy::PolicyHandlerInterface& policy_handler); ~RPCProtectionManagerImpl() OVERRIDE {} @@ -50,23 +55,22 @@ class RPCProtectionManagerImpl : public RPCProtectionManager { bool CheckPolicyEncryptionFlag( const uint32_t function_id, const ApplicationSharedPtr app, - const uint32_t conrrelation_id, const bool is_rpc_service_secure) const OVERRIDE; bool IsInEncryptionNeededCache(const uint32_t app_id, const uint32_t conrrelation_id) const OVERRIDE; - smart_objects::SmartObjectSPtr CreateEncryptionNeededResponse( - const uint32_t connection_key, - const uint32_t function_id, - const uint32_t conrrelation_id) OVERRIDE; - void AddToEncryptionNeededCache(const uint32_t app_id, const uint32_t correlation_id) OVERRIDE; void RemoveFromEncryptionNeededCache(const uint32_t app_id, const uint32_t correlation_id) OVERRIDE; + // PolicyHandlerObserver interface + void OnPTUFinished(const bool ptu_result) OVERRIDE; + + void OnPTInited() OVERRIDE; + private: /* * @brief check whether given rpc is an exeption @@ -77,17 +81,32 @@ class RPCProtectionManagerImpl : public RPCProtectionManager { bool IsExceptionRPC(const uint32_t function_id) const; /* - * @brief checks whether given function is in functional group - * @param function_name function name - * @param group group name - * @return true if the function exists in group else return false + * @brief retreives list of rpcs that require encryption by policy + * @param policy_app_id policy application name + * @return container with function names that require encryption by policy */ - bool IsFunctionInGroup(const std::string& function_name, - const std::string& group) const; + FunctionNames GetEncryptedRPCsForApp(const std::string& policy_app_id); + + /* + * @brief checks whether given function name is in saved encrypted rpc list + * @param policy_app_id policy application name + * @param function_name policy function name + * @return true if function_name for this policy_app_id is saved, otherwise - + * false + */ + bool IsEncryptionRequiredByPolicy(const std::string& policy_app_id, + const std::string& function_name) const; + + /* + * @brief saves rpcs that have encryption_required flag in policy table to + * internal container + */ + void SaveEncryptedRPC(); policy::PolicyHandlerInterface& policy_handler_; - typedef std::pair AppIdCorrIdPair; + AppEncryptedRpcMap encrypted_rpcs_; + sync_primitives::Lock encrypted_rpcs_lock_; std::set encryption_needed_cache_; sync_primitives::Lock message_needed_encryption_lock_; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 48b067c3c5..9351ec4e02 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -150,7 +150,7 @@ class RCGetInteriorVehicleDataConsentTest .WillByDefault(Return(true)); ON_CALL(mock_protocol_handler, IsRPCServiceSecure(_)) .WillByDefault(Return(false)); - ON_CALL(*rpc_protection_manager_, CheckPolicyEncryptionFlag(_, _, _, _)) + ON_CALL(*rpc_protection_manager_, CheckPolicyEncryptionFlag(_, _, _)) .WillByDefault(Return(false)); } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index eb3ab180b1..7cfea6eab7 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -212,13 +212,15 @@ ApplicationManagerImpl::ApplicationManagerImpl( timer_pool_.push_back(clearing_timer); rpc_handler_.reset(new rpc_handler::RPCHandlerImpl(*this)); commands_holder_.reset(new CommandHolderImpl(*this)); - rpc_service_.reset(new rpc_service::RPCServiceImpl( - *this, - request_ctrl_, - protocol_handler_, - hmi_handler_, - *commands_holder_, - std::make_shared(*policy_handler_))); + std::shared_ptr rpc_protection_manager = + std::make_shared(*policy_handler_); + policy_handler_->add_listener(rpc_protection_manager.get()); + rpc_service_.reset(new rpc_service::RPCServiceImpl(*this, + request_ctrl_, + protocol_handler_, + hmi_handler_, + *commands_holder_, + rpc_protection_manager)); } ApplicationManagerImpl::~ApplicationManagerImpl() { diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 0a2a4ce3a8..438f36ad26 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -369,12 +369,25 @@ bool PolicyHandler::InitPolicyTable() { hmi_apis::FunctionID::BasicCommunication_OnReady); std::string preloaded_file = get_settings().preloaded_pt_file(); if (file_system::FileExists(preloaded_file)) { - return policy_manager_->InitPT(preloaded_file, &get_settings()); + const bool pt_inited = + policy_manager_->InitPT(preloaded_file, &get_settings()); + OnPTInited(); + return pt_inited; } LOG4CXX_FATAL(logger_, "The file which contains preloaded PT is not exist"); return false; } +void PolicyHandler::OnPTInited() { + LOG4CXX_AUTO_TRACE(logger_); + + sync_primitives::AutoLock lock(listeners_lock_); + + std::for_each(listeners_.begin(), + listeners_.end(), + std::mem_fun(&PolicyHandlerObserver::OnPTInited)); +} + bool PolicyHandler::ResetPolicyTable() { LOG4CXX_TRACE(logger_, "Reset policy table."); POLICY_LIB_CHECK(false); diff --git a/src/components/application_manager/src/rpc_protection_manager_impl.cc b/src/components/application_manager/src/rpc_protection_manager_impl.cc index d784d9c2c9..3250e0d0b8 100644 --- a/src/components/application_manager/src/rpc_protection_manager_impl.cc +++ b/src/components/application_manager/src/rpc_protection_manager_impl.cc @@ -54,40 +54,16 @@ RPCProtectionManagerImpl::RPCProtectionManagerImpl( LOG4CXX_AUTO_TRACE(logger_); } -bool RPCProtectionManagerImpl::IsFunctionInGroup( - const std::string& function_name, const std::string& group) const { - const auto policy_encryption_flag_getter = - policy_handler_.PolicyEncryptionFlagGetter(); - - const auto group_rpcs = - policy_encryption_flag_getter->GetRPCsForFunctionGroup(group); - - const auto it = - std::find(group_rpcs.begin(), group_rpcs.end(), function_name); - - const bool is_function_in_group = it != group_rpcs.end(); - - LOG4CXX_DEBUG(logger_, - "Function is in group " << std::boolalpha - << is_function_in_group); - - return is_function_in_group; -} - bool RPCProtectionManagerImpl::CheckPolicyEncryptionFlag( const uint32_t function_id, const ApplicationSharedPtr app, - const uint32_t correlation_id, const bool is_rpc_service_secure) const { LOG4CXX_AUTO_TRACE(logger_); const auto& policy_encryption_flag_getter = policy_handler_.PolicyEncryptionFlagGetter(); const std::string function_name = policy_encryption_flag_getter->GetPolicyFunctionName(function_id); - LOG4CXX_DEBUG(logger_, - "Function for check is " << function_name - << " conrrelation_id is " - << correlation_id); + LOG4CXX_DEBUG(logger_, "Function for check is " << function_name); if (!is_rpc_service_secure && IsExceptionRPC(function_id)) { LOG4CXX_WARN(logger_, @@ -102,27 +78,27 @@ bool RPCProtectionManagerImpl::CheckPolicyEncryptionFlag( } const auto policy_app_id = app->policy_app_id(); - if (!policy_encryption_flag_getter->AppNeedEncryption(policy_app_id)) { - LOG4CXX_TRACE(logger_, "Application does not require encryption"); - return false; - } - const auto app_rpc_groups = - policy_encryption_flag_getter->GetFunctionGroupsForApp(policy_app_id); + return IsEncryptionRequiredByPolicy(policy_app_id, function_name); +} - for (const auto& group : app_rpc_groups) { - const bool is_function_in_group = IsFunctionInGroup(function_name, group); +bool RPCProtectionManagerImpl::IsEncryptionRequiredByPolicy( + const std::string& policy_app_id, const std::string& function_name) const { + LOG4CXX_AUTO_TRACE(logger_); - if (is_function_in_group && - policy_encryption_flag_getter->FunctionGroupNeedEncryption(group)) { - LOG4CXX_DEBUG(logger_, - "Message needs encryption. Function name is " - << function_name); - return true; - } + auto it = encrypted_rpcs_.find(policy_app_id); + + if (encrypted_rpcs_.end() == it) { + LOG4CXX_WARN(logger_, + "App specific policies for app: " << policy_app_id + << " not found"); + it = encrypted_rpcs_.find(policy_table::kDefaultApp); + return encrypted_rpcs_.end() != it + ? (*it).second.find(function_name) != (*it).second.end() + : false; } - return false; + return (*it).second.find(function_name) != (*it).second.end(); } bool RPCProtectionManagerImpl::IsInEncryptionNeededCache( @@ -163,25 +139,80 @@ void RPCProtectionManagerImpl::RemoveFromEncryptionNeededCache( encryption_needed_cache_.erase(std::make_pair(app_id, correlation_id)); } -smart_objects::SmartObjectSPtr -RPCProtectionManagerImpl::CreateEncryptionNeededResponse( - const uint32_t connection_key, - const uint32_t function_id, - const uint32_t correlation_id) { +void RPCProtectionManagerImpl::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); - auto it = encryption_needed_cache_.find( - std::make_pair(connection_key, correlation_id)); - if (it != encryption_needed_cache_.end()) { - encryption_needed_cache_.erase(it); + sync_primitives::AutoLock lock(encrypted_rpcs_lock_); + + if (ptu_result) { + LOG4CXX_TRACE(logger_, + "PTU finished successfully, commencing internal encrypted " + "RPC cache update"); + encrypted_rpcs_.clear(); + SaveEncryptedRPC(); } else { LOG4CXX_WARN(logger_, - "RPC for correlation id: " << correlation_id << " and app id: " - << connection_key << " not found"); + "PTU was unsuccessful. Keeping internal RPC cache from " + "current snapshot"); + } +} + +void RPCProtectionManagerImpl::SaveEncryptedRPC() { + LOG4CXX_AUTO_TRACE(logger_); + + const auto policy_encryption_flag_getter = + policy_handler_.PolicyEncryptionFlagGetter(); + + const auto policy_policy_app_ids = + policy_encryption_flag_getter->GetApplicationPolicyIDs(); + + for (const auto& app : policy_policy_app_ids) { + LOG4CXX_DEBUG(logger_, "Processing app name: " << app); + + encrypted_rpcs_[app] = GetEncryptedRPCsForApp(app); } - return MessageHelper::CreateNegativeResponse( - connection_key, - function_id, - correlation_id, - static_cast(mobile_apis::Result::ENCRYPTION_NEEDED)); } + +void RPCProtectionManagerImpl::OnPTInited() { + LOG4CXX_AUTO_TRACE(logger_); + + encrypted_rpcs_.clear(); + + SaveEncryptedRPC(); +} + +RPCProtectionManagerImpl::FunctionNames +RPCProtectionManagerImpl::GetEncryptedRPCsForApp( + const std::string& policy_app_id) { + LOG4CXX_AUTO_TRACE(logger_); + FunctionNames encrypted_rpcs; + + const auto policy_encryption_flag_getter = + policy_handler_.PolicyEncryptionFlagGetter(); + + if (!policy_encryption_flag_getter->AppNeedEncryption(policy_app_id)) { + return encrypted_rpcs; + } + + const auto function_groups = + policy_encryption_flag_getter->GetFunctionGroupsForApp(policy_app_id); + + auto fill_encrypted_rpcs = [&encrypted_rpcs]( + const std::string& function_name) { + LOG4CXX_DEBUG(logger_, "Adding required encryprion rpc: " << function_name); + encrypted_rpcs.insert(function_name); + }; + + for (const auto& function_group : function_groups) { + if (policy_encryption_flag_getter->FunctionGroupNeedEncryption( + function_group)) { + auto rpcs = policy_encryption_flag_getter->GetRPCsForFunctionGroup( + function_group); + + std::for_each(rpcs.begin(), rpcs.end(), fill_encrypted_rpcs); + } + } + + return encrypted_rpcs; +} + } // namespace protocol_handler diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index 150eb50c5b..c3e3873dba 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -78,7 +78,7 @@ EncryptionFlagCheckResult RPCServiceImpl::IsEncryptionRequired( message[strings::params][strings::message_type].asUInt(); const bool policy_encryption_flag = rpc_protection_manager_->CheckPolicyEncryptionFlag( - function_id, app, correlation_id, is_rpc_service_secure); + function_id, app, is_rpc_service_secure); if (MessageType::kRequest == message_type) { const bool message_protected = message[strings::params][strings::protection].asBool(); @@ -165,9 +165,12 @@ bool RPCServiceImpl::ManageMobileCommand( *message, app, protocol_handler_->IsRPCServiceSecure(connection_key))) { - const auto response = - rpc_protection_manager_->CreateEncryptionNeededResponse( - connection_key, function_id, correlation_id); + const auto response = MessageHelper::CreateNegativeResponse( + connection_key, + function_id, + correlation_id, + static_cast(mobile_apis::Result::ENCRYPTION_NEEDED)); + ; SendMessageToMobile(response); return false; } @@ -428,7 +431,6 @@ void RPCServiceImpl::Handle(const impl::MessageToMobile message) { ? rpc_protection_manager_->CheckPolicyEncryptionFlag( message->function_id(), app_manager_.application(app_id), - correlation_id, is_service_secure) : rpc_protection_manager_->IsInEncryptionNeededCache(app_id, correlation_id); diff --git a/src/components/application_manager/test/include/application_manager/mock_rpc_protection_manager.h b/src/components/application_manager/test/include/application_manager/mock_rpc_protection_manager.h index 0060ea9ed3..74690a0253 100644 --- a/src/components/application_manager/test/include/application_manager/mock_rpc_protection_manager.h +++ b/src/components/application_manager/test/include/application_manager/mock_rpc_protection_manager.h @@ -39,10 +39,9 @@ namespace application_manager { class MockRPCProtectionManager : public RPCProtectionManager { public: - MOCK_CONST_METHOD4(CheckPolicyEncryptionFlag, + MOCK_CONST_METHOD3(CheckPolicyEncryptionFlag, bool(const uint32_t function_id, const ApplicationSharedPtr app, - const uint32_t conrrelation_id, const bool is_rpc_service_secure)); MOCK_METHOD3(CreateEncryptionNeededResponse, diff --git a/src/components/include/application_manager/policies/policy_encryption_flag_getter.h b/src/components/include/application_manager/policies/policy_encryption_flag_getter.h index fb80eca7dc..f93f12c838 100644 --- a/src/components/include/application_manager/policies/policy_encryption_flag_getter.h +++ b/src/components/include/application_manager/policies/policy_encryption_flag_getter.h @@ -95,6 +95,11 @@ class PolicyEncryptionFlagGetterInterface { */ virtual const std::string GetPolicyFunctionName( const uint32_t function_id) const = 0; + /* + * @brief retrieves application names from policy table + * @return container with policy application names + */ + virtual const std::vector GetApplicationPolicyIDs() const = 0; }; } // policy diff --git a/src/components/include/application_manager/policies/policy_handler_interface.h b/src/components/include/application_manager/policies/policy_handler_interface.h index bfc1edee3f..a84c73d421 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -338,6 +338,8 @@ class PolicyHandlerInterface { virtual void OnPTUFinished(const bool ptu_result) = 0; + virtual void OnPTInited() = 0; + #ifdef EXTERNAL_PROPRIETARY_MODE virtual void OnCertificateDecrypted(bool is_succeeded) = 0; #endif // EXTERNAL_PROPRIETARY_MODE diff --git a/src/components/include/application_manager/policies/policy_handler_observer.h b/src/components/include/application_manager/policies/policy_handler_observer.h index 9c1091d0a8..42348e7705 100644 --- a/src/components/include/application_manager/policies/policy_handler_observer.h +++ b/src/components/include/application_manager/policies/policy_handler_observer.h @@ -53,6 +53,8 @@ class PolicyHandlerObserver { virtual void OnPTUFinished(const bool ptu_result) {} + virtual void OnPTInited() {} + virtual ~PolicyHandlerObserver() {} }; } // namespace policy diff --git a/src/components/include/protocol_handler/protocol_handler.h b/src/components/include/protocol_handler/protocol_handler.h index 4eefc43b22..619c47ac34 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -70,6 +70,7 @@ class ProtocolHandler { /** * \brief Method for sending message to Mobile Application. * \param message RawMessage with params to be sent to Mobile App. + * \param needs_encryption whether message needs to be encrypted by policy * \param final_message tells whether message's * connection must be closed when message is processed */ diff --git a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h index a37e09e62a..ef1604c3f9 100644 --- a/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h +++ b/src/components/include/test/application_manager/policies/mock_policy_handler_interface.h @@ -187,6 +187,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { void(std::map app_hmi_types)); MOCK_METHOD1(OnCertificateUpdated, void(const std::string& certificate_data)); MOCK_METHOD1(OnPTUFinished, void(const bool ptu_result)); + MOCK_METHOD0(OnPTInited, void()); MOCK_METHOD1(OnCertificateDecrypted, void(bool is_succeeded)); MOCK_METHOD0(CanUpdate, bool()); MOCK_METHOD2(OnDeviceConsentChanged, diff --git a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h index 801f01dd2d..84696b52f5 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_cache_manager.h @@ -309,6 +309,7 @@ class MockCacheManagerInterface : public ::policy::CacheManagerInterface { MOCK_CONST_METHOD2(GetApplicationParams, void(const std::string& application_name, policy_table::ApplicationParams& application_params)); + MOCK_CONST_METHOD0(GetPolicyAppNames, const policy_table::Strings()); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index 4a5a789287..fd4133c4e4 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -58,6 +58,7 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD1( GetFunctionGroupsForApp, const std::vector(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetApplicationPolicyIDs, const std::vector()); MOCK_CONST_METHOD2(FunctionNeedEncryption, bool(const std::string& policy_group, const std::string& policy_function_id)); diff --git a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h index a5c0d7ce6c..057495bb5b 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_cache_manager.h @@ -270,6 +270,7 @@ class MockCacheManagerInterface : public CacheManagerInterface { MOCK_CONST_METHOD2(GetApplicationParams, void(const std::string& application_name, policy_table::ApplicationParams& application_params)); + MOCK_CONST_METHOD0(GetPolicyAppNames, const policy_table::Strings()); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h index 22cefe554c..91ab3e8c2e 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_manager.h @@ -59,6 +59,7 @@ class MockPolicyManager : public PolicyManager { MOCK_CONST_METHOD1( GetFunctionGroupsForApp, const std::vector(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetApplicationPolicyIDs, const std::vector()); MOCK_CONST_METHOD2(FunctionNeedEncryption, bool(const std::string& policy_group, const std::string& policy_function_id)); diff --git a/src/components/policy/policy_external/include/policy/cache_manager.h b/src/components/policy/policy_external/include/policy/cache_manager.h index aab70f0bf8..b348f360f0 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -413,6 +413,12 @@ class CacheManager : public CacheManagerInterface { */ bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups); + /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + const policy_table::Strings GetPolicyAppNames() const OVERRIDE; + /** * Checks if the application is represented in policy table * @param app_id application id diff --git a/src/components/policy/policy_external/include/policy/cache_manager_interface.h b/src/components/policy/policy_external/include/policy/cache_manager_interface.h index 17ccd00eba..d21218f820 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_external/include/policy/cache_manager_interface.h @@ -435,6 +435,12 @@ class CacheManagerInterface { virtual bool GetFunctionalGroupings( policy_table::FunctionalGroupings& groups) = 0; + /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + virtual const policy_table::Strings GetPolicyAppNames() const = 0; + /** * Checks if the application is represented in policy table * @param app_id application id diff --git a/src/components/policy/policy_external/include/policy/policy_manager_impl.h b/src/components/policy/policy_external/include/policy/policy_manager_impl.h index 17824b2787..e36080309e 100644 --- a/src/components/policy/policy_external/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_external/include/policy/policy_manager_impl.h @@ -74,6 +74,8 @@ class PolicyManagerImpl : public PolicyManager { const std::vector GetFunctionGroupsForApp( const std::string& policy_app_id) const OVERRIDE; + const std::vector GetApplicationPolicyIDs() const OVERRIDE; + /* * \param policy_group group * \return true if the group need encryption diff --git a/src/components/policy/policy_external/include/policy/policy_table/types.h b/src/components/policy/policy_external/include/policy/policy_table/types.h index 574b78ee56..b25789643a 100644 --- a/src/components/policy/policy_external/include/policy/policy_table/types.h +++ b/src/components/policy/policy_external/include/policy/policy_table/types.h @@ -116,7 +116,6 @@ typedef Integer FunctionIDInt; typedef Map RemoteRpcs; typedef Map AccessModules; typedef Array, 0, 255> ModuleTypes; - typedef AppHMIType AppHmiType; typedef std::vector AppHmiTypes; diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index fed2042f39..90b33f7728 100644 --- a/src/components/policy/policy_external/src/cache_manager.cc +++ b/src/components/policy/policy_external/src/cache_manager.cc @@ -325,6 +325,20 @@ const policy_table::Strings& CacheManager::GetGroups(const PTString& app_id) { return pt_->policy_table.app_policies_section.apps[app_id].groups; } +const policy_table::Strings CacheManager::GetPolicyAppNames() const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock auto_lock(cache_lock_); + + const auto apps = pt_->policy_table.app_policies_section.apps; + + policy_table::Strings policy_app_ids; + for (const auto& app : apps) { + policy_app_ids.push_back(app.first); + } + + return policy_app_ids; +} + bool CacheManager::CanAppKeepContext(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); sync_primitives::AutoLock auto_lock(cache_lock_); diff --git a/src/components/policy/policy_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 9c2bc27577..5ebe2adb2c 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -2357,6 +2357,20 @@ const std::vector PolicyManagerImpl::GetFunctionGroupsForApp( return function_groups; } +const std::vector PolicyManagerImpl::GetApplicationPolicyIDs() + const { + LOG4CXX_AUTO_TRACE(logger_); + std::vector policy_app_ids; + + const auto apps = cache_->GetPolicyAppNames(); + + for (const auto& app : apps) { + policy_app_ids.push_back(app); + } + + return policy_app_ids; +} + bool PolicyManagerImpl::FunctionGroupNeedEncryption( const std::string& policy_group) const { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/policy/policy_regular/include/policy/cache_manager.h b/src/components/policy/policy_regular/include/policy/cache_manager.h index f3e86f4fc5..09fde06dc4 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -395,6 +395,12 @@ class CacheManager : public CacheManagerInterface { */ bool GetFunctionalGroupings(policy_table::FunctionalGroupings& groups); + /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + const policy_table::Strings GetPolicyAppNames() const OVERRIDE; + /** * Checks if the application is represented in policy table * @param app_id application id diff --git a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h index 0b93d86b7d..2c0cd70583 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager_interface.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager_interface.h @@ -418,6 +418,12 @@ class CacheManagerInterface { virtual bool GetFunctionalGroupings( policy_table::FunctionalGroupings& groups) = 0; + /** + * @brief Get policy app names from PT + * @return container of strings representing policy application names + */ + virtual const policy_table::Strings GetPolicyAppNames() const = 0; + /** * Checks if the application is represented in policy table * @param app_id application id diff --git a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h index 6b4b6506a6..86eb91b67f 100644 --- a/src/components/policy/policy_regular/include/policy/policy_manager_impl.h +++ b/src/components/policy/policy_regular/include/policy/policy_manager_impl.h @@ -76,6 +76,9 @@ class PolicyManagerImpl : public PolicyManager { */ const std::vector GetFunctionGroupsForApp( const std::string& policy_app_id) const OVERRIDE; + + const std::vector GetApplicationPolicyIDs() const OVERRIDE; + /* * \param policy_group group * \return true if the group need encryption diff --git a/src/components/policy/policy_regular/src/cache_manager.cc b/src/components/policy/policy_regular/src/cache_manager.cc index 1edb79501b..6902a5fe81 100644 --- a/src/components/policy/policy_regular/src/cache_manager.cc +++ b/src/components/policy/policy_regular/src/cache_manager.cc @@ -124,6 +124,20 @@ const policy_table::Strings& CacheManager::GetGroups(const PTString& app_id) { return pt_->policy_table.app_policies_section.apps[app_id].groups; } +const policy_table::Strings CacheManager::GetPolicyAppNames() const { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock auto_lock(cache_lock_); + + const auto apps = pt_->policy_table.app_policies_section.apps; + + policy_table::Strings policy_app_ids; + for (const auto& app : apps) { + policy_app_ids.push_back(app.first); + } + + return policy_app_ids; +} + bool CacheManager::CanAppKeepContext(const std::string& app_id) const { CACHE_MANAGER_CHECK(false); bool result = true; diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index e4bb37ace8..c2f017fefd 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -1590,6 +1590,20 @@ const std::vector PolicyManagerImpl::GetFunctionGroupsForApp( return function_groups; } +const std::vector PolicyManagerImpl::GetApplicationPolicyIDs() + const { + LOG4CXX_AUTO_TRACE(logger_); + std::vector policy_app_ids; + + const auto apps = cache_->GetPolicyAppNames(); + + for (const auto& app : apps) { + policy_app_ids.push_back(app); + } + + return policy_app_ids; +} + bool PolicyManagerImpl::FunctionGroupNeedEncryption( const std::string& policy_group) const { LOG4CXX_AUTO_TRACE(logger_); -- cgit v1.2.1