SET(TARGET_TEF_SIMULATOR_OSAL ${TARGET_TEF_SIMULATOR}-osal)
SET(TARGET_TEF_SIMULATOR_DAEMON ${TARGET_TEF_SIMULATOR}-daemon)
SET(TARGET_TEF_SIMULATOR_SSFLIB ${TARGET_TEF_SIMULATOR}-ssflib)
+SET(TARGET_TEF_SIMULATOR_HELLO_WORLD_CA ${TARGET_TEF_SIMULATOR}-helloworld)
+
+# helloworld TA needs to be named after its UUID
+SET(TARGET_TEF_SIMULATOR_HELLO_WORLD_TA 00000000-0000-0000-0000-112233445566)
# below targets need different names due to linking with CAs and TAs (libteec for client)
SET(TARGET_TEF_SIMULATOR_TEEC_LIB teec)
# TEEStub
SET(TEE_STUB_PATH ${TEF_SIMULATOR_ROOT_PATH}/TEEStub)
+# helloworld
+SET(HELLO_WORLD_PATH ${TEF_SIMULATOR_ROOT_PATH}/helloworld)
+SET(HELLO_WORLD_TA_PATH ${HELLO_WORLD_PATH}/ta)
+SET(HELLO_WORLD_CA_PATH ${HELLO_WORLD_PATH}/host)
+
############################# subdirectories ##################################
ADD_SUBDIRECTORY(ssflib)
ADD_SUBDIRECTORY(TEECLib)
ADD_SUBDIRECTORY(TEEStub)
+ADD_SUBDIRECTORY(helloworld)
TEE_Result initStatus;
char uuid[100];
int uuidlen = strlen(argv[0]);
- printf("argv[0]: %s\n", argv[0]);
+ printf("TEESTUB argv[0]: %s\n", argv[0]);
+ printf("TEESTUB 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++) {
--- /dev/null
+# Copyright (c) 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 Lukasz Kostyra (l.kostyra@samsung.com)
+# @brief CMakeLists for tef-simulator CA and TA
+#
+
+############# TA #############
+
+SET(HELLO_WORLD_TA_SOURCES
+ ${HELLO_WORLD_TA_PATH}/hello_world.c
+ )
+
+ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
+ ${HELLO_WORLD_TA_SOURCES}
+ )
+
+ADD_DEPENDENCIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
+ ${TARGET_TEF_SIMULATOR_TEE_STUB}
+ )
+
+INCLUDE_DIRECTORIES(
+ ${TEF_SIMULATOR_INCLUDE_PATH}/include
+ )
+
+TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
+ ${TARGET_TEF_SIMULATOR_TEE_STUB}
+ )
+
+# TODO directory for TAs
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA} DESTINATION ${TASTORE_DIR})
+
+
+############# CA #############
+
+SET(HELLO_WORLD_CA_SOURCES
+ ${HELLO_WORLD_CA_PATH}/main.c
+ )
+
+ADD_EXECUTABLE(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
+ ${HELLO_WORLD_CA_SOURCES}
+ )
+
+ADD_DEPENDENCIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
+ ${TARGET_TEF_SIMULATOR_TEEC_LIB}
+ ${TARGET_TEF_SIMULATOR_HELLO_WORLD_TA}
+ )
+
+INCLUDE_DIRECTORIES(
+ ${TEF_SIMULATOR_INCLUDE_PATH}/include
+ ${HELLO_WORLD_TA_PATH}
+ )
+
+TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA}
+ ${TARGET_TEF_SIMULATOR_TEEC_LIB}
+ )
+
+INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_HELLO_WORLD_CA} DESTINATION ${BIN_DIR})
--- /dev/null
+/**
+ * Copyright (c) 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 Lukasz Kostyra (l.kostyra@samsung.com)
+ * @brief Example Hello World CA for TEF Simulator
+ */
+
+
+#include <err.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <tee_client_api.h>
+#include <hello_world.h>
+
+int main(int argc, char *argv[])
+{
+ TEEC_Result result;
+ TEEC_Context ctx;
+ TEEC_Session sess;
+ TEEC_Operation op;
+ TEEC_UUID uuid = HELLO_WORLD_UUID;
+ uint32_t error;
+
+ result = TEEC_InitializeContext(NULL, &ctx);
+ if (result != TEEC_SUCCESS) {
+ printf("TEEC_InitializeContext failed with result %x\n", result);
+ return -1;
+ }
+
+ result = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &error);
+ if (result != TEEC_SUCCESS) {
+ printf("TEEC_OpenSession failed with result %x\n", result);
+ return -2;
+ }
+
+ memset(&op, 0, sizeof(op));
+ op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
+ op.params[0].value.a = 1;
+
+ printf("Incrementing %d via TA\n", op.params[0].value.a);
+ result = TEEC_InvokeCommand(&sess, HELLO_WORLD_CMD_INC, &op, &error);
+ if (result != TEEC_SUCCESS) {
+ printf("TEEC_InvokeCommand failed with result %x, error %x\n", result, error);
+ return -3;
+ }
+
+ printf("TA incremented value to %d\n", op.params[0].value.a);
+ TEEC_CloseSession(&sess);
+ TEEC_FinalizeContext(&ctx);
+
+ return 0;
+}
--- /dev/null
+/**
+ * Copyright (c) 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 Lukasz Kostyra (l.kostyra@samsung.com)
+ * @brief Example Hello World TA for TEF Simulator
+ */
+
+#include <tee_internal_api.h>
+
+#include "hello_world.h"
+#include <stdio.h>
+
+#define LOG_FUNC() printf("%s has been called\n", __func__)
+
+
+TEE_Result TA_CreateEntryPoint(void)
+{
+ LOG_FUNC();
+ return TEE_SUCCESS;
+}
+
+void TA_DestroyEntryPoint(void)
+{
+ LOG_FUNC();
+}
+
+TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types,
+ TEE_Param params[4],
+ void **sess_ctx)
+{
+ (void)¶ms;
+ (void)&sess_ctx;
+
+ LOG_FUNC();
+
+ uint32_t expectedParams = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE,
+ TEE_PARAM_TYPE_NONE,
+ TEE_PARAM_TYPE_NONE,
+ TEE_PARAM_TYPE_NONE);
+ if (param_types != expectedParams)
+ return TEE_ERROR_BAD_PARAMETERS;
+
+ printf("Hello world!\n");
+
+ return TEE_SUCCESS;
+}
+
+void TA_CloseSessionEntryPoint(const void *sess_ctx)
+{
+ (void)&sess_ctx;
+ LOG_FUNC();
+}
+
+static TEE_Result inc_value(uint32_t param_types,
+ TEE_Param params[4])
+{
+ uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INOUT,
+ TEE_PARAM_TYPE_NONE,
+ TEE_PARAM_TYPE_NONE,
+ TEE_PARAM_TYPE_NONE);
+
+ LOG_FUNC();
+ if (param_types != exp_param_types)
+ return TEE_ERROR_BAD_PARAMETERS;
+
+ printf("Got value %u\n", params[0].value.a);
+ params[0].value.a++;
+ printf("Increased value to %u\n", params[0].value.a);
+ return TEE_SUCCESS;
+}
+
+TEE_Result TA_InvokeCommandEntryPoint(const void *sess_ctx,
+ uint32_t cmd_id,
+ uint32_t param_types,
+ TEE_Param params[4])
+{
+ (void)&sess_ctx;
+
+ LOG_FUNC();
+
+ switch (cmd_id) {
+ case HELLO_WORLD_CMD_INC:
+ return inc_value(param_types, params);
+ default:
+ return TEE_ERROR_BAD_PARAMETERS;
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 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 Lukasz Kostyra (l.kostyra@samsung.com)
+ * @brief Example Hello World TA for TEF Simulator
+ */
+
+#ifndef HELLO_WORLD_H
+#define HELLO_WORLD_H
+
+#define HELLO_WORLD_UUID { 0x00000000, 0x0000, 0x0000, \
+ { 0x00, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66} }
+
+enum HelloWorldCmds {
+ HELLO_WORLD_CMD_INC = 0
+};
+
+#endif // HELLO_WORLD_H
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns="http://www.samsungdforum.com/ns/packages" >
+ <properties>
+ <!-- Trusted Application Configuration Properties GPD TEE Internal API Specification v1.0 -->
+ <general
+ appID="00000000000000000000112233445566"
+ singleInstance="true"
+ multiSession="true"
+ instanceKeepAlive="false"
+ stackSize="4096"
+ dataSize="4096" />
+
+ <!-- Extended TEE specific -->
+ <extension
+ appName="tef-simulator-helloworld"
+ appVersion="1"
+ type="application"
+ zone="internal"
+ sdkVersion="2.0"
+ launchMode="debug" />
+ </properties>
+ <!-- Access Control Policy -->
+ <policy>
+ <privilege name = "tef-simulator-helloworld" />
+ <protectionDomain>
+ <createDomain name = "testtefsimulator" />
+ <allowedDomain name = "testtefsimulator" />
+ </protectionDomain>
+
+ <permission>
+ <uses-permission name="system.permission.storage" />
+ </permission>
+ </policy>
+
+ <taEncryption>
+ <model>
+ <modelName value="Debug"/>
+ <plainkeydata value="Y2FlZTI3MGJlN2IwZjMyNTM3OWRlZDU0OGQxMGMwZmZiZmJhYTc5NTY5MzY3Y2Q5ZTIzZWNjMmZiY2ExOGViZg0K" />
+ </model>
+ </taEncryption>
+
+ <information>
+ <description> "Sample Hello World application." </description>
+ <author> "Samsung Electronics" </author>
+ <terms> "This sample Application is provided as is. All rights reserved." </terms>
+ <copyright> "Copyright (c) 2017 Samsung Electronics" </copyright>
+ </information>
+
+</manifest>
#define TEE_PROP_FILE "/usr/bin/GPD_TEE_PROP"
#define TA_ROOT "/tmp/"
-#define TEE_TASTORE_ROOT "/tmp/tastore/"
+#define TEE_TASTORE_ROOT "/usr/lib/tastore/"
#endif /* INCLUDE_CONFIG_H_ */
%global bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir}
%global sbin_dir %{?TZ_SYS_SBIN:%TZ_SYS_SBIN}%{!?TZ_SYS_SBIN:%_sbindir}
+%global lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir}
+%global tastore_dir %{lib_dir}/tastore
%description
TEF Simulator provides a TrustZone simulated environment
%cmake . \
-DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \
-DBIN_DIR=%{bin_dir} \
- -DSBIN_DIR=%{sbin_dir}
+ -DSBIN_DIR=%{sbin_dir} \
+ -DTASTORE_DIR=%{tastore_dir}
make %{?silent:--silent} %{?jobs:-j%jobs}
%install
%files -n tef-simulator
%{bin_dir}/tef-simulator-daemon
+%{bin_dir}/tef-simulator-helloworld
%{_libdir}/libtef-simulator-log.so
%{_libdir}/libtef-simulator-osal.so
%{_libdir}/libtef-simulator-ssflib.so
%{_libdir}/libteec.so
+%{tastore_dir}/00000000-0000-0000-0000-112233445566
%{sbin_dir}/tef-simulator-update-uuid-list.sh
/*-----------------------------------------------------------------------------
* MACROS
*-----------------------------------------------------------------------------*/
-#define TA_STORE_PATH "/tmp/tastore/"
-#define TA_UUID_LIST_PATH "/tmp/tastore/uuidlist.list"
+#define TA_STORE_PATH "/usr/lib/tastore/"
+#define TA_UUID_LIST_PATH "/usr/lib/tastore/uuidlist.list"
#endif /* CONFIG_H_ */
if(uuidFileStream) {
getline(uuidFileStream, str);
line = line + str;
+ } else {
+ LOGD(SIM_DAEMON, "Failed to open uuid file");
}
/*
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;
info.port = port;
} else info.port = "";
}
- //cout << "UUID: " << uuid << endl;
- //cout << "port: " << info.port << endl;
+
// Open file
- FILE *fpTA=fopen((string(TA_STORE_PATH) + "ta.tmp").c_str(),"r+");
+ 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, 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);
bool TABinaryManager::unpackBinary(const string &uuid, StructBinaryInfo& info) {
TAUnpack* unpacker = TAUnpack::getInstance();
bool ret = false;
- LOGE(SIM_DAEMON, "");
+ LOGE(SIM_DAEMON, "Unpacking TA");
if (0 == unpacker->unpackTA(string(TA_STORE_PATH), uuid)) {
+ LOGE(SIM_DAEMON, "Unpacked, filling info");
// 1. Set binary info
info.path = string(TA_STORE_PATH) + uuid;
info.extractpath = string(TA_STORE_PATH) + uuid + "-ext/";
info.manifestPath = info.extractpath + uuid + ".manifest";
// 2. Parse manifest and store results
info.manifest.processXML(info.manifestPath);
+
+ LOGE(SIM_DAEMON, "Decrypting");
// 3. Decrypt image using secret value in manifest
if (info.manifest.properties.extension.launchMode == "debug")
decryptImage(info);
// Get TABinaryManager instance
TABinaryManager *TABin = TABinaryManager::getInstance();
// Get TA Image path for launching
+ LOGD(SIM_DAEMON, TAUUID.c_str());
string argvPath = TABin->getImagePath(TAUUID);
if ("" == argvPath) {
LOGE(SIM_DAEMON, "Trusted Application does not exist");
boost::system::error_code error = boost::asio::error::host_not_found;
stream_protocol::endpoint ep(string("/tmp/") + str.str());
- LOGD(SIM_DAEMON, "Connect to TEEStub");
+ LOGD(SIM_DAEMON, "Connect to TEEStub %s", str.str().c_str());
// Try to connect to TA RETRY_COUNT number of times
while (error && (retry_count < RETRY_COUNT)) {
#if 0
# UUID pattern is: ....-....-....-............
# This script should be executed once all the TA packages are transferred to /tmp/tastore
-# Author: Krishna Devale
+# Author: Krishna Devale
# Samsung R & D Institute, Bangalore
# 7 May 2015
#uuidfile="./tastore/uuidlist.list";
-uuidfile="/tmp/tastore/uuidlist.list";
+uuidfile="/usr/lib/tastore/uuidlist.list";
retval=""
file="/tmp/fileLock"
#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
+#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);
+#(echo "${filename:13}" >> $uuidfile);
#done