TEEStub: Use TA executable path to find manifest 58/154058/3
authorLukasz Kostyra <l.kostyra@samsung.com>
Thu, 5 Oct 2017 16:26:08 +0000 (18:26 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Fri, 6 Oct 2017 12:08:54 +0000 (14:08 +0200)
When launching downloadable TAs, TEEStub still attempted to
search for TA's manifest on system TA store, which resulted
in crashing TA and failing OpenSession call.

TEEStub now uses argv[0] to extract both UUID and home directory
of TA, which are used to open manifest file.

Change-Id: I7c1037ccc34574517a882c4f3e6532199a6d64f1

TEEStub/PropertyAccess/PropertyApi.cpp
TEEStub/PropertyAccess/PropertyApi.h
TEEStub/teestubmain.cpp

index 51e1093..93c67ba 100644 (file)
@@ -33,6 +33,7 @@
 #include "config.h"\r
 #include <string.h>\r
 #include <set>\r
+#include "log.h"\r
 \r
 using namespace std;\r
 \r
@@ -68,26 +69,27 @@ std::set<PropertyEnumHandle*> propertyEnumHandleSet;
 /**\r
  * Initialization routine of PropertyAccess Module. This function should be\r
  * called when TA stub starts with UUID of this TA.\r
- * @param UUID[in]          UUID of this TA\r
+ * @param uuid[in]          UUID of our TA\r
+ * @param taDir[in]         Directory in which TA resides\r
  * @param clientLogin[in]   login method to this TA from client.\r
  *                          Refer Table 4-13: Client Identities\r
  * @return TEE_ERROR_OUT_OF_MEMORY on failure to initialize else TEE_SUCCESS\r
  */\r
-TEE_Result InitPropertyModule(char* UUID, uint32_t clientLogin) {\r
+TEE_Result InitPropertyModule(const std::string& uuid,\r
+       const std::string& taDir, uint32_t clientLogin) {\r
        PropertyValue pv;\r
        pv.type = "identity";\r
        pv.value = "" + clientLogin;\r
-       string thisTA_UUID(UUID);\r
+\r
        clientLoginGlobal = clientLogin;\r
-       thisTAUUIDGlobal = thisTA_UUID;\r
+       thisTAUUIDGlobal = uuid;\r
+\r
        try {\r
                clientProperty = new ClientProperty(pv);\r
                clientProperty->start();\r
                teeProperty = new TEEProperty();\r
                teeProperty->start();\r
-               taProperty = new TAProperty(\r
-                   string(TEE_TASTORE_ROOT) + thisTA_UUID + "-ext/" + thisTA_UUID\r
-                       + ".manifest");\r
+               taProperty = new TAProperty(taDir + uuid + ".manifest");\r
                taProperty->start();\r
        } catch (std::bad_alloc &ba) {\r
                return TEE_ERROR_OUT_OF_MEMORY;\r
index 64cba1d..1137ffb 100644 (file)
@@ -36,7 +36,8 @@ extern "C" {
 /*-----------------------------------------------------------------------------\r
  *  Functions\r
  *-----------------------------------------------------------------------------*/\r
-TEE_Result InitPropertyModule(char* UUID, uint32_t clientLogin);\r
+TEE_Result InitPropertyModule(const std::string& uuid,\r
+       const std::string& taDir, uint32_t clientLogin);\r
 void DeInitPropertyModule();\r
 \r
 #ifdef  __cplusplus\r
index f522487..d62e74a 100644 (file)
@@ -79,26 +79,28 @@ int main(int argc, char* argv[]) {
        //for export function
        getSharedMemoryAddress(0);
 
+       std::string fullPath(argv[0]);
+
+       // parse UUID from TA's full executable path
+       size_t lastSlashPos = fullPath.rfind('/');
+       size_t taExtPos = fullPath.rfind('.');
+       std::string uuid = fullPath.substr(lastSlashPos + 1, taExtPos - lastSlashPos - 1);
+
+       // grab full TA directory to be able to open the manifest
+       std::string taDir = fullPath.substr(0, lastSlashPos + 1);
+       LOGI(TEE_STUB, "UUID: %s, TA directory: %s", uuid.c_str(), taDir.c_str());
+
        // Initialize Properties module
        // TODO: fetch login method from Context, not to be hardcoded
        TEE_Result initStatus;
-       char uuid[100];
-       int uuidlen = strlen(argv[0]);
-       LOGI(TEE_STUB, "argv[0]: %s\n", argv[0]);
-       LOGI(TEE_STUB, "argv[1]: %s\n", argv[1]);
-       // fetch uuid from argv[0]
-       int i, j;
-       for (i = uuidlen - 38, j = 0; i < uuidlen - 6; j++, i++) {
-               uuid[j] = argv[0][i];
-       }
-       uuid[j] = '\0';
        // Inititalize the property module
-       initStatus = InitPropertyModule(uuid, TEE_LOGIN_PUBLIC);
+       initStatus = InitPropertyModule(uuid, taDir, TEE_LOGIN_PUBLIC);
+
        // Pass UUID to SSF
        TEE_UUID out;
        PropertyValue pv;
        pv.type = "uuid";
-       pv.value = string(uuid);
+       pv.value = uuid;
        PropertyUtility::convertToUUID(pv, out);
        ssf_sharedthisTAUUID = out;