# Trusted Execution Environment(Secure World) GlobalPlatform が策定したプロセッサ上に隔離された実行環境を作ることで事でセキュリティを高める技術のこと。一般の実行環境は `Rich Execution Environment(Normal World)` と呼ばれる。 一般的なコンピュータアーキテクチャはTEE環境をサポートしているのでその上で柔軟にTEEを使うことができる。 - ARM TrustZone - Intel SGX - RISC-V Keystone なので思ったよりOSに近い概念。 これらをいい感じに使うOSSはたくさんある。 機密情報管理 - AndroidのKeyMaster https://source.android.com/docs/security/keystore?hl=ja - AndroidのWidevine https://helpcenter.skyperfectv.co.jp/articles/knowledge/SPID4915 コード、データの隠蔽 - https://source.android.com/docs/security/trusty?hl=ja なお、AWSでも`AWS Nitro Enclaves` というEC2でTEEを使うサービスが提供されているので よくあるTEE対応サービスはこれを使って機密データを扱っていると思われる。 https://zenn.dev/koron/scraps/6299a4023a486d https://dev.classmethod.jp/articles/reinvent-2020-sec318-deep-dive-on-aws-nitro-enclaves/ ![](https://i.imgur.com/T8wWkhW.png) ### Hardware-assisted Isolated Execution Environments TEEも含まれるハードウェアレベルでの実行環境隔離を指す単語。 なおTEEは物理レベルでは隔離されておらず、これはTrusted Platform Module(TPM)という。 ### Open Source Trusted OS - OP-TEE (Linaro) - Open-TEE (Aalto University[TrustCom15]) - Trusty (Google) - SierraTEE (Sierra) - SafeG (Nagoya University) 企業が提供するものもある。 ### Enterprise Trusted OS - Appleʼs Secure Enclave(互換性がある?) - Qualcommʼs QTEE, ex. QSEE - Samsungʼs Knox - Samsungʻs Teegris - Trustonicʼs Kinibi OS, ex. Mobicore/t-base/G&D - Huaweiʼs TrustedCore 有名なのは OP-TEE。 ただ、OP-TEEはArmのTrustZoneをベースにしているためIntel機では使えない。(Intelも対応しようとしているがGitHubを見る限りまだまだ) https://www.intel.com/content/www/us/en/developer/topic-technology/open/op-tee/overview.html ) # OP TEE 試す(失敗) ```shell= /# apt update /# apt install -y git wget make cmake gcc g++ pkg-config /# apt install -y uuid-dev # https://ubuntuforums.org/showthread.php?t=1356037 /# git clone https://github.com/OP-TEE/optee_client.gi /# cd optee_client/ /optee_client/# mkdir build; cd build /optee_client/build/# cmake .. /optee_client/build/# make /optee_client/build/# make install /# git clone https://github.com/linaro-swg/optee_examples.git /# cd optee_examples/ /optee_examples/# mkdir build; cd build /optee_examples/build/# cmake .. /optee_examples/build/# make /optee_examples/build# ./secure_storage/optee_example_secure_storage Prepare session with the TA optee_example_secure_storage: TEEC_InitializeContext failed with code 0xffff000 ``` エラーが出た。`TEEC_InitializeContext` に失敗している。 https://github.com/OP-TEE/optee_client/blob/e7cba71cc6e2ecd02f412c7e9ee104f0a5dffc6f/public/tee_client_api.h#L414 実装を見ると ```c TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *ctx) { ... for (n = 0; n < TEEC_MAX_DEV_SEQ; n++) { uint32_t gen_caps = 0; snprintf(devname, sizeof(devname), "/dev/tee%zu", n); fd = teec_open_dev(devname, name, &gen_caps); if (fd >= 0) { ctx->fd = fd; ctx->reg_mem = gen_caps & TEE_GEN_CAP_REG_MEM; ctx->memref_null = gen_caps & TEE_GEN_CAP_MEMREF_NULL; return TEEC_SUCCESS; } } return TEEC_ERROR_ITEM_NOT_FOUND; ``` `#define TEEC_ERROR_ITEM_NOT_FOUND 0xFFFF0008` `/dev/tee` がサポートされていないと動かない. qemu上で動かすと書かれていたので中断。 # Refs https://www.timesys.com/webinars/Secure-by-Design-NXP-Webinar-Series-OP-TEE.pdf https://docs.kernel.org/staging/tee.html https://www.trustonic.com/technical-articles/what-is-a-trusted-execution-environment-tee/ https://lepidum.co.jp/blog/2020-03-13/tee/ https://www.jstage.jst.go.jp/article/essfr/14/2/14_107/_pdf/-char/ja https://logmi.jp/tech/articles/324252 https://www.eaglys.co.jp/news/column/tee/#:~:text=TEE%E3%81%AE%E6%A7%8B%E9%80%A0%E3%81%A8%E3%81%97%E3%81%A6%E3%81%AF,%E9%A0%98%E5%9F%9F%E3%81%8C%E7%94%9F%E6%88%90%E3%81%95%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82 https://qiita.com/Cliffford/items/2f155f40a1c3eec288cf https://ithub.com/pengyuan-zhou/Privacy-Preserving-Computation-PaperList https://www.kernel.org/doc/Documentation/tee.txt