summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Keeler <jacob.keeler@livioradio.com>2018-09-19 17:19:11 -0400
committerGitHub <noreply@github.com>2018-09-19 17:19:11 -0400
commitc5cc091fae7c6b4651c32186bddb46526fe2b1d9 (patch)
treefb0cc665a180a20481cf10d12d1a031f5e686d2e
parent351f06cf1288dd9cfd56d046e7270ec99a147f8a (diff)
parent0ece6ac12019dd99b6d04a364619b5972bfaa93d (diff)
downloadsdl_core-c5cc091fae7c6b4651c32186bddb46526fe2b1d9.tar.gz
Merge pull request #2622 from smartdevicelink/fix/reject_audio_video_by_transport
Reject StartService for audio or video based on settings
-rw-r--r--src/components/protocol_handler/src/protocol_handler_impl.cc40
-rw-r--r--src/components/protocol_handler/test/protocol_handler_tm_test.cc284
2 files changed, 317 insertions, 7 deletions
diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc
index 093d89490b..138a18df3f 100644
--- a/src/components/protocol_handler/src/protocol_handler_impl.cc
+++ b/src/components/protocol_handler/src/protocol_handler_impl.cc
@@ -1556,15 +1556,9 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
logger_,
"Protocol version:" << static_cast<int>(packet->protocol_version()));
const ServiceType service_type = ServiceTypeFromByte(packet->service_type());
- BsonObject bson_obj;
- if (packet->data() != NULL) {
- bson_obj = bson_object_from_bytes(packet->data());
- } else {
- bson_object_initialize_default(&bson_obj);
- }
-#ifdef ENABLE_SECURITY
const uint8_t protocol_version = packet->protocol_version();
+#ifdef ENABLE_SECURITY
const bool protection =
// Protocol version 1 does not support protection
(protocol_version > PROTOCOL_VERSION_1) ? packet->protection_flag()
@@ -1575,6 +1569,31 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
const ConnectionID connection_id = packet->connection_id();
const uint8_t session_id = packet->session_id();
+ const std::string& transport =
+ session_observer_.TransportTypeProfileStringFromConnHandle(connection_id);
+
+ const auto video_transports = settings_.video_service_transports();
+ const bool is_video_allowed =
+ video_transports.empty() ||
+ std::find(video_transports.begin(), video_transports.end(), transport) !=
+ video_transports.end();
+
+ const auto audio_transports = settings_.audio_service_transports();
+ const bool is_audio_allowed =
+ audio_transports.empty() ||
+ std::find(audio_transports.begin(), audio_transports.end(), transport) !=
+ audio_transports.end();
+
+ if ((ServiceType::kMobileNav == service_type && !is_video_allowed) ||
+ (ServiceType::kAudio == service_type && !is_audio_allowed)) {
+ LOG4CXX_DEBUG(logger_,
+ "Rejecting StartService for service:"
+ << service_type << ", over transport: " << transport
+ << ", disallowed by settings.");
+ SendStartSessionNAck(
+ connection_id, session_id, protocol_version, service_type);
+ return RESULT_OK;
+ }
LOG4CXX_INFO(logger_,
"StartSession ID " << static_cast<int>(session_id)
@@ -1587,6 +1606,13 @@ RESULT_CODE ProtocolHandlerImpl::HandleControlMessageStartSession(
packet;
}
+ BsonObject bson_obj;
+ if (packet->data() != NULL) {
+ bson_obj = bson_object_from_bytes(packet->data());
+ } else {
+ bson_object_initialize_default(&bson_obj);
+ }
+
session_observer_.OnSessionStartedCallback(
connection_id, packet->session_id(), service_type, protection, &bson_obj);
bson_object_deinitialize(&bson_obj);
diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
index 615900c7fa..51284dfcda 100644
--- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc
+++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
@@ -269,6 +269,21 @@ class ProtocolHandlerImplTest : public ::testing::Test {
HASH_ID_WRONG,
callback_protection_flag);
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -452,6 +467,24 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
ServiceType service_type;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .Times(call_times)
+ .WillRepeatedly(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .Times(call_times)
+ .WillRepeatedly(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .Times(call_times)
+ .WillRepeatedly(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(
session_observer_mock,
@@ -520,6 +553,24 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) {
TestAsyncWaiter waiter;
uint32_t times = 0;
ServiceType service_type;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .Times(call_times)
+ .WillRepeatedly(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .Times(call_times)
+ .WillRepeatedly(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .Times(call_times)
+ .WillRepeatedly(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(
session_observer_mock,
@@ -578,6 +629,21 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -694,6 +760,26 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id1))
+ .WillOnce(Return("TCP_WIFI"));
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id2))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .Times(2)
+ .WillRepeatedly(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .Times(2)
+ .WillRepeatedly(ReturnRef(video_service_transports));
+
BsonObject bson_params1;
bson_object_initialize_default(&bson_params1);
bson_object_put_string(&bson_params1,
@@ -830,6 +916,84 @@ TEST_F(ProtocolHandlerImplTest,
bson_object_deinitialize(&bson_params2);
}
+/*
+ * ProtocolHandler shall send NAck on session_observer rejection
+ * Check protection flag OFF for all services from kControl to kBulk
+ */
+TEST_F(ProtocolHandlerImplTest, StartSession_Audio_RejectByTransportType) {
+ using namespace protocol_handler;
+ AddConnection();
+ const ServiceType start_service = kAudio;
+
+ TestAsyncWaiter waiter;
+ uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("AOA_USB");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
+ // Expect send Ack
+ EXPECT_CALL(transport_manager_mock,
+ SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK,
+ PROTECTION_OFF)))
+ .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS)));
+ times++;
+
+ SendControlMessage(
+ PROTECTION_OFF, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE);
+
+ EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout));
+}
+
+/*
+ * ProtocolHandler shall send NAck on session_observer rejection
+ * Check protection flag OFF for all services from kControl to kBulk
+ */
+TEST_F(ProtocolHandlerImplTest, StartSession_Video_RejectByTransportType) {
+ using namespace protocol_handler;
+ AddConnection();
+ const ServiceType start_service = kMobileNav;
+
+ TestAsyncWaiter waiter;
+ uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("AOA_USB");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
+ // Expect send Ack
+ EXPECT_CALL(transport_manager_mock,
+ SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK,
+ PROTECTION_OFF)))
+ .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS)));
+ times++;
+
+ SendControlMessage(
+ PROTECTION_OFF, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE);
+
+ EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout));
+}
+
// TODO(EZamakhov): add test for get_hash_id/set_hash_id from
// protocol_handler_impl.cc
/*
@@ -910,6 +1074,21 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) {
// Add security manager
AddSecurityManager();
const ServiceType start_service = kRpc;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -966,6 +1145,21 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) {
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1021,6 +1215,21 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) {
PROTECTION_ON);
context.is_new_service_ = true;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1074,6 +1283,21 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1150,6 +1374,21 @@ TEST_F(ProtocolHandlerImplTest,
PROTECTION_ON);
context.is_new_service_ = true;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1231,6 +1470,21 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1329,6 +1583,21 @@ TEST_F(
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,
@@ -1425,6 +1694,21 @@ TEST_F(ProtocolHandlerImplTest,
TestAsyncWaiter waiter;
uint32_t times = 0;
+ // Expect verification of allowed transport
+ EXPECT_CALL(session_observer_mock,
+ TransportTypeProfileStringFromConnHandle(connection_id))
+ .WillOnce(Return("TCP_WIFI"));
+
+ std::vector<std::string> audio_service_transports;
+ audio_service_transports.push_back("TCP_WIFI");
+ std::vector<std::string> video_service_transports;
+ video_service_transports.push_back("TCP_WIFI");
+
+ EXPECT_CALL(protocol_handler_settings_mock, audio_service_transports())
+ .WillOnce(ReturnRef(audio_service_transports));
+ EXPECT_CALL(protocol_handler_settings_mock, video_service_transports())
+ .WillOnce(ReturnRef(video_service_transports));
+
// Expect ConnectionHandler check
EXPECT_CALL(session_observer_mock,
OnSessionStartedCallback(connection_id,