Use TEEC_UUID instead of string for map keys 00/174800/3
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Thu, 14 Dec 2017 10:04:08 +0000 (11:04 +0100)
committerTomasz Swierczek <t.swierczek@samsung.com>
Thu, 12 Apr 2018 07:00:24 +0000 (07:00 +0000)
Change-Id: I9328ba8b6cf7ad4fca5acef839b77e1f3644d6c9
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/inc/TAFactory.h
simulatordaemon/src/ControlConnectionHandler.cpp
simulatordaemon/src/ResponseCommands/ResCommandCloseSession.cpp
simulatordaemon/src/Session.cpp
simulatordaemon/src/TABinaryManager/TABinaryManager.cpp
simulatordaemon/src/TABinaryManager/TABinaryManager.h
simulatordaemon/src/TABinaryManager/TestMain.cpp
simulatordaemon/src/TAFactory.cpp
simulatordaemon/src/TEEContext.cpp

index 3f7b092..933b6d9 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.
@@ -21,7 +21,7 @@
  */
 
 
-#if !defined(_TAFACTORY_H)
+#ifndef _TAFACTORY_H
 #define _TAFACTORY_H
 
 /*-----------------------------------------------------------------------------
@@ -37,6 +37,7 @@
 #include "ISession.h"
 #include "TAInstance.h"
 #include "TABinaryManager.h"
+#include "UUIDUtils.h"
 
 /*-----------------------------------------------------------------------------
  *  Class definitions
@@ -44,7 +45,7 @@
 class TAFactory {
 public:
        pthread_rwlock_t mTAInstanceMapLock;
-       multimap<string, TAInstancePtr> mTAInstanceMap;
+       multimap<TEEC_UUID, TAInstancePtr, UUIDComparator> mTAInstanceMap;
        static TAFactory* getInstance();
        TAInstancePtr getTAInstance(TEEC_UUID TAUUID, ISession* session);
 private:
@@ -53,9 +54,9 @@ private:
        pthread_rwlock_t instIDLock;
        uint32_t InstID;
        TAFactory();
-       bool checkIfTARunning(string TAUUID);
-       TAInstancePtr createUninitalizedTAInstance(string TAUUID, ISession* session);
-       bool launchTA(string TAUUID, std::stringstream& str, bool debug, pid_t& pid);
+       bool checkIfTARunning(TEEC_UUID TAUUID);
+       TAInstancePtr createUninitalizedTAInstance(TEEC_UUID TAUUID, ISession* session);
+       bool launchTA(TEEC_UUID TAUUID, std::stringstream& str, bool debug, pid_t& pid);
        static void* waitForChild(void *pid);
        void cleanupTAInstance(pid_t PID);
        ~TAFactory();
index 73a9a96..67f7d26 100644 (file)
@@ -93,7 +93,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 = UUIDToString(cmd.uuid);
-       ret = binaryManager->setPort(uuidString, portString);
+       ret = binaryManager->setPort(cmd.uuid, portString);
        if (!ret) {
                reply.status = CTL_REPLY_SUCCESS;
                LOGI(SIM_DAEMON, "Set debug port of UUID %s to %s",
index 896d008..9c8f3db 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.
@@ -62,9 +62,8 @@ void ResCommandCloseSession::execute() {
                ISession* session = it->second;
                (session->getTAInstance())->takeSessionMapLock();
                pSessionMap->erase(it);
-               multimap<string, TAInstancePtr>::iterator itTAMap;
                pthread_rwlock_wrlock(&TAFact->mTAInstanceMapLock);
-               for (itTAMap = TAFact->mTAInstanceMap.begin();
+               for (auto itTAMap = TAFact->mTAInstanceMap.begin();
                    itTAMap != TAFact->mTAInstanceMap.end(); ++itTAMap) {
                        if (itTAMap->second == session->getTAInstance()) {
                                if (pSessionMap->size() == 0) {
index 0301d6d..35f435d 100644 (file)
@@ -111,16 +111,11 @@ TEEC_Result Session::createSession(OpenSessionData data) {
                LOGE(SIM_DAEMON, "Creating TABinaryManager Instance FAILED - ");
                return TEEC_ERROR_GENERIC;
        }
-       string TAUUID = UUIDToString(data.uuid);
-       string argvPort = TABin->getPort(TAUUID);
-
-       string TAName(TAUUID);
-       std::transform(TAName.begin(), TAName.end(), TAName.begin(), ::toupper);
+       string argvPort = TABin->getPort(data.uuid);
 
        if (argvPort != "") {
                pthread_rwlock_wrlock(&TAFact->mTAInstanceMapLock);
-               multimap<string, TAInstancePtr>::iterator itr;
-               itr = TAFact->mTAInstanceMap.find(TAUUID);
+               auto itr = TAFact->mTAInstanceMap.find(data.uuid);
                if (itr != TAFact->mTAInstanceMap.end()) {
                        mTAInstance = itr->second;
                        LOGD(SIM_DAEMON, "KILL pid = %d", mTAInstance->getPID());
@@ -151,8 +146,7 @@ TEEC_Result Session::createSession(OpenSessionData data) {
                if (TEEC_SUCCESS != result) { // failure
                        LOGE(SIM_DAEMON, "Create TA entry point FAILED");
                        pthread_rwlock_wrlock(&TAFact->mTAInstanceMapLock);
-                       multimap<string, TAInstancePtr>::iterator it;
-                       for (it = TAFact->mTAInstanceMap.begin();
+                       for (auto it = TAFact->mTAInstanceMap.begin();
                            it != TAFact->mTAInstanceMap.end(); ++it) {
                                if (it->second == mTAInstance) {
                                        // Kill the TA process
@@ -313,13 +307,11 @@ TEEC_Result Session::finalize(uint32_t contextID) {
                mTAInstance->takeSessionMapLock();
                mTAInstance->eraseSessionMap(mSessionID);
 
-               multimap<string, TAInstancePtr>::iterator itTAMap;
-
                /* Check if this is the last session associated with the TA Instance.
                 * If it is the last instance then check for KeepAlive flag.
                 */
                pthread_rwlock_wrlock(&TAFact->mTAInstanceMapLock);
