#include <tee_client_api.h>
+#include <km_ta_defines.h>
+
#include <system_info.h>
#include <string>
#include <sstream>
#include <memory>
-#include <fstream>
#include <unistd.h>
#include <iostream>
#include <iomanip>
-#include <exception>
#include <grp.h>
#define DEFINETOSTR(name) case name: return #name
#undef DEFINETOSTR
-template <typename T>
-void toString(std::ostream& stream, T t)
-{
- stream << std::hex << std::setw(sizeof(T)*2) << std::setfill('0') << t;
-}
-
-template <>
-void toString<unsigned char>(std::ostream& stream, unsigned char t)
-{
- stream << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned short>(t);
-}
-
-template <typename T, size_t N>
-void toString(std::ostream& stream, const T (&t)[N])
-{
- for (size_t i = 0; i < N; i++)
- toString(stream, t[i]);
-}
-
-std::string uuidToString(const TEEC_UUID& uuid)
-{
- std::stringstream ss;
- toString(ss, uuid.timeLow);
-#ifdef TEF_BACKEND_OPTEE
- // OpTEE use uuid format defined in RFC4122
- ss << "-";
- toString(ss, uuid.timeMid);
- ss << "-";
- toString(ss, uuid.timeHiAndVersion);
- ss << "-";
- toString(ss, uuid.clockSeqAndNode[0]);
- toString(ss, uuid.clockSeqAndNode[1]);
- ss << "-";
- toString(ss, uuid.clockSeqAndNode[2]);
- toString(ss, uuid.clockSeqAndNode[3]);
- toString(ss, uuid.clockSeqAndNode[4]);
- toString(ss, uuid.clockSeqAndNode[5]);
- toString(ss, uuid.clockSeqAndNode[6]);
- toString(ss, uuid.clockSeqAndNode[7]);
- ss << ".ta";
-#else // TEF_BACKEND_OPTEE
- toString(ss, uuid.timeMid);
- toString(ss, uuid.timeHiAndVersion);
- toString(ss, uuid.clockSeqAndNode);
-#endif // TEF_BACKEND_OPTEE
- return ss.str();
-}
-
namespace
{
- const TEEC_UUID taUuid =
- { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x74, 0x63, 0x74, 0x65, 0x73, 0x74} };
+ const TEEC_UUID taUuid = KM_TA_UUID;
}
-class Ta
-{
-public:
- explicit Ta(const TEEC_UUID& uuid)
- : m_uuidStr(uuidToString(uuid))
- {
- m_path = "/usr/lib/tastore/";
- RUNNER_ASSERT_MSG(std::ifstream(m_path).good(), "tastore folder not found");
-
- std::string src_path = TA_FILES_DIR + m_uuidStr;
- std::string dest_path = m_path + m_uuidStr;
- RUNNER_ASSERT_MSG(std::ifstream(src_path).good(), "TA file not found in test assets: "
- << TA_FILES_DIR + m_uuidStr);
-
- std::ifstream src(src_path, std::ios::binary);
- std::ofstream dest(dest_path, std::ios::binary);
- dest << src.rdbuf();
-
- RUNNER_ASSERT_MSG(isInstalled(), "Installing test TA failed: " << dest_path);
- int res = smack_set_label_for_path(dest_path.c_str(), XATTR_NAME_SMACK, 1, "_");
- RUNNER_ASSERT_MSG(res >= 0, "Failed to set smack label on TA file");
- }
-
- ~Ta()
- {
- try {
- std::string rmPath = m_path + m_uuidStr;
- std::remove(rmPath.c_str());
-
-#ifndef TEF_BACKEND_OPTEE
- std::string extPath = m_path + m_uuidStr + "-ext/";
- std::string extPathUuid = extPath + m_uuidStr;
-
- rmPath = extPathUuid + ".image";
- std::remove(rmPath.c_str());
- rmPath = extPathUuid + ".manifest";
- std::remove(rmPath.c_str());
- rmPath = extPath;
- std::remove(rmPath.c_str());
-#endif // TEF_BACKEND_OPTEE
-
- } catch (std::exception& e) {
- std::cerr << "Exception thrown in SystemTa destructor: " << e.what() << std::endl;
- } catch (...) {
- std::cerr << "Unknown exception thrown in SystemTa destructor" << std::endl;
- }
- }
-
- bool isInstalled() const
- {
- return std::ifstream(m_path + m_uuidStr).good();
- }
-
-protected:
- std::string m_uuidStr;
- std::string m_path;
-};
-
bool checkIfTeeEnabled()
{
static bool isChecked;
RUNNER_CHILD_TEST(libteec_01_load_TA_as_app)
{
- auto taPtr = std::unique_ptr<Ta>(nullptr);
-
TemporaryTestUser tmpUser("libteec_01_test_user", GUM_USERTYPE_NORMAL);
tmpUser.create();
bool isTeeEnabled = checkIfTeeEnabled();
- if (isTeeEnabled)
- {
- taPtr.reset(new Ta(taUuid));
- }
-
auto fun = [&]()
{
auto contextPtr = std::unique_ptr<TEEC_Context, decltype(&TEEC_FinalizeContext)>
RUNNER_CHILD_TEST(libteec_02_load_TA_as_system)
{
- auto taPtr = std::unique_ptr<Ta>(nullptr);
-
bool isTeeEnabled = checkIfTeeEnabled();
- if (isTeeEnabled)
- {
- taPtr.reset(new Ta(taUuid));
- }
-
auto fun = [&]()
{
auto contextPtr = std::unique_ptr<TEEC_Context, decltype(&TEEC_FinalizeContext)>
+++ /dev/null
-
-window.onload = function() {
- // add eventListener for tizenhwkey
- document.addEventListener('tizenhwkey', function(e) {
- if (e.keyName === "back") {
- try {
- tizen.application.getCurrentApplication().exit();
- } catch (ignore) {}
- }
- });
-
- // Sample code
- var mainPage = document.querySelector('#main');
- var test1 = mainPage.querySelector('#test1-button');
- var test2 = mainPage.querySelector('#test2-button');
- var test3 = mainPage.querySelector('#test3-button');
- var test4 = mainPage.querySelector('#test4-button');
-
- var testData = function (data, result, resultText) {
- for (var i in result) {
- if (data[i] !== result[i]) {
- resultText.innerHTML = "Failure:<br>Received data does not match input data:<br>";
- for (var j in data) {
- resultText.innerHTML += data[j] + " ";
- }
- resultText.innerHTML += "<br>vs. received:<br>";
- for (var k in result) {
- resultText.innerHTML += result[k] + " ";
- }
- return;
- }
- }
-
- var outMsg = "Success:<br>Received data: ";
- for (i in result) {
- outMsg += result[i] + " ";
- }
- resultText.innerHTML = outMsg;
- };
-
- test1.addEventListener("click", function() {
- var resultText = document.querySelector('#test1-text');
- var globalSession = null;
-
- function commandError(err) {
- console.log("Failed command");
- globalSession.close();
- resultText.innerHTML = "Failure:<br>invokeCommand: " + err.name + ": " + err.message;
- }
- function commandSuccess(cmd, params) {
- globalSession.close();
- resultText.innerHTML = "Success:<br>Incremented param to " + params[0].a;
- }
-
- function sessionSuccess(session) {
- //session opened, now we can communicate with TA
- globalSession = session;
-
- var p1 = new tizen.TeecValue(3, 2, 'INOUT');
- session.invokeCommand(1, [p1], commandSuccess, commandError);
- }
- function sessionError(err) {
- console.log("openSession: " + err.name + ": " + err.message);
- resultText.innerHTML = "Failure:<br>openSession: " + err.name + ": " + err.message;
- }
-
- var ctx = tizen.libteec.getContext();
- ctx.openSession("00000000-0000-0000-0000746374657374", 'PUBLIC', null, null, sessionSuccess, sessionError);
- });
-
- test2.addEventListener("click", function() {
- var resultText = document.querySelector('#test2-text');
- var ctx = tizen.libteec.getContext();
- var globalSession = null;
- var data = [1,2,3,4,45,6,7,7,7];
-
- function commandError(err) {
- console.log("Failed command");
- globalSession.close();
- resultText.innerHTML = "Failure:<br>invokeCommand: " + err.name + ": " + err.message;
- }
- function commandSuccess(cmd, params) {
- globalSession.close();
-
- var result = [0,0,0,0,0,0,0,0,0];
- params[1].shm.getData(result, 0);
- testData(data, result, resultText);
- }
-
- function sessionSuccess(session) {
- //session opened, now can communicate with TA
- globalSession = session;
-
- var emptyData = [0,0,0,0, 0,0,0,0,0];
- var shmem1 = ctx.allocateSharedMemory(data.length, 'INPUT');
- shmem1.setData(data, 0);
- var shmem2 = ctx.allocateSharedMemory(emptyData.length, 'OUTPUT');
- shmem2.setData(emptyData);
-
- var p1 = new tizen.TeecRegisteredMemory(shmem1, 0, data.length, 'WHOLE');
- var p2 = new tizen.TeecRegisteredMemory(shmem2, 0, emptyData.length, 'WHOLE');
- session.invokeCommand(2, [p1, p2], commandSuccess, commandError);
- }
- function sessionError(err) {
- console.log("openSession: " + err.name + ": " + err.message);
- resultText.innerHTML = "Failure:<br>openSession: " + err.name + ": " + err.message;
- }
-
- ctx.openSession("00000000000000000000746374657374", 'PUBLIC', null, null, sessionSuccess, sessionError);
- });
-
- test3.addEventListener("click", function() {
- var resultText = document.querySelector('#test3-text');
- var ctx = tizen.libteec.getContext();
- var globalSession = null;
- var data = [7,6,5,4,3,21,1,2,3];
-
- function commandError(err) {
- console.log("Failed command");
- globalSession.close();
- resultText.innerHTML = "Failure:<br>invokeCommand: " + err.name + ": " + err.message;
- }
- function commandSuccess(cmd, params) {
- globalSession.close();
- testData(data, params[1].mem, resultText);
- }
-
- function sessionSuccess(session) {
- //session opened, now can communicate with TA
- globalSession = session;
-
- var emptyData = [0,0,0,0,0,0,0,0,0];
- var p1 = new tizen.TeecTempMemory(data, 'INPUT');
- var p2 = new tizen.TeecTempMemory(emptyData, 'OUTPUT');
- session.invokeCommand(3, [p1, p2], commandSuccess, commandError);
- }
- function sessionError(err) {
- console.log("openSession: " + err.name + ": " + err.message);
- resultText.innerHTML = "Failure:<br>openSession: " + err.name + ": " + err.message;
- }
-
- ctx.openSession("00000000000000000000746374657374", 'PUBLIC', null, null, sessionSuccess, sessionError);
- });
-
- test4.addEventListener("click", function() {
- var resultText = document.querySelector('#test4-text');
- var ctx = tizen.libteec.getContext();
- var globalSession = null;
- var data = [0,1,2,3,4,35,2,1,0];
-
- function commandError(err) {
- console.log("Failed command");
- globalSession.close();
- resultText.innerHTML = "Failure:<br>invokeCommand: " + err.name + ": " + err.message;
- }
- function commandSuccess(cmd, params) {
- globalSession.close();
- var result = [0,0,0,0,0,0,0,0,0];
- params[1].shm.getData(result, 0);
- testData(data, result, resultText);
- }
-
- function sessionSuccess(session) {
- //session opened, now can communicate with TA
- globalSession = session;
-
- var emptyData = [0,0,0,0,0,0,0,0,0];
- var shmem = ctx.allocateSharedMemory(data.length * 2, 'INOUT');
- shmem.setData(data, 0);
- shmem.setData(emptyData, data.length);
-
- var p1 = new tizen.TeecRegisteredMemory(shmem, 0, data.length, 'PARTIAL_INPUT');
- var p2 = new tizen.TeecRegisteredMemory(shmem, data.length, data.length, 'PARTIAL_OUTPUT');
- session.invokeCommand(4, [p1, p2], commandSuccess, commandError);
- }
- function sessionError(err) {
- console.log("openSession: " + err.name + ": " + err.message);
- resultText.innerHTML = "Failure:<br>openSession: " + err.name + ": " + err.message;
- }
-
- ctx.openSession("00000000000000000000746374657374", 'PUBLIC', null, null, sessionSuccess, sessionError);
- });
-};