Skip to content

JackYoung27/secure-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Secure Runtime Demo

A demonstration of cryptographic manifest verification for machine learning artifacts.

Prerequisites

1. Generate Keys (First Time Only)

# Create keys directory and generate dev signing keypair
mkdir -p keys
python3 -c "
from cryptography.hazmat.primitives.asymmetric import ed25519
from cryptography.hazmat.primitives import serialization
import base64

# Generate keypair
private_key = ed25519.Ed25519PrivateKey.generate()
public_key = private_key.public_key()

# Save private key
with open('keys/dev_signing_key.pem', 'wb') as f:
    f.write(private_key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.PKCS8,
        encryption_algorithm=serialization.NoEncryption()
    ))

# Save public key
with open('keys/dev_signing_key.pub', 'wb') as f:
    f.write(public_key.public_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PublicFormat.SubjectPublicKeyInfo
    ))

print('Generated dev_signing_key.pem and dev_signing_key.pub')
"

2. Install Dependencies

# Install Python dependencies
pip install -r requirements.txt

Quick Start

# Run complete demo with README.md
make demo

# Run demo with your own model
make demo MODEL=path/to/your/model.onnx

What It Does

The demo shows a complete verification workflow:

  1. Fingerprint - Generate cryptographic hash of a file
  2. Sign - Sign the manifest with a private key
  3. Verify - Verify signatures and policy compliance via REST API

Makefile Commands

Command Description
make demo MODEL=model.onnx Runs the entire pipeline end-to-end
make setup Ensures .venv exists and installs deps
make fingerprint Generates manifest for the specified model
make sign Signs manifest with dev_signing_key.pem
make start Launches verifier API in background
make verify Sends signed manifest to verifier, prints receipt
make clean Kills server + removes manifests and receipts

Manual Testing

Once the demo is running, test the API:

# Health check
curl http://localhost:8080/health

# Test verification endpoint
curl http://localhost:8080/verify -X POST -H "Content-Type: application/json" -d '{"manifest": {"model_id": "test", "format": "onnx", "weights": [], "created_at": "2024-01-01T00:00:00Z", "signatures": []}}'

Troubleshooting

Common Issues

Port 8080 already in use:

# Kill any existing verifier processes
make clean
# Or manually:
pkill -f "python3 services/verifier.py"

Missing keys:

# Re-generate keys if missing
python3 -c "
from cryptography.hazmat.primitives.asymmetric import ed25519
from cryptography.hazmat.primitives import serialization
import os

os.makedirs('keys', exist_ok=True)
private_key = ed25519.Ed25519PrivateKey.generate()
public_key = private_key.public_key()

with open('keys/dev_signing_key.pem', 'wb') as f:
    f.write(private_key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.PKCS8,
        encryption_algorithm=serialization.NoEncryption()
    ))

with open('keys/dev_signing_key.pub', 'wb') as f:
    f.write(public_key.public_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PublicFormat.SubjectPublicKeyInfo
    ))
print('Keys generated successfully')
"

Dependencies missing:

# Install all required packages
pip install fastapi uvicorn cryptography blake3 requests pydantic

Manual Steps (If Makefile Fails)

# 1. Setup environment
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

# 2. Generate fingerprint
python3 tools/fingerprint.py README.md

# 3. Sign manifest
python3 tools/sign_manifest.py manifests/README.json keys/dev_signing_key.pem

# 4. Start verifier service (in background)
python3 services/verifier.py &

# 5. Test verification
curl -X POST http://localhost:8080/verify \
  -H "Content-Type: application/json" \
  -d @manifests/README.json

Project Structure

secure-runtime/
├── README.md
├── Dockerfile
├── requirements.txt
├── Makefile
├── keys/                    # Cryptographic keys
│   ├── dev_signing_key.pem
│   └── dev_signing_key.pub
├── manifests/               # Generated manifests
├── receipts/                # Verification receipts
├── services/
│   └── verifier.py         # Main verification service
└── tools/                  # Command-line tools
    ├── fingerprint.py      # Generate file fingerprints
    ├── sign_manifest.py    # Sign manifests
    ├── verify_manifest.py  # Verify receipts
    └── test_verifier_manual.py  # Manual testing

Key Features

  • One-command demo - Complete workflow in seconds
  • BLAKE3/SHA-256 hashing for file integrity
  • Ed25519 signatures for authenticity
  • Policy enforcement for compliance
  • REST API for verification
  • Signed receipts for audit trails

This is a focused demonstration of secure runtime verification for ML artifacts.

About

Portable AI runtime for verifiable, policy-enforced inference with signed outputs.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors