Skip to main content
Thistle ensures that AI models running on edge devices are verifiably the same model you signed at release time — even when using external AI frameworks like Edge Impulse, Roboflow, DEEPX, MemryX, and TensorFlow Lite (LiteRT). This guide walks you through the pattern for integrating model signature verification at runtime using tuc in Python applications.
See also: AI Model Update Overview for model signing and release preparation using TRH or Thistle Control Center.

Overview

AI models deployed to edge devices — whether for vision, robotics, or sensor analytics — are susceptible to tampering if their integrity is not verified before use. Thistle’s approach enforces a simple runtime pattern:
  1. Verify model signature using tuc
  2. Abort application startup on verification failure
  3. Load the model only on successful verification
This ensures your device never loads a tampered or unauthorized model.

Unified Secure Loader (Python)

To make integration seamless across platforms, we provide a unified secure loader module that encapsulates signature verification and model loading logic.

Secure Loader Module: thistle_secure_loader.py

import os
import subprocess
from pathlib import Path
from typing import Callable, Any

class ModelVerificationError(Exception):
    pass

def get_tuc_config_path() -> str:
    """
    Read TUC config path from the TUC_CONFIG_PATH environment
    variable, falling back to the default if unset.
    """
    return os.environ.get("TUC_CONFIG_PATH", "./tuc-config.json")

def verify_model(model_path: str) -> None:
    """
    Verify a model file using tuc before loading.
    Raises ModelVerificationError on failure.
    
    Requires TUC v1.7.1 or above for verify-file command.
    """
    model_path = Path(model_path)
    sig_path = model_path.with_suffix(model_path.suffix + ".thistlesig")
    config_path = get_tuc_config_path()

    result = subprocess.run(
        [
            "tuc",
            "-c",
            config_path,
            "verify-file",
            str(model_path),
            str(sig_path),
        ],
        capture_output=True,
        text=True,
        check=False,
    )

    if result.returncode != 0:
        raise ModelVerificationError(
            f"Model verification failed for {model_path}:\n{result.stderr}"
        )

def secure_load(
    model_path: str,
    loader_func: Callable[[str], Any],
) -> Any:
    """
    Securely verifies and loads a model file.
    """
    verify_model(model_path)
    return loader_func(model_path)

Setting Up Your Environment

Before using the secure loader, set your TUC configuration path:
export TUC_CONFIG_PATH="./tuc-config.json"
You can also define this in container environments, Kubernetes manifests, or systemd unit files for consistent deployment.

Platform Examples

See the platform-specific guides for integration examples:

Summary

Thistle’s secure loader module brings the same robust provenance guarantees used for OTA updates to AI model consumption on edge platforms. By verifying model signatures at application startup using tuc, your code only ever uses models that were signed and released through your secure Thistle workflow. Secure model usage is now a one-function call integration:
model = secure_load("model.onnx", loader_function)