Move UUID conversion to string outside binary manager 99/174799/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Thu, 14 Dec 2017 11:22:40 +0000 (12:22 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 12 Apr 2018 06:59:42 +0000 (06:59 +0000)
Change-Id: I2e87b716d07e87341bdd753a2e3e3267258fe9ec
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/CMakeLists.txt
simulatordaemon/inc/UUIDUtils.h
simulatordaemon/src/ControlConnectionHandler.cpp
simulatordaemon/src/Session.cpp
simulatordaemon/src/TABinaryManager/TABinaryManager.cpp
simulatordaemon/src/TABinaryManager/TABinaryManager.h
simulatordaemon/src/TAFactory.cpp
simulatordaemon/src/TEEContext.cpp
simulatordaemon/src/UUIDUtils.cpp [new file with mode: 0644]

index a844f10..f223a11 100644 (file)
@@ -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
index ca6a5cd..9a6083e 100644 (file)
 #ifndef UUIDUTILS_H_
 #define UUIDUTILS_H_
 
+#include <string>
+#include "tee_client_api.h"
+
+std::string UUIDToString(TEEC_UUID uuid);
+
 class UUIDComparator {
 public:
        bool operator() (const TEEC_UUID &u1, const TEEC_UUID &u2);
index 20ec75f..73a9a96 100644 (file)
@@ -25,6 +25,7 @@
 #include "log.h"
 #include "ControlConnectionHandler.h"
 #include "IConnectionWriter.h"
+#include "UUIDUtils.h"
 
 void ControlConnectionHandler::setWriter(IConnectionWriter<enum ControlCommand> &writer)
 {
@@ -91,7 +92,7 @@ void ControlConnectionHandler::handleSetPortCommand(std::vector<char> &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;
index e57ee3d..0301d6d 100644 (file)
@@ -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);
index 4ab2d1c..1dfb74a 100644 (file)
@@ -36,6 +36,7 @@
 #include <algorithm>
 #include <boost/filesystem.hpp>
 #include <config.h>
+#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);
index 4526a62..b2f7215 100644 (file)
@@ -65,12 +65,6 @@ private:
        map<string, StructBinaryInfo> binaryMap;
        TABinaryManager();
        bool unpackBinary(const string &uuid, const string& tapath, StructBinaryInfo& info);
-       template<typename T>
-       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);
 
index 272b912..f01bf74 100644 (file)
@@ -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.
  *-----------------------------------------------------------------------------*/
 #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;
index bef3ed0..13aa4c1 100644 (file)
@@ -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 (file)
index 0000000..fd6ef7a
--- /dev/null
@@ -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 <string>
+#include <sstream>
+#include <iomanip>
+
+#include "tee_client_api.h"
+
+template<typename T>
+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();
+}