diff options
author | sniukalov <sniukalov@luxoft.com> | 2019-05-30 09:40:59 +0300 |
---|---|---|
committer | mked-luxoft <mked@luxoft.com> | 2019-08-29 17:50:31 +0300 |
commit | 19e83e31fe80ab32c27eca8e269b915adb032c64 (patch) | |
tree | 0f65614e528de63a52f4d9a9d600983f17e1ae08 | |
parent | 47629eedfa6bbb6c75acb8baec6f1fd932f0a76d (diff) | |
download | sdl_core-19e83e31fe80ab32c27eca8e269b915adb032c64.tar.gz |
Added handling of service status update
- introduced ServiceStatusUpdateHandler and ServiceStatusUpdateHandlerListener interfaces
- added lacking interface functions to corresponding entities
- added notification of listeners
- introduced ServiceStatusUpdateNotificationBuilder
- replaced shared_ptr with unique_ptr
- moved SERVICE_RECEIVED
41 files changed, 920 insertions, 142 deletions
diff --git a/src/appMain/life_cycle_impl.cc b/src/appMain/life_cycle_impl.cc index 10f0fc0d52..c903fb1a8a 100644 --- a/src/appMain/life_cycle_impl.cc +++ b/src/appMain/life_cycle_impl.cc @@ -103,6 +103,13 @@ bool LifeCycleImpl::StartComponents() { app_manager_ = new application_manager::ApplicationManagerImpl(profile_, profile_); + auto service_status_update_handler = + std::unique_ptr<protocol_handler::ServiceStatusUpdateHandler>( + new protocol_handler::ServiceStatusUpdateHandler(app_manager_)); + + protocol_handler_->set_service_status_update_handler( + std::move(service_status_update_handler)); + DCHECK(!hmi_handler_); hmi_handler_ = new hmi_message_handler::HMIMessageHandlerImpl(profile_); diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index a224d51a33..7071610acb 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -58,6 +58,8 @@ #include "application_manager/rpc_service.h" #include "application_manager/state_controller_impl.h" +#include "application_manager/rpc_handler.h" + #include "application_manager/policies/policy_handler_interface.h" #include "application_manager/policies/policy_handler_observer.h" #include "connection_handler/connection_handler.h" @@ -69,6 +71,7 @@ #include "policies/policy_handler.h" #include "protocol_handler/protocol_handler.h" #include "protocol_handler/protocol_observer.h" +#include "protocol_handler/service_status_update_handler_listener.h" #include "interfaces/HMI_API.h" #include "interfaces/HMI_API_schema.h" @@ -132,7 +135,8 @@ typedef std::shared_ptr<timer::Timer> TimerSPtr; class ApplicationManagerImpl : public ApplicationManager, public connection_handler::ConnectionHandlerObserver, - public policy::PolicyHandlerObserver + public policy::PolicyHandlerObserver, + public protocol_handler::ServiceStatusUpdateHandlerListener #ifdef ENABLE_SECURITY , public security_manager::SecurityManagerListener @@ -538,6 +542,51 @@ class ApplicationManagerImpl */ void OnPTUFinished(const bool ptu_result) FINAL; +#if defined(EXTERNAL_PROPRIETARY_MODE) && defined(ENABLE_SECURITY) + /** + * @brief OnCertDecryptFailed is called when certificate decryption fails in + * external flow + * @return since this callback is a part of SecurityManagerListener, bool + * return value is used to indicate whether listener instance can be deleted + * by calling entity. if true - listener can be deleted and removed from + * listeners by SecurityManager, false - listener retains its place within + * SecurityManager. + */ + bool OnCertDecryptFailed() FINAL; + + /** + * @brief OnCertDecryptFinished is called when certificate decryption is + * finished in the external flow + * @param decrypt_result bool value indicating whether decryption was + * successful + */ + void OnCertDecryptFinished(const bool decrypt_result) FINAL; +#endif + + /** + * @brief OnPTUTimeoutExceeded is called on policy table update timed out + */ + void OnPTUTimeoutExceeded() FINAL; + + /** + *@brief ProcessServiceStatusUpdate callback that is invoked in case of + *service status update + *@param connection_key - connection key + *@param service_type enum value containing type of service. + *@param service_event enum value containing event that occured during service + *start. + *@param service_update_reason enum value containing reason why service_event + *occured. + **/ + void ProcessServiceStatusUpdate( + const uint32_t connection_key, + hmi_apis::Common_ServiceType::eType service_type, + hmi_apis::Common_ServiceEvent::eType service_event, + utils::Optional<hmi_apis::Common_ServiceUpdateReason::eType> + service_update_reason) FINAL; + + void OnPTUFailed() FINAL {} + /* * @brief Starts audio pass thru thread * @@ -657,7 +706,7 @@ class ApplicationManagerImpl * @brief Notification about handshake failure * @return true on success notification handling or false otherwise */ - bool OnHandshakeFailed() OVERRIDE; + bool OnGetSystemTimeFailed() OVERRIDE; /** * @brief Notification that certificate update is required. diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 7dac442ef0..7b390d7adf 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -90,32 +90,61 @@ class MessageHelper { hmi_apis::FunctionID::eType function_id); /** - * @brief CreateOnServiceStatusUpdateNotification creates on status update hmi - * notification smart object - * @param app_id - application id - * @param service_type - enum value representing service_type - * @param service_event - enum value representing service update event - * @return smart object containing on status update notification - */ - static smart_objects::SmartObjectSPtr CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event); - - /** - * @brief CreateOnServiceStatusUpdateNotification creates on status update hmi - * notification smart object - * @param app_id - application id - * @param service_type - enum value representing service_type - * @param service_event - enum value representing service update event - * @param service_event_reason - enum value representing service update reason - * @return smart object containing on status update notification - */ - static smart_objects::SmartObjectSPtr CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event, - const hmi_apis::Common_ServiceUpdateReason::eType service_update_reason); + * @brief ServiceStatusUpdateNotificationBuilder small utility class used for + * more flexible construction of OnServiceUpdateNotification + */ + class ServiceStatusUpdateNotificationBuilder { + public: + typedef hmi_apis::Common_ServiceType::eType ServiceType; + typedef hmi_apis::Common_ServiceEvent::eType ServiceEvent; + typedef hmi_apis::Common_ServiceUpdateReason::eType ServiceUpdateReason; + + /** + * @brief CreateBuilder creates builder instance + * @param service_type - enum value containing service type + * @param service_event - enum value containing service event + * @returns builder instance + */ + static ServiceStatusUpdateNotificationBuilder CreateBuilder( + const ServiceType service_type, const ServiceEvent service_event); + + /** + * @brief AddAppID adds app id to notification + * @param app_id application id to add + * @returns ref to builder instance + */ + ServiceStatusUpdateNotificationBuilder& AddAppID(const uint32_t app_id); + + /** + * @brief AddServiceUpdateReason adds service update reason to notification + * @param service_update_reason enum value containing update reason + * @returns ref to builder instance + */ + ServiceStatusUpdateNotificationBuilder& AddServiceUpdateReason( + const ServiceUpdateReason service_update_reason); + + /** + * @brief notification gets notification SO + * @returns shared ptr to notification SO + */ + smart_objects::SmartObjectSPtr notification() const; + + protected: + smart_objects::SmartObjectSPtr notification_; + + /** + * @brief class constructor + * @param service_type - enum value containing service type + * @param service_event - enum value containing service event + */ + ServiceStatusUpdateNotificationBuilder(const ServiceType service_type, + const ServiceEvent service_event); + + /** + * @brief class constructor + */ + ServiceStatusUpdateNotificationBuilder(){}; + }; /** * @brief Creates request for different interfaces(JSON) 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 dddd1b333d..39026b3420 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 @@ -176,6 +176,9 @@ class PolicyHandler : public PolicyHandlerInterface, const std::string& policy_app_id, const std::string& hmi_level) OVERRIDE; +#ifndef EXTERNAL_PROPRIETARY_MODE + void OnPTUTimeOut() OVERRIDE; +#endif /** * Gets all allowed module types * @param app_id unique identifier of application @@ -502,11 +505,11 @@ class PolicyHandler : public PolicyHandlerInterface, virtual void OnCertificateUpdated( const std::string& certificate_data) OVERRIDE; + #ifdef EXTERNAL_PROPRIETARY_MODE void OnCertificateDecrypted(bool is_succeeded) OVERRIDE; + void ProcessCertDecryptFailed(); #endif // EXTERNAL_PROPRIETARY_MODE - void OnAuthTokenUpdated(const std::string& policy_app_id, - const std::string& auth_token); virtual bool CanUpdate() OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h index 3c4dce2fbc..fdfed698c4 100644 --- a/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h +++ b/src/components/application_manager/include/application_manager/policies/regular/policy_handler_observer.h @@ -53,6 +53,8 @@ class PolicyHandlerObserver { virtual void OnPTUFinished(const bool ptu_result) {} + virtual void OnPTUTimeoutExceeded() {} + virtual ~PolicyHandlerObserver() {} }; } // namespace policy diff --git a/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h b/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h index 46aa98e6c1..a8ba796a1b 100644 --- a/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h +++ b/src/components/application_manager/include/application_manager/system_time/system_time_handler_impl.h @@ -130,6 +130,12 @@ class SystemTimeHandlerImpl : public utils::SystemTimeHandler, void ProcessSystemTimeReadyNotification(); /** + * @brief ResetPendingSystemTimeRequests resets waiting for system time + * requests flag + */ + void ResetPendingSystemTimeRequests() OVERRIDE; + + /** * @brief Checks if UTC time is ready to provided by HMI * and can be requested by GetSystemTime request * @return True if HMI is ready to provide UTC time diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_status_update_notification.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_status_update_notification.h index 93f7da8b5f..f51b0c2907 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_status_update_notification.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/hmi/on_service_status_update_notification.h @@ -39,7 +39,6 @@ namespace sdl_rpc_plugin { namespace app_mngr = application_manager; namespace commands { - namespace hmi { /** @@ -77,9 +76,7 @@ class OnServiceStatusUpdateNotification }; } // namespace hmi - } // namespace commands - } // namespace sdl_rpc_plugin #endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_SDL_RPC_PLUGIN_INCLUDE_SDL_RPC_PLUGIN_COMMANDS_HMI_ON_SERVICE_STATUS_UPDATE_NOTIFICATION_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc index fb87612e19..19c9fa91d8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/basic_communication_get_system_time_request.cc @@ -51,7 +51,7 @@ BasicCommunicationGetSystemTimeRequest::BasicCommunicationGetSystemTimeRequest( void BasicCommunicationGetSystemTimeRequest::onTimeOut() { LOG4CXX_AUTO_TRACE(logger_); - application_manager_.protocol_handler().NotifyOnFailedHandshake(); + application_manager_.protocol_handler().NotifyOnGetSystemTimeFailed(); } } // namespace commands diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_status_update_notification.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_status_update_notification.cc index 8224325f8e..6dc5f9a7fc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_status_update_notification.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/on_service_status_update_notification.cc @@ -55,9 +55,9 @@ OnServiceStatusUpdateNotification::~OnServiceStatusUpdateNotification() {} void OnServiceStatusUpdateNotification::Run() { LOG4CXX_AUTO_TRACE(logger_); - SendNotification(); } + } // namespace hmi } // namespace commands } // namespace sdl_rpc_plugin diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc index 0251c4873d..9cd87b053d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc @@ -60,7 +60,7 @@ TEST_F(BasicCommunicationGetSystemTimeRequestTest, OnTimeout) { ON_CALL(app_mngr_, protocol_handler()) .WillByDefault(ReturnRef(mock_protocol_handler)); - EXPECT_CALL(mock_protocol_handler, NotifyOnFailedHandshake()); + EXPECT_CALL(mock_protocol_handler, NotifyOnGetSystemTimeFailed()); command->onTimeOut(); } diff --git a/src/components/application_manager/src/application_manager_impl.cc b/src/components/application_manager/src/application_manager_impl.cc index 3829005047..6f5c5a82e3 100644 --- a/src/components/application_manager/src/application_manager_impl.cc +++ b/src/components/application_manager/src/application_manager_impl.cc @@ -1917,7 +1917,7 @@ void ApplicationManagerImpl::OnServiceStartedCallback( "ServiceType = " << type << ". Session = " << std::hex << session_key); std::vector<std::string> empty; - if (type == kRpc) { + if (kRpc == type) { LOG4CXX_DEBUG(logger_, "RPC service is about to be started."); connection_handler().NotifyServiceStartedResult(session_key, true, empty); return; @@ -1944,6 +1944,7 @@ void ApplicationManagerImpl::OnServiceStartedCallback( } else { LOG4CXX_WARN(logger_, "Refuse unknown service"); } + connection_handler().NotifyServiceStartedResult(session_key, false, empty); } @@ -2026,6 +2027,36 @@ void ApplicationManagerImpl::OnServiceEndedCallback( } } +void ApplicationManagerImpl::ProcessServiceStatusUpdate( + const uint32_t connection_key, + hmi_apis::Common_ServiceType::eType service_type, + hmi_apis::Common_ServiceEvent::eType service_event, + utils::Optional<hmi_apis::Common_ServiceUpdateReason::eType> + service_update_reason) { + LOG4CXX_AUTO_TRACE(logger_); + + LOG4CXX_DEBUG(logger_, + "Processing status update with connection key: " + << connection_key << " service type: " << service_type + << " service_event " << service_event + << " service_update_reason " << service_update_reason); + + const auto app = application(connection_key); + auto notification_builder = + MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder( + service_type, service_event); + + if (app) { + notification_builder.AddAppID(app->app_id()); + } + + if (service_update_reason) { + notification_builder.AddServiceUpdateReason(*service_update_reason); + } + + rpc_service_->ManageHMICommand(notification_builder.notification()); +} + void ApplicationManagerImpl::OnSecondaryTransportStartedCallback( const connection_handler::DeviceHandle device_handle, const int32_t session_key) { @@ -2118,7 +2149,12 @@ bool ApplicationManagerImpl::OnHandshakeDone( using namespace helpers; ApplicationSharedPtr app = application(connection_key); - DCHECK_OR_RETURN(app, false); + if (!app) { + LOG4CXX_WARN(logger_, + "Application for connection key: " << connection_key + << " was not found"); + return false; + } if (Compare<SSLContext::HandshakeResult, EQ, ONE>( result, SSLContext::Handshake_Result_CertExpired, @@ -2131,7 +2167,7 @@ bool ApplicationManagerImpl::OnHandshakeDone( return false; } -bool ApplicationManagerImpl::OnHandshakeFailed() { +bool ApplicationManagerImpl::OnGetSystemTimeFailed() { LOG4CXX_AUTO_TRACE(logger_); return false; } @@ -3889,6 +3925,7 @@ void ApplicationManagerImpl::ProcessReconnection( void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { LOG4CXX_AUTO_TRACE(logger_); if (!ptu_result) { + protocol_handler_->ProcessFailedPTU(); return; } @@ -3907,6 +3944,25 @@ void ApplicationManagerImpl::OnPTUFinished(const bool ptu_result) { plugin_manager_->ForEachPlugin(on_app_policy_updated); } +#if defined(EXTERNAL_PROPRIETARY_MODE) && defined(ENABLE_SECURITY) +void ApplicationManagerImpl::OnCertDecryptFinished(const bool decrypt_result) { + LOG4CXX_AUTO_TRACE(logger_); + if (!decrypt_result) { + protocol_handler_->ProcessFailedCertDecrypt(); + } +} + +bool ApplicationManagerImpl::OnCertDecryptFailed() { + LOG4CXX_AUTO_TRACE(logger_); + return false; +} +#endif + +void ApplicationManagerImpl::OnPTUTimeoutExceeded() { + LOG4CXX_AUTO_TRACE(logger_); + protocol_handler_->ProcessFailedPTU(); +} + void ApplicationManagerImpl::SendDriverDistractionState( ApplicationSharedPtr application) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index d99ca90916..c90711b675 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -2234,45 +2234,45 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateNegativeResponse( return std::make_shared<smart_objects::SmartObject>(response_data); } -smart_objects::SmartObjectSPtr -MessageHelper::CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event) { - auto on_status_update_notification = CreateHMINotification( +MessageHelper::ServiceStatusUpdateNotificationBuilder:: + ServiceStatusUpdateNotificationBuilder(const ServiceType service_type, + const ServiceEvent service_event) { + notification_ = MessageHelper::CreateHMINotification( hmi_apis::FunctionID::BasicCommunication_OnServiceUpdate); - if (0 < app_id) { - (*on_status_update_notification)[strings::msg_params][strings::app_id] = - app_id; - } - - (*on_status_update_notification)[strings::msg_params] - [hmi_notification::service_type] = - service_type; - (*on_status_update_notification)[strings::msg_params] - [hmi_notification::service_event] = - service_event; + (*notification_)[strings::msg_params][hmi_notification::service_type] = + service_type; + (*notification_)[strings::msg_params][hmi_notification::service_event] = + service_event; +} - return on_status_update_notification; +MessageHelper::ServiceStatusUpdateNotificationBuilder +MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder( + const ServiceType service_type, const ServiceEvent service_event) { + MessageHelper::ServiceStatusUpdateNotificationBuilder builder{service_type, + service_event}; + return builder; } -smart_objects::SmartObjectSPtr -MessageHelper::CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event, - const hmi_apis::Common_ServiceUpdateReason::eType service_update_reason) { - auto notification = CreateOnServiceStatusUpdateNotification( - app_id, service_type, service_event); +MessageHelper::ServiceStatusUpdateNotificationBuilder& +MessageHelper::ServiceStatusUpdateNotificationBuilder::AddAppID( + const uint32_t app_id) { + (*notification_)[strings::msg_params][strings::app_id] = app_id; - if (hmi_apis::Common_ServiceUpdateReason::eType::INVALID_ENUM != - service_update_reason) { - (*notification)[strings::msg_params][hmi_notification::reason] = - service_update_reason; - } + return *this; +} - return notification; +MessageHelper::ServiceStatusUpdateNotificationBuilder& +MessageHelper::ServiceStatusUpdateNotificationBuilder::AddServiceUpdateReason( + const ServiceUpdateReason service_update_reason) { + (*notification_)[strings::msg_params][hmi_notification::reason] = + service_update_reason; + + return *this; +} +smart_objects::SmartObjectSPtr +MessageHelper::ServiceStatusUpdateNotificationBuilder::notification() const { + return notification_; } void MessageHelper::SendNaviSetVideoConfig( diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 1bad50b34f..7085d7a86c 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1461,6 +1461,11 @@ void PolicyHandler::OnPermissionsUpdated(const std::string& device_id, << policy_app_id << " and connection_key " << app->app_id()); } +#ifndef EXTERNAL_PROPRIETARY_MODE +void PolicyHandler::OnPTUTimeOut() { + application_manager_.protocol_handler().ProcessFailedPTU(); +} +#endif bool PolicyHandler::SaveSnapshot(const BinaryMessage& pt_string, std::string& snap_path) { @@ -1630,6 +1635,11 @@ uint32_t PolicyHandler::TimeoutExchangeMSec() const { void PolicyHandler::OnExceededTimeout() { POLICY_LIB_CHECK_VOID(); + + std::for_each(listeners_.begin(), + listeners_.end(), + std::mem_fn(&PolicyHandlerObserver::OnPTUTimeoutExceeded)); + policy_manager_->OnExceededTimeout(); } @@ -1787,6 +1797,7 @@ void PolicyHandler::OnCertificateDecrypted(bool is_succeeded) { if (!is_succeeded) { LOG4CXX_ERROR(logger_, "Couldn't delete file " << file_name); + ProcessCertDecryptFailed(); return; } @@ -1809,6 +1820,17 @@ void PolicyHandler::OnCertificateDecrypted(bool is_succeeded) { std::bind2nd(std::mem_fun(&PolicyHandlerObserver::OnCertificateUpdated), certificate_data)); } + +void PolicyHandler::ProcessCertDecryptFailed() { + LOG4CXX_AUTO_TRACE(logger_); + sync_primitives::AutoLock lock(listeners_lock_); + + std::for_each( + listeners_.begin(), + listeners_.end(), + std::bind2nd(std::mem_fn(&PolicyHandlerObserver::OnCertDecryptFinished), + false)); +} #else // EXTERNAL_PROPRIETARY_MODE void PolicyHandler::OnCertificateUpdated(const std::string& certificate_data) { LOG4CXX_AUTO_TRACE(logger_); diff --git a/src/components/application_manager/src/system_time/system_time_handler_impl.cc b/src/components/application_manager/src/system_time/system_time_handler_impl.cc index f5d08a8ebf..deb92d5d81 100644 --- a/src/components/application_manager/src/system_time/system_time_handler_impl.cc +++ b/src/components/application_manager/src/system_time/system_time_handler_impl.cc @@ -82,6 +82,13 @@ void SystemTimeHandlerImpl::DoSubscribe(utils::SystemTimeListener* listener) { system_time_listener_ = listener; } +void SystemTimeHandlerImpl::ResetPendingSystemTimeRequests() { + LOG4CXX_AUTO_TRACE(logger_); + unsubscribe_from_event( + hmi_apis::FunctionID::BasicCommunication_GetSystemTime); + awaiting_get_system_time_ = false; +} + void SystemTimeHandlerImpl::DoUnsubscribe(utils::SystemTimeListener* listener) { LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(system_time_listener_lock_); @@ -145,6 +152,14 @@ void SystemTimeHandlerImpl::ProcessSystemTimeResponse( const application_manager::event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); const smart_objects::SmartObject& message = event.smart_object(); + + const auto result = static_cast<hmi_apis::Common_Result::eType>( + message[strings::params][hmi_response::code].asInt()); + + if (hmi_apis::Common_Result::SUCCESS != result) { + system_time_listener_->OnSystemTimeFailed(); + } + const smart_objects::SmartObject& system_time_so = message[strings::msg_params][hmi_response::system_time]; diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index f8a4253cb4..eec8d464a5 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -354,7 +354,27 @@ class MockMessageHelper { const hmi_apis::Common_ServiceUpdateReason::eType service_update_reason)); + class MockServiceStatusUpdateNotificationBuilder { + public: + MOCK_METHOD2(CreateBuilder, + MessageHelper::ServiceStatusUpdateNotificationBuilder( + hmi_apis::Common_ServiceType::eType, + hmi_apis::Common_ServiceEvent::eType)); + + MOCK_METHOD1(AddAppID, + MessageHelper::ServiceStatusUpdateNotificationBuilder&( + const uint32_t app_id)); + + MOCK_METHOD1(AddServiceUpdateReason, + MessageHelper::ServiceStatusUpdateNotificationBuilder&( + const hmi_apis::Common_ServiceUpdateReason::eType)); + + MOCK_CONST_METHOD0(notification, smart_objects::SmartObjectSPtr()); + }; + static MockMessageHelper* message_helper_mock(); + static MockServiceStatusUpdateNotificationBuilder* + on_service_update_builder_mock(); }; } // namespace application_manager diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc index a174d74d5d..249d7231d7 100644 --- a/src/components/application_manager/test/message_helper/message_helper_test.cc +++ b/src/components/application_manager/test/message_helper/message_helper_test.cc @@ -69,6 +69,14 @@ using namespace application_manager; typedef std::shared_ptr<MockApplication> MockApplicationSharedPtr; typedef std::vector<std::string> StringArray; typedef std::shared_ptr<application_manager::Application> ApplicationSharedPtr; +typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceType + ServiceType; +typedef MessageHelper::ServiceStatusUpdateNotificationBuilder::ServiceEvent + ServiceEvent; +typedef MessageHelper::ServiceStatusUpdateNotificationBuilder:: + ServiceUpdateReason UpdateReason; +typedef MessageHelper::ServiceStatusUpdateNotificationBuilder + ServiceStatusUpdateBuilder; using testing::_; using testing::AtLeast; diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 4269e172df..d33e98cb6f 100644..100755 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -601,24 +601,38 @@ void MessageHelper::SendUnsubscribeButtonNotification( ->SendUnsubscribeButtonNotification(button, application, app_mngr); } -smart_objects::SmartObject -MessageHelper::CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event) { - return MockMessageHelper::message_helper_mock() - ->CreateOnStatusUpdateNotification(app_id, service_type, service_event); +MockMessageHelper::MockServiceStatusUpdateNotificationBuilder* +MockMessageHelper::on_service_update_builder_mock() { + static ::testing::NiceMock< + MockMessageHelper::MockServiceStatusUpdateNotificationBuilder> + on_service_update_builder_mock; + return &on_service_update_builder_mock; } -smart_objects::SmartObject -MessageHelper::CreateOnServiceStatusUpdateNotification( - const uint32_t app_id, - const hmi_apis::Common_ServiceType::eType service_type, - const hmi_apis::Common_ServiceEvent::eType service_event, - const hmi_apis::Common_ServiceUpdateReason service_update_reason) { - return MockMessageHelper::message_helper_mock() - ->CreateOnStatusUpdateNotification( - app_id, service_type, service_event, service_update_reason); +MessageHelper::ServiceStatusUpdateNotificationBuilder +MessageHelper::ServiceStatusUpdateNotificationBuilder::CreateBuilder( + hmi_apis::Common_ServiceType::eType service_type, + hmi_apis::Common_ServiceEvent::eType service_event) { + return MockMessageHelper::on_service_update_builder_mock()->CreateBuilder( + service_type, service_event); +} + +MessageHelper::ServiceStatusUpdateNotificationBuilder& +MessageHelper::ServiceStatusUpdateNotificationBuilder::AddAppID( + const uint32_t app_id) { + return MockMessageHelper::on_service_update_builder_mock()->AddAppID(app_id); +} + +MessageHelper::ServiceStatusUpdateNotificationBuilder& +MessageHelper::ServiceStatusUpdateNotificationBuilder::AddServiceUpdateReason( + const hmi_apis::Common_ServiceUpdateReason::eType service_update_reason) { + return MockMessageHelper::on_service_update_builder_mock() + ->AddServiceUpdateReason(service_update_reason); +} + +smart_objects::SmartObjectSPtr +MessageHelper::ServiceStatusUpdateNotificationBuilder::notification() const { + return MockMessageHelper::on_service_update_builder_mock()->notification(); } smart_objects::SmartObject MessageHelper::CreateAppServiceCapabilities( 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 42348e7705..fc22d196df 100644 --- a/src/components/include/application_manager/policies/policy_handler_observer.h +++ b/src/components/include/application_manager/policies/policy_handler_observer.h @@ -55,6 +55,18 @@ class PolicyHandlerObserver { virtual void OnPTInited() {} + virtual void OnPTUTimeoutExceeded() {} + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief OnCertDecryptFinished is called when certificate decryption is + * finished in the external flow + * @param decrypt_result bool value indicating whether decryption was + * successful + */ + virtual void OnCertDecryptFinished(const bool decrypt_result) {} +#endif + virtual ~PolicyHandlerObserver() {} }; } // namespace policy diff --git a/src/components/include/policy/policy_regular/policy/policy_listener.h b/src/components/include/policy/policy_regular/policy/policy_listener.h index d717822cac..3e23df9710 100644 --- a/src/components/include/policy/policy_regular/policy/policy_listener.h +++ b/src/components/include/policy/policy_regular/policy/policy_listener.h @@ -119,6 +119,11 @@ class PolicyListener { virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; /** + * @brief OnPTUTimeOut the callback which signals if PTU timeout occured + */ + virtual void OnPTUTimeOut() = 0; + + /** * @brief OnAuthTokenUpdated the callback which signals if an app's auth token * field has been updated during a PTU * diff --git a/src/components/include/protocol_handler/protocol_handler.h b/src/components/include/protocol_handler/protocol_handler.h index 619c47ac34..aacb31c260 100644 --- a/src/components/include/protocol_handler/protocol_handler.h +++ b/src/components/include/protocol_handler/protocol_handler.h @@ -118,7 +118,7 @@ class ProtocolHandler { /** * \brief Called to notify all handsheke handlers about handshake failure. */ - virtual void NotifyOnFailedHandshake() = 0; + virtual void NotifyOnGetSystemTimeFailed() = 0; /** * \brief Protocol handler settings getter @@ -141,6 +141,16 @@ class ProtocolHandler { virtual bool IsRPCServiceSecure(const uint32_t connection_key) const = 0; + virtual void ProcessFailedPTU() = 0; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief ProcessFailedCertDecrypt is called to notify security manager that + * certificate decryption failed in the external flow + */ + virtual void ProcessFailedCertDecrypt() = 0; +#endif + protected: /** * \brief Destructor diff --git a/src/components/include/security_manager/security_manager.h b/src/components/include/security_manager/security_manager.h index e02a3a1cbe..358c4e5268 100644 --- a/src/components/include/security_manager/security_manager.h +++ b/src/components/include/security_manager/security_manager.h @@ -166,7 +166,17 @@ class SecurityManager : public protocol_handler::ProtocolObserver, /** * @brief Notify all listeners that handshake was failed */ - virtual void NotifyListenersOnHandshakeFailed() = 0; + virtual void NotifyListenersOnGetSystemTimeFailed() = 0; + + virtual void ProcessFailedPTU() = 0; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief ProcessFailedCertDecrypt is called to notify listeners that + * certificate decryption failed in the external flow + */ + virtual void ProcessFailedCertDecrypt() = 0; +#endif /** * @brief Check if policy certificate data is empty @@ -175,6 +185,12 @@ class SecurityManager : public protocol_handler::ProtocolObserver, virtual bool IsPolicyCertificateDataEmpty() = 0; /** + * @brief ResetPendingSystemTimeRequests resets waiting for system time + * requests flag + */ + virtual void ResetPendingSystemTimeRequests() = 0; + + /** * \brief Add/Remove for SecurityManagerListener */ virtual void AddListener(SecurityManagerListener* const listener) = 0; diff --git a/src/components/include/security_manager/security_manager_listener.h b/src/components/include/security_manager/security_manager_listener.h index 00a4c68134..f7148d3165 100644 --- a/src/components/include/security_manager/security_manager_listener.h +++ b/src/components/include/security_manager/security_manager_listener.h @@ -52,13 +52,28 @@ class SecurityManagerListener { * @brief Notification about handshake failure * @return true on success notification handling or false otherwise */ - virtual bool OnHandshakeFailed() = 0; + virtual bool OnGetSystemTimeFailed() = 0; /** * @brief Notify listeners that certificate update is required. */ virtual void OnCertificateUpdateRequired() = 0; + virtual void OnPTUFailed() = 0; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief OnCertDecryptFailed is called when certificate decryption fails in + * external flow + * @return since this callback is a part of SecurityManagerListener, bool + * return value is used to indicate whether listener instance can be deleted + * by calling entity. if true - listener can be deleted and removed from + * listeners by SecurityManager, false - listener retains its place within + * SecurityManager. + */ + virtual bool OnCertDecryptFailed() = 0; +#endif + /** * @brief Get certificate data from policy * @param reference to string where to save certificate data diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h index 16341ed4f4..f65138e489 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_listener.h @@ -112,6 +112,7 @@ class MockPolicyListener : public ::policy::PolicyListener { const std::string& policy_app_id, const std::string& hmi_level)); MOCK_METHOD0(OnLockScreenDismissalStateChanged, void()); + MOCK_METHOD1(OnCertDecryptFinished, void(bool)); }; } // namespace policy_test diff --git a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h index d0d85409a2..cb5feb3126 100644 --- a/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h +++ b/src/components/include/test/policy/policy_regular/policy/mock_policy_listener.h @@ -105,6 +105,7 @@ class MockPolicyListener : public ::policy::PolicyListener { const std::string& policy_app_id, const std::string& hmi_level)); MOCK_METHOD0(OnLockScreenDismissalStateChanged, void()); + MOCK_METHOD0(OnPTUTimeOut, void()); }; } // namespace policy_test diff --git a/src/components/include/test/protocol_handler/mock_protocol_handler.h b/src/components/include/test/protocol_handler/mock_protocol_handler.h index 772b63b582..df75c71c49 100644 --- a/src/components/include/test/protocol_handler/mock_protocol_handler.h +++ b/src/components/include/test/protocol_handler/mock_protocol_handler.h @@ -67,8 +67,11 @@ class MockProtocolHandler : public ::protocol_handler::ProtocolHandler { MOCK_METHOD2(NotifySessionStarted, void(const ::protocol_handler::SessionContext& context, std::vector<std::string>& rejected_params)); - MOCK_METHOD0(NotifyOnFailedHandshake, void()); + MOCK_METHOD0(NotifyOnGetSystemTimeFailed, void()); MOCK_CONST_METHOD1(IsRPCServiceSecure, bool(const uint32_t connection_key)); +#ifdef EXTERNAL_PROPRIETARY_MODE + MOCK_METHOD0(ProcessFailedCertDecrypt, void()); +#endif }; } // namespace protocol_handler_test } // namespace components diff --git a/src/components/include/test/security_manager/mock_security_manager.h b/src/components/include/test/security_manager/mock_security_manager.h index 2b5d99c156..e44d6207c1 100644 --- a/src/components/include/test/security_manager/mock_security_manager.h +++ b/src/components/include/test/security_manager/mock_security_manager.h @@ -68,11 +68,16 @@ class MockSecurityManager : public ::security_manager::SecurityManager { void(const ::protocol_handler::RawMessagePtr)); MOCK_METHOD1(IsCertificateUpdateRequired, bool(const uint32_t)); MOCK_METHOD0(NotifyOnCertificateUpdateRequired, void()); - MOCK_METHOD0(NotifyListenersOnHandshakeFailed, void()); + MOCK_METHOD0(NotifyListenersOnGetSystemTimeFailed, void()); MOCK_METHOD0(IsPolicyCertificateDataEmpty, bool()); + MOCK_METHOD0(ProcessFailedPTU, void()); MOCK_METHOD1(OnCertificateUpdated, bool(const std::string&)); MOCK_METHOD1(PostponeHandshake, void(const uint32_t)); MOCK_CONST_METHOD0(IsSystemTimeProviderReady, bool()); + MOCK_METHOD0(ResetPendingSystemTimeRequests, void()); +#ifdef EXTERNAL_PROPRIETARY_MODE + MOCK_METHOD0(ProcessFailedCertDecrypt, void()); +#endif }; /* diff --git a/src/components/include/test/security_manager/mock_security_manager_listener.h b/src/components/include/test/security_manager/mock_security_manager_listener.h index 7a7714d299..1673a27087 100644 --- a/src/components/include/test/security_manager/mock_security_manager_listener.h +++ b/src/components/include/test/security_manager/mock_security_manager_listener.h @@ -49,7 +49,11 @@ class MockSecurityManagerListener ::security_manager::SSLContext::HandshakeResult result)); MOCK_METHOD0(OnCertificateUpdateRequired, void()); MOCK_CONST_METHOD1(GetPolicyCertificateData, bool(std::string& data)); - MOCK_METHOD0(OnHandshakeFailed, bool()); + MOCK_METHOD0(OnGetSystemTimeFailed, bool()); + MOCK_METHOD0(OnPTUFailed, void()); +#ifdef EXTERNAL_PROPRIETARY_MODE + MOCK_METHOD0(OnCertDecryptFailed, bool()); +#endif }; } // namespace security_manager_test } // namespace components diff --git a/src/components/include/test/utils/mock_system_time_handler.h b/src/components/include/test/utils/mock_system_time_handler.h index 7bb2a7f0a5..5d82c0a8c7 100644 --- a/src/components/include/test/utils/mock_system_time_handler.h +++ b/src/components/include/test/utils/mock_system_time_handler.h @@ -50,6 +50,7 @@ class MockSystemTimeHandler : public ::utils::SystemTimeHandler { void(utils::SystemTimeListener* listener)); MOCK_METHOD0(GetUTCTime, time_t()); MOCK_CONST_METHOD0(system_time_can_be_received, bool()); + MOCK_METHOD0(ResetPendingSystemTimeRequests, void()); ~MockSystemTimeHandler() {} private: 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 d8ab079cf0..c14fb0e142 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 @@ -1019,7 +1019,7 @@ class PolicyManagerImpl : public PolicyManager { /** * @brief Starts new retry sequence */ - void RetrySequence(); + void StartRetrySequence(); private: /** 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 e3d2c1780c..6871a5c416 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -81,7 +81,7 @@ PolicyManagerImpl::PolicyManagerImpl() , retry_sequence_index_(0) , timer_retry_sequence_("Retry sequence timer", new timer::TimerTaskImpl<PolicyManagerImpl>( - this, &PolicyManagerImpl::RetrySequence)) + this, &PolicyManagerImpl::StartRetrySequence)) , ignition_check(true) , retry_sequence_url_(0, 0, "") , wrong_ptu_update_received_(false) @@ -1217,6 +1217,7 @@ uint32_t PolicyManagerImpl::NextRetryTimeout() { } void PolicyManagerImpl::RefreshRetrySequence() { + LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock auto_lock(retry_sequence_lock_); retry_sequence_timeout_ = cache_->TimeoutResponse(); retry_sequence_seconds_.clear(); @@ -1438,6 +1439,7 @@ bool PolicyManagerImpl::IsNewApplication( } bool PolicyManagerImpl::ResetPT(const std::string& file_name) { + LOG4CXX_AUTO_TRACE(logger_); cache_->ResetCalculatedPermissions(); const bool result = cache_->ResetPT(file_name); if (result) { @@ -1502,8 +1504,17 @@ void PolicyManagerImpl::set_cache_manager( cache_ = std::shared_ptr<CacheManagerInterface>(cache_manager); } -void PolicyManagerImpl::RetrySequence() { - LOG4CXX_INFO(logger_, "Start new retry sequence"); +void PolicyManagerImpl::StartRetrySequence() { + LOG4CXX_DEBUG(logger_, "Start new retry sequence"); + + const bool is_exceeded_retries_count = + (retry_sequence_seconds_.size() < retry_sequence_index_); + + if (is_exceeded_retries_count) { + LOG4CXX_WARN(logger_, "Exceeded allowed PTU retry count"); + listener_->OnPTUTimeOut(); + } + update_status_manager_.OnUpdateTimeoutOccurs(); const uint32_t timeout_msec = NextRetryTimeout(); diff --git a/src/components/protocol_handler/CMakeLists.txt b/src/components/protocol_handler/CMakeLists.txt index d18c13337c..b4123aaf06 100644 --- a/src/components/protocol_handler/CMakeLists.txt +++ b/src/components/protocol_handler/CMakeLists.txt @@ -35,6 +35,7 @@ include_directories( ${COMPONENTS_DIR}/protocol_handler/include/ ${COMPONENTS_DIR}/connection_handler/include/ ${COMPONENTS_DIR}/application_manager/include + ${CMAKE_BINARY_DIR}/src/components/ ${LOG4CXX_INCLUDE_DIRECTORY} ${BSON_INCLUDE_DIRECTORY} ) diff --git a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h index cb52c9d375..2c7f7de67e 100644 --- a/src/components/protocol_handler/include/protocol_handler/handshake_handler.h +++ b/src/components/protocol_handler/include/protocol_handler/handshake_handler.h @@ -57,7 +57,8 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { utils::SemanticVersion& full_version, const SessionContext& context, const uint8_t protocol_version, - std::shared_ptr<BsonObject> payload); + std::shared_ptr<BsonObject> payload, + ServiceStatusUpdateHandler& service_status_update_handler); ~HandshakeHandler(); @@ -82,13 +83,28 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { * @brief Notification about handshake failure * @return true on success notification handling or false otherwise */ - bool OnHandshakeFailed() OVERRIDE; + bool OnGetSystemTimeFailed() OVERRIDE; /** * @brief Notification that certificate update is required. */ void OnCertificateUpdateRequired() OVERRIDE; + void OnPTUFailed() OVERRIDE; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief OnCertDecryptFailed is called when certificate decryption fails in + * external flow + * @return since this callback is a part of SecurityManagerListener, bool + * return value is used to indicate whether listener instance can be deleted + * by calling entity. if true - listener can be deleted and removed from + * listeners by SecurityManager, false - listener retains its place within + * SecurityManager. + */ + bool OnCertDecryptFailed() OVERRIDE; +#endif + /** * @brief Get connection key of this handler * @return connection key @@ -107,8 +123,21 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { /** * @brief Performs related actions if handshake was failed * @param params set of params used in bson part of message + * @param service_status - service status to be sent to HMI + */ + void ProcessFailedHandshake(BsonObject& params, ServiceStatus service_status); + + /** + * @brief Determines whether service can be protected + * @return true is service can be protected, otherwise - false + */ + bool CanBeProtected() const; + + /** + * @brief Determines whether service is already protected + * @return true is service is already protected, otherwise - false */ - void ProcessFailedHandshake(BsonObject& params); + bool IsAlreadyProtected() const; ProtocolHandlerImpl& protocol_handler_; SessionObserver& session_observer_; @@ -116,6 +145,7 @@ class HandshakeHandler : public security_manager::SecurityManagerListener { utils::SemanticVersion full_version_; const uint8_t protocol_version_; std::shared_ptr<BsonObject> payload_; + ServiceStatusUpdateHandler& service_status_update_handler_; }; } // namespace protocol_handler diff --git a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h index 9d6243e274..336ed1f338 100644 --- a/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h +++ b/src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h @@ -55,6 +55,7 @@ #include "protocol_handler/protocol_handler_settings.h" #include "protocol_handler/protocol_observer.h" #include "protocol_handler/protocol_packet.h" +#include "protocol_handler/service_status_update_handler.h" #include "protocol_handler/session_observer.h" #include "transport_manager/common.h" #include "transport_manager/transport_adapter/transport_adapter.h" @@ -210,6 +211,16 @@ class ProtocolHandlerImpl void RemoveProtocolObserver(ProtocolObserver* observer) OVERRIDE; + void ProcessFailedPTU() OVERRIDE; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief ProcessFailedCertDecrypt is called to notify security manager that + * certificate decryption failed in the external flow + */ + void ProcessFailedCertDecrypt() OVERRIDE; +#endif + #ifdef ENABLE_SECURITY /** * \brief Sets pointer for SecurityManager layer for managing protection @@ -220,6 +231,9 @@ class ProtocolHandlerImpl security_manager::SecurityManager* security_manager); #endif // ENABLE_SECURITY + void set_service_status_update_handler( + std::unique_ptr<ServiceStatusUpdateHandler> handler); + /** * \brief Stop all handling activity */ @@ -278,7 +292,7 @@ class ProtocolHandlerImpl uint8_t session_id, uint8_t service_type); - void NotifyOnFailedHandshake() OVERRIDE; + void NotifyOnGetSystemTimeFailed() OVERRIDE; // TODO(Ezamakhov): move Ack/Nack as interface for StartSessionHandler /** @@ -436,9 +450,6 @@ class ProtocolHandlerImpl void NotifySessionStarted(const SessionContext& context, std::vector<std::string>& rejected_params) OVERRIDE; - void OnAuthTokenUpdated(const std::string& policy_app_id, - const std::string& auth_token) OVERRIDE; - #ifdef BUILD_TESTS const impl::FromMobileQueue& get_from_mobile_queue() const { return raw_ford_messages_from_mobile_; @@ -523,10 +534,6 @@ class ProtocolHandlerImpl void OnTMMessageSendFailed(const transport_manager::DataSendError& error, const RawMessagePtr message) OVERRIDE; - void OnConnectionPending( - const transport_manager::DeviceInfo& device_info, - const transport_manager::ConnectionUID connection_id) OVERRIDE; - void OnConnectionEstablished( const transport_manager::DeviceInfo& device_info, const transport_manager::ConnectionUID connection_id) OVERRIDE; @@ -790,6 +797,8 @@ class ProtocolHandlerImpl sync_primitives::Lock start_session_frame_map_lock_; StartSessionFrameMap start_session_frame_map_; + std::unique_ptr<ServiceStatusUpdateHandler> service_status_update_handler_; + // Map policy app id -> auth token sync_primitives::Lock auth_token_map_lock_; std::map<std::string, std::string> auth_token_map_; diff --git a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h new file mode 100644 index 0000000000..125f3b2909 --- /dev/null +++ b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h @@ -0,0 +1,86 @@ +/* + Copyright (c) 2019, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_SERVICE_STATUS_UPDATE_HANDLER_H_ +#define SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_SERVICE_STATUS_UPDATE_HANDLER_H_ + +#include "protocol_handler/service_status_update_handler_listener.h" + +namespace protocol_handler { + +/** + * @brief ServiceUpdateFailureReason helper enum containing reasons for + * service + * status to be updated + */ +enum class ServiceStatus { + INVALID_ENUM = -1, + SERVICE_RECEIVED, + SERVICE_ACCEPTED, + SERVICE_START_FAILED, + PTU_FAILED, + CERT_INVALID, + INVALID_TIME +}; + +/** + * @brief ServiceStatusUpdateHandler class is used to notify listeners about + * occured events during service start + */ +class ServiceStatusUpdateHandler { + public: + /** + * @brief ServiceStatusUpdateHandler class constructor + * @param listener pointer to ServiceStatusUpdateHandlerListener instance + */ + ServiceStatusUpdateHandler(ServiceStatusUpdateHandlerListener* listener) + : listener_(listener) {} + + /** + * @brief OnServiceUpdate callback that is invoked in case of + * service status update needed + * @param connection_key - connection key + * @param service_type enum value containing type of service. + * @param service_status enum value containing status of service. + * received + */ + void OnServiceUpdate(const uint32_t connection_key, + const protocol_handler::ServiceType service_type, + const ServiceStatus service_status); + + private: + ServiceStatusUpdateHandlerListener* listener_; +}; + +} // namespace protocol_handler + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_SERVICE_STATUS_UPDATE_HANDLER_H_ diff --git a/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h new file mode 100644 index 0000000000..6e1e4ee6c2 --- /dev/null +++ b/src/components/protocol_handler/include/protocol_handler/service_status_update_handler_listener.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_SERVICE_STATUS_UPDATE_HANDLER_LISTENER_H_ +#define SRC_COMPONENTS_PROTOCOL_HANDLER_INCLUDE_PROTOCOL_HANDLER_SERVICE_STATUS_UPDATE_HANDLER_LISTENER_H_ + +#include "interfaces/HMI_API.h" +#include "protocol_handler/protocol_handler.h" +#include "transport_manager/transport_manager.h" +#include "utils/optional.h" + +namespace protocol_handler { +/** + * @brief Converts service type enum value from protocol_handler to hmi_apis. + * @param service_type protocol_handler enum value. + **/ +hmi_apis::Common_ServiceType::eType GetHMIServiceType( + protocol_handler::ServiceType service_type); + +/** + * @brief ServiceStatusUpdateHandlerListener provides callbacks interface with + * a purpose to notify HMI on successful or failed state updates of different + * services + **/ +class ServiceStatusUpdateHandlerListener { + public: + /** + * @brief ProcessServiceStatusUpdate callback that is invoked in case of + * service + * status update + * @param connection_key - connection key + * @param service_type enum value containing type of service. + * @param service_event enum value containing event that occured during + * service start. + * @param service_update_reason enum value containing reason why service_event + * occured. + **/ + virtual void ProcessServiceStatusUpdate( + const uint32_t connection_key, + hmi_apis::Common_ServiceType::eType service_type, + hmi_apis::Common_ServiceEvent::eType service_event, + utils::Optional<hmi_apis::Common_ServiceUpdateReason::eType> + service_update_reason) = 0; +}; + +} // namespace protocol_handler + +#endif diff --git a/src/components/protocol_handler/src/handshake_handler.cc b/src/components/protocol_handler/src/handshake_handler.cc index fa0b375018..2109e637a4 100644 --- a/src/components/protocol_handler/src/handshake_handler.cc +++ b/src/components/protocol_handler/src/handshake_handler.cc @@ -38,23 +38,27 @@ #include "protocol_handler/protocol_packet.h" #include "protocol_handler/session_observer.h" #include "security_manager/security_manager.h" +#include "utils/helpers.h" namespace protocol_handler { CREATE_LOGGERPTR_GLOBAL(logger_, "ProtocolHandler") -HandshakeHandler::HandshakeHandler(ProtocolHandlerImpl& protocol_handler, - SessionObserver& session_observer, - utils::SemanticVersion& full_version, - const SessionContext& context, - const uint8_t protocol_version, - std::shared_ptr<BsonObject> payload) +HandshakeHandler::HandshakeHandler( + ProtocolHandlerImpl& protocol_handler, + SessionObserver& session_observer, + utils::SemanticVersion& full_version, + const SessionContext& context, + const uint8_t protocol_version, + std::shared_ptr<BsonObject> payload, + ServiceStatusUpdateHandler& service_status_update_handler) : protocol_handler_(protocol_handler) , session_observer_(session_observer) , context_(context) , full_version_(full_version) , protocol_version_(protocol_version) - , payload_(payload) {} + , payload_(payload) + , service_status_update_handler_(service_status_update_handler) {} HandshakeHandler::~HandshakeHandler() { LOG4CXX_DEBUG(logger_, "Destroying of HandshakeHandler: " << this); @@ -69,26 +73,51 @@ bool HandshakeHandler::GetPolicyCertificateData(std::string& data) const { return false; } -void HandshakeHandler::OnCertificateUpdateRequired() {} +void HandshakeHandler::OnCertificateUpdateRequired() { + LOG4CXX_AUTO_TRACE(logger_); +} -bool HandshakeHandler::OnHandshakeFailed() { +#if defined(EXTERNAL_PROPRIETARY_MODE) && defined(ENABLE_SECURITY) +bool HandshakeHandler::OnCertDecryptFailed() { + LOG4CXX_AUTO_TRACE(logger_); if (payload_) { - ProcessFailedHandshake(*payload_); + ProcessFailedHandshake(*payload_, ServiceStatus::CERT_INVALID); + } + + return true; +} +#endif + +bool HandshakeHandler::OnGetSystemTimeFailed() { + LOG4CXX_AUTO_TRACE(logger_); + + if (payload_) { + ProcessFailedHandshake(*payload_, ServiceStatus::INVALID_TIME); } else { BsonObject params; bson_object_initialize_default(¶ms); - ProcessFailedHandshake(params); + ProcessFailedHandshake(params, ServiceStatus::INVALID_TIME); bson_object_deinitialize(¶ms); } return true; } +void HandshakeHandler::OnPTUFailed() { + LOG4CXX_AUTO_TRACE(logger_); + if (payload_) { + ProcessFailedHandshake(*payload_, ServiceStatus::PTU_FAILED); + } +} + bool HandshakeHandler::OnHandshakeDone( uint32_t connection_key, security_manager::SSLContext::HandshakeResult result) { LOG4CXX_AUTO_TRACE(logger_); + LOG4CXX_DEBUG(logger_, + "OnHandshakeDone for service : " << context_.service_type_); + if (connection_key != this->connection_key()) { LOG4CXX_DEBUG(logger_, "Listener " << this @@ -106,7 +135,7 @@ bool HandshakeHandler::OnHandshakeDone( if (success) { ProcessSuccessfulHandshake(connection_key, *payload_); } else { - ProcessFailedHandshake(*payload_); + ProcessFailedHandshake(*payload_, ServiceStatus::CERT_INVALID); } } else { BsonObject params; @@ -114,7 +143,7 @@ bool HandshakeHandler::OnHandshakeDone( if (success) { ProcessSuccessfulHandshake(connection_key, params); } else { - ProcessFailedHandshake(params); + ProcessFailedHandshake(params, ServiceStatus::CERT_INVALID); } bson_object_deinitialize(¶ms); } @@ -122,20 +151,25 @@ bool HandshakeHandler::OnHandshakeDone( return true; } +bool HandshakeHandler::CanBeProtected() const { + const auto& force_unprotected = + protocol_handler_.get_settings().force_unprotected_service(); + + return !(helpers::in_range(force_unprotected, context_.service_type_)); +} + +bool HandshakeHandler::IsAlreadyProtected() const { + return (session_observer_.GetSSLContext(this->connection_key(), + context_.service_type_) != NULL); +} + void HandshakeHandler::ProcessSuccessfulHandshake(const uint32_t connection_key, BsonObject& params) { LOG4CXX_AUTO_TRACE(logger_); - const std::vector<int>& force_unprotected = - protocol_handler_.get_settings().force_unprotected_service(); - const bool can_be_protected = - std::find(force_unprotected.begin(), - force_unprotected.end(), - context_.service_type_) == force_unprotected.end(); + const bool is_service_already_protected = IsAlreadyProtected(); - const bool is_service_already_protected = - session_observer_.GetSSLContext(connection_key, context_.service_type_) != - NULL; + const bool can_be_protected = CanBeProtected(); LOG4CXX_DEBUG(logger_, "Service can be protected: " << can_be_protected @@ -144,6 +178,10 @@ void HandshakeHandler::ProcessSuccessfulHandshake(const uint32_t connection_key, if (can_be_protected && !is_service_already_protected) { session_observer_.SetProtectionFlag(connection_key, context_.service_type_); + service_status_update_handler_.OnServiceUpdate( + this->connection_key(), + context_.service_type_, + ServiceStatus::SERVICE_ACCEPTED); protocol_handler_.SendStartSessionAck(context_.connection_id_, context_.new_session_id_, protocol_version_, @@ -153,6 +191,10 @@ void HandshakeHandler::ProcessSuccessfulHandshake(const uint32_t connection_key, full_version_, params); } else { + service_status_update_handler_.OnServiceUpdate( + this->connection_key(), + context_.service_type_, + ServiceStatus::SERVICE_START_FAILED); protocol_handler_.SendStartSessionNAck(context_.connection_id_, context_.new_session_id_, protocol_version_, @@ -160,7 +202,8 @@ void HandshakeHandler::ProcessSuccessfulHandshake(const uint32_t connection_key, } } -void HandshakeHandler::ProcessFailedHandshake(BsonObject& params) { +void HandshakeHandler::ProcessFailedHandshake(BsonObject& params, + ServiceStatus service_status) { LOG4CXX_AUTO_TRACE(logger_); LOG4CXX_DEBUG(logger_, "Handshake failed"); const std::vector<int>& force_protected = @@ -177,6 +220,10 @@ void HandshakeHandler::ProcessFailedHandshake(BsonObject& params) { << context_.is_new_service_); if (can_be_unprotected && context_.is_new_service_) { + service_status_update_handler_.OnServiceUpdate( + this->connection_key(), + context_.service_type_, + ServiceStatus::SERVICE_ACCEPTED); protocol_handler_.SendStartSessionAck(context_.connection_id_, context_.new_session_id_, protocol_version_, @@ -186,6 +233,8 @@ void HandshakeHandler::ProcessFailedHandshake(BsonObject& params) { full_version_, params); } else { + service_status_update_handler_.OnServiceUpdate( + this->connection_key(), context_.service_type_, service_status); protocol_handler_.SendStartSessionNAck(context_.connection_id_, context_.new_session_id_, protocol_version_, diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc index d95c57f0cc..70148a1d73 100644 --- a/src/components/protocol_handler/src/protocol_handler_impl.cc +++ b/src/components/protocol_handler/src/protocol_handler_impl.cc @@ -1129,13 +1129,25 @@ void ProtocolHandlerImpl::OnUnexpectedDisconnect( OnConnectionClosed(connection_id); } -void ProtocolHandlerImpl::NotifyOnFailedHandshake() { +void ProtocolHandlerImpl::NotifyOnGetSystemTimeFailed() { LOG4CXX_AUTO_TRACE(logger_); + security_manager_->ResetPendingSystemTimeRequests(); #ifdef ENABLE_SECURITY - security_manager_->NotifyListenersOnHandshakeFailed(); + security_manager_->NotifyListenersOnGetSystemTimeFailed(); #endif // ENABLE_SECURITY } +void ProtocolHandlerImpl::ProcessFailedPTU() { + security_manager_->ProcessFailedPTU(); +} + +#ifdef EXTERNAL_PROPRIETARY_MODE +void ProtocolHandlerImpl::ProcessFailedCertDecrypt() { + LOG4CXX_AUTO_TRACE(logger_); + security_manager_->ProcessFailedCertDecrypt(); +} +#endif + void ProtocolHandlerImpl::OnTransportConfigUpdated( const transport_manager::transport_adapter::TransportConfig& configs) { LOG4CXX_AUTO_TRACE(logger_); @@ -1639,6 +1651,12 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession( std::find(audio_transports.begin(), audio_transports.end(), transport) != audio_transports.end(); + const uint32_t connection_key = session_observer_.KeyFromPair( + packet->connection_id(), packet->session_id()); + + service_status_update_handler_->OnServiceUpdate( + connection_key, service_type, ServiceStatus::SERVICE_RECEIVED); + if ((ServiceType::kMobileNav == service_type && !is_video_allowed) || (ServiceType::kAudio == service_type && !is_audio_allowed)) { LOG4CXX_DEBUG(logger_, @@ -1836,12 +1854,14 @@ void ProtocolHandlerImpl::NotifySessionStarted( context.connection_id_, context.new_session_id_); std::shared_ptr<HandshakeHandler> handler = - std::make_shared<HandshakeHandler>(*this, - session_observer_, - *fullVersion, - context, - packet->protocol_version(), - start_session_ack_params); + std::make_shared<HandshakeHandler>( + *this, + session_observer_, + *fullVersion, + context, + packet->protocol_version(), + start_session_ack_params, + *(service_status_update_handler_.get())); security_manager::SSLContext* ssl_context = security_manager_->CreateSSLContext( @@ -1872,6 +1892,10 @@ void ProtocolHandlerImpl::NotifySessionStarted( // mark service as protected session_observer_.SetProtectionFlag(connection_key, service_type); // Start service as protected with current SSLContext + service_status_update_handler_->OnServiceUpdate( + connection_key, + context.service_type_, + ServiceStatus::SERVICE_ACCEPTED); SendStartSessionAck(context.connection_id_, context.new_session_id_, packet->protocol_version(), @@ -1908,7 +1932,11 @@ void ProtocolHandlerImpl::NotifySessionStarted( return; } #endif // ENABLE_SECURITY + const uint32_t connection_key = session_observer_.KeyFromPair( + context.connection_id_, context.new_session_id_); if (rejected_params.empty()) { + service_status_update_handler_->OnServiceUpdate( + connection_key, context.service_type_, ServiceStatus::SERVICE_ACCEPTED); SendStartSessionAck(context.connection_id_, context.new_session_id_, packet->protocol_version(), @@ -1918,6 +1946,10 @@ void ProtocolHandlerImpl::NotifySessionStarted( *fullVersion, *start_session_ack_params); } else { + service_status_update_handler_->OnServiceUpdate( + connection_key, + context.service_type_, + ServiceStatus::SERVICE_START_FAILED); SendStartSessionNAck(context.connection_id_, packet->session_id(), protocol_version, @@ -2099,6 +2131,11 @@ void ProtocolHandlerImpl::Stop() { start_session_frame_map_.clear(); } +void ProtocolHandlerImpl::set_service_status_update_handler( + std::unique_ptr<ServiceStatusUpdateHandler> handler) { + service_status_update_handler_ = std::move(handler); +} + #ifdef ENABLE_SECURITY void ProtocolHandlerImpl::set_security_manager( security_manager::SecurityManager* security_manager) { diff --git a/src/components/protocol_handler/src/service_status_update_handler.cc b/src/components/protocol_handler/src/service_status_update_handler.cc new file mode 100644 index 0000000000..b0ffaee9b4 --- /dev/null +++ b/src/components/protocol_handler/src/service_status_update_handler.cc @@ -0,0 +1,82 @@ +#include "protocol_handler/service_status_update_handler.h" +#include "interfaces/HMI_API.h" + +namespace protocol_handler { + +hmi_apis::Common_ServiceType::eType GetHMIServiceType( + protocol_handler::ServiceType service_type) { + using namespace hmi_apis; + using namespace protocol_handler; + switch (service_type) { + case SERVICE_TYPE_RPC: { + return Common_ServiceType::RPC; + } + case SERVICE_TYPE_AUDIO: { + return Common_ServiceType::AUDIO; + } + case SERVICE_TYPE_NAVI: { + return Common_ServiceType::VIDEO; + } + default: { return Common_ServiceType::INVALID_ENUM; } + } +} + +void ServiceStatusUpdateHandler::OnServiceUpdate( + const uint32_t connection_key, + const protocol_handler::ServiceType service_type, + ServiceStatus service_status) { + using namespace hmi_apis; + typedef utils::Optional<Common_ServiceUpdateReason::eType> + UpdateReasonOptional; + auto hmi_service_type = GetHMIServiceType(service_type); + + switch (service_status) { + case ServiceStatus::SERVICE_RECEIVED: { + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_RECEIVED, + UpdateReasonOptional(UpdateReasonOptional::EMPTY)); + } + case ServiceStatus::SERVICE_ACCEPTED: { + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_ACCEPTED, + UpdateReasonOptional(UpdateReasonOptional::EMPTY)); + } + case ServiceStatus::SERVICE_START_FAILED: { + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_REJECTED, + UpdateReasonOptional(UpdateReasonOptional::EMPTY)); + } + case ServiceStatus::PTU_FAILED: { + auto update_reason = Common_ServiceUpdateReason::PTU_FAILED; + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_REJECTED, + update_reason); + } + case ServiceStatus::CERT_INVALID: { + auto update_reason = Common_ServiceUpdateReason::INVALID_CERT; + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_REJECTED, + update_reason); + } + case ServiceStatus::INVALID_TIME: { + auto update_reason = Common_ServiceUpdateReason::INVALID_TIME; + return listener_->ProcessServiceStatusUpdate( + connection_key, + hmi_service_type, + Common_ServiceEvent::REQUEST_REJECTED, + update_reason); + } + default: { return; } + } +} +} // namespace protocol_handler diff --git a/src/components/security_manager/include/security_manager/security_manager_impl.h b/src/components/security_manager/include/security_manager/security_manager_impl.h index f2a417a43d..ee00e0774a 100644 --- a/src/components/security_manager/include/security_manager/security_manager_impl.h +++ b/src/components/security_manager/include/security_manager/security_manager_impl.h @@ -200,7 +200,7 @@ class SecurityManagerImpl : public SecurityManager, /** * @brief Notify all listeners that handshake was failed */ - void NotifyListenersOnHandshakeFailed() OVERRIDE; + void NotifyListenersOnGetSystemTimeFailed() OVERRIDE; /** * @brief Check is policy certificate data is empty @@ -214,6 +214,16 @@ class SecurityManagerImpl : public SecurityManager, */ static const char* ConfigSection(); + void ProcessFailedPTU() OVERRIDE; + +#ifdef EXTERNAL_PROPRIETARY_MODE + /** + * @brief ProcessFailedCertDecrypt is called to notify listeners that + * certificate decryption failed in the external flow + */ + void ProcessFailedCertDecrypt() OVERRIDE; +#endif + private: /** * \brief Sends Handshake binary data to mobile application @@ -280,6 +290,17 @@ class SecurityManagerImpl : public SecurityManager, */ void OnSystemTimeArrived(const time_t utc_time) OVERRIDE; + /** + * @brief OnSystemTimeFailed Notify about system request failure + */ + void OnSystemTimeFailed() OVERRIDE; + + /** + * @brief ResetPendingSystemTimeRequests resets waiting for system time + * requests flag + */ + void ResetPendingSystemTimeRequests(); + // Thread that pumps handshake data SecurityMessageLoop security_messages_; diff --git a/src/components/security_manager/src/security_manager_impl.cc b/src/components/security_manager/src/security_manager_impl.cc index 19c2ee2b11..488b4745be 100644 --- a/src/components/security_manager/src/security_manager_impl.cc +++ b/src/components/security_manager/src/security_manager_impl.cc @@ -213,6 +213,13 @@ void SecurityManagerImpl::ResumeHandshake(uint32_t connection_key) { return; } + LOG4CXX_DEBUG(logger_, + "Connection key : " + << connection_key + << " is waiting for certificate: " << std::boolalpha + << waiting_for_certificate_ << " and has certificate: " + << ssl_context->HasCertificate()); + ssl_context->ResetConnection(); if (!waiting_for_certificate_ && !ssl_context->HasCertificate()) { NotifyListenersOnHandshakeDone(connection_key, @@ -228,6 +235,7 @@ void SecurityManagerImpl::StartHandshake(uint32_t connection_key) { LOG4CXX_INFO(logger_, "StartHandshake: connection_key " << connection_key); security_manager::SSLContext* ssl_context = session_observer_->GetSSLContext( connection_key, protocol_handler::kControl); + if (!ssl_context) { const std::string error_text( "StartHandshake failed, " @@ -277,6 +285,7 @@ void SecurityManagerImpl::ProceedHandshake( time_t cert_due_date; if (!ssl_context->GetCertificateDueDate(cert_due_date)) { LOG4CXX_ERROR(logger_, "Failed to get certificate due date!"); + PostponeHandshake(connection_key); return; } @@ -388,6 +397,56 @@ void SecurityManagerImpl::OnSystemTimeArrived(const time_t utc_time) { awaiting_time_connections_.clear(); } +void SecurityManagerImpl::OnSystemTimeFailed() { + LOG4CXX_AUTO_TRACE(logger_); + { + sync_primitives::AutoLock lock(waiters_lock_); + waiting_for_time_ = false; + } + + NotifyListenersOnGetSystemTimeFailed(); + + awaiting_time_connections_.clear(); +} + +void SecurityManagerImpl::ProcessFailedPTU() { + LOG4CXX_AUTO_TRACE(logger_); + if (listeners_.empty()) { + LOG4CXX_DEBUG(logger_, "listeners arrays IS EMPTY!"); + return; + } + std::for_each(listeners_.begin(), + listeners_.end(), + std::mem_fun(&SecurityManagerListener::OnPTUFailed)); +} + +#ifdef EXTERNAL_PROPRIETARY_MODE +void SecurityManagerImpl::ProcessFailedCertDecrypt() { + LOG4CXX_AUTO_TRACE(logger_); + { + sync_primitives::AutoLock lock(waiters_lock_); + waiting_for_certificate_ = false; + } + + std::list<SecurityManagerListener*> listeners_to_remove; + for (auto listener : listeners_) { + if (listener->OnCertDecryptFailed()) { + listeners_to_remove.push_back(listener); + } + } + + for (auto& listener : listeners_to_remove) { + auto it = std::find(listeners_.begin(), listeners_.end(), listener); + DCHECK(it != listeners_.end()); + LOG4CXX_DEBUG(logger_, "Destroying listener: " << *it); + delete (*it); + listeners_.erase(it); + } + + awaiting_certificate_connections_.clear(); +} +#endif + void SecurityManagerImpl::NotifyListenersOnHandshakeDone( const uint32_t& connection_key, SSLContext::HandshakeResult error) { LOG4CXX_AUTO_TRACE(logger_); @@ -412,11 +471,15 @@ void SecurityManagerImpl::NotifyOnCertificateUpdateRequired() { } } -void SecurityManagerImpl::NotifyListenersOnHandshakeFailed() { +void SecurityManagerImpl::ResetPendingSystemTimeRequests() { + system_time_handler_->ResetPendingSystemTimeRequests(); +} + +void SecurityManagerImpl::NotifyListenersOnGetSystemTimeFailed() { LOG4CXX_AUTO_TRACE(logger_); std::list<SecurityManagerListener*>::iterator it = listeners_.begin(); while (it != listeners_.end()) { - if ((*it)->OnHandshakeFailed()) { + if ((*it)->OnGetSystemTimeFailed()) { LOG4CXX_DEBUG(logger_, "Destroying listener: " << *it); delete (*it); it = listeners_.erase(it); diff --git a/src/components/utils/include/utils/system_time_handler.h b/src/components/utils/include/utils/system_time_handler.h index 15b2dd0cca..2013622f30 100644 --- a/src/components/utils/include/utils/system_time_handler.h +++ b/src/components/utils/include/utils/system_time_handler.h @@ -50,6 +50,11 @@ class SystemTimeListener { * @param utc_time current system time. */ virtual void OnSystemTimeArrived(const time_t utc_time) = 0; + + /** + * @brief OnSystemTimeFailed Notify about system request failure + */ + virtual void OnSystemTimeFailed() = 0; }; /** @@ -97,6 +102,12 @@ class SystemTimeHandler { time_t GetUTCTime(); /** + * @brief ResetPendingSystemTimeRequests resets waiting for system time + * requests flag + */ + virtual void ResetPendingSystemTimeRequests() = 0; + + /** * @brief Checks if system time is ready * and can be requested by GetSystemTime request * @return True if HMI is ready to provide UTC time |