From: Uladzislau Harbuz Date: Thu, 21 Sep 2017 11:25:11 +0000 (+0200) Subject: Remove UUID list. X-Git-Tag: submit/tizen/20171006.123809~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82d81b491429a88c90a42a449cdc6619893ced86;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Remove UUID list. Change-Id: Ic4b19d896c962261d4bb3366077459c147babb65 --- diff --git a/packaging/tef-simulator-helloworld.spec b/packaging/tef-simulator-helloworld.spec index 8af3ce1..c446ff8 100644 --- a/packaging/tef-simulator-helloworld.spec +++ b/packaging/tef-simulator-helloworld.spec @@ -44,7 +44,6 @@ make install %pre %post -tef-simulator-update-uuid-list.sh 00000000000000000000112233445566 %preun diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index bff2591..521bcbf 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -22,14 +22,12 @@ PreReq: tef-libteec %{?systemd_requires} %define bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir} -%define sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir} %define lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir} %define data_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:%_datadir} %define include_dir %{?TZ_SYS_INCLUDE:%TZ_SYS_INCLUDE}%{!?TZ_SYS_INCLUDE:%_includedir} %define tastore_dir %{lib_dir}/tastore %define build_bin_dir %{buildroot}%{bin_dir} -%define build_sbin_dir %{buildroot}%{sbin_dir} %define build_lib_dir %{buildroot}%{lib_dir} %define build_data_dir %{buildroot}%{data_dir} %define build_include_dir %{buildroot}%{include_dir} @@ -75,7 +73,6 @@ with TEF Simulator. cmake . \ -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \ -DBIN_DIR=%{build_bin_dir} \ - -DSBIN_DIR=%{build_sbin_dir} \ -DLIB_DIR=%{build_lib_dir} \ -DDATA_DIR=%{build_data_dir} \ -DINCLUDE_DIR=%{build_include_dir} \ @@ -103,7 +100,6 @@ tef-update.sh %files -n %{name} %{bin_dir}/tef-simulator-daemon %{lib_dir}/libtef-simulator-ssflib.so -%{sbin_dir}/tef-simulator-update-uuid-list.sh %{_unitdir}/tef-simulator.service %{_unitdir}/tef-simulator.socket %{_unitdir}/tef-simulator.target diff --git a/simulatordaemon/CMakeLists.txt b/simulatordaemon/CMakeLists.txt index e5e2897..ad60059 100644 --- a/simulatordaemon/CMakeLists.txt +++ b/simulatordaemon/CMakeLists.txt @@ -102,5 +102,3 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DAEMON} ) INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_DAEMON} DESTINATION ${BIN_DIR}) -INSTALL(PROGRAMS ${DAEMON_PATH}/src/scripts/update_uuid_list.sh DESTINATION ${SBIN_DIR} - RENAME ${TARGET_TEF_SIMULATOR}-update-uuid-list.sh) diff --git a/simulatordaemon/src/TABinaryManager/Config.h b/simulatordaemon/src/TABinaryManager/Config.h index fdd3b1b..0bd4c64 100644 --- a/simulatordaemon/src/TABinaryManager/Config.h +++ b/simulatordaemon/src/TABinaryManager/Config.h @@ -27,6 +27,5 @@ * MACROS *-----------------------------------------------------------------------------*/ #define TA_STORE_PATH "/usr/lib/tastore/" -#define TA_UUID_LIST_PATH "/usr/lib/tastore/uuidlist.list" #endif /* CONFIG_H_ */ diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp index 17fff38..77aba5e 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp @@ -34,6 +34,7 @@ #include #include #include +#include /*----------------------------------------------------------------------------- * Globals *-----------------------------------------------------------------------------*/ @@ -134,11 +135,6 @@ TABinaryManager::TABinaryManager() { "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; - struct stat attr; - if (stat(TA_UUID_LIST_PATH, &attr) == -1) { - LOGE(SIM_DAEMON, "stat FAILED %d", errno); - } - lastModTimeUUIDList = attr.st_mtime; pthread_rwlock_init(&binaryMapLock, NULL); pthread_mutex_init(&taLock, NULL); } @@ -166,12 +162,11 @@ bool TABinaryManager::initTAatPath(const string &path, const string &uuid) { LOGD(SIM_DAEMON, ""); pthread_rwlock_wrlock(&binaryMapLock); - map::iterator it = binaryMap.find(uuid); StructBinaryInfo value; bool res = false; StructBinaryInfo info; - if (it != binaryMap.end()) { + if (boost::filesystem::exists(path + uuid)) { pthread_mutex_lock(&taLock); try { if (unpackBinary(uuid, path, info)) { @@ -187,114 +182,6 @@ bool TABinaryManager::initTAatPath(const string &path, const string &uuid) { return res; } -/** - * This function reads UUID list file and unpacks files to their respective - * locations. - * @return On successful completion of above operations returns true else false. - * It is very important to check for return value from this function. - */ - -bool TABinaryManager::readUUIDList() { - LOGD(SIM_DAEMON, ""); - string line; - struct flock fl = {F_RDLCK, SEEK_SET, 0, 0, 0}; - - fl.l_pid = getpid(); - - // Open file - int fd = open(TA_UUID_LIST_PATH, O_RDONLY); - - if (fd == -1) return false; - FILE *fp = fdopen(fd, "r"); - if (fcntl(fd, F_SETLKW, &fl) == -1) { - perror("fcntl"); - fclose(fp); - return false; - } - pthread_rwlock_wrlock(&binaryMapLock); - - //wh - std::ifstream uuidFileStream(TA_UUID_LIST_PATH); - std::string str; - if(uuidFileStream) { - getline(uuidFileStream, str); - line = line + str; - } else { - LOGD(SIM_DAEMON, "Failed to open uuid file"); - } - - /* - int ch = fgetc(fp); - while ((ch != '\n') && (ch != EOF)) { - line = line + ch; - ch = fgetc(fp); - }*/ - - while (line != "") { - line = line + "\0"; - StructBinaryInfo info; - - char* data = (char*)OsaMalloc((strlen(line.c_str()) + 1) * sizeof(char)); - char* uuid_data; - strncpy(data, line.c_str(), (strlen(line.c_str()) + 1) * sizeof(char)); - uuid_data = strtok(data, ","); - - const string uuid(data); - if (uuid_data != NULL) { - char* port_data; - port_data = strtok(NULL, ","); - if (port_data != NULL) { - string port(port_data); - info.port = port; - } else info.port = ""; - } - - // Open file - FILE *fpTA=fopen((string(TA_STORE_PATH) + uuid).c_str(),"r+"); - if (flock(fileno(fpTA),LOCK_EX) != 0) { // do an exclusive lock - LOGE(SIM_DAEMON, "Failed to lock the file"); - } - - pthread_mutex_lock(&taLock); - if (unpackBinary(uuid, TA_STORE_PATH, info)) { - binaryMap[uuid] = info; - } - pthread_mutex_unlock(&taLock); - - if (flock(fileno(fpTA),LOCK_UN) != 0) { - LOGE(SIM_DAEMON, "Failed to unlock the file"); - } - - fclose(fpTA); - OsaFree(data); - - line = ""; - - if(uuidFileStream) { - getline(uuidFileStream, str); - line = line + str; - } - - /* - ch = fgetc(fp); - while ((ch != '\n') && (ch != EOF)) { - line = line + ch; - ch = fgetc(fp); - }*/ - - } - pthread_rwlock_unlock(&binaryMapLock); - fl.l_type = F_UNLCK; - if (fcntl(fd, F_SETLKW, &fl) == -1) { - perror("fcntl"); - fclose(fp); - return false; - } - if(uuidFileStream) - uuidFileStream.close(); - fclose(fp); - return true; -} /** * This function decrypts the TA Binary image @@ -387,18 +274,6 @@ bool TABinaryManager::unpackBinary(const string &uuid, const string &path, Struc return ret; } -/** - * This is the main function of TABinaryManger. This function reads UUID list file - * and unpacks files to their respective locations. It also reads manifest file and - * keeps it ready for queries on fields in manifest. - * @return On successful completion of above operations returns true else false. - * It is very important to check for return value from this function. - */ -bool TABinaryManager::initBinaryManager() { - LOGD(SIM_DAEMON, ""); - return readUUIDList(); -} - /** * Check if TA is single instance * @param[in] uuid UUID of TA @@ -407,7 +282,6 @@ bool TABinaryManager::initBinaryManager() { */ int TABinaryManager::isSingleInstance(string uuid, bool &SingleInstance) { - checkUUIDUpdate(); pthread_rwlock_wrlock(&binaryMapLock); map::iterator it = binaryMap.find(uuid); StructBinaryInfo value; @@ -430,7 +304,6 @@ int TABinaryManager::isSingleInstance(string uuid, bool &SingleInstance) { */ int TABinaryManager::isKeepAlive(string uuid, bool &KeepAlive) { - checkUUIDUpdate(); pthread_rwlock_wrlock(&binaryMapLock); map::iterator it = binaryMap.find(uuid); StructBinaryInfo value; @@ -452,7 +325,6 @@ int TABinaryManager::isKeepAlive(string uuid, bool &KeepAlive) { * @return -1 if uuid is not found else on success 0 */ int TABinaryManager::isMultipleSession(string uuid, bool &MultipleSession) { - checkUUIDUpdate(); pthread_rwlock_wrlock(&binaryMapLock); map::iterator it = binaryMap.find(uuid); StructBinaryInfo value; @@ -473,7 +345,6 @@ int TABinaryManager::isMultipleSession(string uuid, bool &MultipleSession) { * @return Empty string if UUID doesn't exist, else path to TA */ string TABinaryManager::getImagePath(string uuid) { - checkUUIDUpdate(); pthread_rwlock_wrlock(&binaryMapLock); map::iterator it = binaryMap.find(uuid); StructBinaryInfo value; @@ -493,7 +364,6 @@ string TABinaryManager::getImagePath(string uuid) { * @return NULL pointer if */ const TAManifest* TABinaryManager::getManifest(string uuid) { - checkUUIDUpdate(); pthread_rwlock_wrlock(&binaryMapLock); map::iterator it = binaryMap.find(uuid); TAManifest *returnValue = NULL; @@ -526,7 +396,6 @@ string TABinaryManager::getPort(string uuid) { * @return string of TEEC_UUID */ string TABinaryManager::getUUIDAsString(TEEC_UUID uuid) { - checkUUIDUpdate(); // E.g. returns a string in the format 79B7778897894a7aA2BEB60155EEF5F3 std::stringstream strStream; strStream << IntToHex(uuid.timeLow); @@ -538,24 +407,6 @@ string TABinaryManager::getUUIDAsString(TEEC_UUID uuid) { return strStream.str(); } -/** - * This function checks for UUID update and reads the list in case of update - */ -void TABinaryManager::checkUUIDUpdate() { - struct stat attr; - if (stat(TA_UUID_LIST_PATH, &attr) == -1) { - LOGE(SIM_DAEMON, "stat FAILED"); - return; - } - if (lastModTimeUUIDList != attr.st_mtime) { - readUUIDList(); - if (stat(TA_UUID_LIST_PATH, &attr) == -1) { - LOGE(SIM_DAEMON, "stat FAILED"); - return; - } - lastModTimeUUIDList = attr.st_mtime; - } -} TABinaryManager::~TABinaryManager() { pthread_rwlock_destroy(&binaryMapLock); diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.h b/simulatordaemon/src/TABinaryManager/TABinaryManager.h index fc60d12..ab852b8 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.h +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.h @@ -65,9 +65,7 @@ private: std::string base64_chars; // map < string uuid, StructBinaryInfo> map binaryMap; - time_t lastModTimeUUIDList; TABinaryManager(); - bool readUUIDList(); bool unpackBinary(const string &uuid, const string &path, StructBinaryInfo& info); template std::string IntToHex(T i, int width = sizeof(T) * 2) { @@ -75,7 +73,6 @@ private: stream << std::setfill('0') << std::setw(width) << std::hex << i; return stream.str(); } - void checkUUIDUpdate(); void decryptImage(StructBinaryInfo& info); string base64_decode(std::string const& encoded_string); bool is_base64(unsigned char c); @@ -90,7 +87,6 @@ public: */ pthread_mutex_t taLock; static TABinaryManager* getInstance(); - bool initBinaryManager(); bool initTAatPath(const string &path, const string &uuid); /* diff --git a/simulatordaemon/src/TABinaryManager/TestMain.cpp b/simulatordaemon/src/TABinaryManager/TestMain.cpp index dc9de89..2d9e1dc 100644 --- a/simulatordaemon/src/TABinaryManager/TestMain.cpp +++ b/simulatordaemon/src/TABinaryManager/TestMain.cpp @@ -69,21 +69,19 @@ int test_main() { // Test TA Binary Manager case 4: { TABinaryManager *bm = TABinaryManager::getInstance(); - if (bm->initBinaryManager()) { - std::cout << "[SIM_DAEMON] Binary Manager successfully initialized" - << std::endl; - std::cout - << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000000000c7: " - << bm->getImagePath("0000-0000-0000-0000000000c7") << std::endl; - std::cout - << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000001234d5: " - << bm->getImagePath("0000-0000-0000-0000001234d5") << std::endl; - std::cout - << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000004567c8: " - << bm->getImagePath("0000-0000-0000-0000004567c8") << std::endl; - bm->getManifest("0000-0000-0000-0000004567c8")->printProcessedData(); + std::cout << "[SIM_DAEMON] Binary Manager successfully initialized" + << std::endl; + std::cout + << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000000000c7: " + << bm->getImagePath("0000-0000-0000-0000000000c7") << std::endl; + std::cout + << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000001234d5: " + << bm->getImagePath("0000-0000-0000-0000001234d5") << std::endl; + std::cout + << "[SIM_DAEMON] Image Path of 0000-0000-0000-0000004567c8: " + << bm->getImagePath("0000-0000-0000-0000004567c8") << std::endl; + bm->getManifest("0000-0000-0000-0000004567c8")->printProcessedData(); - } break; } diff --git a/simulatordaemon/src/TAFactory.cpp b/simulatordaemon/src/TAFactory.cpp index b744b70..9b71174 100644 --- a/simulatordaemon/src/TAFactory.cpp +++ b/simulatordaemon/src/TAFactory.cpp @@ -62,19 +62,9 @@ TAFactory* TAFactory::getInstance() { LOGD(SIM_DAEMON, "Entry"); pthread_mutex_lock(&instLock); - bool result; // Check if the instance is not yet craeted if (NULL == instance) { - // Create a new instance of TA Binary Manager - TABinaryManager *TABin = TABinaryManager::getInstance(); - // Initialize TA Binary Manager - result = TABin->initBinaryManager(); - if (true != result) { - LOGD(SIM_DAEMON, "initBinaryManager FAILED"); - pthread_mutex_unlock(&instLock); - return instance; - } // Create a new instance of TA Factory instance = new TAFactory(); } diff --git a/simulatordaemon/src/scripts/update_uuid_list.sh b/simulatordaemon/src/scripts/update_uuid_list.sh deleted file mode 100755 index 940bf4f..0000000 --- a/simulatordaemon/src/scripts/update_uuid_list.sh +++ /dev/null @@ -1,1203 +0,0 @@ -#!/bin/sh -# Copyright (c) 2015-2017 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 Krishna Raghottam Devale -# -# This script creates a uuidlist.list file and populates it with TA UUID packages names. -# Ths file is populated based on the existing files in directory /tmp/tastore/ -# UUID pattern is: ....-....-....-............ -# This script should be executed once all the TA packages are transferred to /tmp/tastore - - -#uuidfile="./tastore/uuidlist.list"; -uuidfile="/usr/lib/tastore/uuidlist.list"; - -retval="" -file="/tmp/fileLock" - -S=< $uuidfile - - # just for testing script input - #echo $@ >> $uuidfile - - #if port exists, test if it is blocked - if [ -n "$port" ] - then - #Test if port number is blocked - process=`netstat -nlp | grep $port | awk '{print $7}' | cut -d '/' -f 1` - - # check if port is blocked and find empty port by looping - if [ -n "$process" ]; then - while [ -n "$process" ] - do - port=`expr $port + 1` - process=`netstat -nlp | grep $port | awk '{print $7}' | cut -d '/' -f 1` - var="$uuid,$port" - done - retval="$retval#$var" - fi - fi - - echo $var >> $uuidfile -done -sed '/^$/d' $uuidfile > $uuidfile.temp && mv $uuidfile.temp $uuidfile -echo $S 1 | openssl base64 -d -echo $retval - -# OLD SCRIPT FILE BACKUP - -#uuidfile="/tmp/tastore/uuidlist.list"; -#rm -f $uuidfile; - -#for filename in $(find /tmp/tastore/ -maxdepth 1 -regex ".*/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" ! -name "*ext"); do -#strip off the complete path, retain only the file names -#(echo "${filename:13}" >> $uuidfile); -#done diff --git a/ssflib/src/ssf_storage.cpp b/ssflib/src/ssf_storage.cpp index 8f6b021..33a494e 100644 --- a/ssflib/src/ssf_storage.cpp +++ b/ssflib/src/ssf_storage.cpp @@ -39,7 +39,6 @@ #define PO_INTERNAL_MODULE_NAME "po_file" #define PO_STAT_INTERNAL_MODULE_NAME "po_stat" #define PI_FILE_NAME "pi_file" -#define UUID_FILE "/usr/lib/tastore/uuidlist.uuid" TEE_UUID ssf_sharedthisTAUUID; static TEE_UUID this_uuid; @@ -82,60 +81,6 @@ int get_uuid() { this_uuid = ssf_sharedthisTAUUID; uuid_got = 1; return 0; -#if 0 - if (uuid_got) - { - return 0; - } - char ta_name[256] = - { 0}; - if (0 != get_ta_name(ta_name)) - { - MSG("Failed to get ta name."); - return -1; - } - FILE* f = fopen(UUID_FILE, "r"); - if (!f) - { - MSG("Can't open file %s\n", UUID_FILE); - return -1; - } - char name[256]; - char *line = NULL; - size_t len = 0; - ssize_t read_bytes; - int matched = 0; - TEE_UUID uuid; - while (-1 != getline(&line, &len, f)) - { - matched = - sscanf(line, - "TA={ %x , %hx , %hx , { %hhx , %hhx , %hhx , %hhx , %hhx , %hhx , %hhx , %hhx } } : %64s", - &uuid.timeLow, &uuid.timeMid, &uuid.timeHiAndVersion, - &uuid.clockSeqAndNode[0], &uuid.clockSeqAndNode[1], - &uuid.clockSeqAndNode[2], &uuid.clockSeqAndNode[3], - &uuid.clockSeqAndNode[4], &uuid.clockSeqAndNode[5], - &uuid.clockSeqAndNode[6], &uuid.clockSeqAndNode[7], - name); - if (matched != 12 || matched == EOF) - { - MSG("bad format for uuid:%s\n", line); - continue; - } - OsaFree(line); - line = NULL; - MSG("ta_name [%s] <=> name [%s]", ta_name, name); - if (0 == memcmp(ta_name, name, strlen(ta_name))) - { - this_uuid = uuid; - uuid_got = 1; - fclose(f); - return 0; - } - } - fclose(f); - return -1; -#endif } void printhex(unsigned char* buf, unsigned int size) {