ADD_DEFINITIONS("-D_GNU_SOURCE")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
# Set compiler warning flags
# TODO uncomment these when it's cleanup time
uint32_t i, type;
// Check if Session is valid
- if (session)
- context = ((TEEC_SessionImp *)session->imp)->context;
- else return TEEC_ERROR_BAD_PARAMETERS;
+ if (!session) {
+ LOGE(TEEC_LIB, "Bad parameters");
+ return TEEC_ERROR_BAD_PARAMETERS;
+ }
+ context = ((TEEC_SessionImp *)session->imp)->context;
// Check if output Operation structure is valid
if (!op)
op->paramTypes |= type << (8 * i);
if (!tmpSharedMem[i]) {
- result = tempSharedMemAllocate(&tmpSharedMem[i], type,
- ((TEEC_SessionImp *)session->imp)->context, operation->params[i]);
+ result = tempSharedMemAllocate(&tmpSharedMem[i], type, context, operation->params[i]);
if (result != TEEC_SUCCESS)
goto cleanup;
}
break;
default:
+ LOGE(TEEC_LIB, "Bad parameters");
result = TEEC_ERROR_BAD_PARAMETERS;
goto cleanup;
}
* Include files
*-----------------------------------------------------------------------------*/
#include "teec_connection.h"
+#include <config.h>
/*-----------------------------------------------------------------------------
* Macros
*-----------------------------------------------------------------------------*/
-#define SOCKPATH "/tmp/simdaemon"
/*-----------------------------------------------------------------------------
* TEST MACROS
daemonsock.sun_family = AF_UNIX;
- sock_path_len = strlen(SOCKPATH);
- strncpy(daemonsock.sun_path, SOCKPATH, sock_path_len + 1);
+ sock_path_len = strlen(SIMDAEMON_SOCK_PATH);
+ strncpy(daemonsock.sun_path, SIMDAEMON_SOCK_PATH, sock_path_len + 1);
socklen = sizeof(daemonsock);
sockptr = (struct sockaddr *)&daemonsock;
// Connect to Simulator Daemon
if (connect(serverSocket, sockptr, socklen) == -1) {
- LOGE(TEEC_LIB, "connection to simdaemon failed");
+ LOGE(TEEC_LIB, "connection to simdaemon(%s) failed errno=%d", SIMDAEMON_SOCK_PATH, errno);
close(serverSocket);
return -1;
}
* @return true if property file successfully read else false\r
*/\r
bool TEEProperty::start() {\r
- bool ret = readPropertyFile(string(TEE_PROP_FILE));\r
+ bool ret = readPropertyFile(string(TEE_PROP_PATH));\r
currentItr = propertiesMap.begin();\r
return ret;\r
}\r
#include "TEEStubServer/TEEStubServer.h"
#include <PropertyAccess/PropertyApi.h>
#include <PropertyAccess/PropertyUtility.h>
+#include <config.h>
#include "log.h"
/*-----------------------------------------------------------------------------
void StartServer(string socketName) {
try {
::unlink(socketName.c_str());
- LOGD(TEE_STUB, "Waiting on socket");
+ LOGD(TEE_STUB, "Waiting on socket %s", socketName.c_str());
TEEStubServer s(io_service, socketName.c_str());
io_service.run();
} catch (std::exception& e) {
// Once the server is started, it exits only after the
// connection is lost or gracefully disconnected.
- StartServer(string("/tmp/") + string(argv[1]));
+ StartServer(string(TEE_TASOCK_ROOT) + string(argv[1]));
LOGD(TEE_STUB, "Exiting TEEStub\n");
// Deallocate property objects
if (TEE_SUCCESS == initStatus) DeInitPropertyModule();
#ifndef INCLUDE_CONFIG_H_
#define INCLUDE_CONFIG_H_
-#define TEE_PROP_FILE "/usr/bin/GPD_TEE_PROP"
-#define TA_ROOT "/tmp/"
-#if _ARCH_ == 32
- #define TEE_TASTORE_ROOT "/usr/lib/tastore/"
-#elif _ARCH_ == 64
- #define TEE_TASTORE_ROOT "/usr/lib64/tastore/"
-#else
- #error "Invalid architecture was set!"
-#endif
+//this is ln -s to /usr/lib/tastore or /usr/lib64/tastore (see spec file)
+#define TEE_TASTORE_ROOT "/opt/tastore/"
+
+//TEEStub must have write access in this directory (creating socket per TA)
+#define TEE_TASOCK_ROOT "/tmp/"
+
+#define SHM_PATH "/tmp/shm"
+#define SIMDAEMON_SOCK_PATH "/tmp/simdaemon"
+
+#define TEE_PROP_PATH "/usr/bin/GPD_TEE_PROP"
#endif /* INCLUDE_CONFIG_H_ */
%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 /opt/tastore
-%define link_tastore_dir %{lib_dir}/tastore
+%define tastore_dir %{lib_dir}/tastore
+%define link_tastore_dir /opt/tastore
%define build_bin_dir %{buildroot}%{bin_dir}
%define build_lib_dir %{buildroot}%{lib_dir}
%pre
%post
+rm -f %{link_tastore_dir}
+mkdir -p %{link_tastore_dir}
+rmdir %{link_tastore_dir}
ln -sf %{tastore_dir} %{link_tastore_dir}
tef-update.sh simulator
systemctl enable tef-simulator
#include <string>
#include "log.h"
-#include "config.h"
+#include <config.h>
#include <cynara/cynara-client.h>
#define TA_LOCAL_PATH "/res/tee"
+++ /dev/null
-/**
- * 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 CHERYL (cb) (cheryl.b@samsung.com)
- * @brief Configuration details
- */
-
-#ifndef CONFIG_H_
-#define CONFIG_H_
-
-/*-----------------------------------------------------------------------------
- * MACROS
- *-----------------------------------------------------------------------------*/
-#define TA_STORE_PATH "/usr/lib/tastore/"
-
-#endif /* CONFIG_H_ */
* Include files
*-----------------------------------------------------------------------------*/
#include "TABinaryManager.h"
-#include "Config.h"
+#include <config.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
bool res = false;
StructBinaryInfo info;
- if (boost::filesystem::exists(TA_STORE_PATH + uuid)) {
+ if (boost::filesystem::exists(TEE_TASTORE_ROOT + uuid)) {
pthread_mutex_lock(&taLock);
try {
if (unpackBinary(uuid, info)) {
bool TABinaryManager::unpackBinary(const string &uuid, StructBinaryInfo& info) {
TAUnpack* unpacker = TAUnpack::getInstance();
bool ret = false;
- if (0 == unpacker->unpackTA(string(TA_STORE_PATH), uuid)) {
+ if (0 == unpacker->unpackTA(string(TEE_TASTORE_ROOT), uuid)) {
LOGD(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.path = string(TEE_TASTORE_ROOT)+ uuid;
+ info.extractpath = string(TEE_TASTORE_ROOT) + uuid + "-ext/";
info.imagePath = info.extractpath + uuid + ".image";
info.manifestPath = info.extractpath + uuid + ".manifest";
// 2. Parse manifest and store results
#include "TAUnpack.h"
#include <iostream>
#include <fstream>
+#include <memory>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include <log.h>
using namespace std;
}
// 2. Verify header
if (SECURITY_HEADER_MAGIC1 == packageHeader.magic1 &&
- SECURITY_HEADER_MAGIC2 == packageHeader.magic2) {
+ SECURITY_HEADER_MAGIC2 == packageHeader.magic2) {
+ string imageFile = extract_dir_path + uuid + ".image";
+ string manifestFile = extract_dir_path + uuid + ".manifest";
+ unlink(imageFile.c_str());
+ unlink(manifestFile.c_str());
+
// 3. Read image and write to FS
tapackage.seekg(packageHeader.image_offset);
- char *imagedump = new char[packageHeader.image_size];
- tapackage.read(imagedump, packageHeader.image_size);
+ auto imagedump = std::make_unique<char[]>(packageHeader.image_size);
+ tapackage.read(imagedump.get(), packageHeader.image_size);
if (tapackage.fail()) {
LOGE(SIM_DAEMON, "Read failed");
return -1;
}
- string removeImage = "rm -f " + extract_dir_path + uuid + ".image";
- int result = system(removeImage.c_str());
- if (result != 0) {
- LOGE(SIM_DAEMON, "Failed to remove existing TA image");
- }
- ofstream image((extract_dir_path + uuid + ".image").c_str(),
- ios::out | ios::binary);
- ofstream manifest((extract_dir_path + uuid + ".manifest").c_str(),
- ios::out | ios::binary);
- image.write(imagedump, packageHeader.image_size);
- image.flush();
- delete[] imagedump;
+ ofstream image(imageFile.c_str(), ios::out | ios::binary);
+ if (image.fail()) {
+ LOGE(SIM_DAEMON, "Open failed %s %s", imageFile.c_str(), strerror(errno));
+ return -1;
+ }
+ image.write(imagedump.get(), packageHeader.image_size);
+ image.close();
// 4. Read manifest and write to FS
tapackage.seekg(packageHeader.manifest_offset);
- char *manifestdump = new char[packageHeader.manifest_size];
- tapackage.read(manifestdump, packageHeader.manifest_size);
+ auto manifestdump = std::make_unique<char[]>(packageHeader.manifest_size);
+ tapackage.read(manifestdump.get(), packageHeader.manifest_size);
if (tapackage.fail()) {
LOGE(SIM_DAEMON, "Read failed");
return -1;
}
- manifest.write(manifestdump, packageHeader.manifest_size);
- manifest.flush();
- delete[] manifestdump;
+
+ ofstream manifest(manifestFile.c_str(), ios::out | ios::binary);
+ if (manifest.fail()) {
+ LOGE(SIM_DAEMON, "Open failed %s %s", manifestFile.c_str(), strerror(errno));
+ return -1;
+ }
+ manifest.write(manifestdump.get(), packageHeader.manifest_size);
+ manifest.close();
} else {
LOGE(SIM_DAEMON, "Header verification failed");
return -1;
unsigned long int retry_count = 0;
try {
boost::system::error_code error = boost::asio::error::host_not_found;
- stream_protocol::endpoint ep(string("/tmp/") + str.str());
+ stream_protocol::endpoint ep(string(TEE_TASOCK_ROOT) + str.str());
LOGD(SIM_DAEMON, "Connect to TEEStub %s", str.str().c_str());
// Try to connect to TA RETRY_COUNT number of times
#include "ss_misc.h"
#include "OsaLinuxUser.h"
#include <new>
+#include <config.h>
#ifdef _SECOS_SIM_
#include "file_op.h"
-#define SWD_SS_ROOT "/tmp/tastore2/"
-
#endif
// this is RNG SEED for mask
char* ptr = data_name;
int remain = maxlen;
- strncpy(ptr, SWD_SS_ROOT, remain);
+ strncpy(ptr, TEE_TASTORE_ROOT, remain);
if (ptr[remain - 1] != '\0')
return -1;
ptr += strlen(ptr);
#include <assert.h>
#include "ssf_client.h"
#include <unistd.h>
+#include <config.h>
/*-----------------------------------------------------------------------------
* MACROS
*-----------------------------------------------------------------------------*/
-#define SOCKPATH "/tmp/simdaemon" //path to be updated
/*-----------------------------------------------------------------------------
}
daemonsock.sun_family = AF_UNIX;
- sock_path_len = strlen(SOCKPATH);
- strncpy(daemonsock.sun_path, SOCKPATH, sock_path_len+1);
+ sock_path_len = strlen(SIMDAEMON_SOCK_PATH);
+ strncpy(daemonsock.sun_path, SIMDAEMON_SOCK_PATH, sock_path_len+1);
socklen = sizeof(daemonsock);
sockptr = (struct sockaddr*)&daemonsock;
if (connect(serverSocket, sockptr, socklen) == -1) {
- LOGE(SSF_LIB, "connection to simdaemon failed");
+ LOGE(SSF_LIB, "connection to simdaemon failed (s=%s)", SIMDAEMON_SOCK_PATH);
close(serverSocket);
return -1;
}