TEE學習(一) OP-TEE

来源:https://www.cnblogs.com/ppddcsz/archive/2022/11/09/16872594.html
-Advertisement-
Play Games

TEE學習(一) OP-TEE OP-TEE CONCEPT OP-TEE(open source project Trusted Execution Environment),REE中的系統和應用無法直接訪問TEE中的資源,只能通過TEE提供的介面獲取一個結果。 main design goals ...


TEE學習(一) OP-TEE

OP-TEE

CONCEPT

  1. OP-TEE(open source project Trusted Execution Environment),REE中的系統和應用無法直接訪問TEE中的資源,只能通過TEE提供的介面獲取一個結果

  2. main design goals:

  • isolation: provide isolation between REE and TEE; protect TAs from each other,
  • small footprint: TEE should be small enough to reside in a reasonable memory,
  • portability: TEE aims to be loaded in different architecture and hardware,support various setups(multiple clients OSes,mutiple TEEs).

COMPONENT

components feature
A secure privileged layer Arm secure PL-1 (v7-A) or EL-1 (v8-A) level
A set of secure user space libraries for TAs needs
A Linux kernel TEE framework and driver
A Linux user space library upon the GP TEE Client API specifications
A Linux user space supplicant daemon for remote services expected by the TEE OS
A test suite for doing regression testing and testing the consistency of the API implementations.
An example git containing a couple of simple host- and TA-examples
some build scripts,debugging tools ease integration and the development of Trusted Applications and secure services

QEMU

一款模擬軟體,可以模擬虛擬電腦/嵌入式開發板(支持ARM、MIPS、RISC-V等各種架構)。run OP-TEE using QEMU for Armv8-A.

在沒有硬體虛擬化的支持下,QEMU本質上完成的工作是二進位的翻譯,如在Ubuntu(x86)系統上使用Qemu模擬ARM64處理器時,Guest OS中的ARM64程式是無法在x86架構運行的,但使用Qemu進行翻譯,可以將Guest代碼指令翻譯成TCG(Tiny Code Generator)中間代碼,最終翻譯成Host架構支持的代碼指令

RUNNING OP-TEE on QEMU v8

ENVIRONMENT

software/OS version
VMware Workstation 16.2.1
Ubuntu 20.04

OPERATION

  1. download necessary tools and libraries:

    sudo apt-get install android-tools-fastboot autoconf bison cscope curl flex gdisk libc6:i386 libfdt-dev libglib2.0-dev libpixman-1-dev libstdc++6:i386 libz1:i386 netcat python-crypto uuid-dev xz-utils zlib1g-dev
    
  2. install repo:

    mkdir ~/.bin
    cd ~/.bin
    wget https://storage.googleapis.com/git-repo-downloads/repo -P ~/bin/ # 使用鏡像
    chmod a+x ~/bin/repo
    export PATH=~/bin:$PATH
    
  3. download the sourcecode of OP-TEE:

    repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml # git需要設置代理 
    # With these you will get a setup containing the all necessary software components to run OP-TEE on the chosen device.
    repo sync
    cd build
    make toolchains # .mk文件里的交叉編譯器下載地址已遷移,需要更換
    make run #編譯的過程中缺少依賴需下載
    
  4. successfully run OP-TEE:

    image-20221107150510394

ANALYZE HELLO_WORLD

hello_world folder

image-20221107153813266

ta folder

image-20221107153755239

  • Makefile: a make file that should set some configuration variables and include the TA-devkit(TA 的開發工具包) make file.

    • TA_DEV_KIT_DIR: Base directory of the TA-devkit.
    • BINARY: BINARY shall provide the TA filename used to load the TA.The built and signed TA binary file will be named ${BINARY}.ta.In native OP-TEE, it is the TA UUID.
  • sub.mk: a make file that lists the sources to build (local source files, subdirectories to parse, source file specific build directives).

    • the entry point for listing the source files to build and other specific build directives.
  • user_ta_header_defines.h: a specific ANSI-C header file to define most of the TA properties.

  • Andriod.mk: Android’s build system will parse the Android.mk file for the TA which in turn will parse a TA-devkit Android make file to locate TA build resources.

  • hello_world_ta.c:

    TEE_Result TA_CreateEntryPoint(void); 
    //Allocate some resources, init something
    
    void TA_DestroyEntryPoint(void); 
    //Release resources if required before TA destruction
    
    TEE_Result TA_OpenSessionEntryPoint(uint32_t ptype,
                                        TEE_Param param[4],
                                        void **session_id_ptr); 
    //Check client identity, and alloc/init some session resources if any
    
    void TA_CloseSessionEntryPoint(void *sess_ptr); 
    //check client and handle session resource release, if any
    
    TEE_Result TA_InvokeCommandEntryPoint(void *session_id,
                                          uint32_t command_id,
                                          uint32_t parameters_type,
                                          TEE_Param parameters[4]); 
    //Decode the command and process execution of the target service
    
    
    

