From: Igor Kotrasinski Date: Thu, 14 Dec 2017 11:22:40 +0000 (+0100) Subject: Move UUID conversion to string outside binary manager X-Git-Tag: submit/tizen/20180412.092951~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0fc61e11a2ddc9309f12b3de7fb0e5f92e7db23;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Move UUID conversion to string outside binary manager Change-Id: I2e87b716d07e87341bdd753a2e3e3267258fe9ec Signed-off-by: Igor Kotrasinski --- diff --git a/simulatordaemon/CMakeLists.txt b/simulatordaemon/CMakeLists.txt index a844f10..f223a11 100644 --- a/simulatordaemon/CMakeLists.txt +++ b/simulatordaemon/CMakeLists.txt @@ -53,6 +53,7 @@ SET(DAEMON_SOURCES ${DAEMON_PATH}/src/UUIDConfig.cpp ${DAEMON_PATH}/src/UUIDConfigManager.cpp ${DAEMON_PATH}/src/UUIDComparator.cpp + ${DAEMON_PATH}/src/UUIDUtils.cpp ${DAEMON_PATH}/src/ClientCommands/CommandCloseSession.cpp ${DAEMON_PATH}/src/ClientCommands/CommandCloseTASession.cpp ${DAEMON_PATH}/src/ClientCommands/CommandFinContext.cpp diff --git a/simulatordaemon/inc/UUIDUtils.h b/simulatordaemon/inc/UUIDUtils.h index ca6a5cd..9a6083e 100644 --- a/simulatordaemon/inc/UUIDUtils.h +++ b/simulatordaemon/inc/UUIDUtils.h @@ -23,6 +23,11 @@ #ifndef UUIDUTILS_H_ #define UUIDUTILS_H_ +#include +#include "tee_client_api.h" + +std::string UUIDToString(TEEC_UUID uuid); + class UUIDComparator { public: bool operator() (const TEEC_UUID &u1, const TEEC_UUID &u2); diff --git a/simulatordaemon/src/ControlConnectionHandler.cpp b/simulatordaemon/src/ControlConnectionHandler.cpp index 20ec75f..73a9a96 100644 --- a/simulatordaemon/src/ControlConnectionHandler.cpp +++ b/simulatordaemon/src/ControlConnectionHandler.cpp @@ -25,6 +25,7 @@ #include "log.h" #include "ControlConnectionHandler.h" #include "IConnectionWriter.h" +#include "UUIDUtils.h" void ControlConnectionHandler::setWriter(IConnectionWriter &writer) { @@ -91,7 +92,7 @@ void ControlConnectionHandler::handleSetPortCommand(std::vector &data) std::memcpy(&cmd, data.data(), sizeof(cmd)); std::string portString = std::to_string(cmd.port); - std::string uuidString = binaryManager->getUUIDAsString(cmd.uuid); + std::string uuidString = UUIDToString(cmd.uuid); ret = binaryManager->setPort(uuidString, portString); if (!ret) { reply.status = CTL_REPLY_SUCCESS; diff --git a/simulatordaemon/src/Session.cpp b/simulatordaemon/src/Session.cpp index e57ee3d..0301d6d 100644 --- a/simulatordaemon/src/Session.cpp +++ b/simulatordaemon/src/Session.cpp @@ -28,6 +28,7 @@ #include "TAFactory.h" #include "TEEContext.h" #include "TEEConnectionHandler.h" +#include "UUIDConfigManager.h" /*----------------------------------------------------------------------------- * Member functions @@ -105,15 +106,12 @@ TEEC_Result Session::createSession(OpenSessionData data) { // Update member variable mSessionID with the assigned session ID mSessionID = data.sessionID; - //Check if the TA is to be launched in Debug mode, Kill alive TA process - TAInstancePtr TAInst; - TABinaryManager *TABin = TABinaryManager::getInstance(); if(TABin == NULL) { LOGE(SIM_DAEMON, "Creating TABinaryManager Instance FAILED - "); return TEEC_ERROR_GENERIC; } - string TAUUID = TABin->getUUIDAsString(data.uuid); + string TAUUID = UUIDToString(data.uuid); string argvPort = TABin->getPort(TAUUID); string TAName(TAUUID); diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp index 4ab2d1c..1dfb74a 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp @@ -36,6 +36,7 @@ #include #include #include +#include "UUIDUtils.h" namespace fs = boost::filesystem; /*----------------------------------------------------------------------------- @@ -433,23 +434,6 @@ int TABinaryManager::setPort(string uuid, string port) { return ret; } -/** - * Converts UUID from TEEC_UUID to a string - * @return string of TEEC_UUID - */ -string TABinaryManager::getUUIDAsString(TEEC_UUID uuid) { - // E.g. returns a string in the format 79B7778897894a7aA2BEB60155EEF5F3 - std::stringstream strStream; - strStream << IntToHex(uuid.timeLow); - strStream << IntToHex(uuid.timeMid); - strStream << IntToHex(uuid.timeHiAndVersion); - for (int i = 0; i < 8; i++) { - strStream << IntToHex((short)uuid.clockSeqAndNode[i], 2); - } - return strStream.str(); -} - - TABinaryManager::~TABinaryManager() { pthread_rwlock_destroy(&binaryMapLock); pthread_mutex_destroy(&taLock); diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.h b/simulatordaemon/src/TABinaryManager/TABinaryManager.h index 4526a62..b2f7215 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.h +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.h @@ -65,12 +65,6 @@ private: map binaryMap; TABinaryManager(); bool unpackBinary(const string &uuid, const string& tapath, StructBinaryInfo& info); - template - std::string IntToHex(T i, int width = sizeof(T) * 2) { - std::stringstream stream; - stream << std::setfill('0') << std::setw(width) << std::hex << i; - return stream.str(); - } void decryptImage(StructBinaryInfo& info); string base64_decode(std::string const& encoded_string); bool is_base64(unsigned char c); @@ -94,7 +88,6 @@ public: int isMultipleSession(string uuid, bool &MultipleSession); string getImagePath(string uuid); const TAManifest* getManifest(string uuid); - string getUUIDAsString(TEEC_UUID uuid); string getPort(string uuid); int isKeepAlive(string uuid, bool &KeepAlive); diff --git a/simulatordaemon/src/TAFactory.cpp b/simulatordaemon/src/TAFactory.cpp index 272b912..f01bf74 100644 --- a/simulatordaemon/src/TAFactory.cpp +++ b/simulatordaemon/src/TAFactory.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,10 @@ *-----------------------------------------------------------------------------*/ #include "TAFactory.h" #include "SecurityContext.h" +#include "UUIDUtils.h" #include "ResponseCommands/ResMakeCommand.h" + /*----------------------------------------------------------------------------- * Globals *-----------------------------------------------------------------------------*/ @@ -85,7 +87,7 @@ TAInstancePtr TAFactory::getTAInstance(TEEC_UUID uuid, ISession* session) { // Get TA Binary Manager instance TABinaryManager *TABin = TABinaryManager::getInstance(); // Get TEEC_UUID format uuid converted to string form - string TAUUID = TABin->getUUIDAsString(uuid); + string TAUUID = UUIDToString(uuid); // Change to upper char. TA list has upper char. locale loc; diff --git a/simulatordaemon/src/TEEContext.cpp b/simulatordaemon/src/TEEContext.cpp index bef3ed0..13aa4c1 100644 --- a/simulatordaemon/src/TEEContext.cpp +++ b/simulatordaemon/src/TEEContext.cpp @@ -27,6 +27,7 @@ #include "TEEContext.h" #include "TABinaryManager.h" #include "TEEConnectionHandler.h" +#include "UUIDUtils.h" /*----------------------------------------------------------------------------- * Globals @@ -575,8 +576,8 @@ TEEC_Result TEEContext::checkTADomain(IntTAOpenSessionData data) { memcpy(&src, &data.source, sizeof(TEEC_UUID)); memcpy(&dst, &data.destination, sizeof(TEEC_UUID)); - source_uuid = TABin->getUUIDAsString(src); - dest_uuid = TABin->getUUIDAsString(dst); + source_uuid = UUIDToString(src); + dest_uuid = UUIDToString(dst); std::transform(source_uuid.begin(), source_uuid.end(), source_uuid.begin(), ::toupper); std::transform(dest_uuid.begin(), dest_uuid.end(), dest_uuid.begin(), ::toupper); diff --git a/simulatordaemon/src/UUIDUtils.cpp b/simulatordaemon/src/UUIDUtils.cpp new file mode 100644 index 0000000..fd6ef7a --- /dev/null +++ b/simulatordaemon/src/UUIDUtils.cpp @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ + +/** + * @file + * @author Igor Kotrasinski (i.kotrasinsk@partner.samsung.com) + * @brief Useful functions for dealing with UUIDs + */ + +#include +#include +#include + +#include "tee_client_api.h" + +template +static std::string IntToHex(T i, int width = sizeof(T) * 2) { + std::stringstream stream; + stream << std::setfill('0') << std::setw(width) << std::hex << std::uppercase << i; + return stream.str(); +} + +std::string UUIDToString(TEEC_UUID uuid) { + std::stringstream strStream; + strStream << IntToHex(uuid.timeLow); + strStream << IntToHex(uuid.timeMid); + strStream << IntToHex(uuid.timeHiAndVersion); + for (int i = 0; i < 8; i++) { + strStream << IntToHex((short)uuid.clockSeqAndNode[i], 2); + } + return strStream.str(); +}