Skip to content

joelvaz0x01/off-chain-secure-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Off-Chain Data Storage using OP-TEE

Trusted Application for secure off-chain data storage

πŸ“„ Project Overview

Note

This is based on OP-TEE Sample Application secure storage example.

Application name UUID
off_chain_secure_storage e3ae8c32-5fc1-42e4-b476-b35fe3f8f07d

πŸ“‹ Project Description

This project implements a secure off-chain data storage solution using OP-TEE (Open Portable Trusted Execution Environment) for IoT sensor data management. The system main purpose is storing sensitive data off-chain while maintaining blockchain-level integrity and auditability through cryptographic hashing.

πŸ“‚ Project Structure

off_chain_secure_storage/
β”œβ”€β”€ docs/      # Documentation files
β”‚
β”œβ”€β”€ host/             # Client Application (Normal World)
β”‚   β”œβ”€β”€ main.c        # Main CLI application
β”‚   └── Makefile
β”‚
β”œβ”€β”€ iot-json/      # Sample IoT data files
β”‚
β”œβ”€β”€ ta/                               # Trusted Application (Secure World)
β”‚   β”œβ”€β”€ include/
β”‚   β”‚   β”œβ”€β”€ crypto_operations.h       # Functions and macros for cryptography
β”‚   β”‚   └── secure_storage_ta.h       # TA header file
β”‚   β”‚
β”‚   β”œβ”€β”€ crypto_operations.c           # Main TA implementation
β”‚   β”œβ”€β”€ secure_storage_ta.c           # Main TA implementation
β”‚   β”œβ”€β”€ Makefile
β”‚   β”œβ”€β”€ user_ta_header_defines.h      # TA configuration
β”‚   └── sub.mk
β”‚
β”œβ”€β”€ Android.mk
β”œβ”€β”€ CMakeLists.txt
β”œβ”€β”€ LICENSE
β”œβ”€β”€ Makefile            
└── README.md

πŸ’» System Architecture

Security Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Normal World                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚          Client Application (CA)                β”‚    β”‚
β”‚  β”‚  β€’ Command parsing                              β”‚    β”‚
β”‚  β”‚  β€’ TEE Client API calls                         β”‚    β”‚
β”‚  β”‚  β€’ User interface                               β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                           β”‚                             β”‚
β”‚                    TEE Client API                       β”‚
β”‚                           β”‚                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚ TrustZone Boundary
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Secure World                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚       Trusted Application (TA)                  β”‚    β”‚
β”‚  β”‚  β€’ JSON data encryption/decryption              β”‚    β”‚
β”‚  β”‚  β€’ SHA-256 hash computation                     β”‚    β”‚
β”‚  β”‚  β€’ RSA key management                           β”‚    β”‚
β”‚  β”‚  β€’ Persistent storage access                    β”‚    β”‚
β”‚  β”‚  β€’ Digital attestation                          β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚           OP-TEE OS Services                    β”‚    β”‚
β”‚  β”‚  β€’ Secure storage                               β”‚    β”‚
β”‚  β”‚  β€’ Cryptographic operations                     β”‚    β”‚
β”‚  β”‚  β€’ Memory management                            β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

System Components

Trusted Application (TA) - Runs in OP-TEE Secure World:

  • Secure data storage and retrieval
  • Cryptographic operations (SHA-256 hashing)
  • Key management and encryption
  • Attestation services

Client Application (CA) - Runs in Normal World:

  • Command-line interface for user interactions
  • Communication bridge to TA

QEMU Emulation Environment

  • ARM TrustZone simulation for development:
  • Secure and Normal World isolation

Command Line Interface

The application provides the following commands:


  1. Store JSON File
./off_chain_secure_storage store <iot_device_id> <json_data>

Purpose: Securely store IoT sensor data with device identification

Response: Returns the file ID (SHA-256 hash of contents)

Example:

./off_chain_secure_storage store FARM001 '{"temperature": 24.5, "humidity": 65.2}'

  1. Retrieve JSON File
./off_chain_secure_storage retrieve <json_hash>

Purpose: Retrieve stored data using its SHA-256 hash

Response: Returns the decrypted JSON file contents

Example:

./off_chain_secure_storage retrieve 'a1b2c3d4e5f6789...'

  1. Get File Hash
./off_chain_secure_storage hash <json_data>

Purpose: Generate SHA-256 hash without storing the file

Response: Returns cryptographic hash for blockchain anchoring

Example:

./off_chain_secure_storage hash '{"sensor_id": "ENV001", "reading": 42}'

  1. Get Digital Attestation
./off_chain_secure_storage attest

Purpose: Obtain cryptographic proof of TA authenticity

Response: Returns RSA-PSS signature of TA UUID


  1. Get Public Key
./off_chain_secure_storage public-key

Purpose: Extract TA's public key for signature verification

Response: Returns RSA-2048 public key components

πŸ”§ Installation and Setup

Prerequisites

export OPTEE_DIR=~/optee

# Create OP-TEE directory and initialize repository
mkdir $OPTEE_DIR && cd $OPTEE_DIR
repo init -u https://github.com/OP-TEE/manifest.git -m qemu_v8.xml
repo sync

# Build OP-TEE system
cd $OPTEE_DIR/build
make toolchains
make --jobs=$(nproc)

# Clone this project
cd $OPTEE_DIR/optee_examples
git clone https://github.com/joelvaz0x01/off-chain-secure-storage.git off_chain_secure_storage

# Rebuild OP-TEE with the new project
cd $OPTEE_DIR/build
make --jobs=$(nproc)

Running OP-TEE with built Application

Execute the following commands to run OP-TEE in QEMU:

cd $OPTEE_DIR/build
make run-only

Then follow these steps:

  1. Press c or cont to start the QEMU emulation
  2. Login as root in Normal World console

Now you can run the off_chain_secure_storage command in the QEMU terminal:

/usr/bin/off_chain_secure_storage <command>

Commands:
    store <iot_device_id> <json_data> - Store JSON data for a given IoT device ID
    retrieve <json_hash> - Retrieve JSON data for a given hash
    hash <json_data> - Get SHA256 hash of a given JSON data
    attest - Get attestation data of the TA
    public-key - Get public key of the TA

πŸ“– Documentation

To build the documentation, you will need to install Python and make the following commands:

# Install Python virtual environment
cd $OPTEE_DIR/optee_examples/off_chain_secure_storage
python -m venv .venv
source .venv/bin/activate

# Build documentation
pip install -r docs/requirements.txt
sphinx-build -b html docs/ docs/_build/html

The documentation will be generated in the _build/html directory. You can open the index.html file in a web browser to view it or consult the online documentation.

🀝 Contributors

πŸ”— References

  1. OP-TEE Documentation - Official OP-TEE development guide
  2. TEE Internal Core API Specifications - Trusted application specifications
  3. TEE Client API Specification - Client application specifications

About

Practical group work made for Secure Execution Environments @ UA - Portugal.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published