From 3fdc864a361c0c3566a534f007e023aaa3b5d4d4 Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Tue, 13 Feb 2018 10:15:32 +0100 Subject: [PATCH] Separate extract path support Change-Id: I0741a959e01858941e3e5a23e5f032f237af2a33 --- CMakeLists.txt | 1 + TEEStub/PropertyAccess/PropertyApi.cpp | 2 +- include/include/config.h | 5 +++++ packaging/tef-simulator.spec | 3 +++ simulatordaemon/CMakeLists.txt | 1 + simulatordaemon/src/TABinaryManager/TABinaryManager.cpp | 4 ++-- simulatordaemon/src/TABinaryManager/TAUnpack.cpp | 15 ++++++++------- simulatordaemon/src/TABinaryManager/TAUnpack.h | 2 +- 8 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e3144b..147e771 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ ADD_DEFINITIONS("-Werror") # Make all warnings into errors. ADD_DEFINITIONS("-D_ARCH_=${ARCH}") ADD_DEFINITIONS(-DTEE_TASTORE_ROOT="${TASTORE_DIR}/") +ADD_DEFINITIONS(-DTEE_EXTRACT_ROOT="${EXTRACT_DIR}/") ADD_DEFINITIONS(-DTEE_SS_ROOT="${STORAGE_DIR}/") ADD_DEFINITIONS(-DTEE_TALOG_ROOT="${TALOG_DIR}/") diff --git a/TEEStub/PropertyAccess/PropertyApi.cpp b/TEEStub/PropertyAccess/PropertyApi.cpp index 50e3a99..da9da5e 100644 --- a/TEEStub/PropertyAccess/PropertyApi.cpp +++ b/TEEStub/PropertyAccess/PropertyApi.cpp @@ -326,7 +326,7 @@ void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator, switch ((uintptr_t)propSet) { case TEE_PROPSET_CURRENT_TA: { newEnumHandle->property = new TAProperty( - string(TEE_TASTORE_ROOT) + thisTAUUIDGlobal + "-ext/" + string(TEE_EXTRACT_ROOT) + thisTAUUIDGlobal + "-ext/" + thisTAUUIDGlobal + ".manifest"); break; } diff --git a/include/include/config.h b/include/include/config.h index a037025..97abb4b 100644 --- a/include/include/config.h +++ b/include/include/config.h @@ -33,6 +33,10 @@ #endif #endif +#ifndef TEE_EXTRACT_ROOT +#define TEE_EXTRACT_ROOT "/opt/usr/apps/ta_sdk/extract/" +#endif + #ifndef TEE_SS_ROOT #define TEE_SS_ROOT "/opt/usr/apps/ta_sdk/data/" #endif @@ -41,6 +45,7 @@ #define TEE_TALOG_ROOT "/var/log/ta/" #endif + //keep in sync with systemd/tef-simulator.socket #define SIMDAEMON_SOCK_PATH "/var/run/simdaemon" diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index 33645b4..8cab70e 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -32,6 +32,7 @@ PreReq: tef-libteec %define tastore_dir /opt/usr/apps/ta_sdk/tee %endif %define storage_dir /opt/usr/apps/ta_sdk/data +%define extract_dir /opt/usr/apps/ta_sdk/extract %define talog_dir /var/log/ta %define build_bin_dir %{buildroot}%{bin_dir} @@ -85,6 +86,7 @@ cmake . \ -DDATA_DIR=%{build_data_dir} \ -DINCLUDE_DIR=%{build_include_dir} \ -DTASTORE_DIR=%{tastore_dir} \ + -DEXTRACT_DIR=%{extract_dir} \ -DSTORAGE_DIR=%{storage_dir} \ -DTALOG_DIR=%{talog_dir} \ -DSYSTEMD_UNIT_DIR=%{build_unit_dir} \ @@ -132,6 +134,7 @@ fi %attr(755,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so %attr(770,root,security_fw) %{talog_dir} %attr(770,root,security_fw) %{storage_dir} +%attr(770,root,security_fw) %{extract_dir} %files -n %{name}-devkit %license LICENSE diff --git a/simulatordaemon/CMakeLists.txt b/simulatordaemon/CMakeLists.txt index e57cc44..f330065 100644 --- a/simulatordaemon/CMakeLists.txt +++ b/simulatordaemon/CMakeLists.txt @@ -105,4 +105,5 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DAEMON} INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_DAEMON} DESTINATION ${BIN_DIR}) INSTALL(DIRECTORY DESTINATION ${BUILD_ROOT}${TASTORE_DIR}) +INSTALL(DIRECTORY DESTINATION ${BUILD_ROOT}${EXTRACT_DIR}) INSTALL(DIRECTORY DESTINATION ${BUILD_ROOT}${STORAGE_DIR}) diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp index 52fba75..c609831 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp @@ -252,11 +252,11 @@ void TABinaryManager::decryptImage(StructBinaryInfo& info) { bool TABinaryManager::unpackBinary(const string &uuid, StructBinaryInfo& info) { TAUnpack* unpacker = TAUnpack::getInstance(); bool ret = false; - if (0 == unpacker->unpackTA(string(TEE_TASTORE_ROOT), uuid)) { + if (0 == unpacker->unpackTA(TEE_TASTORE_ROOT, uuid)) { LOGD(SIM_DAEMON, "Unpacked, filling info"); // 1. Set binary info info.path = string(TEE_TASTORE_ROOT) + uuid; - info.extractpath = string(TEE_TASTORE_ROOT) + uuid + "-ext/"; + info.extractpath = string(TEE_EXTRACT_ROOT) + uuid + "-ext/"; info.imagePath = info.extractpath + uuid + ".image"; info.manifestPath = info.extractpath + uuid + ".manifest"; // 2. Parse manifest and store results diff --git a/simulatordaemon/src/TABinaryManager/TAUnpack.cpp b/simulatordaemon/src/TABinaryManager/TAUnpack.cpp index cce3913..28c906a 100644 --- a/simulatordaemon/src/TABinaryManager/TAUnpack.cpp +++ b/simulatordaemon/src/TABinaryManager/TAUnpack.cpp @@ -61,15 +61,13 @@ TAUnpack* TAUnpack::getInstance() { * @param uuid uuid of package * @return -1 on error otherwise 0 */ -int TAUnpack::unpackTA(string path, string uuid) { +int TAUnpack::unpackTA(const string& path, const string& uuid) { LOGD(SIM_DAEMON, ""); TAPackageHeaderV2 packageHeader; memset(&packageHeader, 0, sizeof(TAPackageHeaderV2)); - // Open file - string path_to_file = path + uuid; - ifstream tapackage(path_to_file.c_str(), ios::in | ios::binary); - // Create directory for UUID - string extract_dir_path = path + uuid + "-ext/"; + + // Create directory for TA extracted files + string extract_dir_path = TEE_EXTRACT_ROOT + uuid + "-ext/"; struct stat info; if (stat(extract_dir_path.c_str(), &info) != 0) { if (0 != mkdir(extract_dir_path.c_str(), 0777)) { @@ -78,8 +76,11 @@ int TAUnpack::unpackTA(string path, string uuid) { } } + // Open TA package file + string path_to_file = path + uuid; + ifstream tapackage(path_to_file.c_str(), ios::in | ios::binary); if (!tapackage.is_open()) { - LOGE(SIM_DAEMON, "Already open - failed"); + LOGE(SIM_DAEMON, "Cannot open ta: %s", path_to_file.c_str()); return -1; //> unable to open file } // 1. Read header diff --git a/simulatordaemon/src/TABinaryManager/TAUnpack.h b/simulatordaemon/src/TABinaryManager/TAUnpack.h index a598e0a..b701d67 100644 --- a/simulatordaemon/src/TABinaryManager/TAUnpack.h +++ b/simulatordaemon/src/TABinaryManager/TAUnpack.h @@ -78,7 +78,7 @@ private: unsigned int paddedSize); public: static TAUnpack* getInstance(); - int unpackTA(string path, string uuid); + int unpackTA(const string& path, const string& uuid); virtual ~TAUnpack(); }; -- 2.7.4