Check security.tee feature when opening context 18/181418/2
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Mon, 11 Jun 2018 13:11:42 +0000 (15:11 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Thu, 13 Dec 2018 15:05:58 +0000 (16:05 +0100)
Change-Id: Ide9097d8e413a5dae3e81427b12d8bc3b3e2b7ca
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
packaging/webapi-plugins-teec.spec
src/teec/TeecContext.cc
src/teec/TeecContext.h
src/teec/teec.gyp

index f8bf5ee..5f53d38 100644 (file)
@@ -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
index 280db24..4e6c114 100644 (file)
@@ -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 <algorithm>
 #include <common/platform_exception.h>
+#include <system_info.h>
 
 
 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) {
index 2a5f73f..2e175eb 100644 (file)
@@ -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<TeecContext>;
@@ -66,4 +68,4 @@ using TeecContextPtr = std::shared_ptr<TeecContext>;
 } // namespace libteec
 } // namespace extension
 
-#endif // LIBTEEC_TEEC_CONTEXT_H_
\ No newline at end of file
+#endif // LIBTEEC_TEEC_CONTEXT_H_
index 3d2bb02..fd9ae94 100644 (file)
@@ -34,6 +34,7 @@
         'packages': [
           'webapi-plugins',
           'tef-libteec',
+          'capi-system-info',
         ],
       },
     },