This repository contains a coding exercise for implementing a private KMS import/export service.
Implement a private KMS import/export service that lets a client:
- Start an import session → receive an ImportEnvelope and session public key.
- Finish the import → TEE decrypts material, stores it encrypted under the TEE master key, returns a wallet_id.
- Export that wallet encrypted for any caller-supplied P-256 public key.
- Everything (key-gen, AES-GCM, ECIES, signing, random) runs inside a secure-environment service.
- Wallet data at rest is encrypted with a single TEE-resident key.
- Bonus points: Add an optional proof so clients can verify the TEE really generated the session key.
You can assume that authentication has already been handled by another system. There's also no need to link any user private keys - just treat the database as if it's personal to the user making the call.
This project implements the KMS service with a clear trust boundary separation:
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────────┐
│ Client App │ │ KMS API │ │ Secure Environment │
│ (port 3002) │◄──►│ (untrusted) │◄──►│ (trusted) │
│ │ │ port 3002 │ │ port 3000 │
└─────────────────┘ └──────────────────┘ └─────────────────────┘
- KMS API: Considered untrusted - acts as a coordinator
- Secure Environment: Trusted - handles all cryptographic operations
- All encryption/decryption operations must occur within the secure environment
Trusted Component - Handles all cryptographic operations
- Port: 3000
- Responsibilities:
- Key generation and management using
RootKey - Symmetric encryption/decryption (AES-GCM)
- Public key exposure for client verification
- Secure cryptographic operations isolation
- All SecureRuntime.trustedEnvExec calls happen here
- Key generation and management using
Untrusted Component - API Coordinator
- Port: 3002
- Responsibilities:
- Client-facing API endpoints
- Coordination of requests to secure environment
- No direct cryptographic operations
- Service health monitoring
- Cannot perform any cryptographic operations directly
Demonstration Client
- Demonstrates complete import/export workflow
- Interacts with KMS API (not directly with secure environment)
- Rust 1.85.0 or later
- Cargo package manager
- Start the Secure Environment (must run first):
cargo run --bin secure-environment- Start the KMS API (in a new terminal):
cargo run --bin kms-api- Run the Client Example (in a new terminal):
cargo run --bin client-exampleYour implementation should include:
- Import Session Initiation: Generate session keys and return import envelope
- Import Completion: Decrypt imported material and store securely
- Export Functionality: Export wallets encrypted for caller's public key
- Secure Execution: All cryptographic operations must run within SecureRuntime.trustedEnvExec
- TEE Master Key: Single key for encrypting wallet data at rest
- Trust Boundary: KMS API must never perform crypto operations - only coordinate with secure environment
- All cryptographic operations isolated to secure environment
- KMS API cannot perform encryption/decryption operations
- Clear separation between trusted and untrusted components
- AES-256-GCM: Authenticated symmetric encryption
- P-256 ECDSA: Digital signatures for authenticity
- ECIES: Hybrid encryption for asymmetric operations
- HKDF: Secure key derivation with domain separation
- Optional proof generation to verify TEE-generated session keys
Run the full test suite:
cargo test