Skip to content

Commit e0f9826

Browse files
committed
Fix force unprotected service
1 parent 81f3743 commit e0f9826

File tree

4 files changed

+75
-31
lines changed

4 files changed

+75
-31
lines changed

src/components/protocol_handler/include/protocol_handler/protocol_handler_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,12 @@ class ProtocolHandlerImpl
717717
const std::string TransportTypeFromTransport(
718718
const utils::custom_string::CustomString& transport) const;
719719

720+
const ServiceStatus ServiceDisallowedBySettings(
721+
const ServiceType service_type,
722+
const ConnectionID connection_id,
723+
const uint8_t session_id,
724+
const bool protection) const;
725+
720726
const ProtocolHandlerSettings& settings_;
721727

722728
/**

src/components/protocol_handler/include/protocol_handler/service_status_update_handler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ enum class ServiceStatus {
5151
CERT_INVALID,
5252
INVALID_TIME,
5353
PROTECTION_ENFORCED,
54-
PROTECTION_DISABLED
54+
PROTECTION_DISABLED,
55+
UNSECURE_START_FAILED
5556
};
5657

5758
/**

src/components/protocol_handler/src/protocol_handler_impl.cc

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,56 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndSession(
15961596
return RESULT_OK;
15971597
}
15981598

1599+
const ServiceStatus ProtocolHandlerImpl::ServiceDisallowedBySettings(
1600+
const ServiceType service_type,
1601+
const ConnectionID connection_id,
1602+
const uint8_t session_id,
1603+
const bool protection) const {
1604+
const std::string& transport =
1605+
session_observer_.TransportTypeProfileStringFromConnHandle(connection_id);
1606+
1607+
const auto video_transports = settings_.video_service_transports();
1608+
const bool is_video_allowed =
1609+
video_transports.empty() ||
1610+
std::find(video_transports.begin(), video_transports.end(), transport) !=
1611+
video_transports.end();
1612+
1613+
const auto audio_transports = settings_.audio_service_transports();
1614+
const bool is_audio_allowed =
1615+
audio_transports.empty() ||
1616+
std::find(audio_transports.begin(), audio_transports.end(), transport) !=
1617+
audio_transports.end();
1618+
1619+
const auto& force_protected = get_settings().force_protected_service();
1620+
1621+
const auto& force_unprotected = get_settings().force_unprotected_service();
1622+
1623+
const bool is_force_protected =
1624+
(helpers::in_range(force_protected, service_type));
1625+
1626+
const bool is_force_unprotected =
1627+
(helpers::in_range(force_unprotected, service_type));
1628+
1629+
const bool can_start_protected = is_force_protected && protection;
1630+
1631+
const bool can_start_unprotected = is_force_unprotected && !protection;
1632+
1633+
if ((ServiceType::kMobileNav == service_type && !is_video_allowed) ||
1634+
(ServiceType::kAudio == service_type && !is_audio_allowed)) {
1635+
return ServiceStatus::SERVICE_START_FAILED;
1636+
}
1637+
1638+
if (is_force_protected && !can_start_protected) {
1639+
return ServiceStatus::PROTECTION_ENFORCED;
1640+
}
1641+
1642+
if (is_force_unprotected && !can_start_unprotected) {
1643+
return ServiceStatus::UNSECURE_START_FAILED;
1644+
}
1645+
1646+
return ServiceStatus::INVALID_ENUM;
1647+
}
1648+
15991649
RESULT_CODE ProtocolHandlerImpl::HandleControlMessageEndServiceACK(
16001650
const ProtocolPacket& packet) {
16011651
LOG4CXX_AUTO_TRACE(logger_);
@@ -1636,43 +1686,21 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
16361686

16371687
const ConnectionID connection_id = packet->connection_id();
16381688
const uint8_t session_id = packet->session_id();
1639-
const std::string& transport =
1640-
session_observer_.TransportTypeProfileStringFromConnHandle(connection_id);
1641-
1642-
const auto video_transports = settings_.video_service_transports();
1643-
const bool is_video_allowed =
1644-
video_transports.empty() ||
1645-
std::find(video_transports.begin(), video_transports.end(), transport) !=
1646-
video_transports.end();
1647-
1648-
const auto audio_transports = settings_.audio_service_transports();
1649-
const bool is_audio_allowed =
1650-
audio_transports.empty() ||
1651-
std::find(audio_transports.begin(), audio_transports.end(), transport) !=
1652-
audio_transports.end();
1653-
1654-
const uint32_t connection_key = session_observer_.KeyFromPair(
1655-
packet->connection_id(), packet->session_id());
1656-
1657-
const auto& force_protected = get_settings().force_protected_service();
1658-
1659-
const bool is_force_protected =
1660-
(helpers::in_range(force_protected, service_type));
1661-
1662-
const bool can_start_unprotected = is_force_protected && protection;
1689+
const uint32_t connection_key =
1690+
session_observer_.KeyFromPair(connection_id, session_id);
16631691

16641692
service_status_update_handler_->OnServiceUpdate(
16651693
connection_key, service_type, ServiceStatus::SERVICE_RECEIVED);
16661694

1667-
if ((ServiceType::kMobileNav == service_type && !is_video_allowed) ||
1668-
(ServiceType::kAudio == service_type && !is_audio_allowed) ||
1669-
(is_force_protected && !can_start_unprotected)) {
1695+
const auto settings_check = ServiceDisallowedBySettings(
1696+
service_type, connection_id, session_id, protection);
1697+
1698+
if (ServiceStatus::INVALID_ENUM != settings_check) {
16701699
LOG4CXX_DEBUG(logger_,
16711700
"Rejecting StartService for service:"
1672-
<< service_type << ", over transport: " << transport
1673-
<< ", disallowed by settings.");
1701+
<< service_type << ", disallowed by settings.");
16741702
service_status_update_handler_->OnServiceUpdate(
1675-
connection_key, service_type, ServiceStatus::PROTECTION_ENFORCED);
1703+
connection_key, service_type, settings_check);
16761704
SendStartSessionNAck(
16771705
connection_id, session_id, protocol_version, service_type);
16781706
return RESULT_OK;

src/components/protocol_handler/src/service_status_update_handler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ void ServiceStatusUpdateHandler::OnServiceUpdate(
9797
Common_ServiceEvent::REQUEST_ACCEPTED,
9898
update_reason);
9999
}
100+
case ServiceStatus::UNSECURE_START_FAILED: {
101+
auto update_reason =
102+
Common_ServiceStatusUpdateReason::PROTECTION_DISABLED;
103+
return listener_->ProcessServiceStatusUpdate(
104+
connection_key,
105+
hmi_service_type,
106+
Common_ServiceEvent::REQUEST_REJECTED,
107+
update_reason);
108+
}
100109
default: {
101110
LOG4CXX_WARN(logger_,
102111
"Received unknown ServiceStatus: "

0 commit comments

Comments
 (0)