Fix looking for TA in res/tee/ 96/151696/13
authorakoszewski <a.koszewski@samsung.com>
Thu, 21 Sep 2017 13:41:07 +0000 (15:41 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Fri, 6 Oct 2017 12:08:19 +0000 (14:08 +0200)
Search for TA is now non recursive

Change-Id: Ibc1b1e724a6a2762840e72ff9ec43ff1cba4eb35

simulatordaemon/src/SecurityContext.cpp
simulatordaemon/src/TABinaryManager/TABinaryManager.cpp
simulatordaemon/src/TAFactory.cpp

index 3a5c377..adff21a 100644 (file)
@@ -101,6 +101,10 @@ std::string SecurityContext::getCaFullPathFromPkgId(char* pkgid) {
 
        path += "/" + std::string(pkgid) + TA_LOCAL_PATH;
        LOGD(SIM_DAEMON, "Path: %s", path.c_str());
+       if (!fs::exists(path)) {
+               LOGE(SIM_DAEMON, "Path: %s not found", path.c_str());
+               return "";
+       }
 
        return path;
 }
@@ -145,18 +149,13 @@ bool SecurityContext::findRequestedTa(const std::string &ta_name, std::string &a
                return false;
        }
 
-/* Now it searches client’s TA  recursively in subdirectories of it. Maybe
- * in future we will know exact predefined subdirectories or even
- * map Client <-> allowed directories for it*/
-       for(fs::recursive_directory_iterator end, dir(ca_pkg_path); dir != end; ++dir){
-               std::string ta_full_path = dir->path().filename().string() + "/" + ta_name;
-               if(fs::exists(ta_full_path)){
-                       allowed_path = dir->path().filename().string();
-                       return true;
-               }
+       if (!fs::exists(ca_pkg_path + "/" + ta_name)) {
+               LOGE(SIM_DAEMON, "TA %s not found in res/tee/", ta_name.c_str());
+               return false;
        }
 
-       return false;
+       allowed_path = ca_pkg_path + "/";
+       return true;
 }
 
 
index 15ea234..d7b3b79 100644 (file)
@@ -159,7 +159,7 @@ TABinaryManager* TABinaryManager::getInstance() {
  * @return On successful completion of above operations returns true else false.
  */
 bool TABinaryManager::initTAatPath(const string &path, const string &uuid) {
-       LOGD(SIM_DAEMON, "");
+       LOGD(SIM_DAEMON, "Entry");
 
        pthread_rwlock_wrlock(&binaryMapLock);
        StructBinaryInfo value;
@@ -247,9 +247,9 @@ void TABinaryManager::decryptImage(StructBinaryInfo& info) {
 bool TABinaryManager::unpackBinary(const string &uuid, const string &path, StructBinaryInfo& info) {
        TAUnpack* unpacker = TAUnpack::getInstance();
        bool ret = false;
-       LOGE(SIM_DAEMON, "Unpacking TA %s in %s", uuid.c_str(), path.c_str());
+       LOGD(SIM_DAEMON, "Unpacking TA %s in %s", uuid.c_str(), path.c_str());
        if (0 == unpacker->unpackTA(path, uuid)) {
-               LOGE(SIM_DAEMON, "Unpacked, filling info");
+               LOGD(SIM_DAEMON, "Unpacked, filling info");
                // 1. Set binary info
                info.path = path + uuid;
                info.extractpath = path + uuid + "-ext/";
@@ -258,7 +258,7 @@ bool TABinaryManager::unpackBinary(const string &uuid, const string &path, Struc
                // 2. Parse manifest and store results
                info.manifest.processXML(info.manifestPath);
 
-               LOGE(SIM_DAEMON, "Decrypting");
+               LOGD(SIM_DAEMON, "Decrypting");
                // 3. Decrypt image using secret value in manifest
                if (info.manifest.properties.extension.launchMode == "debug")
                  decryptImage(info);
index 9b71174..cc6b3b2 100644 (file)
@@ -359,6 +359,7 @@ bool TAFactory::launchTA(string path, string TAUUID, std::stringstream& str, boo
        int32_t result = -1;
        pthread_t thread;
        LOGD(SIM_DAEMON, "Entry");
+       LOGD(SIM_DAEMON, "Path: %s", path.c_str());
 
        // Get TABinaryManager instance
        TABinaryManager *TABin = TABinaryManager::getInstance();
@@ -366,6 +367,7 @@ bool TAFactory::launchTA(string path, string TAUUID, std::stringstream& str, boo
        string argvPath = "";
        if (TABin->initTAatPath(path, TAUUID)) {
                argvPath = TABin->getImagePath(TAUUID);
+               LOGD(SIM_DAEMON, "argvPath: ", argvPath.c_str());
        }
        if ("" == argvPath) {
                LOGE(SIM_DAEMON, "Trusted Application does not exist");