- Boost::asio needs pthreads.
- Replace deprecated boost::signals with signals2.
- Replace deprecated boost::asio::io_service with
boost::asio::executor/boost::asio::io_context.
- Silence compiler warnings
- Replace boost socket's native() with native_handle()
- Update socket paths
Change-Id: Ie4fde5239b42b3ba7bcadd40b46fe6b9b84ca66b
/**
- * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd. All rights reserved
+ * Copyright (c) 2015-2020 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.
return TEEC_ERROR_BAD_PARAMETERS;
}
- if (name) strncpy(ctx.TEEName, name, ctx.nameLength);
+ if (name) strcpy(ctx.TEEName, name);
// Connect to Simulator Daemon as a client
TEEC_Result conn_result = connectToServer(&(context_imp->sockfd));
/**\r
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved\r
+ * Copyright (c) 2015-2020 Samsung Electronics Co., Ltd All Rights Reserved\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
out.clockSeqAndNode[i] = std::stoul(clockSeqStr.substr(i * 2, 2),\r
nullptr, 16);\r
}\r
- } catch (std::invalid_argument) {\r
+ } catch (const std::invalid_argument&) {\r
return TEE_ERROR_BAD_FORMAT;\r
- } catch (std::out_of_range) {\r
+ } catch (const std::out_of_range&) {\r
return TEE_ERROR_BAD_FORMAT;\r
}\r
return TEE_SUCCESS;\r
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
//keep in sync with systemd/tef-simulator.socket
-#define SIMDAEMON_SOCK_PATH "/var/run/simdaemon"
-#define SIMDAEMON_CTL_PATH "/var/run/simdaemonctl"
+#define SIMDAEMON_SOCK_PATH "/run/simdaemon"
+#define SIMDAEMON_CTL_PATH "/run/simdaemonctl"
-#define DEBUGPROXY_SOCK_PATH "/var/run/simdaemon-debugproxy"
+#define DEBUGPROXY_SOCK_PATH "/run/simdaemon-debugproxy"
//TEEStub must have write access in this directory (creating socket per TA)
-#define TEE_TASOCK_ROOT "/var/run/"
+#define TEE_TASOCK_ROOT "/run/"
// from manpages: For portable use, a shared memory object
// should be identified by a name of the form /somename
/**
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
void getDebugLogName(char* __name)
{
- if(__name != NULL) {
- int length = strlen(log_label) + 1;
- strncpy(__name, log_label, length);
- }
+ if(__name != NULL)
+ strcpy(__name, log_label);
}
void setDebugLogName(const char* __name)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(openssl1.1)
BuildRequires: pkgconfig(libsystemd-daemon)
-Requires: boost-coroutine boost-filesystem boost-program-options boost-regex boost-signals boost-system boost-thread
+Requires: boost-coroutine boost-filesystem boost-program-options boost-regex boost-system boost-thread
Requires: tef-libteec
%{?systemd_requires}
Description: TEF Simulator TA development kit
Version: @PKGCFG_VERSION@
Requires: boost dlog
-Libs: -L${libdir} -lTEEStub -lTEEStubEx -ltef-simulator-ssflib -ltef-simulator-log -lboost_thread -lboost_filesystem -lboost_system -ldlog -lrt
+Libs: -L${libdir} -lTEEStub -lTEEStubEx -ltef-simulator-ssflib -ltef-simulator-log -lboost_thread -lboost_filesystem -lboost_system -ldlog -lrt -lpthread
Cflags: -I${includedir}/
-# Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2018 - 2020 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.
)
TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DAEMONCTL}
+ ${CMAKE_THREAD_LIBS_INIT}
boost_system boost_program_options boost_regex
)
-# Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+# Copyright (c) 2018 - 2020 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.
)
TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DEBUGPROXY}
- boost_system boost_signals boost_coroutine pthread
+ boost_system boost_coroutine pthread
${TARGET_TEF_SIMULATOR_LOG}
${DEBUGPROXY_DEPS_LIBRARIES}
)
#include <memory>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
-
-/* FIXME - signals is already deprecated and signals2 is not yet in the repo */
-#define BOOST_SIGNALS_NO_DEPRECATION_WARNING
-#include <boost/signals.hpp>
+#include <boost/signals2.hpp>
#include "common.h"
*/
class AsyncEvent {
public:
- AsyncEvent(boost::asio::io_service &io);
+ AsyncEvent(boost::asio::executor executor);
void wait(yield_ctx yield);
void set();
- boost::signal<void ()> done_signal;
+ boost::signals2::signal<void ()> done_signal;
private:
boost::asio::deadline_timer timer;
};
class EventList {
public:
typedef std::vector<std::shared_ptr<AsyncEvent>> Events;
- EventList(Events events, boost::asio::io_service &io);
+ EventList(Events events, boost::asio::executor executor);
~EventList();
EventList(const EventList &) = delete;
EventList& operator=(const EventList &) = delete;
private:
AsyncEvent event;
Events awaited_on_events;
- std::vector<boost::signals::connection> connections;
+ std::vector<boost::signals2::connection> connections;
};
#endif /* __ASYNC_EVENT_H__ */
class DebugproxySocket
{
public:
- DebugproxySocket(int sock, boost::asio::io_service &io);
- DebugproxySocket(std::string sock_path, boost::asio::io_service &io);
+ DebugproxySocket(int sock, boost::asio::io_context &io);
+ DebugproxySocket(std::string sock_path, boost::asio::io_context &io);
void start_accept();
void shutdown();
private:
void async_accept(yield_ctx yield);
void handle_connection(std::shared_ptr<local_sock> local_sock,
yield_ctx yield);
- boost::asio::io_service &io;
+ boost::asio::io_context &io;
local::stream_protocol::acceptor acceptor;
std::shared_ptr<AsyncEvent> quit_event;
};
~ProxySession();
void async_session(yield_ctx yield);
private:
- boost::asio::io_service &io();
+ boost::asio::executor executor();
uint32_t read_forwarded_port(yield_ctx yield);
void setup_port_socket(int port, yield_ctx yield);
/* This might be scheduled after ProxySession is destroyed, so let's keep it static */
void close_session();
std::shared_ptr<AsyncEvent> quit_event;
- std::shared_ptr<local::stream_protocol::socket> local_socket;
+ std::shared_ptr<local_sock> local_socket;
std::shared_ptr<tcp_sock> port_socket;
static const boost::posix_time::seconds PORT_TIMEOUT;
#include "AsyncEvent.h"
-AsyncEvent::AsyncEvent(boost::asio::io_service &io)
+AsyncEvent::AsyncEvent(boost::asio::executor executor)
: done_signal()
-, timer(io)
+, timer(executor)
{
this->timer.expires_at(boost::posix_time::pos_infin);
}
}
EventList::EventList(EventList::Events events,
- boost::asio::io_service &io)
-: event(io)
+ boost::asio::executor executor)
+: event(executor)
, awaited_on_events(events)
, connections()
{
#include "DebugproxySocket.h"
#include "ProxySession.h"
-DebugproxySocket::DebugproxySocket(int sock, boost::asio::io_service &io)
+DebugproxySocket::DebugproxySocket(int sock, boost::asio::io_context &io)
: io(io)
, acceptor(io, local::stream_protocol(), sock)
-, quit_event(std::make_shared<AsyncEvent>(io))
+, quit_event(std::make_shared<AsyncEvent>(io.get_executor()))
{}
-DebugproxySocket::DebugproxySocket(std::string sock_path, boost::asio::io_service &io)
+DebugproxySocket::DebugproxySocket(std::string sock_path, boost::asio::io_context &io)
: io(io)
, acceptor(io, sock_path)
-, quit_event(std::make_shared<AsyncEvent>(io))
+, quit_event(std::make_shared<AsyncEvent>(io.get_executor()))
{}
{
try {
while(true) {
- auto sock = std::make_shared<local::stream_protocol::socket>(this->io);
+ auto sock = std::make_shared<local::stream_protocol::socket>(this->io.get_executor());
this->acceptor.async_accept(*sock, yield);
boost::asio::spawn(
this->io,
std::shared_ptr<AsyncEvent> quit_event)
: quit_event(quit_event)
, local_socket(local_socket)
-, port_socket(std::make_shared<tcp_sock>(local_socket->get_io_service()))
+, port_socket(std::make_shared<tcp_sock>(local_socket->get_executor()))
{}
ProxySession::~ProxySession()
this->close_session();
}
-boost::asio::io_service &ProxySession::io()
+boost::asio::executor ProxySession::executor()
{
- return this->local_socket->get_io_service();
+ return this->local_socket->get_executor();
}
uint32_t ProxySession::read_forwarded_port(yield_ctx yield)
void ProxySession::setup_port_socket(int port, yield_ctx yield)
{
ip::tcp::endpoint port_ep(ip::address::from_string("127.0.0.1"), port);
- auto port_acceptor = std::make_shared<ip::tcp::acceptor>(this->io(), port_ep);
+ auto port_acceptor = std::make_shared<ip::tcp::acceptor>(this->executor(), port_ep);
/* FIXME: We don't want to read data from local socket before
* forwarding it, so checking if it closed while we're listening on the
* port is difficult. Let's just timeout instead.
*/
- auto timeout = std::make_shared<boost::asio::deadline_timer>(this->io());
- boost::asio::spawn(this->io(), boost::bind(
+ auto timeout = std::make_shared<boost::asio::deadline_timer>(this->executor());
+ boost::asio::spawn(this->executor(), boost::bind(
&ProxySession::stop_port_listening_at_timeout,
timeout, port_acceptor, _1));
try {
std::shared_ptr<AsyncEvent> ProxySession::start_forwarding()
{
LOGD(MODULE_DEBUGPROXY, "(%p) Two-way forwarding started", this);
- auto connection_lost_event = std::make_shared<AsyncEvent>(this->io());
+ auto connection_lost_event = std::make_shared<AsyncEvent>(this->executor());
char tag[100];
std::sprintf(tag, "(%p) local -> port", this);
boost::asio::spawn(
- this->io(),
+ this->executor(),
boost::bind(&forward<local::stream_protocol, ip::tcp>,
this->local_socket, this->port_socket,
connection_lost_event, tag, _1));
std::sprintf(tag, "(%p) port -> local", this);
boost::asio::spawn(
- this->io(),
+ this->executor(),
boost::bind(&forward<ip::tcp, local::stream_protocol>,
this->port_socket, this->local_socket,
connection_lost_event, tag, _1));
EventList events(EventList::Events{this->quit_event,
connection_lost_event},
- this->io());
+ this->executor());
events.wait_on_any(yield);
LOGD(MODULE_DEBUGPROXY, "(%p) Received session end event", this);
}
int main()
{
try {
- boost::asio::io_service io;
+ boost::asio::io_context io;
int sock = take_socket_from_systemd();
DebugproxySocket socket = sock >= 0 ? DebugproxySocket(sock, io)
: DebugproxySocket(DEBUGPROXY_SOCK_PATH, io);
public:
pthread_mutex_t connLock;
typedef boost::shared_ptr<ConnectionSession<header_t>> session_ptr;
- static session_ptr create(boost::asio::io_service& io_service, handler_ptr handler)
+ static session_ptr create(boost::asio::executor executor, handler_ptr handler)
{
- return session_ptr(new ConnectionSession(io_service, handler));
+ return session_ptr(new ConnectionSession(executor, handler));
}
- ConnectionSession(boost::asio::io_service& io_service, handler_ptr handler);
+ ConnectionSession(boost::asio::executor executor, handler_ptr handler);
stream_protocol::socket& socket()
{
return clientSocket;
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
*-----------------------------------------------------------------------------*/
template<typename header_t>
-ConnectionSession<header_t>::ConnectionSession(boost::asio::io_service& io_service,
+ConnectionSession<header_t>::ConnectionSession(boost::asio::executor executor,
handler_ptr handler):
- m_handler(handler), clientSocket(io_service), clientData()
+ m_handler(handler), clientSocket(executor), clientData()
{
pthread_mutex_init(&connLock, NULL);
currentState = CMD_READ;
*/
template<typename header_t>
void ConnectionSession<header_t>::start() {
- m_handler->handleConnect(clientSocket.native());
+ m_handler->handleConnect(clientSocket.native_handle());
currentState = CMD_READ;
// read bytes to identify the command and execute callback when
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
boost::optional<uint32_t> port;
try {
port = UUIDConfig->at(cmd.uuid)->getDebugPort();
- } catch (std::out_of_range) {
+ } catch (const std::out_of_range&) {
port = boost::none;
}
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
try {
auto confInfo = UUIDConf->at(data.uuid);
runAsDebug = (confInfo->getDebugPort().is_initialized());
- } catch (std::out_of_range) { /* No special config set */
+ } catch (const std::out_of_range&) { /* No special config set */
runAsDebug = false;
}
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
new TEEConnectionHandler());
ConnectionSession<int8_t>::session_ptr newSession =
ConnectionSession<int8_t>::create(
- m_tee_acceptor->get_io_service(), teeHandler);
+ m_tee_acceptor->get_executor(), teeHandler);
m_tee_acceptor->async_accept(newSession->socket(),
boost::bind(&SimulatorDaemonServer::handleTEEAccept, this, newSession,
new ControlConnectionHandler());
ConnectionSession<enum ControlCommand>::session_ptr newSession =
ConnectionSession<enum ControlCommand>::create(
- m_ctl_acceptor->get_io_service(), ctlHandler);
+ m_ctl_acceptor->get_executor(), ctlHandler);
m_ctl_acceptor->async_accept(newSession->socket(),
boost::bind(&SimulatorDaemonServer::handleCtlAccept, this, newSession,
/**
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
string extract_dir_path = TEE_EXTRACT_ROOT + uuid + "-ext/";
boost::system::error_code ec;
fs::remove_all(extract_dir_path, ec);
- if (ec != 0){
+ if (ec.failed()){
LOGE(MODULE_SIM_DAEMON, "remove_all failed %s %s (trying to continue)", extract_dir_path.c_str(), ec.message().c_str());
}
fs::create_directory(extract_dir_path, ec);
- if (ec != 0){
+ if (ec.failed()){
LOGE(MODULE_SIM_DAEMON, "create_directory failed %s %s", extract_dir_path.c_str(), ec.message().c_str());
return -1;
}
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
try {
debugPort = UUIDConf->at(TAUUID)->getDebugPort();
debug = true;
- } catch (std::out_of_range) {
+ } catch (const std::out_of_range&) {
debugPort = boost::none;
debug = false;
}
/**
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
if (isDebug == false) {
LOGD(MODULE_SIM_DAEMON, "Entry");
//Set socket timeout for mTAConnectionSocket
- result = setsockopt(mTAConnectionSocket.native(), SOL_SOCKET, SO_RCVTIMEO,
+ result = setsockopt(mTAConnectionSocket.native_handle(), SOL_SOCKET, SO_RCVTIMEO,
(char*)&timeout, sizeof(timeout));
if (result < 0) {
LOGE(MODULE_SIM_DAEMON, "setsockopt timeout = %d FAILED", timeout.tv_usec);
/**
- * Copyright (c) 2015-2018 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
std::lock_guard<std::mutex> guard(m_mapLock);
try {
return m_TAMap.at(uuid);
- } catch (std::out_of_range) {
+ } catch (const std::out_of_range&) {
std::shared_ptr<UUIDConfig> newUUIDConf =
std::shared_ptr<UUIDConfig>(new UUIDConfig());
m_TAMap[uuid] = newUUIDConf;
/**
- * Copyright (c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2013-2020 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.
m_full_path[SS_MAX_UUID_LEN] = '\0';
remaining -= SS_MAX_UUID_LEN;
- strncat(m_full_path, "/", 1);
+ strcat(m_full_path, "/");
remaining -= 1;
strncat(m_full_path, m_data_name, remaining - 1);
return SS_RET_DATA_SIZE_IS_TOO_BIG;
}
- memset(&m_file_content, 0, sizeof(m_file_content));
+ m_file_content = {};
+ memset(m_file_content.m_EncryptedKeyBuffer, 0, sizeof(m_file_content.m_EncryptedKeyBuffer));
int iRet = prepare_data(&m_write_data, &m_write_data_size, buffer, buf_size,
offset);
*read_size = 0;
// cleaning internal file structure representation
- memset(&m_file_content, 0, sizeof(m_file_content));
+ m_file_content = {};
+ memset(m_file_content.m_EncryptedKeyBuffer, 0, sizeof(m_file_content.m_EncryptedKeyBuffer));
derive_file_path();
int ret = 0;
// cleaning internal file structure representation
- memset(&m_file_content, 0, sizeof(m_file_content));
+ m_file_content = {};
+ memset(m_file_content.m_EncryptedKeyBuffer, 0, sizeof(m_file_content.m_EncryptedKeyBuffer));
// drive path
derive_file_path();
return 0;
}
#endif
-
/**
- * Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2011-2020 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.
LOGE(MODULE_SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__); \
return; }
+#define PERMISSION_CHECK_RETURN_BOOL(variable) \
+ if (CheckPermission(variable)) { \
+ LOGE(MODULE_SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__); \
+ return false; }
+
typedef enum {
PERM_CRYPTO = 0x00000001,
PERM_STORAGE = 0x00000002,
/**
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2020 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.
* least significant bit
*/
bool TEE_BigIntGetBit(const TEE_BigInt* object_raw, const uint32_t index) {
- PERMISSION_CHECK(PERM_ARITHMETIC);
+ PERMISSION_CHECK_RETURN_BOOL(PERM_ARITHMETIC);
SDRM_BIG_NUM *objBn = (SDRM_BIG_NUM*)object_raw;
bool bitValue = (bool)SDRM_BN_num_bits_index(objBn, index);
LOGD(TAG, "Success");
* @param op2 Pointer to the second operand
*/
bool TEE_BigIntRelativePrime(const TEE_BigInt* op1, const TEE_BigInt* op2) {
- PERMISSION_CHECK(PERM_ARITHMETIC);
+ PERMISSION_CHECK_RETURN_BOOL(PERM_ARITHMETIC);
(void)op1;
(void)op2;
return false;