Checking TA Parameters

TEE_PARAM_TYPE_GET(param_type, param_index)to get the type of a parameter and check its value according to the expected parameter.

Signing of TAs

對於離線簽名,需要三步過程:在第一步中,必鬚生成已編譯二進位文件的摘要,在第二步中,使用私鑰對該摘要進行離線簽名,最後在第三步中,對二進位文件及其摘要進行簽名。 簽名被縫合到完整的TA中。

host folder

image-20221107200905242

workflow

image-20221107202832755

  1. initialize context(host),open op-tee driver,獲取到操作句柄並存放到TEE_Context類型的變數中

    TEEC_InitializeContext(NULL, &ctx);
    
  2. open session(CA),創建一個特定CA與特定TA之間進行通信的通道

    TEEC_OpenSession(&ctx, &sess, &uuid,TEEC_LOGIN_PUBLIC, NULL, NULL,&err_origin);
    

    Then TA's TA_OpenSessionEntryPoint() will print "Hello World!". (in TEE core)

  3. initialize paramTypes

    op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
    
  4. invoke command, use command ID and op

    TEEC_InvokeCommand(&sess, TA_HELLO_WORLD_CMD_INC_VALUE, &op, &err_origin);
    

    Then OP-TEE and TA deal with the request and return the result to CA (TA_InvokeCommandEntryPoint).


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 哈嘍兄弟們,今天咱們來複習一下Python基礎中的列表操作,不知道各位還記得多少呢? 遍歷整個列表加粗樣式 遍歷列表的所有元素,對每一個元素進行相同的操作,是我們常常所需要的。在python中可使用for()迴圈。 假如我們需要將一個列表中的手機品牌一一列印,我們可以分別獲取手機品牌的名字。如果數據 ...
  • 一、基本介紹 參考:https://www.hangge.com/blog/cache/detail_2844.html 1、為什麼搭建私服 如果沒有私服,需要的構件都需要通過maven的中央倉庫或者第三方的maven倉庫下載到本地,而一個團隊的所有人都重覆的從maven倉庫下載構件加大了倉庫的負載 ...
  • 1. 什麼是死鎖 在多線程環境中,多個進程可以競爭有限數量的資源。當一個進程申請資源時,如果這時沒有可用資源,那麼這個進程進入等待狀態。有時,如果所申請的資源被其他等待進程占有,那麼該等待進程有可能再也無法改變狀態。這種情況稱為死鎖 在Java中使用多線程,就會有可能導致死鎖問題。死鎖會讓程式一直卡 ...
  • 前言 之前想用Markdown來寫框架文檔,找來找去發現還是Jekyll的多,但又感覺不是很合我的需求 於是打算自己簡單弄一個展示Markdown文檔的網站工具,要支持多版本、多語言、導航、頁內導航等,並且支持Github Pages免費站點 組件選擇 我自己呢比較喜歡C#,恰好現在ASP.Net ...
  • 一:背景 1.講故事 這篇文章起源於昨天的一位朋友發給我的dump文件,說它的程式出現了卡死,看了下程式的主線程棧,居然又碰到了 OnUserPreferenceChanged 導致的掛死問題,真的是經典中的經典,線程棧如下: 0:000:x86> !clrstack OS Thread Id: 0 ...
  • Red Giant PluralEyes for Mac雖然只是Shooter Suite其中的一部分,但是卻十分受歡迎,功能也非常強大。PluralEyes Mac版提供了用戶需要的音頻和視頻同步的一切功能,可以自動分析視頻和音頻文件,並同步起來。 詳情:Red Giant PluralEyes ...
  • PasteNow mac是一款強大的剪貼板工具,該軟體使你的日常工作更輕鬆和快捷。你可以通過它存儲各種各樣的臨時數據:文本、鏈接、圖像等等,功能非常的豐富。 詳情:PasteNow for Mac 功能特色 - 在多台設備同步數據 - 創建智能列表以更方便地過濾數據 - 支持各種風格不同的列表樣式 ...
  • EdgeView 3是一款運行在Mac系統上的圖片查看器,不僅可以打開JPEG、PNG、TIFF、BMP、DSlr、Eps、PDF、AI(Adobe illustrator)的RAW文件等各種圖像文件,還可以直接打開存檔中的圖像文件,無需提取。 詳情:EdgeView 3 for Mac 亮點特征: ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...