diff options
author | Maksym Ked <mked@luxoft.com> | 2019-05-23 22:45:57 +0300 |
---|---|---|
committer | Maksym Ked (GitHub) <mked@luxoft.com> | 2019-06-25 13:58:39 +0300 |
commit | edb48c5f83382186c8c5d3cfe29f8e47d03ba56c (patch) | |
tree | 51c7774bd023b7bee10f52e7e79fe2d4bda75678 | |
parent | 777b00aaf4bcdab60c774b95009f9cb9c61f9281 (diff) | |
download | sdl_core-edb48c5f83382186c8c5d3cfe29f8e47d03ba56c.tar.gz |
Added storage of encryption required rpcs
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 aeb6ca6963..ec4aeb9298 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 @@ -654,6 +654,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 <memory> #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 <set> +#include <map> #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<uint32_t, uint32_t> AppIdCorrIdPair; + typedef std::set<std::string> FunctionNames; + typedef std::map<std::string, FunctionNames> 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<uint32_t, uint32_t> AppIdCorrIdPair; + AppEncryptedRpcMap encrypted_rpcs_; + sync_primitives::Lock encrypted_rpcs_lock_; std::set<AppIdCorrIdPair> 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 30e1d84fd1..4dba003897 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -203,13 +203,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<RPCProtectionManagerImpl>(*policy_handler_))); + std::shared_ptr<RPCProtectionManager> rpc_protection_manager = + std::make_shared<RPCProtectionManagerImpl>(*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 dea059e07b..ce05b80efb 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -400,12 +400,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<int32_t>(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 7830fdcd78..2401c8c022 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(); @@ -164,9 +164,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<int32_t>(mobile_apis::Result::ENCRYPTION_NEEDED)); + ; SendMessageToMobile(response); return false; } @@ -425,7 +428,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<std::string> 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 64931d97b3..4bb77b1087 100644 --- a/src/components/include/application_manager/policies/policy_handler_interface.h +++ b/src/components/include/application_manager/policies/policy_handler_interface.h @@ -319,6 +319,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 d44a65a934..73edf982c7 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 @@ -177,6 +177,7 @@ class MockPolicyHandlerInterface : public policy::PolicyHandlerInterface { void(std::map<std::string, policy::StringArray> 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 89f4a69514..ad47284140 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 @@ -305,6 +305,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 a979ce39e2..d59efb25c5 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<std::string>(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetApplicationPolicyIDs, const std::vector<std::string>()); 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 b0259d3e07..75700cf1da 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 @@ -266,6 +266,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 f935114cda..00737c6969 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<std::string>(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetApplicationPolicyIDs, const std::vector<std::string>()); 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 abe2457913..26259062ea 100644 --- a/src/components/policy/policy_external/include/policy/cache_manager.h +++ b/src/components/policy/policy_external/include/policy/cache_manager.h @@ -408,6 +408,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 * @return true if application is represented in policy table 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 028bba34e3..2bee07211e 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 @@ -417,6 +417,12 @@ class CacheManagerInterface { 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 * @return true if application is represented in policy table 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 323a728732..973199970b 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<std::string> GetFunctionGroupsForApp( const std::string& policy_app_id) const OVERRIDE; + const std::vector<std::string> 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 a4b12d99b4..40a5776438 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<int32_t, 0, INT32_MAX> FunctionIDInt; typedef Map<Strings, 0, 255> RemoteRpcs; typedef Map<RemoteRpcs, 0, 255> AccessModules; typedef Array<Enum<ModuleType>, 0, 255> ModuleTypes; - typedef AppHMIType AppHmiType; typedef std::vector<AppHMIType> AppHmiTypes; diff --git a/src/components/policy/policy_external/src/cache_manager.cc b/src/components/policy/policy_external/src/cache_manager.cc index f44602ea69..8bfeb8407d 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 0c4de750d4..9008840358 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -2295,6 +2295,20 @@ const std::vector<std::string> PolicyManagerImpl::GetFunctionGroupsForApp( return function_groups; } +const std::vector<std::string> PolicyManagerImpl::GetApplicationPolicyIDs() + const { + LOG4CXX_AUTO_TRACE(logger_); + std::vector<std::string> 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 730bcd0818..47d34ce2d4 100644 --- a/src/components/policy/policy_regular/include/policy/cache_manager.h +++ b/src/components/policy/policy_regular/include/policy/cache_manager.h @@ -391,6 +391,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 * @return true if application is represented in policy table 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 dce7883fa8..8569395c96 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 @@ -400,6 +400,12 @@ class CacheManagerInterface { 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 * @return true if application is represented in policy table 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 8c7cbbe811..93d0c45fcc 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<std::string> GetFunctionGroupsForApp( const std::string& policy_app_id) const OVERRIDE; + + const std::vector<std::string> 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 9025ce71bf..a920661322 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 4b0a3a9c37..fee95a7b9f 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -1564,6 +1564,20 @@ const std::vector<std::string> PolicyManagerImpl::GetFunctionGroupsForApp( return function_groups; } +const std::vector<std::string> PolicyManagerImpl::GetApplicationPolicyIDs() + const { + LOG4CXX_AUTO_TRACE(logger_); + std::vector<std::string> 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_); |