diff --git a/DisplaySettings/CMakeLists.txt b/DisplaySettings/CMakeLists.txt index d9a6dcbf6b..e0f95486ae 100644 --- a/DisplaySettings/CMakeLists.txt +++ b/DisplaySettings/CMakeLists.txt @@ -22,8 +22,7 @@ find_package(${NAMESPACE}Plugins REQUIRED) add_library(${MODULE_NAME} SHARED DisplaySettings.cpp - Module.cpp - ../helpers/UtilsSecurityToken.cpp) + Module.cpp) set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 @@ -39,9 +38,9 @@ if (DS_FOUND) add_definitions(-DDS_FOUND) target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}SecurityUtil ${IARMBUS_LIBRARIES} ${DS_LIBRARIES} "-ltr181api") + target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${DS_LIBRARIES} "-ltr181api") else (DS_FOUND) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}SecurityUtil) + target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins) endif(DS_FOUND) install(TARGETS ${MODULE_NAME} diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index b01b045a1c..cb158b3b04 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -48,7 +48,6 @@ #include "UtilsCStr.h" #include "UtilsIarm.h" #include "UtilsJsonRpc.h" -#include "UtilsSecurityToken.h" #include "UtilsString.h" #include "UtilsisValidInt.h" #include "dsRpc.h" @@ -370,10 +369,12 @@ namespace WPEFramework { LOG_DEVICE_EXCEPTION1(string("HDMI_ARC0")); } - bool isPluginActivated = Utils::isPluginActivated(HDMICECSINK_CALLSIGN); + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); - if(isPluginActivated) { - if(!m_subscribed) { + if(!m_subscribed) { if((subscribeForHdmiCecSinkEvent(HDMICECSINK_ARC_INITIATION_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_ARC_TERMINATION_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_SHORT_AUDIO_DESCRIPTOR_EVENT)== Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_SYSTEM_AUDIO_MODE_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_AUDIO_DEVICE_CONNECTED_STATUS_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_CEC_ENABLED_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_AUDIO_DEVICE_POWER_STATUS_EVENT) == Core::ERROR_NONE)) { m_subscribed = true; LOGINFO("%s: HdmiCecSink event subscription completed.\n",__FUNCTION__); @@ -486,8 +487,14 @@ namespace WPEFramework { } } - const string DisplaySettings::Initialize(PluginHost::IShell* /* service */) + const string DisplaySettings::Initialize(PluginHost::IShell* service) { + ASSERT(service != nullptr); + ASSERT(m_service == nullptr); + + m_service = service; + m_service->AddRef(); + m_arcRoutingThread = std::thread(cecArcRoutingThread); m_timer.connect(std::bind(&DisplaySettings::onTimer, this)); m_AudioDeviceDetectTimer.connect(std::bind(&DisplaySettings::checkAudioDeviceDetectionTimer, this)); @@ -507,7 +514,7 @@ namespace WPEFramework { return (string()); } - void DisplaySettings::Deinitialize(PluginHost::IShell* /* service */) + void DisplaySettings::Deinitialize(PluginHost::IShell* service) { LOGINFO("Enetering DisplaySettings::Deinitialize"); isCecArcRoutingThreadEnabled = false; @@ -536,6 +543,11 @@ namespace WPEFramework { DeinitializeIARM(); DisplaySettings::_instance = nullptr; + + ASSERT(service == m_service); + + m_service->Release(); + m_service = nullptr; } void DisplaySettings::InitializeIARM() @@ -3934,7 +3946,11 @@ namespace WPEFramework { { bool success = true; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink Initialisation failed\n"); @@ -3969,7 +3985,11 @@ namespace WPEFramework { { bool cecEnable = false; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink Initialisation failed\n"); @@ -3998,7 +4018,11 @@ namespace WPEFramework { { bool hdmiAudioDeviceDetected = false; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink Initialisation failed\n"); @@ -4027,7 +4051,11 @@ namespace WPEFramework { { bool success = true; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink Initialisation failed\n"); @@ -4056,7 +4084,11 @@ namespace WPEFramework { { bool success = true; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink plugin not accessible\n"); @@ -4085,7 +4117,11 @@ namespace WPEFramework { { bool success = true; - if (Utils::isPluginActivated(HDMICECSINK_CALLSIGN)) { + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + getHdmiCecSinkPlugin(); if (!m_client) { LOGERR("HdmiCecSink plugin not accessible\n"); @@ -4915,17 +4951,47 @@ namespace WPEFramework { // lock to prevent: parallel onTimer runs, destruction during onTimer lock_guard lck(m_callMutex); - bool isPluginActivated = Utils::isPluginActivated(HDMICECSINK_CALLSIGN); + bool isPluginActivated = false; + + auto hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + isPluginActivated = true; + } if (!isPluginActivated) { /*HDMICECSINK_CALLSIGN plugin activation moved to onTimer. *To decouple from displyasettings init. Since its time taking*/ - Utils::activatePlugin(HDMICECSINK_CALLSIGN); + + auto controller = m_service->QueryInterfaceByCallsign("Controller"); + if (controller != nullptr) { + auto message = (Core::ProxyType(PluginHost::IFactories::Instance().JSONRPC())); + message->JSONRPC = Core::JSONRPC::Message::DefaultVersion; + message->Id = 0; + message->Designator = "Controller.1.activate"; + message->Parameters = "{\"callsign\":\"org.rdk.HdmiCecSink\"}"; + auto resp = controller->Invoke("", ~0, *message); + if (resp->Error.IsSet()) { + std::cout << "Call failed: " << message->Designator.Value() << " error: " << resp->Error.Text.Value() << "\n"; + } + controller->Release(); + } + LOGWARN ("DisplaySettings::onTimer after activatePlugin HDMICECSINK_CALLSIGN line:%d", __LINE__); sleep(HDMICECSINK_PLUGIN_ACTIVATION_TIME); } - bool pluginActivated = Utils::isPluginActivated(HDMICECSINK_CALLSIGN); + static bool isInitDone = false; + bool pluginActivated = false; + + hdmiCecSink = m_service->QueryInterfaceByCallsign(HDMICECSINK_CALLSIGN); + if (hdmiCecSink != nullptr) { + LOGINFO("%s is active", HDMICECSINK_CALLSIGN); + hdmiCecSink->Release(); + pluginActivated = true; + } + LOGWARN ("DisplaySettings::onTimer pluginActivated:%d line:%d", pluginActivated, __LINE__); if(!m_subscribed) { if (pluginActivated && (subscribeForHdmiCecSinkEvent(HDMICECSINK_ARC_INITIATION_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_ARC_TERMINATION_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_SHORT_AUDIO_DESCRIPTOR_EVENT)== Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_SYSTEM_AUDIO_MODE_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_AUDIO_DEVICE_CONNECTED_STATUS_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_CEC_ENABLED_EVENT) == Core::ERROR_NONE) && (subscribeForHdmiCecSinkEvent(HDMICECSINK_AUDIO_DEVICE_POWER_STATUS_EVENT) == Core::ERROR_NONE)) @@ -4940,10 +5006,6 @@ namespace WPEFramework { } else { LOGERR("Could not subscribe this time, one more attempt in %d msec. Plugin is %s", RECONNECTION_TIME_IN_MILLISECONDS, pluginActivated ? "ACTIVE" : "BLOCKED"); - if (!pluginActivated) - { - Utils::activatePlugin(HDMICECSINK_CALLSIGN); - } } } else { //Standby ON transitions case diff --git a/DisplaySettings/DisplaySettings.h b/DisplaySettings/DisplaySettings.h index 20e21611a8..c25db1b7f2 100644 --- a/DisplaySettings/DisplaySettings.h +++ b/DisplaySettings/DisplaySettings.h @@ -256,7 +256,9 @@ namespace WPEFramework { }; int m_hdmiInAudioDevicePowerState; - int m_currentArcRoutingState; + int m_currentArcRoutingState; + + PluginHost::IShell* m_service; public: static DisplaySettings* _instance; diff --git a/MaintenanceManager/CMakeLists.txt b/MaintenanceManager/CMakeLists.txt index ecf6fe2605..10e6aa668b 100644 --- a/MaintenanceManager/CMakeLists.txt +++ b/MaintenanceManager/CMakeLists.txt @@ -22,8 +22,7 @@ find_package(${NAMESPACE}Plugins REQUIRED) add_library(${MODULE_NAME} SHARED MaintenanceManager.cpp - Module.cpp - ../helpers/UtilsSecurityToken.cpp) + Module.cpp) set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 @@ -37,11 +36,11 @@ list(APPEND CMAKE_MODULE_PATH find_package(IARMBus) if (IARMBus_FOUND) target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}SecurityUtil ${IARMBUS_LIBRARIES}) + target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES}) else (IARMBus_FOUND) message ("Module IARMBus required.") target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}SecurityUtil ${IARMBUS_LIBRARIES}) + target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES}) endif(IARMBus_FOUND) target_include_directories(${MODULE_NAME} PRIVATE ../helpers) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 74990a2a14..4b9da4b8bc 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -41,7 +41,6 @@ #include "UtilsIarm.h" #include "UtilsJsonRpc.h" -#include "UtilsSecurityToken.h" #include "UtilscRunScript.h" #include "UtilsfileExists.h" @@ -345,19 +344,17 @@ namespace WPEFramework { JsonObject joGetParams; JsonObject joGetResult; std::string callsign = "org.rdk.AuthService.1"; - std::string token; uint8_t i = 0; - bool isAuthSerivcePluginActive = false; std::string ret_status("invalid"); /* check if plugin active */ - isAuthSerivcePluginActive = Utils::isPluginActivated("org.rdk.AuthService"); - if (!isAuthSerivcePluginActive){ + auto auth = m_service->QueryInterfaceByCallsign("org.rdk.AuthService"); + if (auth == nullptr){ LOGINFO("AuthService plugin is not activated.Retrying.. \n"); //if plugin is not activated we need to retry do{ - isAuthSerivcePluginActive = Utils::isPluginActivated("org.rdk.AuthService"); - if ( !isAuthSerivcePluginActive ){ + auth = m_service->QueryInterfaceByCallsign("org.rdk.AuthService"); + if (auth == nullptr){ sleep(10); i++; LOGINFO("AuthService retries [%d/4] \n",i); @@ -367,7 +364,7 @@ namespace WPEFramework { } }while( i < MAX_ACTIVATION_RETRIES ); - if ( !isAuthSerivcePluginActive ){ + if (auth == nullptr){ LOGINFO("AuthService plugin is Still not active"); return ret_status; } @@ -375,8 +372,10 @@ namespace WPEFramework { LOGINFO("AuthService plugin is Now active"); } } - - Utils::SecurityToken::getSecurityToken(token); + if (auth != nullptr){ + LOGINFO("AuthService is active"); + auth->Release(); + } Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), _T(SERVER_DETAILS)); auto thunder_client = make_shared >(callsign.c_str(), ""); @@ -457,17 +456,7 @@ namespace WPEFramework { JsonObject joGetParams; JsonObject joGetResult; std::string callsign = "org.rdk.Network.1"; - std::string token; - - /* check if plugin active */ - if (false == Utils::isPluginActivated("org.rdk.Network")) { - LOGINFO("Network plugin is not activated \n"); - return false; - } - Utils::SecurityToken::getSecurityToken(token); - - string query = "token=" + token; Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), _T(SERVER_DETAILS)); auto thunder_client = make_shared >(callsign.c_str(), ""); if (thunder_client != nullptr) { @@ -517,21 +506,33 @@ namespace WPEFramework { MaintenanceManager::_instance = nullptr; } - const string MaintenanceManager::Initialize(PluginHost::IShell*) + const string MaintenanceManager::Initialize(PluginHost::IShell* service) { + ASSERT(service != nullptr); + ASSERT(m_service == nullptr); + + m_service = service; + m_service->AddRef(); + #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) InitializeIARM(); #endif /* defined(USE_IARMBUS) || defined(USE_IARM_BUS) */ + /* On Success; return empty to indicate no error text. */ return (string()); } - void MaintenanceManager::Deinitialize(PluginHost::IShell*) + void MaintenanceManager::Deinitialize(PluginHost::IShell* service) { #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) stopMaintenanceTasks(); DeinitializeIARM(); #endif /* defined(USE_IARMBUS) || defined(USE_IARM_BUS) */ + + ASSERT(service == m_service); + + m_service->Release(); + m_service = nullptr; } #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) diff --git a/MaintenanceManager/MaintenanceManager.h b/MaintenanceManager/MaintenanceManager.h index 9f24c46273..f0f76b427a 100644 --- a/MaintenanceManager/MaintenanceManager.h +++ b/MaintenanceManager/MaintenanceManager.h @@ -137,6 +137,7 @@ namespace WPEFramework { std::thread m_thread; std::map m_task_map; + PluginHost::IShell* m_service; bool isDeviceOnline(); void task_execution_thread(); diff --git a/RDKShell/CMakeLists.txt b/RDKShell/CMakeLists.txt index 80521bd97b..1b4a4d9e63 100755 --- a/RDKShell/CMakeLists.txt +++ b/RDKShell/CMakeLists.txt @@ -28,7 +28,6 @@ find_package(IARMBus) add_library(${MODULE_NAME} SHARED RDKShell.cpp Module.cpp - ../helpers/UtilsSecurityToken.cpp ) set_target_properties(${MODULE_NAME} PROPERTIES @@ -47,7 +46,7 @@ target_include_directories(${MODULE_NAME} PRIVATE ../helpers ${IARMBUS_INCLUDE_D set(RDKSHELL_INCLUDES $ENV{RDKSHELL_INCLUDES}) separate_arguments(RDKSHELL_INCLUDES) include_directories(BEFORE ${RDKSHELL_INCLUDES}) -target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${NAMESPACE}SecurityUtil -lrdkshell ${PLUGIN_RDKSHELL_EXTRA_LIBRARIES} trower-base64) +target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins -lrdkshell ${PLUGIN_RDKSHELL_EXTRA_LIBRARIES} trower-base64) install(TARGETS ${MODULE_NAME} DESTINATION lib/${STORAGE_DIRECTORY}/plugins) diff --git a/RDKShell/RDKShell.cpp b/RDKShell/RDKShell.cpp index 1982e4a401..7d42b8f248 100755 --- a/RDKShell/RDKShell.cpp +++ b/RDKShell/RDKShell.cpp @@ -40,10 +40,8 @@ #include "UtilsJsonRpc.h" #include "UtilsLOG_MILESTONE.h" -#include "UtilsSecurityToken.h" #include "UtilsUnused.h" #include "UtilsgetRFCConfig.h" -#include "UtilsSecurityToken.h" #ifdef RDKSHELL_READ_MAC_ON_STARTUP #include "FactoryProtectHal.h" @@ -597,7 +595,7 @@ namespace WPEFramework { static void updateSurfaceClientIdentifiers( void) { uint32_t status = 0; - auto thunderController = getThunderControllerClient(); + auto thunderController = RDKShell::getThunderControllerClient(); WPEFramework::Core::JSON::String configString; Core::JSON::ArrayType availablePluginResult; status = thunderController->Get>(RDKSHELL_THUNDER_TIMEOUT, "status", availablePluginResult); @@ -1038,7 +1036,20 @@ namespace WPEFramework { enableInactivityReporting(true); #endif - Utils::SecurityToken::getSecurityToken(sThunderSecurityToken); + auto auth = mCurrentService->QueryInterfaceByCallsign("SecurityAgent"); + if (auth != nullptr) { + string payload = "http://localhost"; + string token; + if (auth->CreateToken( + static_cast(payload.length()), + reinterpret_cast(payload.c_str()), + token) + == WPEFramework::Core::ERROR_NONE) { + sThunderSecurityToken = token; + std::cout << "RDKShell got security token" << std::endl; + } + } + service->Register(mClientsMonitor); static PluginHost::IShell* pluginService = nullptr; @@ -6793,8 +6804,11 @@ namespace WPEFramework { { int32_t status = Core::ERROR_GENERAL; - if (Utils::isPluginActivated(SYSTEM_SERVICE_CALLSIGN)) + auto systemService = mCurrentService->QueryInterfaceByCallsign(SYSTEM_SERVICE_CALLSIGN); + if (systemService != nullptr) { + systemService->Release(); + std::cout << "SystemService is already activated" << std::endl; if (nullptr == gSystemServiceConnection) diff --git a/RDKShell/RDKShell.h b/RDKShell/RDKShell.h index a232efeb7e..54d6a30edd 100755 --- a/RDKShell/RDKShell.h +++ b/RDKShell/RDKShell.h @@ -328,7 +328,10 @@ namespace WPEFramework { bool getBlockedAVApplications(JsonArray& appsList); bool enableInputEvents(const JsonArray& clients, bool enable); + public: static std::shared_ptr > getThunderControllerClient(std::string callsign="", std::string localidentifier=""); + + private: static std::shared_ptr > getPackagerPlugin(); static std::shared_ptr > getOCIContainerPlugin(); diff --git a/helpers/UtilsSecurityToken.cpp b/helpers/UtilsSecurityToken.cpp deleted file mode 100644 index e0afb1288c..0000000000 --- a/helpers/UtilsSecurityToken.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2019 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#include "UtilsSecurityToken.h" - -#include -#include -#include - -#include "UtilsCStr.h" -#include "UtilsLogging.h" -#include "UtilsgetRFCConfig.h" - -#define MAX_STRING_LENGTH 2048 - -#define SERVER_DETAILS "127.0.0.1:9998" - -using namespace WPEFramework; -using namespace std; -using namespace WPEFramework; - -void Utils::SecurityToken::getSecurityToken(std::string& token) -{ - static std::mutex mtx; - std::unique_lock lock(mtx); - - if(m_sThunderSecurityChecked) - { - token = m_sToken; - return; - } - - // Thunder Security is enabled by Default. - bool thunderSecurityRFCEnabled = true; - RFC_ParamData_t param; - const char* rfcKey = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.ThunderSecurity.Enable"; - if (getRFCConfig((char*)rfcKey, param)) - { - if (param.type == WDMP_BOOLEAN && (strncasecmp(param.value,"false",5) == 0)) - { - thunderSecurityRFCEnabled = false; - } - } - std::cout << "Thunder Security RFC enabled: " << thunderSecurityRFCEnabled << std::endl; - if(!isThunderSecurityConfigured() || !thunderSecurityRFCEnabled) - { - m_sThunderSecurityChecked = true; - std::cout << "Thunder Security is not enabled. Not getting token\n"; - return; - } - m_sThunderSecurityChecked = true; - unsigned char buffer[MAX_STRING_LENGTH] = {0}; - - int ret = GetSecurityToken(MAX_STRING_LENGTH,buffer); - if(ret < 0) - { - std::cout << "Error in getting token\n"; - } - else - { - std::cout << "retrieved token successfully\n"; - token = (char*)buffer; - m_sToken = token; - } -} - -static size_t writeCurlResponse(void *ptr, size_t size, size_t nmemb, string stream) -{ - size_t realsize = size * nmemb; - string temp(static_cast(ptr), realsize); - stream.append(temp); - return realsize; -} - -bool Utils::SecurityToken::isThunderSecurityConfigured() -{ - bool configured = false; - long http_code = 0; - std::string jsonResp; - CURL *curl_handle = NULL; - CURLcode res = CURLE_OK; - curl_handle = curl_easy_init(); - string serialNumber = ""; - string url = "http://127.0.0.1:9998/Service/Controller/Configuration/Controller"; - if (curl_handle && - !curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str()) && - !curl_easy_setopt(curl_handle, CURLOPT_HTTPGET,1) && - !curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1) && //when redirected, follow the redirections - !curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCurlResponse) && - !curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &jsonResp)) { - - res = curl_easy_perform(curl_handle); - if(curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code) != CURLE_OK) - { - std::cout << "curl_easy_getinfo failed\n"; - } - std::cout << "Thunder Controller Configuration ret: " << res << " http response code: " << http_code << std::endl; - curl_easy_cleanup(curl_handle); - } - else - { - std::cout << "Could not perform curl to read Thunder Controller Configuration\n"; - } - if ((res == CURLE_OK) && (http_code == 200)) - { - //check for "Security" in response - JsonObject responseJson = JsonObject(jsonResp); - if (responseJson.HasLabel("subsystems")) - { - const JsonArray subsystemList = responseJson["subsystems"].Array(); - for (int i=0; i > Utils::getThunderControllerClient(std::string callsign) -{ - string token; - Utils::SecurityToken::getSecurityToken(token); - string query = "token=" + token; - - Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T(SERVER_DETAILS))); - static std::shared_ptr > thunderClient = make_shared >(callsign.c_str(), "",false,query); - return thunderClient; -} - -void Utils::activatePlugin(const char* callSign) -{ - JsonObject joParams; - joParams.Set("callsign",callSign); - JsonObject joResult; - - if(!isPluginActivated(callSign)) - { - LOGINFO("Activating %s", callSign); - uint32_t status = getThunderControllerClient()->Invoke(2000, "activate", joParams, joResult); - string strParams; - string strResult; - joParams.ToString(strParams); - joResult.ToString(strResult); - LOGINFO("Called method %s, with params %s, status: %d, result: %s" - , "activate" - , C_STR(strParams) - , status - , C_STR(strResult)); - if (status == Core::ERROR_NONE) - { - LOGINFO("%s Plugin activation status ret: %d ", callSign, status); - } - } -} - -bool Utils::isPluginActivated(const char* callSign) -{ - string method = "status@" + string(callSign); - Core::JSON::ArrayType joResult; - uint32_t status = getThunderControllerClient()->Get >(2000, method.c_str(),joResult); - bool pluginActivated = false; - if (status == Core::ERROR_NONE) - { - LOGINFO("Getting status for callSign %s, result: %s", callSign, joResult[0].JSONState.Data().c_str()); - pluginActivated = joResult[0].JSONState == PluginHost::IShell::ACTIVATED; - } - else - { - LOGWARN("Getting status for callSign %s, status: %d", callSign, status); - } - - if(!pluginActivated){ - LOGWARN("Plugin %s is not active", callSign); - } else { - LOGINFO("Plugin %s is active ", callSign); - } - return pluginActivated; -} - -std::string Utils::SecurityToken::m_sToken = ""; -bool Utils::SecurityToken::m_sThunderSecurityChecked = false; diff --git a/helpers/UtilsSecurityToken.h b/helpers/UtilsSecurityToken.h deleted file mode 100644 index 1fc820409c..0000000000 --- a/helpers/UtilsSecurityToken.h +++ /dev/null @@ -1,54 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2019 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#pragma once - -#include - -/** - * DO NOT USE THIS. - * - * Instead, use: - * - ThunderInterfaces - * - IShell notifications: - * PluginHost::IShell::Register - * PluginHost::IPlugin::INotification - * - PluginHost::IShell::Job - * - Preconditions - */ - -namespace Utils -{ - struct SecurityToken - { - static void getSecurityToken(std::string& token); - static bool isThunderSecurityConfigured(); - - private: - static std::string m_sToken; - static bool m_sThunderSecurityChecked; - }; - - // Thunder Plugin Communication - std::shared_ptr> getThunderControllerClient(std::string callsign=""); - - void activatePlugin(const char* callSign); - - bool isPluginActivated(const char* callSign); -} // namespace Utils