/**
- * 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.
#include <algorithm>
#include <common/platform_exception.h>
+#include <system_info.h>
namespace {
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: " +
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) {
/**
- * 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.
TEEC_Context mContext;
TeecSessionMap mSessions;
TeecSharedMemoryMap mSharedMemories;
+ static const std::string teeFeatureName;
+ bool teeIsEnabled();
};
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_