From: Lukasz Kostyra Date: Tue, 12 Sep 2017 13:34:08 +0000 (+0200) Subject: Adjust to use tef-libteec X-Git-Tag: submit/tizen/20170914.115510~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d073a1a5a4200deae4783fc0fa86aff64aa3adca;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Adjust to use tef-libteec Change-Id: I97a8fa41dc33dd7cbf932ba684b57313519572bf --- diff --git a/TEECLib/CMakeLists.txt b/TEECLib/CMakeLists.txt index bc1e195..b5421f2 100644 --- a/TEECLib/CMakeLists.txt +++ b/TEECLib/CMakeLists.txt @@ -19,15 +19,15 @@ FIND_PACKAGE(Threads REQUIRED) +PKG_CHECK_MODULES(TEEC_LIB_DEPS REQUIRED + tef-libteec + ) + SET(TEEC_LIB_SOURCES ${TEEC_LIB_PATH}/src/teec_api.c ${TEEC_LIB_PATH}/src/teec_connection.c ) -SET(TEEC_LIB_HEADERS - ${TEF_SIMULATOR_INCLUDE_PATH}/include/tee_client_api.h - ) - ADD_LIBRARY(${TARGET_TEF_SIMULATOR_TEEC_LIB} SHARED ${TEEC_LIB_SOURCES} ) @@ -42,13 +42,14 @@ INCLUDE_DIRECTORIES( ${TEF_SIMULATOR_INCLUDE_PATH}/include ${OSAL_PATH} ${LOG_PATH} + ${TEEC_LIB_DEPS_INCLUDE_DIRS} ) TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_TEEC_LIB} ${CMAKE_THREAD_LIBS_INIT} ${TARGET_TEF_SIMULATOR_OSAL} ${TARGET_TEF_SIMULATOR_LOG} + ${TEEC_LIB_DEPS_LIBRARIES} ) -INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEEC_LIB} DESTINATION ${LIB_DIR}) -INSTALL(FILES ${TEEC_LIB_HEADERS} DESTINATION ${INCLUDE_DIR}) +INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_TEEC_LIB} DESTINATION ${LIB_DIR}/tef/simulator) diff --git a/TEECLib/inc/teec_connection.h b/TEECLib/inc/teec_connection.h index a921a03..cde7184 100644 --- a/TEECLib/inc/teec_connection.h +++ b/TEECLib/inc/teec_connection.h @@ -25,8 +25,8 @@ #include #include #include +#include #include "OsaLinuxUser.h" -#include "tee_client_api.h" #include "tee_command.h" #include "teec_data.h" #include "log.h" diff --git a/TEECLib/src/teec_api.c b/TEECLib/src/teec_api.c index 8505cd2..5df4a33 100644 --- a/TEECLib/src/teec_api.c +++ b/TEECLib/src/teec_api.c @@ -20,6 +20,7 @@ * Include files *-----------------------------------------------------------------------------*/ #include "teec_connection.h" +#include #include /*----------------------------------------------------------------------------- diff --git a/TEEStub/CMakeLists.txt b/TEEStub/CMakeLists.txt index d723930..fdf0a66 100644 --- a/TEEStub/CMakeLists.txt +++ b/TEEStub/CMakeLists.txt @@ -19,6 +19,7 @@ PKG_CHECK_MODULES(TEE_STUB_DEPS REQUIRED dlog + tef-libteec ) SET(TEE_STUB_SOURCES @@ -59,6 +60,7 @@ INCLUDE_DIRECTORIES( ${OSAL_PATH} ${LOG_PATH} ${SSFLIB_PATH}/inc + ${TEE_STUB_DEPS_INCLUDE_DIRS} ) TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_TEE_STUB} diff --git a/helloworld/CMakeLists.txt b/helloworld/CMakeLists.txt index 3c270c7..b52cad1 100644 --- a/helloworld/CMakeLists.txt +++ b/helloworld/CMakeLists.txt @@ -28,6 +28,10 @@ PKG_CHECK_MODULES(HELLO_WORLD_TA_DEPS REQUIRED tef-simulator-devkit ) +PKG_CHECK_MODULES(HELLO_WORLD_CA_DEPS REQUIRED + tef-libteec + ) + # TODO CMake include provided by devkit to encrypt/sign TA INCLUDE(TEFSimulatorDevkit) @@ -38,6 +42,14 @@ SET(HELLO_WORLD_PATH ${PROJECT_SOURCE_DIR}) SET(HELLO_WORLD_TA_PATH ${HELLO_WORLD_PATH}/ta) SET(HELLO_WORLD_CA_PATH ${HELLO_WORLD_PATH}/host) +IF (CMAKE_BUILD_TYPE MATCHES "DEBUG") + MESSAGE("Debug build") + ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG") + ADD_DEFINITIONS("-ggdb -O0") + # undefine _FORTIFY_SOURCE - it makes no sense without optimization and produces warnings + ADD_DEFINITIONS("-Wp,-U_FORTIFY_SOURCE") +ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG") + ############# TA ############# SET(HELLO_WORLD_TA_SOURCES @@ -74,10 +86,11 @@ ADD_EXECUTABLE(${TARGET_HELLO_WORLD_CA} INCLUDE_DIRECTORIES( ${HELLO_WORLD_TA_PATH} + ${HELLO_WORLD_CA_DEPS_INCLUDE_DIRS} ) TARGET_LINK_LIBRARIES(${TARGET_HELLO_WORLD_CA} - teec + ${HELLO_WORLD_CA_DEPS_LIBRARIES} ) INSTALL(TARGETS ${TARGET_HELLO_WORLD_CA} DESTINATION ${BIN_DIR}) diff --git a/helloworld/host/main.c b/helloworld/host/main.c index 86f9e13..b5cdc1b 100644 --- a/helloworld/host/main.c +++ b/helloworld/host/main.c @@ -49,9 +49,9 @@ int main(int argc, char *argv[]) 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; + op.params[0].value.b = 0; printf("Incrementing %d via TA\n", op.params[0].value.a); result = TEEC_InvokeCommand(&sess, HELLO_WORLD_CMD_INC, &op, &error); diff --git a/include/include/tee_client_api.h b/include/include/tee_client_api.h deleted file mode 100644 index c002367..0000000 --- a/include/include/tee_client_api.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - * ===================================================================================== - * - * Filename: tee_client_api.h - * - * Description: TEEC API Header file - * - * Version: 1.0 - * Created: Thursday 26 March 2015 12:42:45 IST - * Revision: Original - * Compiler: gcc - * - * Author: CHERYL (cb), cheryl.b@samsung.com - * Organization: Samsung Electronics - * - * ===================================================================================== - */ - -#ifndef __TEE_CLIENT_API_H__ -#define __TEE_CLIENT_API_H__ - -/*----------------------------------------------------------------------------- - * Include files - *-----------------------------------------------------------------------------*/ -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/*----------------------------------------------------------------------------- - * TEE Client API types and constants definitions - *-----------------------------------------------------------------------------*/ -#define TEEC_SUCCESS 0x00000000 // The operation was successful -#define TEEC_ERROR_GENERIC 0xFFFF0000 // Non-specific cause -#define TEEC_ERROR_ACCESS_DENIED 0xFFFF0001 // Access privileges are not sufficient -#define TEEC_ERROR_CANCEL 0xFFFF0002 // The operation was cancelled -#define TEEC_ERROR_ACCESS_CONFLICT 0xFFFF0003 // Concurrent accesses caused conflict -#define TEEC_ERROR_EXCESS_DATA 0xFFFF0004 // Too much data for the requested operation was passed -#define TEEC_ERROR_BAD_FORMAT 0xFFFF0005 // Input data was of invalid format -#define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006 // Input parameters were invalid -#define TEEC_ERROR_BAD_STATE 0xFFFF0007 // Operation is not valid in the current state -#define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008 // The requested data item is not found -#define TEEC_ERROR_NOT_IMPLEMENTED 0xFFFF0009 // The requested operation should exist but is not yet implemented -#define TEEC_ERROR_NOT_SUPPORTED 0xFFFF000A // The requested operation is valid but is not supported in this Implementation -#define TEEC_ERROR_NO_DATA 0xFFFF000B // Expected data was missing -#define TEEC_ERROR_OUT_OF_MEMORY 0xFFFF000C // System ran out of resources -#define TEEC_ERROR_BUSY 0xFFFF000D // The system is busy working on something else. -#define TEEC_ERROR_COMMUNICATION 0xFFFF000E // Communication with a remote party failed. -#define TEEC_ERROR_SECURITY 0xFFFF000F // A security fault was detected. -#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010 // The supplied buffer is too short for the generated output. -#define TEEC_ERROR_TARGET_DEAD 0xFFFF3024 // Targed TA panic'ed -#define TEEC_IMP_MIN 0x00000001 -#define TEEC_IMP_MAX 0xFFFEFFFF -#define TEEC_RFU_MIN 0xFFFF0011 -#define TEEC_RFU_MAX 0xFFFFFFFF - -#define TEEC_ORIGIN_API 0x1 -#define TEEC_ORIGIN_COMMS 0x2 -#define TEEC_ORIGIN_TEE 0x3 -#define TEEC_ORIGIN_TRUSTED_APP 0x4 - -#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0x800000 - -#define TEEC_MEM_INPUT (1 << 0) -#define TEEC_MEM_OUTPUT (1 << 1) - -#define TEEC_NONE 0x00000000 -#define TEEC_VALUE_INPUT 0x00000001 -#define TEEC_VALUE_OUTPUT 0x00000002 -#define TEEC_VALUE_INOUT 0x00000003 -#define TEEC_MEMREF_TEMP_INPUT 0x00000005 -#define TEEC_MEMREF_TEMP_OUTPUT 0x00000006 -#define TEEC_MEMREF_TEMP_INOUT 0x00000007 -#define TEEC_MEMREF_WHOLE 0x0000000C -#define TEEC_MEMREF_PARTIAL_INPUT 0x0000000D -#define TEEC_MEMREF_PARTIAL_OUTPUT 0x0000000E -#define TEEC_MEMREF_PARTIAL_INOUT 0x0000000F - -#define TEE_PARAM_TYPE_NONE 0x00000000 -#define TEE_PARAM_TYPE_VALUE_INPUT 0x00000001 -#define TEE_PARAM_TYPE_VALUE_OUTPUT 0x00000002 -#define TEE_PARAM_TYPE_VALUE_INOUT 0x00000003 -#define TEE_PARAM_TYPE_MEMREF_INPUT 0x00000005 -#define TEE_PARAM_TYPE_MEMREF_OUTPUT 0x00000006 -#define TEE_PARAM_TYPE_MEMREF_INOUT 0x00000007 - -#define TEEC_LOGIN_PUBLIC 0x00000000 -#define TEEC_LOGIN_USER 0x00000001 -#define TEEC_LOGIN_GROUP 0x00000002 -#define TEEC_LOGIN_APPLICATION 0x00000004 -#define TEEC_LOGIN_USER_APPLICATION 0x00000005 -#define TEEC_LOGIN_GROUP_APPLICATION 0x00000006 - -#define MAX_CONTEXT_NAME_LEN 128 - -typedef uint32_t TEEC_Result; - -typedef struct { - uint32_t timeLow; - uint16_t timeMid; - uint16_t timeHiAndVersion; - uint8_t clockSeqAndNode[8]; -} TEEC_UUID; - -typedef struct { - void* imp; -} TEEC_Context; - -typedef struct { - void *imp; -} TEEC_Session; - -typedef struct { - void *buffer; - size_t size; - uint32_t flags; - void *imp; -} TEEC_SharedMemory; - -typedef struct { - void *buffer; - size_t size; -} TEEC_TempMemoryReference; - -typedef struct { - TEEC_SharedMemory* parent; - size_t size; - size_t offset; -} TEEC_RegisteredMemoryReference; - -typedef struct { - uint32_t a; - uint32_t b; -} TEEC_Value; - -typedef union { - TEEC_TempMemoryReference tmpref; - TEEC_RegisteredMemoryReference memref; - TEEC_Value value; -} TEEC_Parameter; - -typedef struct { - uint32_t started; - uint32_t paramTypes; - TEEC_Parameter params[4]; - void *imp; -} TEEC_Operation; - -/*----------------------------------------------------------------------------- - * TEE Client API functions and macros definitions - *-----------------------------------------------------------------------------*/ -TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context); - -void TEEC_FinalizeContext(TEEC_Context *context); - -TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, - TEEC_SharedMemory *sharedMem); - -TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, - TEEC_SharedMemory *sharedMem); - -void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMem); - -TEEC_Result TEEC_OpenSession(TEEC_Context *context, - TEEC_Session *session, - const TEEC_UUID *destination, - uint32_t connectionMethod, - const void *connectionData, - TEEC_Operation *operation, - uint32_t *returnOrigin); - -void TEEC_CloseSession(TEEC_Session *session); - -TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, - uint32_t commandID, - TEEC_Operation *operation, - uint32_t *returnOrigin); - -void TEEC_RequestCancellation(TEEC_Operation *operation); - -#define TEEC_PARAM_TYPES(param0Type, param1Type, param2Type, param3Type) \ - (uint32_t)(((param0Type) & 0x7f) | \ - (((param1Type) & 0x7f) << 8) | \ - (((param2Type) & 0x7f) << 16) | \ - (((param3Type) & 0x7f) << 24)) - -#ifdef __cplusplus -} -#endif - -#endif /* __TEE_CLIENT_API_H__ */ diff --git a/include/include/teec_data.h b/include/include/teec_data.h index b673eb9..cd746be 100644 --- a/include/include/teec_data.h +++ b/include/include/teec_data.h @@ -16,11 +16,13 @@ * ===================================================================================== */ -#include "tee_client_api.h" +#include #ifndef __TEEC_DATA_H__ #define __TEEC_DATA_H__ +#define MAX_CONTEXT_NAME_LEN 128 + typedef struct { uint32_t shmKey; size_t size; diff --git a/packaging/tef-simulator-helloworld.spec b/packaging/tef-simulator-helloworld.spec index ca72eb3..487e640 100644 --- a/packaging/tef-simulator-helloworld.spec +++ b/packaging/tef-simulator-helloworld.spec @@ -7,8 +7,8 @@ License: Apache-2.0 and BSD-3-Clause Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: boost-devel +BuildRequires: pkgconfig(tef-libteec) BuildRequires: pkgconfig(tef-simulator-devkit) -BuildRequires: tef-simulator-client-devel Requires: tef-simulator %define bin_dir %{?TZ_SYS_BIN:%TZ_SYS_BIN}%{!?TZ_SYS_BIN:%_bindir} diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index d28dc76..dea4928 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -15,6 +15,10 @@ BuildRequires: pkgconfig(cynara-creds-socket) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(security-manager) BuildRequires: pkgconfig(libsystemd-daemon) +BuildRequires: pkgconfig(tef-libteec) + +%define tef_conf /etc/tef/tef.conf +Requires: %{tef_conf} %{?systemd_requires} @@ -52,18 +56,6 @@ TEF Simulator Client contains a libteec library compatible with TEF Simulator, required to build Client Applications. -%package -n %{name}-client-devel -Summary: TEF TrustZone simulator client development package -Group: Security/Libraries -License: Apache-2.0 and BSD-3-Clause - -Requires: tef-simulator-client - -%description -n %{name}-client-devel -TEF Simulator Client Devel contains headers required to build -Client Applications with TEF Simulator Client library. - - %package -n %{name}-devkit Summary: TEF TrustZone simulator devkit for TA compilation Group: Security/Libraries @@ -101,12 +93,18 @@ make %{?jobs:-j%jobs} make install %pre +if [ ! -f %{tef_conf} ]; then + echo "Missing tef.conf file on system" > /dev/stderr; + exit 1; +fi %post +sed -i -e 's/^lib=.*$/lib=simulator/' %{tef_conf} %preun %postun +sed -i -e 's/^lib=simulator.*$/lib=/' %{tef_conf} %files -n %{name} %{bin_dir}/tef-simulator-daemon @@ -117,10 +115,7 @@ make install %{_unitdir}/tef-simulator.target %files -n %{name}-client -%{lib_dir}/libteec.so - -%files -n %{name}-client-devel -%{include_dir}/tee_client_api.h +%{lib_dir}/tef/simulator %files -n %{name}-devkit %{bin_dir}/TA_PackageBuilder.sh diff --git a/simulatordaemon/CMakeLists.txt b/simulatordaemon/CMakeLists.txt index 1c76541..d2916a2 100644 --- a/simulatordaemon/CMakeLists.txt +++ b/simulatordaemon/CMakeLists.txt @@ -24,6 +24,7 @@ PKG_CHECK_MODULES(DAEMON_DEPS REQUIRED security-manager libsystemd-daemon libtzplatform-config + tef-libteec ) FIND_PACKAGE(Threads REQUIRED) diff --git a/ssflib/CMakeLists.txt b/ssflib/CMakeLists.txt index 1ef7fb5..3d456a7 100644 --- a/ssflib/CMakeLists.txt +++ b/ssflib/CMakeLists.txt @@ -19,6 +19,7 @@ PKG_CHECK_MODULES(SSFLIB_DEPS REQUIRED openssl + tef-libteec ) SET(SSFLIB_CRYPTOCORE_SOURCES