Overview
The QIMEM Platform is organized into three primary layers:- Library (
qimem): Core cryptographic engine, envelope serialization, key storage abstractions - Binaries: HTTP API servers (
qimem-api,qauth-api) and CLI tools (qimem,qauth) - APIs: RESTful endpoints for security operations (
/v1/security/*), authentication (/v1/auth/*), and plugin management (/v1/plugins/*)
The platform exposes versioned APIs starting with
/v1/ to ensure backward compatibility as features evolve.Library Components
The coreqimem library (src/lib.rs:1-21) provides:
Cryptography Module
- Algorithm: Enum supporting AES-256-GCM (always available) and ChaCha20-Poly1305 (optional
chachafeature) - CryptoEngine: Handles encryption/decryption operations with AEAD guarantees
Envelope Format
Key Storage
- KeyStore trait: Abstract interface for key lifecycle operations
- InMemoryKeyStore: Fast, ephemeral storage for development
- PostgresKeyStore: Durable, transactional storage for production (requires
statefulfeature)
Binaries
qimem-api
HTTP server exposing key lifecycle and encryption endpoints:POST /keys- Create new encryption keyPOST /encrypt- Encrypt plaintext with key_idPOST /decrypt- Decrypt envelopePOST /rotate- Rotate key to new version
qauth-api
Unified platform server combining security, authentication, and plugin APIs:/v1/security/*- Encryption operations/v1/auth/*- QAuth identity and token management/v1/plugins/*- Plugin manifest registration
CLI Tools
Command-line interfaces for key generation, encryption/decryption, and realm/user management.Request Flow
Encryption Flow
- Client sends
POST /v1/security/encryptwithkey_idand plaintextinput - API Handler (src/platform_api.rs:123-135) extracts key from store
- CryptoEngine generates random nonce, encrypts with AES-256-GCM
- Envelope serialization produces deterministic binary format
- Response returns Base64-encoded envelope
Decryption Flow
- Client sends
POST /v1/security/decryptwith Base64 envelope - API Handler (src/platform_api.rs:147-161) deserializes envelope
- KeyStore retrieves key using
key_idfrom envelope - CryptoEngine validates algorithm match, decrypts with tag verification
- Response returns plaintext
Key Rotation Flow
- Client sends
POST /v1/security/rotatewithkey_id - KeyStore marks old key as
active: false - KeyStore generates new key with incremented
versionand samelineage_id - Response returns new
KeyMetadata
Old keys remain available for decryption. Only the latest active key can encrypt new data.
Storage Backends
In-Memory Store
Source: src/keystore/memory.rs:1-89- Uses
std::sync::RwLockfor thread safety - Data lost on process restart
- No persistence or replication
- Ideal for testing and ephemeral workloads
PostgreSQL Store (stateful feature)
Source: src/keystore/postgres.rs:1-99- Requires
statefulfeature flag: - Uses
sqlxwith connection pooling - Atomic key rotation via transactions (src/keystore/postgres.rs:68-98)
- Supports encrypted disks and managed Postgres
- Migration system via
sqlx::migrate!
Security Boundaries
No Unsafe Code
aes-gcm, chacha20poly1305).
Key Material Protection
Key bytes are wrapped withzeroize::Zeroizing (src/keystore/mod.rs:37):
No Logging of Secrets
Key material is never logged or exposed in error messages.Next Steps
Encryption
Learn about AES-256-GCM and ChaCha20-Poly1305 support
Envelope Format
Understand deterministic serialization and tamper detection
Key Rotation
Explore version tracking and backward compatibility
QAuth Identity
Discover realm-based authentication and RBAC