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
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...