-               for (itTAMap = TAFact->mTAInstanceMap.begin();
+               for (auto itTAMap = TAFact->mTAInstanceMap.begin();
                    itTAMap != TAFact->mTAInstanceMap.end(); ++itTAMap) {
                        if (itTAMap->second == mTAInstance) {
                                /* If this is the last session associated with TA then check for
index 1dfb74a..c659636 100644 (file)
@@ -44,7 +44,7 @@ namespace fs = boost::filesystem;
  *-----------------------------------------------------------------------------*/
 TABinaryManager *TABinaryManager::instance = NULL;
 pthread_rwlock_t binaryMapLock;
-map<string, StructBinaryInfo> binaryMap;
+map<TEEC_UUID, StructBinaryInfo, UUIDComparator> binaryMap;
 
 /*-----------------------------------------------------------------------------
  *  Member functions
@@ -162,7 +162,7 @@ TABinaryManager* TABinaryManager::getInstance() {
  * This function add TA to BinaryManager if it exists.
  * @return On successful completion of above operations returns true else false.
  */
-bool TABinaryManager::initTA(const string &uuid) {
+bool TABinaryManager::initTA(const TEEC_UUID &uuid) {
        LOGD(SIM_DAEMON, "Entry");
 
        std::vector<string> paths;
@@ -170,10 +170,11 @@ bool TABinaryManager::initTA(const string &uuid) {
        paths.push_back(TEE_EMBEDDED_TASTORE_ROOT);
        paths.push_back(TEE_TASTORE_ROOT TEE_DOWNLOADED_TA_SUFFIX);
 
+       string uuidStr = UUIDToString(uuid);
        string tapath;
        for(auto const& p: paths) {
                if (p.empty()) continue; // ignore empty paths
-               string path_to_file = p + uuid;
+               string path_to_file = p + uuidStr;
                boost::system::error_code ec;
                if (fs::exists(path_to_file, ec)) {
                        tapath = p;
@@ -182,7 +183,7 @@ bool TABinaryManager::initTA(const string &uuid) {
        }
 
        if (tapath.empty()) {
-               LOGE(SIM_DAEMON, "Cannot find TA: %s", uuid.c_str());
+               LOGE(SIM_DAEMON, "Cannot find TA: %s", uuidStr.c_str());
                return false;
        }
 
@@ -269,16 +270,17 @@ void TABinaryManager::decryptImage(StructBinaryInfo& info) {
  * It is very important to check for return value from this function.
  */
 
-bool TABinaryManager::unpackBinary(const string &uuid, const string& tapath, StructBinaryInfo& info) {
+bool TABinaryManager::unpackBinary(const TEEC_UUID &uuid, const string& tapath, StructBinaryInfo& info) {
        TAUnpack* unpacker = TAUnpack::getInstance();
+       string uuidStr = UUIDToString(uuid);
        bool ret = false;
-       if (0 == unpacker->unpackTA(tapath, uuid)) {
-               LOGD(SIM_DAEMON, "Unpacked TA %s from %s", uuid.c_str(), tapath.c_str());
+       if (0 == unpacker->unpackTA(tapath, uuidStr)) {
+               LOGD(SIM_DAEMON, "Unpacked TA %s from %s", uuidStr.c_str(), tapath.c_str());
                // 1. Set binary info
-               info.path = tapath + uuid;
-               info.extractpath = string(TEE_EXTRACT_ROOT) + uuid + "-ext/";
-               info.imagePath = info.extractpath + uuid + ".image";
-               info.manifestPath = info.extractpath + uuid + ".manifest";
+               info.path = tapath + uuidStr;
+               info.extractpath = string(TEE_EXTRACT_ROOT) + uuidStr + "-ext/";
+               info.imagePath = info.extractpath + uuidStr + ".image";
+               info.manifestPath = info.extractpath + uuidStr + ".manifest";
                // 2. Parse manifest and store results
                info.manifest.processXML(info.manifestPath);
 
@@ -308,9 +310,9 @@ bool TABinaryManager::unpackBinary(const string &uuid, const string& tapath, Str
  * @return -1 if uuid is not found else on success 0
  */
 
-int TABinaryManager::isSingleInstance(string uuid, bool &SingleInstance) {
+int TABinaryManager::isSingleInstance(TEEC_UUID uuid, bool &SingleInstance) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        StructBinaryInfo value;
        int ret = -1;
        if (it != binaryMap.end()) {
@@ -330,9 +332,9 @@ int TABinaryManager::isSingleInstance(string uuid, bool &SingleInstance) {
  * @return -1 if uuid is not found else on success 0
  */
 
-int TABinaryManager::isKeepAlive(string uuid, bool &KeepAlive) {
+int TABinaryManager::isKeepAlive(TEEC_UUID uuid, bool &KeepAlive) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        StructBinaryInfo value;
        int ret = -1;
        if (it != binaryMap.end()) {
@@ -351,9 +353,9 @@ int TABinaryManager::isKeepAlive(string uuid, bool &KeepAlive) {
  * @param[out] isMultipleSession returns value from this parameter.
  * @return -1 if uuid is not found else on success 0
  */
-int TABinaryManager::isMultipleSession(string uuid, bool &MultipleSession) {
+int TABinaryManager::isMultipleSession(TEEC_UUID uuid, bool &MultipleSession) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        StructBinaryInfo value;
        int ret = -1;
        if (it != binaryMap.end()) {
@@ -371,9 +373,9 @@ int TABinaryManager::isMultipleSession(string uuid, bool &MultipleSession) {
  * @param uuid UUID of TA
  * @return Empty string if UUID doesn't exist, else path to TA
  */
-string TABinaryManager::getImagePath(string uuid) {
+string TABinaryManager::getImagePath(TEEC_UUID uuid) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        StructBinaryInfo value;
        string ret = "";
        if (it != binaryMap.end()) {
@@ -390,9 +392,9 @@ string TABinaryManager::getImagePath(string uuid) {
  * @param uuid UUID of TA
  * @return NULL pointer if
  */
-const TAManifest* TABinaryManager::getManifest(string uuid) {
+const TAManifest* TABinaryManager::getManifest(TEEC_UUID uuid) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        TAManifest *returnValue = NULL;
        if (it != binaryMap.end()) {
                //element found;
@@ -407,9 +409,9 @@ const TAManifest* TABinaryManager::getManifest(string uuid) {
  * @param uuid UUID of TA
  * @return NULL pointer if
  */
-string TABinaryManager::getPort(string uuid) {
+string TABinaryManager::getPort(TEEC_UUID uuid) {
        pthread_rwlock_wrlock(&binaryMapLock);
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        string returnValue = "";
        if (it != binaryMap.end()) {
                returnValue = it->second.port;
@@ -418,11 +420,11 @@ string TABinaryManager::getPort(string uuid) {
        return returnValue;
 }
 
-int TABinaryManager::setPort(string uuid, string port) {
+int TABinaryManager::setPort(TEEC_UUID uuid, string port) {
        int ret;
        pthread_rwlock_wrlock(&binaryMapLock);
 
-       map<string, StructBinaryInfo>::iterator it = binaryMap.find(uuid);
+       auto it = binaryMap.find(uuid);
        if (it != binaryMap.end()) {
                it->second.port = port;
                ret = 0;
index b2f7215..70945a7 100644 (file)
@@ -39,6 +39,7 @@
 #include "TAManifest.h"
 #include "TAUnpack.h"
 #include "tee_internal_api.h"
+#include "UUIDUtils.h"
 
 using namespace std;
 
@@ -61,10 +62,9 @@ class TABinaryManager {
 private:
        static TABinaryManager *instance;
        std::string base64_chars;
-       // map < string uuid, StructBinaryInfo>
-       map<string, StructBinaryInfo> binaryMap;
+       map<TEEC_UUID, StructBinaryInfo, UUIDComparator> binaryMap;
        TABinaryManager();
-       bool unpackBinary(const string &uuid, const string& tapath, StructBinaryInfo& info);
+       bool unpackBinary(const TEEC_UUID &uuid, const string& tapath, StructBinaryInfo& info);
        void decryptImage(StructBinaryInfo& info);
        string base64_decode(std::string const& encoded_string);
        bool is_base64(unsigned char c);
@@ -79,22 +79,22 @@ public:
         */
        pthread_mutex_t taLock;
        static TABinaryManager* getInstance();
-       bool initTA (const string &uuid);
+       bool initTA (const TEEC_UUID &uuid);
 
        /*
         * Query functions on Binary Manager
         */
-       int isSingleInstance(string uuid, bool &SingleInstance);
-       int isMultipleSession(string uuid, bool &MultipleSession);
-       string getImagePath(string uuid);
-       const TAManifest* getManifest(string uuid);
-       string getPort(string uuid);
-       int isKeepAlive(string uuid, bool &KeepAlive);
+       int isSingleInstance(TEEC_UUID uuid, bool &SingleInstance);
+       int isMultipleSession(TEEC_UUID uuid, bool &MultipleSession);
+       string getImagePath(TEEC_UUID uuid);
+       const TAManifest* getManifest(TEEC_UUID uuid);
+       string getPort(TEEC_UUID uuid);
+       int isKeepAlive(TEEC_UUID uuid, bool &KeepAlive);
 
        /*
         * TA property setters
         */
-       int setPort(string uuid, string port);
+       int setPort(TEEC_UUID uuid, string port);
 
        virtual ~TABinaryManager();
 };
index 0882888..d6e4f42 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.
@@ -27,6 +27,7 @@
 #include "TAManifest.h"
 #include "TAUnpack.h"
 #include <config.h>
+#include "tee_client_api.h"
 
 using namespace std;
 
@@ -39,9 +40,29 @@ int test_main() {
        cout
            << "4. TA Binary Manager (Read UUID List, unpack all of the binaries, keep meta data ready)"
            << std::endl;
-
+       TEEC_UUID[3] testUUIDs = {
+               {
+                       .timeLow = 0,
+                       .timeMid = 0,
+                       .timeHiAndVersion = 0,
+                       .clockSeqAndNode = {0, 0, 0, 0, 0, 0, 0, 0xc7},
+               },
+               {
+                       .timeLow = 0,
+                       .timeMid = 0,
+                       .timeHiAndVersion = 0,
+                       .clockSeqAndNode = {0, 0, 0, 0, 0, 0x12, 0x34, 0xd5},
+               },
+               {
+                       .timeLow = 0,
+                       .timeMid = 0,
+                       .timeHiAndVersion = 0,
+                       .clockSeqAndNode = {0, 0, 0, 0, 0, 0x45, 0x67, 0xc8},
+               },
+       }
        try {
                while (inp != 0) {
+
                        std::cout << "[SIM_DAEMON] Enter Choice: " << std::endl;
 
                        scanf("%d", &inp);
@@ -72,15 +93,15 @@ int test_main() {
                                        std::cout << "[SIM_DAEMON] Binary Manager successfully initialized"
                                            << std::endl;
                                        std::cout
-                                           << "[SIM_DAEMON] Image Path of 0000000000000000000000c7: "
-                                           << bm->getImagePath("0000000000000000000000c7") << std::endl;
+                                           << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000000000c7: "
+                                           << bm->getImagePath(testUUIDs[0]) << std::endl;
                                        std::cout
-                                           << "[SIM_DAEMON] Image Path of 0000000000000000001234d5: "
-                                           << bm->getImagePath("0000000000000000001234d5") << std::endl;
+                                           << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000001234d5: "
+                                           << bm->getImagePath(testUUIDs[1]) << std::endl;
                                        std::cout
-                                           << "[SIM_DAEMON] Image Path of 0000000000000000004567c8: "
-                                           << bm->getImagePath("0000000000000000004567c8") << std::endl;
-                                       bm->getManifest("0000000000000000004567c8")->printProcessedData();
+                                           << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000004567c8: "
+                                           << bm->getImagePath(testUUIDs[2]) << std::endl;
+                                       bm->getManifest(testUUIDs[2])->printProcessedData();
 
                                        break;
                                }
index f01bf74..3505659 100644 (file)
@@ -28,6 +28,7 @@
 #include "SecurityContext.h"
 #include "UUIDUtils.h"
 #include "ResponseCommands/ResMakeCommand.h"
+#include "tee_client_api.h"
 
 
 /*-----------------------------------------------------------------------------
@@ -86,35 +87,26 @@ 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 = UUIDToString(uuid);
 
-       // Change to upper char. TA list has upper char.
-       locale loc;
-       for (size_t i = 0; i < TAUUID.length(); ++i)
-               TAUUID[i] = toupper(TAUUID[i], loc);
-
-
-       if ((!checkIfTARunning(TAUUID))
-           || ((TABin->isSingleInstance(TAUUID, result) == 0) && (result == false))) {
+       if ((!checkIfTARunning(uuid))
+           || ((TABin->isSingleInstance(uuid, result) == 0) && (result == false))) {
                /* TA instance is not already alive or is Multi Instance, Create a new TA
                 * Instance
                 */
-               TAInst = createUninitalizedTAInstance(TAUUID, session);
+               TAInst = createUninitalizedTAInstance(uuid, session);
                if (!TAInst == true) {
                        LOGE(SIM_DAEMON, "Creating Trusted Application Instance FAILED");
                        return TAInstancePtr();
                }
-       } else if ((TABin->isSingleInstance(TAUUID, result) == 0)
+       } else if ((TABin->isSingleInstance(uuid, result) == 0)
            && (result == true)) {
                // TA is Single Instance and alive
-               if (TABin->isMultipleSession(TAUUID, result) < 0) {
+               if (TABin->isMultipleSession(uuid, result) < 0) {
                        LOGE(SIM_DAEMON, "TA not in list");
                        return TAInstancePtr();
                } else {
-                       multimap<string, TAInstancePtr>::iterator it;
                        // Find alive TA Instance in TA Factory's Instance Map
-                       it = mTAInstanceMap.find(TAUUID);
+                       auto it = mTAInstanceMap.find(uuid);
                        if (it != mTAInstanceMap.end()) {
                                TAInst = it->second;
                                TAInst->takeSessionMapLock();
@@ -155,26 +147,21 @@ TAInstancePtr TAFactory::getTAInstance(TEEC_UUID uuid, ISession* session) {
 /**
  * Check if TA already alive. Return true if it is present in the TA Instance
  * Map else return false
- * @param TAUUID TA UUID in string form
+ * @param TAUUID TA UUID
  */
-bool TAFactory::checkIfTARunning(string TAUUID) {
+bool TAFactory::checkIfTARunning(TEEC_UUID TAUUID) {
        LOGD(SIM_DAEMON, "Entry");
-       bool result = false;
-
-       // Find TA UUID in the TA Instance Map
-       multimap<string, TAInstancePtr>::iterator itr;
-       itr = mTAInstanceMap.find(TAUUID);
-       if (itr != mTAInstanceMap.end()) result = true;
-       return result;
+       auto itr = mTAInstanceMap.find(TAUUID);
+       return itr != mTAInstanceMap.end();
 }
 
 /**
  * Create a new TA Instance by launching the TA specified by TA UUID
- * @param TAUUID TA UUID in string form
+ * @param TAUUID TA UUID
  * @param session Session which requested the TA Instance to be associated
  * with it
  */
-TAInstancePtr TAFactory::createUninitalizedTAInstance(string TAUUID,
+TAInstancePtr TAFactory::createUninitalizedTAInstance(TEEC_UUID TAUUID,
                ISession* session) {
        LOGD(SIM_DAEMON, "Entry");
 
@@ -187,13 +174,18 @@ TAInstancePtr TAFactory::createUninitalizedTAInstance(string TAUUID,
        TEEC_Result result = TEEC_ERROR_COMMUNICATION;
 
        TABinaryManager *TABin = TABinaryManager::getInstance();
+
+       /* FIXME - determine if the socket cares about case */
+       string uuidStr = UUIDToString(TAUUID);
+       std::transform(uuidStr.begin(), uuidStr.end(), uuidStr.begin(), ::toupper);
+
        pthread_rwlock_wrlock(&instIDLock);
 
        /* Generate the endpoint name using UUID and Instance ID to be sent to
         * TEEStub for socket connection
         */
        std::stringstream str;
-       str << TAUUID << "-";
+       str << uuidStr << "-";
        str << InstID;
 
        if (launchTA(TAUUID, str, debug, pid)) {
@@ -272,7 +264,7 @@ TAInstancePtr TAFactory::createUninitalizedTAInstance(string TAUUID,
                pthread_rwlock_unlock(&instIDLock);
 
                // Add the TAInstance in the TA Factory's TA Instance Map
-               mTAInstanceMap.insert(pair<string, TAInstancePtr>(TAUUID, TAInst));
+               mTAInstanceMap.insert(pair<TEEC_UUID, TAInstancePtr>(TAUUID, TAInst));
                return TAInst;
        }
        pthread_rwlock_unlock(&instIDLock);
@@ -307,8 +299,7 @@ void TAFactory::cleanupTAInstance(pid_t PID) {
        TAInstancePtr Inst;
 
        // Find the TA instance associated with the argument PID
-       multimap<string, TAInstancePtr>::iterator itInstanceMap;
-       for (itInstanceMap = mTAInstanceMap.begin();
+       for (auto itInstanceMap = mTAInstanceMap.begin();
            itInstanceMap != mTAInstanceMap.end(); itInstanceMap++) {
                if (itInstanceMap->second->getPID() == PID) {
                        Inst = itInstanceMap->second;
@@ -324,8 +315,7 @@ void TAFactory::cleanupTAInstance(pid_t PID) {
                Inst->cleanup();
                // Remove the TA Instance from the TA Instance Map maintained in TA Factory
                pthread_rwlock_wrlock(&mTAInstanceMapLock);
-               multimap<string, TAInstancePtr>::iterator itMap;
-               for (itMap = mTAInstanceMap.begin(); itMap != mTAInstanceMap.end();
+               for (auto itMap = mTAInstanceMap.begin(); itMap != mTAInstanceMap.end();
                    ++itMap) {
                        if (itMap->second == Inst) {
                                mTAInstanceMap.erase(itMap);
@@ -338,13 +328,13 @@ void TAFactory::cleanupTAInstance(pid_t PID) {
 
 /**
  * Launch the TA instance
- * @param TAUUID TA UUID is string format
+ * @param TAUUID TA UUID
  * @param str string containing the endpoint name to be passed as an argument
  * to TA while launching
  * @param debug debug flag
  * @param pid PID to be update for launched TA
  */
-bool TAFactory::launchTA(string TAUUID, std::stringstream& str, bool debug,
+bool TAFactory::launchTA(TEEC_UUID TAUUID, std::stringstream& str, bool debug,
     pid_t& pid) {
 
        int32_t result = -1;
@@ -353,6 +343,7 @@ bool TAFactory::launchTA(string TAUUID, std::stringstream& str, bool debug,
 
        // Get TABinaryManager instance
        TABinaryManager *TABin = TABinaryManager::getInstance();
+       string uuidStr = UUIDToString(TAUUID);
        // Get TA Image path for launching
        string argvPath = "";
        if (TABin->initTA(TAUUID)) {
@@ -411,7 +402,7 @@ bool TAFactory::launchTA(string TAUUID, std::stringstream& str, bool debug,
                }
 
                ret = posix_spawn_file_actions_addopen(&child_fd_actions, 1,
-                                                      (TEE_TALOG_ROOT + TAUUID + ".log").c_str(),
+                                                      (TEE_TALOG_ROOT + uuidStr + ".log").c_str(),
                                                       O_WRONLY | O_CREAT | O_APPEND | O_SYNC, 0644);
                if (ret != 0) {
                        LOGE(SIM_DAEMON, "posix_spawn_file_actions_addopen failed");
index 13aa4c1..884af47 100644 (file)
@@ -561,7 +561,6 @@ TEEC_Result TEEContext::checkTADomain(IntTAOpenSessionData data) {
 
        const TAManifest* srcTAManifest;
        const TAManifest* dstTAManifest;
-       string source_uuid, dest_uuid;
        string srcCreateDomain;
        string dstAllowedDomain;
        unsigned int dstAllowedDomainCount;
@@ -576,17 +575,14 @@ TEEC_Result TEEContext::checkTADomain(IntTAOpenSessionData data) {
        memcpy(&src, &data.source, sizeof(TEEC_UUID));
        memcpy(&dst, &data.destination, sizeof(TEEC_UUID));
 
-       source_uuid = UUIDToString(src);
-       dest_uuid = UUIDToString(dst);
+       std::string srcStr = UUIDToString(src);
+       std::string dstStr = 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);
-
-       dstTAManifest = TABin->getManifest(dest_uuid);
-       srcTAManifest = TABin->getManifest(source_uuid);
+       dstTAManifest = TABin->getManifest(dst);
+       srcTAManifest = TABin->getManifest(src);
 
        if(srcTAManifest == NULL || dstTAManifest == NULL) {
-               LOGE(SIM_DAEMON, "Can`t find TA Manifest - source_uuid(%s), destination_uuid(%s)", source_uuid.c_str(), dest_uuid.c_str());
+               LOGE(SIM_DAEMON, "Can`t find TA Manifest - source_uuid(%s), destination_uuid(%s)", srcStr.c_str(), dstStr.c_str());
                return TEEC_ERROR_ACCESS_DENIED;
        }