Trusted Application for secure off-chain data storage
Note
This is based on OP-TEE Sample Application secure storage example.
| Application name | UUID |
|---|---|
| off_chain_secure_storage | e3ae8c32-5fc1-42e4-b476-b35fe3f8f07d |
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.
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┌─────────────────────────────────────────────────────────┐
│ 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 │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
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
The application provides the following commands:
- 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}'- 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...'- 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}'- Get Digital Attestation
./off_chain_secure_storage attestPurpose: Obtain cryptographic proof of TA authenticity
Response: Returns RSA-PSS signature of TA UUID
- Get Public Key
./off_chain_secure_storage public-keyPurpose: Extract TA's public key for signature verification
Response: Returns RSA-2048 public key components
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)Execute the following commands to run OP-TEE in QEMU:
cd $OPTEE_DIR/build
make run-onlyThen follow these steps:
- Press
corcontto start the QEMU emulation - Login as
rootinNormal Worldconsole
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
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/htmlThe 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.
- OP-TEE Documentation - Official OP-TEE development guide
- TEE Internal Core API Specifications - Trusted application specifications
- TEE Client API Specification - Client application specifications