From: Tomasz Marciniak Date: Thu, 18 Aug 2016 08:49:14 +0000 (+0200) Subject: [SecureElement] Adjusted to new native api - part 1. X-Git-Tag: submit/tizen/20160831.012604~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F26%2F84826%2F1;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [SecureElement] Adjusted to new native api - part 1. [Verification] Code compiles. Change-Id: Ic598a7a54d38fbf77ff38ab206c5e47aaf033541 Signed-off-by: Tomasz Marciniak --- diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 128205ac..8b9c4ff5 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -477,8 +477,7 @@ BuildRequires: pkgconfig(feedback) %endif %if 0%{?tizen_feature_se_support} -BuildRequires: pkgconfig(smartcard-service) -BuildRequires: pkgconfig(smartcard-service-common) +BuildRequires: pkgconfig(capi-network-smartcard) %endif %if 0%{?tizen_feature_message_port_support} diff --git a/src/secureelement/secureelement.gyp b/src/secureelement/secureelement.gyp index a302c6a3..9c9bf005 100644 --- a/src/secureelement/secureelement.gyp +++ b/src/secureelement/secureelement.gyp @@ -15,21 +15,13 @@ 'secureelement_extension.h', 'secureelement_instance.cc', 'secureelement_instance.h', - 'secureelement_seservice.cc', - 'secureelement_seservice.h', - 'secureelement_reader.cc', - 'secureelement_reader.h', - 'secureelement_session.cc', - 'secureelement_session.h', - 'secureelement_channel.cc', - 'secureelement_channel.h', ], 'includes': [ '../common/pkg-config.gypi', ], 'conditions': [ [ 'tizen == 1', { - 'variables': { 'packages': ['smartcard-service', 'smartcard-service-common'] }, + 'variables': { 'packages': ['capi-network-smartcard'] }, }], ], }, diff --git a/src/secureelement/secureelement_api.js b/src/secureelement/secureelement_api.js index ccbcde28..9a55298a 100644 --- a/src/secureelement/secureelement_api.js +++ b/src/secureelement/secureelement_api.js @@ -184,7 +184,7 @@ function Reader(reader_handle) { console.log('SEReader_isPresent error: ' + native_.getErrorObject(result)); return false; } else { - return native_.getResultObject(result).isPresent; + return native_.getResultObject(result); } }}, _handle: { configurable: false, @@ -202,7 +202,7 @@ Reader.prototype.getName = function() { throw native_.getErrorObject(result); } - return native_.getResultObject(result).name; + return native_.getResultObject(result); }; Reader.prototype.openSession = function() { diff --git a/src/secureelement/secureelement_channel.cc b/src/secureelement/secureelement_channel.cc deleted file mode 100644 index e7355d30..00000000 --- a/src/secureelement/secureelement_channel.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#include "common/picojson.h" -#include "common/logger.h" -#include "secureelement_channel.h" - -using namespace smartcard_service_api; - -namespace extension { -namespace secureelement { - -void SEChannel::close() { - LoggerD("Entered"); - if (m_channel_ptr && !m_channel_ptr->isClosed()) { - m_channel_ptr->closeSync(); - } -} - - -ByteArray SEChannel::transmit(const picojson::array& v_command) { - LoggerD("Entered"); - ByteArray response; - if ( m_channel_ptr) { - size_t v_command_size = v_command.size(); - uint8_t* command = new uint8_t[v_command_size]; - for (size_t i = 0; i < v_command_size; i++) { - command[i] = (uint8_t) static_cast(v_command[i].get()); - } - ByteArray ba_command(command, v_command.size()); - delete [] command; - m_channel_ptr->transmitSync( ba_command, response); - } - return response; -} - - -ByteArray SEChannel::getSelectResponse() { - LoggerD("Entered"); - ByteArray response; - if ( m_channel_ptr) { - response = m_channel_ptr->getSelectResponse(); - } - return response; -} - -} // secureelement -} // extension diff --git a/src/secureelement/secureelement_channel.h b/src/secureelement/secureelement_channel.h deleted file mode 100644 index 4d626435..00000000 --- a/src/secureelement/secureelement_channel.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#ifndef SECUREELEMENT_CHANNEL_H_ -#define SECUREELEMENT_CHANNEL_H_ - -#include -#include "common/picojson.h" - -namespace extension { -namespace secureelement { - -class SEChannel { -public: - SEChannel( smartcard_service_api::ClientChannel* channel_ptr) : m_channel_ptr(channel_ptr) {}; - virtual ~SEChannel() {}; - void close(); - smartcard_service_api::ByteArray transmit(const picojson::array& v_command); - smartcard_service_api::ByteArray getSelectResponse(); -private: - smartcard_service_api::ClientChannel* m_channel_ptr; -}; - -} // secureelement -} // extension - -#endif // SECUREELEMENT_CHANNEL_H_ diff --git a/src/secureelement/secureelement_instance.cc b/src/secureelement/secureelement_instance.cc index 3b787161..75063a78 100644 --- a/src/secureelement/secureelement_instance.cc +++ b/src/secureelement/secureelement_instance.cc @@ -16,384 +16,286 @@ #include "secureelement/secureelement_instance.h" -#include -#include -#include "common/picojson.h" -#include "common/logger.h" -#include "common/task-queue.h" -#include "common/tools.h" +#include +#include -#include "secureelement_reader.h" -#include "secureelement_session.h" -#include "secureelement_channel.h" +#include "common/tools.h" +#include "common/scope_exit.h" namespace extension { namespace secureelement { -using namespace common; -using namespace smartcard_service_api; +using common::TizenResult; +using common::TizenSuccess; namespace { const std::string kPrivilegeSecureElement = "http://tizen.org/privilege/secureelement"; + +const std::string kHandle = "handle"; + +TizenResult ConvertErrorCode(int error) { + switch (error) { + case SMARTCARD_ERROR_NONE: + return TizenSuccess(); + case SMARTCARD_ERROR_INVALID_PARAMETER: + return common::InvalidValuesError(error); + case SMARTCARD_ERROR_IO_ERROR: + return common::IoError(error); + case SMARTCARD_ERROR_ILLEGAL_STATE: + case SMARTCARD_ERROR_CHANNEL_NOT_AVAILABLE: + return common::InvalidStateError(error); + case SMARTCARD_ERROR_NO_SUCH_ELEMENT: + return common::NotFoundError(error); + case SMARTCARD_ERROR_GENERAL: + case SMARTCARD_ERROR_ILLEGAL_REFERENCE: + case SMARTCARD_ERROR_OPERATION_NOT_SUPPORTED: + case SMARTCARD_ERROR_PERMISSION_DENIED: + case SMARTCARD_ERROR_NOT_INITIALIZED: + case SMARTCARD_ERROR_NOT_SUPPORTED: + default: + return common::UnknownError(error); + } } -SecureElementInstance::SecureElementInstance() - : service_(*this) { - LoggerD("Entered"); +} //namespace + +SecureElementInstance::SecureElementInstance() : + is_initialized_(false) { + ScopeLogger(); - using std::placeholders::_1; - using std::placeholders::_2; + using std::placeholders::_1; + using std::placeholders::_2; #define REGISTER_SYNC(c,x) \ - RegisterSyncHandler(c, std::bind(&SecureElementInstance::x, this, _1, _2)); - - REGISTER_SYNC("SEService_registerSEListener", RegisterSEListener); - REGISTER_SYNC("SEService_unregisterSEListener", UnregisterSEListener); - REGISTER_SYNC("SEService_shutdown", Shutdown); - REGISTER_SYNC("SEReader_getName", GetName); - REGISTER_SYNC("SEReader_isPresent", IsPresent); - REGISTER_SYNC("SEReader_closeSessions", CloseSessions); - REGISTER_SYNC("SESession_getATR", GetATR); - REGISTER_SYNC("SESession_isClosed", IsSessionClosed); - REGISTER_SYNC("SESession_close", CloseSession); - REGISTER_SYNC("SESession_closeChannels", CloseChannels); - REGISTER_SYNC("SEChannel_close", CloseChannel); - REGISTER_SYNC("SEChannel_getSelectResponse", GetSelectResponse); + RegisterSyncHandler(c, std::bind(&SecureElementInstance::x, this, _1)); + + REGISTER_SYNC("SEService_registerSEListener", RegisterSEListener); + REGISTER_SYNC("SEService_unregisterSEListener", UnregisterSEListener); + REGISTER_SYNC("SEService_shutdown", Shutdown); + REGISTER_SYNC("SEReader_getName", GetName); + REGISTER_SYNC("SEReader_isPresent", IsPresent); + REGISTER_SYNC("SEReader_closeSessions", CloseSessions); + REGISTER_SYNC("SESession_getATR", GetATR); + REGISTER_SYNC("SESession_isClosed", IsSessionClosed); + REGISTER_SYNC("SESession_close", CloseSession); + REGISTER_SYNC("SESession_closeChannels", CloseChannels); + REGISTER_SYNC("SEChannel_close", CloseChannel); + REGISTER_SYNC("SEChannel_getSelectResponse", GetSelectResponse); #undef REGISTER_SYNC #define REGISTER(c,x) \ - RegisterSyncHandler(c, std::bind(&SecureElementInstance::x, this, _1, _2)); + RegisterHandler(c, std::bind(&SecureElementInstance::x, this, _1, _2)); - REGISTER("SEService_getReaders", GetReaders); - REGISTER("SEReader_openSession", OpenSession); - REGISTER("SESession_openBasicChannel", OpenBasicChannel); - REGISTER("SESession_openLogicalChannel", OpenLogicalChannel); - REGISTER("SEChannel_transmit", Transmit); + REGISTER("SEService_getReaders", GetReaders); + REGISTER("SEReader_openSession", OpenSession); + REGISTER("SESession_openBasicChannel", OpenBasicChannel); + REGISTER("SESession_openLogicalChannel", OpenLogicalChannel); + REGISTER("SEChannel_transmit", Transmit); #undef REGISTER + + if (SMARTCARD_ERROR_NONE == smartcard_initialize()) { + is_initialized_ = true; + } } SecureElementInstance::~SecureElementInstance() { + ScopeLogger(); + + if (is_initialized_) { + if (SMARTCARD_ERROR_NONE != smartcard_deinitialize()) { + LoggerE("Failed to deinitilize smartcard service"); + } + is_initialized_ = false; + } } -void SecureElementInstance::GetReaders(const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); +// Service methods +TizenResult SecureElementInstance::GetReaders(picojson::object const& args, const common::AsyncToken& token) { + ScopeLogger(); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - double callback_id = 0.0; - if (args.contains("callbackId")) { - callback_id = args.get("callbackId").get(); - } + auto get_readers = [this](const common::AsyncToken& token) -> void { + TizenResult result = TizenSuccess(); - service_.GetReaders(callback_id); - ReportSuccess(out); -} + int* readers = nullptr; + int count = 0; -void SecureElementInstance::RegisterSEListener(const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); + int ret = smartcard_get_readers(&readers, &count); + SCOPE_EXIT { + free(readers); + }; - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + if (SMARTCARD_ERROR_NONE != ret) { + LoggerE("smartcard_get_readers() failed"); + result = ConvertErrorCode(ret); + } else { + picojson::value response{picojson::array{}}; + auto& array = response.get(); + bool is_present = false; + + for (int i = 0; i < count; i++) { + ret = smartcard_reader_is_secure_element_present(readers[i], &is_present); + if (SMARTCARD_ERROR_NONE == ret && is_present) { + array.push_back(picojson::value(static_cast(readers[i]))); + } + } - service_.RegisterSEListener(); - ReportSuccess(out); -} + result = TizenSuccess(response); + } -void SecureElementInstance::UnregisterSEListener( - const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); + this->Post(token, result); + }; - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + std::thread(get_readers, token).detach(); - service_.UnregisterSEListener(); - ReportSuccess(out); + return TizenSuccess(); } -void SecureElementInstance::Shutdown(const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); +TizenResult SecureElementInstance::RegisterSEListener(picojson::object const& args) { + ScopeLogger(); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - service_.Shutdown(); - ReportSuccess(out); + return common::NotSupportedError(); } -void SecureElementInstance::GetName( - const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); +TizenResult SecureElementInstance::UnregisterSEListener(picojson::object const& args) { + ScopeLogger(); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - Reader* reader_ptr = (Reader*) static_cast(args.get("handle").get()); - SEReader seReader(reader_ptr); - picojson::value result = seReader.getName(); - ReportSuccess(result, out); + return common::NotSupportedError(); } -void SecureElementInstance::IsPresent( - const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); +TizenResult SecureElementInstance::Shutdown(picojson::object const& args) { + ScopeLogger(); + + if (is_initialized_) { + int ret = smartcard_deinitialize(); + if (SMARTCARD_ERROR_NONE != ret) { + LogAndReturnTizenError(ConvertErrorCode(ret), ("smartcard_deinitialize() failed")); + } - Reader* reader_ptr = (Reader*) static_cast(args.get("handle").get()); - SEReader seReader(reader_ptr); - picojson::value result = seReader.isPresent(); - ReportSuccess(result, out); + is_initialized_ = false; + } + + return TizenSuccess(); } -void SecureElementInstance::CloseSessions( - const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); +// Reader methods +TizenResult SecureElementInstance::GetName(picojson::object const& args) { + ScopeLogger(); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - Reader* reader_ptr = (Reader*) static_cast(args.get("handle").get()); - SEReader seReader(reader_ptr); - seReader.closeSessions(); - ReportSuccess(out); -} + int reader = static_cast(args.find(kHandle)->second.get()); + char* name = nullptr; -void SecureElementInstance::CloseChannel( const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + int ret = smartcard_reader_get_name(reader, &name); + SCOPE_EXIT { + free(name); + }; - ClientChannel* channel_ptr = (ClientChannel*) static_cast(args.get("handle").get()); - SEChannel seChannel(channel_ptr); - seChannel.close(); - ReportSuccess(out); -} + if (SMARTCARD_ERROR_NONE != ret) { + LogAndReturnTizenError(ConvertErrorCode(ret), ("smartcard_reader_get_name() failed")); + } -void SecureElementInstance::GetSelectResponse( const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + return TizenSuccess(picojson::value(name)); +} - ClientChannel* channel_ptr = (ClientChannel*) static_cast(args.get("handle").get()); - SEChannel seChannel(channel_ptr); +TizenResult SecureElementInstance::IsPresent(picojson::object const& args) { + ScopeLogger(); - ByteArray select_response = seChannel.getSelectResponse(); - picojson::value result = picojson::value(picojson::array()); - picojson::array& arr = result.get(); - size_t select_response_size = select_response.size(); - for (size_t i = 0; i < select_response_size; i++) { - arr.push_back(picojson::value(static_cast(select_response[i]))); - } - ReportSuccess( result, out); + return common::NotSupportedError(); } -void SecureElementInstance::OpenSession( - const picojson::value& args, picojson::object& out) { - LoggerD("Entered"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); - - const double callback_id = args.get("callbackId").get(); - Reader* reader_ptr = (Reader*) static_cast(args.get("handle").get()); - - auto open_session = [this, reader_ptr](const std::shared_ptr& response) -> void { - LoggerD("Opening session"); - try { - SEReader seReader(reader_ptr); - picojson::value result = seReader.openSession(); - ReportSuccess(result, response->get()); - } catch (const ErrorIO& err) { - LogAndReportError(PlatformResult(ErrorCode::IO_ERR), &response->get()); - } catch (const ErrorIllegalState& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR), &response->get()); - } catch (const ErrorIllegalParameter& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR), &response->get()); - } catch (const ErrorSecurity& err) { - LogAndReportError(PlatformResult(ErrorCode::SECURITY_ERR), &response->get()); - } catch (const ExceptionBase& err) { - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR), &response->get()); - } - }; +TizenResult SecureElementInstance::OpenSession(picojson::object const& args, const common::AsyncToken& token) { + ScopeLogger(); - auto open_session_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(this, response->serialize().c_str()); - }; + return common::NotSupportedError(); +} - auto data = std::shared_ptr(new picojson::value(picojson::object())); +TizenResult SecureElementInstance::CloseSessions(picojson::object const& args) { + ScopeLogger(); - TaskQueue::GetInstance().Queue( - open_session, - open_session_response, - data); + CHECK_PRIVILEGE(kPrivilegeSecureElement); + + return common::NotSupportedError(); } // Session functions +TizenResult SecureElementInstance::OpenBasicChannel(picojson::object const& args, const common::AsyncToken& token) { + ScopeLogger(); -void SecureElementInstance::OpenBasicChannel( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); - - const double callback_id = args.get("callbackId").get(); - const picojson::array v_aid = args.get("aid").get(); - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - - auto open = [this, v_aid, session_ptr](const std::shared_ptr& response) -> void { - LoggerD("Opening basic channel"); - try { - SESession seSession(session_ptr); - picojson::value result = seSession.openBasicChannel(v_aid); - ReportSuccess(result, response->get()); - } catch (const ErrorIO& err) { - LogAndReportError(PlatformResult(ErrorCode::IO_ERR), &response->get()); - } catch (const ErrorIllegalState& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR), &response->get()); - } catch (const ErrorIllegalParameter& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR), &response->get()); - } catch (const ErrorSecurity& err) { - LogAndReportError(PlatformResult(ErrorCode::SECURITY_ERR), &response->get()); - } catch (const ExceptionBase& err) { - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR), &response->get()); - } - }; + CHECK_PRIVILEGE(kPrivilegeSecureElement); - auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(this, response->serialize().c_str()); - }; + return common::NotSupportedError(); +} + +TizenResult SecureElementInstance::OpenLogicalChannel(picojson::object const& args, const common::AsyncToken& token) { + ScopeLogger(); - auto data = std::shared_ptr(new picojson::value(picojson::object())); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - TaskQueue::GetInstance().Queue(open, get_response, data); + return common::NotSupportedError(); } +TizenResult SecureElementInstance::GetATR(picojson::object const& args) { + ScopeLogger(); -void SecureElementInstance::OpenLogicalChannel( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); - - const double callback_id = args.get("callbackId").get(); - const picojson::array v_aid = args.get("aid").get(); - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - - auto open = [this, v_aid, session_ptr](const std::shared_ptr& response) -> void { - LoggerD("Opening basic channel"); - try { - SESession seSession(session_ptr); - picojson::value result = seSession.openLogicalChannel(v_aid); - ReportSuccess(result, response->get()); - } catch (const ErrorIO& err) { - LogAndReportError(PlatformResult(ErrorCode::IO_ERR), &response->get()); - } catch (const ErrorIllegalState& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR), &response->get()); - } catch (const ErrorIllegalParameter& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR), &response->get()); - } catch (const ErrorSecurity& err) { - LogAndReportError(PlatformResult(ErrorCode::SECURITY_ERR), &response->get()); - } catch (const ExceptionBase& err) { - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR), &response->get()); - } - }; + CHECK_PRIVILEGE(kPrivilegeSecureElement); - auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(this, response->serialize().c_str()); - }; + return common::NotSupportedError(); +} - auto data = std::shared_ptr(new picojson::value(picojson::object())); +TizenResult SecureElementInstance::IsSessionClosed(picojson::object const& args) { + ScopeLogger(); - TaskQueue::GetInstance().Queue(open, get_response, data); + return common::NotSupportedError(); } +TizenResult SecureElementInstance::CloseSession(picojson::object const& args) { + ScopeLogger(); -void SecureElementInstance::GetATR( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); - - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - SESession seSession(session_ptr); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - ByteArray atr_result = seSession.getATR(); - picojson::value result = picojson::value(picojson::array()); - picojson::array& arr = result.get(); - size_t atr_result_size = atr_result.size(); - for (size_t i = 0; i < atr_result_size; i++) { - arr.push_back(picojson::value(static_cast(atr_result[i]))); - } - ReportSuccess( result, out); + return common::NotSupportedError(); } +TizenResult SecureElementInstance::CloseChannels(picojson::object const& args) { + ScopeLogger(); -void SecureElementInstance::IsSessionClosed( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - SESession seSession(session_ptr); - picojson::value result = seSession.isClosed(); - ReportSuccess( result, out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); + + return common::NotSupportedError(); } +// Channel methods +TizenResult SecureElementInstance::CloseChannel(picojson::object const& args) { + ScopeLogger(); -void SecureElementInstance::CloseSession( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - SESession seSession(session_ptr); - seSession.close(); - ReportSuccess(out); + return common::NotSupportedError(); } +TizenResult SecureElementInstance::Transmit(picojson::object const& args, const common::AsyncToken& token) { + ScopeLogger(); -void SecureElementInstance::CloseChannels( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - Session* session_ptr = (Session*) static_cast(args.get("handle").get()); - SESession seSession(session_ptr); - seSession.closeChannels(); - ReportSuccess(out); + return common::NotSupportedError(); } -void SecureElementInstance::Transmit( const picojson::value& args, picojson::object& out) { - LoggerD("Enter"); - CHECK_PRIVILEGE_ACCESS(kPrivilegeSecureElement, &out); - - const double callback_id = args.get("callbackId").get(); - const picojson::array v_command = args.get("command").get(); - ClientChannel* channel_ptr = (ClientChannel*) static_cast(args.get("handle").get()); - - auto open = [this, v_command, channel_ptr](const std::shared_ptr& response) -> void { - LoggerD("Transmit APDDU command to secure element"); - try { - SEChannel seChannel(channel_ptr); - ByteArray transmit_response = seChannel.transmit(v_command); - picojson::value result = picojson::value(picojson::array()); - picojson::array& arr = result.get(); - size_t transmit_response_size = transmit_response.size(); - for (size_t i = 0; i < transmit_response_size; i++) { - arr.push_back(picojson::value(static_cast(transmit_response[i]))); - } - ReportSuccess( result, response->get()); - } catch (const ErrorIO& err) { - LogAndReportError(PlatformResult(ErrorCode::IO_ERR, "Failed to transmit command."), &response->get()); - } catch (const ErrorIllegalState& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Failed to transmit command."), &response->get()); - } catch (const ErrorIllegalParameter& err) { - LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Failed to transmit command."), &response->get()); - } catch (const ErrorSecurity& err) { - LogAndReportError(PlatformResult(ErrorCode::SECURITY_ERR, "Failed to transmit command."), &response->get()); - } catch (const ExceptionBase& err) { - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to transmit command."), &response->get()); - } - }; - - auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(this, response->serialize().c_str()); - }; +TizenResult SecureElementInstance::GetSelectResponse(picojson::object const& args) { + ScopeLogger(); - auto data = std::shared_ptr(new picojson::value(picojson::object())); + CHECK_PRIVILEGE(kPrivilegeSecureElement); - TaskQueue::GetInstance().Queue(open, get_response, data); + return common::NotSupportedError(); } } // namespace secureelement diff --git a/src/secureelement/secureelement_instance.h b/src/secureelement/secureelement_instance.h index 1f0ff9c8..21a9bcc0 100644 --- a/src/secureelement/secureelement_instance.h +++ b/src/secureelement/secureelement_instance.h @@ -17,44 +17,43 @@ #ifndef SECUREELEMENT_SECUREELEMENT_INSTANCE_H_ #define SECUREELEMENT_SECUREELEMENT_INSTANCE_H_ -#include "common/extension.h" -#include "secureelement_seservice.h" +#include "common/tizen_instance.h" namespace extension { namespace secureelement { -class SecureElementInstance: public common::ParsedInstance { +class SecureElementInstance: public common::TizenInstance { public: SecureElementInstance(); virtual ~SecureElementInstance(); private: - /* SEService methods */ - void GetReaders(const picojson::value& args, picojson::object& out); - void RegisterSEListener(const picojson::value& args, picojson::object& out); - void UnregisterSEListener(const picojson::value& args, picojson::object& out); - void Shutdown(const picojson::value& args, picojson::object& out); + /* Service methods */ + common::TizenResult GetReaders(picojson::object const& args, const common::AsyncToken& token); + common::TizenResult RegisterSEListener(picojson::object const& args); + common::TizenResult UnregisterSEListener(picojson::object const& args); + common::TizenResult Shutdown(picojson::object const& args); /* Reader methods */ - void GetName(const picojson::value& args, picojson::object& out); - void IsPresent(const picojson::value& args, picojson::object& out); - void OpenSession(const picojson::value& args, picojson::object& out); - void CloseSessions(const picojson::value& args, picojson::object& out); + common::TizenResult GetName(picojson::object const& args); + common::TizenResult IsPresent(picojson::object const& args); + common::TizenResult OpenSession(picojson::object const& args, const common::AsyncToken& token); + common::TizenResult CloseSessions(picojson::object const& args); /* Session methods */ - void OpenBasicChannel(const picojson::value& args, picojson::object& out); - void OpenLogicalChannel(const picojson::value& args, picojson::object& out); - void GetATR(const picojson::value& args, picojson::object& out); - void IsSessionClosed(const picojson::value& args, picojson::object& out); - void CloseSession(const picojson::value& args, picojson::object& out); - void CloseChannels(const picojson::value& args, picojson::object& out); + common::TizenResult OpenBasicChannel(picojson::object const& args, const common::AsyncToken& token); + common::TizenResult OpenLogicalChannel(picojson::object const& args, const common::AsyncToken& token); + common::TizenResult GetATR(picojson::object const& args); + common::TizenResult IsSessionClosed(picojson::object const& args); + common::TizenResult CloseSession(picojson::object const& args); + common::TizenResult CloseChannels(picojson::object const& args); /* Channel methods */ - void CloseChannel(const picojson::value& args, picojson::object& out); - void Transmit(const picojson::value& args, picojson::object& out); - void GetSelectResponse(const picojson::value& args, picojson::object& out); + common::TizenResult CloseChannel(picojson::object const& args); + common::TizenResult Transmit(picojson::object const& args, const common::AsyncToken& token); + common::TizenResult GetSelectResponse(picojson::object const& args); - SEService service_; + bool is_initialized_; }; } // namespace secureelement diff --git a/src/secureelement/secureelement_reader.cc b/src/secureelement/secureelement_reader.cc deleted file mode 100644 index 3ad2845f..00000000 --- a/src/secureelement/secureelement_reader.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#include "secureelement_reader.h" - -#include -#include -#include "common/picojson.h" -#include "common/logger.h" - -using namespace smartcard_service_api; -using namespace std; - -namespace extension { -namespace secureelement { - - -picojson::value SEReader::getName() { - LoggerD("Entered"); - - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - - if(m_reader) { - obj.insert(std::make_pair("name", picojson::value(m_reader->getName()))); - } - - return result; -} - -picojson::value SEReader::isPresent() { - LoggerD("Entered"); - - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - - if(m_reader) { - obj.insert(std::make_pair("isPresent", picojson::value(m_reader->isSecureElementPresent()))); - } - - return result; -} - -picojson::value SEReader::openSession() { - LoggerD("Entered"); - - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - - if(m_reader) { - Session *session_ptr = static_cast(m_reader->openSessionSync()); - - obj.insert(std::make_pair("handle", picojson::value((double) (long) session_ptr))); - obj.insert(std::make_pair("isClosed", picojson::value(session_ptr->isClosed()))); - } - - return result; -} - -void SEReader::closeSessions() { - LoggerD("Entered"); - - if(m_reader) { - m_reader->closeSessions(); - } -} - -}// secureelement -}// extension diff --git a/src/secureelement/secureelement_reader.h b/src/secureelement/secureelement_reader.h deleted file mode 100644 index fc2d7775..00000000 --- a/src/secureelement/secureelement_reader.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#ifndef SECUREELEMENT_READER_H_ -#define SECUREELEMENT_READER_H_ - -#include "common/picojson.h" -#include - -namespace extension { -namespace secureelement { - -class SEReader { -public: - SEReader(smartcard_service_api::Reader* reader_ptr) : m_reader(reader_ptr) {}; - ~SEReader() {}; - - picojson::value getName(); - picojson::value isPresent(); - picojson::value openSession(); - void closeSessions(); -private: - smartcard_service_api::Reader* m_reader; -}; - -} // secureelement -} // extension - -#endif // SECUREELEMENT_READER_H_ diff --git a/src/secureelement/secureelement_seservice.cc b/src/secureelement/secureelement_seservice.cc deleted file mode 100644 index 15fe4918..00000000 --- a/src/secureelement/secureelement_seservice.cc +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#include "secureelement/secureelement_seservice.h" - -#include "common/logger.h" -#include "common/platform_result.h" -#include "common/task-queue.h" -#include "common/tools.h" - - -#include "secureelement/secureelement_instance.h" - -using namespace smartcard_service_api; -using namespace common; -using namespace tools; - -namespace extension { -namespace secureelement { - -namespace { -const int SE_INSERTED = 1; -const int SE_REMOVED = 2; -} - -class SEServiceEventHandler : public SEServiceListener { - void serviceConnected(SEServiceHelper *service, void *context) { - LoggerD("Entered"); - if (context) { - (static_cast(context))->ServiceConnected(); - } else { - LoggerE("Context is null"); - } - } - - void eventHandler(SEServiceHelper *service, char *se_name, int event, void *context) { - LoggerD("Entered"); - if (context) { - (static_cast(context))->EventHandler(se_name, event); - } else { - LoggerE("Context is null"); - } - } - - void errorHandler(SEServiceHelper *service, int error, void *context) { - LoggerE("Error handler called, code: %d", error); - if (context) { - (static_cast(context))->ErrorHandler(error); - } else { - LoggerE("Context is null"); - } - } -}; - -static SEServiceEventHandler se_event_handler; - -SEService::SEService(SecureElementInstance& instance) - : is_initialized_(false), - is_listener_set_(false), - is_error_(false), - instance_(instance) { - LoggerD("Entered"); - - se_service_ = new smartcard_service_api::SEService((void *)this, &se_event_handler); -} - -SEService::~SEService() { - LoggerD("Entered"); - - if (is_initialized_) { - se_service_->shutdownSync(); - is_initialized_ = false; - } - - delete se_service_; - se_service_ = nullptr; -} - -void SEService::GetReaders(double callback_id) { - LoggerD("Entered"); - - auto get_readers = [this]( - const std::shared_ptr& response) -> void { - picojson::value result = picojson::value(picojson::array()); - picojson::array& result_array = result.get(); - - std::vector readers = se_service_->getReaders(); - for (std::size_t i = 0; i < readers.size(); i++) { - if (readers[i]->isSecureElementPresent()) { - result_array.push_back(picojson::value((double) (long) readers[i])); - } - } - - ReportSuccess(result, response->get()); - }; - - auto get_readers_response = [this, callback_id]( - const std::shared_ptr& response) -> void { - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value(callback_id))); - Instance::PostMessage(&instance_, response->serialize().c_str()); - }; - - if (is_error_) { - // there has been an error, report it asynchronously - std::shared_ptr response{new picojson::value{picojson::object{}}}; - LogAndReportError( - PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, - "Unable to connect to service."), - &response->get(), - ("Failed: is_error_")); - TaskQueue::GetInstance().Async(get_readers_response, response); - return; - } - - if (!is_initialized_) { - // not yet ready, wait for the platform callback, send the response then - get_readers_callbacks_.push_back(callback_id); - return; - } - - auto data = std::shared_ptr(new picojson::value(picojson::object())); - - // everything's fine, get the readers, send the response - TaskQueue::GetInstance().Queue( - get_readers, - get_readers_response, - data); -} - -void SEService::RegisterSEListener() { - LoggerD("Entered"); - - is_listener_set_ = true; -} - -void SEService::UnregisterSEListener() { - LoggerD("Entered"); - - is_listener_set_ = false; -} - -void SEService::Shutdown() { - LoggerD("Entered"); - - if (is_initialized_) { - se_service_->shutdownSync(); - is_initialized_ = false; - } -} - -void SEService::ServiceConnected() { - LoggerD("Entered"); - - is_initialized_ = true; - - // send the response to pending GetReaders callbacks - for (const auto& callback_id : get_readers_callbacks_) { - GetReaders(callback_id); - } - get_readers_callbacks_.clear(); - - // notify the listeners - if (!is_listener_set_) { - LoggerE("SE listener is not set."); - return; - } - - std::vector readers = se_service_->getReaders(); - for (std::size_t i = 0; i < readers.size(); i++) { - if (readers[i]->isSecureElementPresent()) { - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - - obj.insert(std::make_pair("action", picojson::value("onSEReady"))); - obj.insert(std::make_pair("handle", picojson::value((double) (long) readers[i]))); - - Instance::PostMessage(&instance_, result.serialize().c_str()); - } - } -} - -void SEService::EventHandler(char *se_name, int event) { - LoggerD("Entered"); - - if (SE_INSERTED != event && SE_REMOVED != event) { - LoggerD("Incorrect event type"); - return; - } - - if (is_initialized_ && is_listener_set_) { - bool is_present = event == SE_INSERTED; - - std::vector readers = se_service_->getReaders(); - for (std::size_t i = 0; i < readers.size(); i++) { - if (!strcmp(se_name, readers[i]->getName()) && - readers[i]->isSecureElementPresent() != is_present) { - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - - if (is_present) { - obj.insert(std::make_pair("action", picojson::value("onSEReady"))); - } else { - obj.insert(std::make_pair("action", picojson::value("onSENotReady"))); - } - - obj.insert(std::make_pair("handle", picojson::value((double) (long) readers[i]))); - Instance::PostMessage(&instance_, result.serialize().c_str()); - return; - } - } - } -} - -void SEService::ErrorHandler(int error) { - LoggerD("Entered"); - is_error_ = true; - - for (const auto& callback_id : get_readers_callbacks_) { - GetReaders(callback_id); - } - get_readers_callbacks_.clear(); -} - -} // secureelement -} // extension diff --git a/src/secureelement/secureelement_seservice.h b/src/secureelement/secureelement_seservice.h deleted file mode 100644 index 5ac40675..00000000 --- a/src/secureelement/secureelement_seservice.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#ifndef SECUREELEMENT_SESERVICE_H_ -#define SECUREELEMENT_SESERVICE_H_ - -#include -#include - -namespace extension { -namespace secureelement { - -class SecureElementInstance; - -class SEService { - public: - explicit SEService(SecureElementInstance& instance); - ~SEService(); - - void GetReaders(double callback_id); - void RegisterSEListener(); - void UnregisterSEListener(); - void Shutdown(); - - void ServiceConnected(); - void EventHandler(char *se_name, int event); - void ErrorHandler(int error); - private: - SEService(const SEService&) = delete; - SEService& operator=(const SEService&) = delete; - - smartcard_service_api::SEService *se_service_; - bool is_initialized_; - bool is_listener_set_; - bool is_error_; - std::vector get_readers_callbacks_; - SecureElementInstance& instance_; -}; - -} // secureelement -} // extension - -#endif // SECUREELEMENT_SESERVICE_H_ diff --git a/src/secureelement/secureelement_session.cc b/src/secureelement/secureelement_session.cc deleted file mode 100644 index 35fee11a..00000000 --- a/src/secureelement/secureelement_session.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#include -#include -#include "common/picojson.h" -#include "common/logger.h" -#include "secureelement_session.h" - -using namespace smartcard_service_api; - -namespace extension { -namespace secureelement { - -picojson::value SESession::openBasicChannel(const picojson::array& v_aid) { - LoggerD("Entered"); - - size_t v_aid_size = v_aid.size(); - unsigned char* aid = new unsigned char[v_aid_size]; - for (size_t i = 0; i < v_aid_size; i++) { - aid[i] = static_cast(v_aid[i].get()); - } - ByteArray aid_byte_array( aid, (unsigned int) v_aid.size()); - ClientChannel* channel_ptr = static_cast(m_session_ptr->openBasicChannelSync( aid_byte_array)); - delete [] aid; - - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - obj.insert(std::make_pair("handle", picojson::value((double) (long) channel_ptr))); - obj.insert(std::make_pair("isBasicChannel", picojson::value(channel_ptr->isBasicChannel()))); - - return result; -} - - -picojson::value SESession::openLogicalChannel(const picojson::array& v_aid) { - LoggerD("Entered"); - - size_t v_aid_size = v_aid.size(); - unsigned char* aid = new unsigned char[v_aid_size]; - for (size_t i = 0; i < v_aid_size; i++) { - aid[i] = static_cast(v_aid[i].get()); - } - ByteArray aid_byte_array( aid, (unsigned int) v_aid.size()); - ClientChannel* channel_ptr = static_cast(m_session_ptr->openLogicalChannelSync( aid_byte_array)); - delete [] aid; - - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - obj.insert(std::make_pair("handle", picojson::value((double) (long) channel_ptr))); - obj.insert(std::make_pair("isBasicChannel", picojson::value(channel_ptr->isBasicChannel()))); - - return result; -} - - -picojson::value SESession::isClosed() { - LoggerD("Entered"); - bool is_closed = m_session_ptr->isClosed(); - picojson::value result = picojson::value(picojson::object()); - picojson::object& obj = result.get(); - obj.insert(std::make_pair("isClosed", picojson::value(is_closed))); - return result; -} - - -void SESession::close() { - LoggerD("Entered"); - if ( m_session_ptr) { - m_session_ptr->closeSync(); - } -} - - -ByteArray SESession::getATR() { - LoggerD("Entered"); - ByteArray response; - if ( m_session_ptr) { - response = m_session_ptr->getATRSync(); - } - return response; -} - - -void SESession::closeChannels() { - LoggerD("Entered"); - if ( m_session_ptr) { - m_session_ptr->closeChannels(); - } -} - - -} // secureelement -} // extension diff --git a/src/secureelement/secureelement_session.h b/src/secureelement/secureelement_session.h deleted file mode 100644 index 891380cc..00000000 --- a/src/secureelement/secureelement_session.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2015 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. - */ - -#ifndef SECUREELEMENT_SESSION_H_ -#define SECUREELEMENT_SESSION_H_ - -#include -#include "common/picojson.h" -#include "common/logger.h" - -namespace extension { -namespace secureelement { - -class SESession { -public: - SESession(smartcard_service_api::Session* session_ptr) - : m_session_ptr(session_ptr) { - } - - ~SESession() {}; - picojson::value openBasicChannel( const picojson::array& v_aid); - picojson::value openLogicalChannel( const picojson::array& v_aid); - picojson::value isClosed(); - void close(); - smartcard_service_api::ByteArray getATR(); - void closeChannels(); -private: - smartcard_service_api::Session* m_session_ptr; -}; - -} // secureelement -} // extension - -#endif // SECUREELEMENT_SESSION_H_