From: Igor Kotrasinski Date: Mon, 11 Jun 2018 13:11:42 +0000 (+0200) Subject: Check security.tee feature when opening context X-Git-Tag: submit/tizen/20191113.044831~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a21061be7104dceef291499155eec124592285a5;p=platform%2Fcore%2Fwebapi%2Flibteec.git Check security.tee feature when opening context Change-Id: Ide9097d8e413a5dae3e81427b12d8bc3b3e2b7ca Signed-off-by: Igor Kotrasinski --- diff --git a/packaging/webapi-plugins-teec.spec b/packaging/webapi-plugins-teec.spec index f8bf5ee..5f53d38 100644 --- a/packaging/webapi-plugins-teec.spec +++ b/packaging/webapi-plugins-teec.spec @@ -26,6 +26,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: ninja BuildRequires: pkgconfig(webapi-plugins) BuildRequires: pkgconfig(tef-libteec) +BuildRequires: pkgconfig(capi-system-info) %description Tizen TEF Framework Client API plugin diff --git a/src/teec/TeecContext.cc b/src/teec/TeecContext.cc index 280db24..4e6c114 100644 --- a/src/teec/TeecContext.cc +++ b/src/teec/TeecContext.cc @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017-2018 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. @@ -24,6 +24,7 @@ #include #include +#include namespace { @@ -46,7 +47,12 @@ std::string GenerateShmemID() { namespace extension { namespace libteec { +const std::string TeecContext::teeFeatureName{"http://tizen.org/feature/security.tee"}; + TeecContext::TeecContext(const std::string& name) { + if (!teeIsEnabled()) + throw common::NotSupportedException("Failed to initialize context: " + + teeFeatureName + " is disabled"); TEEC_Result ret = TEEC_InitializeContext(name.empty() ? NULL : name.c_str(), &mContext); if (ret != TEEC_SUCCESS) { throw common::NotSupportedException("Failed to initialize context: " + @@ -60,6 +66,31 @@ TeecContext::~TeecContext() { TEEC_FinalizeContext(&mContext); } + +bool TeecContext::teeIsEnabled() { + bool enabled; + int sys_ret = system_info_get_platform_bool(teeFeatureName.c_str(), &enabled); + if (sys_ret == SYSTEM_INFO_ERROR_NONE) + return enabled; + + std::string error_str; + switch (sys_ret) { + case SYSTEM_INFO_ERROR_INVALID_PARAMETER: + error_str = "Feature key not present"; + break; + case SYSTEM_INFO_ERROR_IO_ERROR: + error_str = "Input/output error"; + break; + case SYSTEM_INFO_ERROR_PERMISSION_DENIED: + error_str = "Permission denied"; + break; + default: + error_str = "Unknown error "+ std::to_string(sys_ret); + } + throw common::NotSupportedException("Failed to query " + teeFeatureName + + ": " + error_str); +} + std::string TeecContext::OpenSession(const std::string& uuidstr, uint32_t connectionMethod, const void* connectionData, TEEC_Operation* operation, uint32_t* returnOrigin) { diff --git a/src/teec/TeecContext.h b/src/teec/TeecContext.h index 2a5f73f..2e175eb 100644 --- a/src/teec/TeecContext.h +++ b/src/teec/TeecContext.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017-2018 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. @@ -59,6 +59,8 @@ private: TEEC_Context mContext; TeecSessionMap mSessions; TeecSharedMemoryMap mSharedMemories; + static const std::string teeFeatureName; + bool teeIsEnabled(); }; using TeecContextPtr = std::shared_ptr; @@ -66,4 +68,4 @@ using TeecContextPtr = std::shared_ptr; } // namespace libteec } // namespace extension -#endif // LIBTEEC_TEEC_CONTEXT_H_ \ No newline at end of file +#endif // LIBTEEC_TEEC_CONTEXT_H_ diff --git a/src/teec/teec.gyp b/src/teec/teec.gyp index 3d2bb02..fd9ae94 100644 --- a/src/teec/teec.gyp +++ b/src/teec/teec.gyp @@ -34,6 +34,7 @@ 'packages': [ 'webapi-plugins', 'tef-libteec', + 'capi-system-info', ], }, },