Skip to content

SuperInstance/token-vault

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Token Vault ๐Ÿ”

Crates.io Documentation License: MIT OR Apache-2.0 Build Status

Secure token storage system with AES-256-GCM encryption-at-rest for API keys, secrets, and credentials.

Token Vault provides military-grade encryption for your sensitive data with a simple, secure API. All secrets are encrypted with AES-256-GCM before storage, using Argon2id key derivation for password-based encryption.

๐Ÿš€ Quick Start

# Cargo.toml
[dependencies]
token-vault = "0.1"
use token_vault::TokenVault;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create vault with password
    let vault = TokenVault::new("my_vault.db", "my-secure-password")?;

    // Store API tokens
    vault.store("github_token", "ghp_1234567890abcdef", None)?;

    // Retrieve securely
    let token = vault.retrieve("github_token", None)?;
    assert_eq!(token, Some("ghp_1234567890abcdef".to_string()));

    Ok(())
}

โœจ Features

  • ๐Ÿ”’ Encryption-at-rest: AES-256-GCM encryption for all stored secrets
  • ๐Ÿ”‘ Key derivation: Argon2id password-based key derivation (256 MB RAM, 3 iterations)
  • ๐Ÿ“ฆ Session isolation: Multiple isolated sessions with separate token namespaces
  • โฐ Token expiration: Automatic expiration and rotation support
  • ๐Ÿ‘ฅ Access control: Role-based access control (RBAC)
  • ๐Ÿ“‹ Audit logging: Comprehensive audit trail for all operations
  • ๐Ÿงน Memory security: Automatic zeroization of sensitive data with zeroize
  • ๐Ÿ”Œ Thread-safe: Arc<Mutex<T>> for concurrent access

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     Token Vault                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                          โ”‚
โ”‚  User Password                                          โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  Argon2id Key Derivation (t=3, m=256MiB, p=4)           โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  Master Key (256-bit)                                   โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ”œโ”€โ”€โ–ถ Encryption Key (AES-256-GCM)                 โ”‚
โ”‚       โ”‚      โ”‚                                          โ”‚
โ”‚       โ”‚      โ–ผ                                          โ”‚
โ”‚       โ”‚  Encrypted Secrets (SQLite)                     โ”‚
โ”‚       โ”‚      โ”‚                                          โ”‚
โ”‚       โ”‚      โ””โ”€โ”€โ–ถ Stored on Disk                        โ”‚
โ”‚       โ”‚                                                 โ”‚
โ”‚       โ””โ”€โ”€โ–ถ HMAC Key (authentication)                    โ”‚
โ”‚              โ”‚                                          โ”‚
โ”‚              โ””โ”€โ”€โ–ถ Verify operations                      โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“– Documentation

Core Operations

Create Vault

let vault = TokenVault::new("path/to/vault.db", "master-password")?;

Store Token

vault.store("api_key", "sk_live_1234567890", None)?;
vault.store("db_password", "secret123", Some("production"))?;

Retrieve Token

let value = vault.retrieve("api_key", None)?;

Update Token

vault.update("api_key", "new_secret_value", None)?;

Delete Token

vault.delete("api_key", None)?;

List Tokens

let tokens = vault.list_tokens(Some("production"))?;
for token in tokens {
    println!("{}", token);
}

Session Management

// Use sessions to isolate different contexts
vault.store("api_key", "prod_key", Some("production"))?;
vault.store("api_key", "dev_key", Some("development"))?;

// Retrieve from specific session
let prod_key = vault.retrieve("api_key", Some("production"))?;
let dev_key = vault.retrieve("api_key", Some("development"))?;

Audit Logging

let entries = vault.audit_entries();
for entry in entries {
    println!("{:?} {} - {:?}", entry.operation, entry.target, entry.result);
}

๐Ÿ” Security

Threat Model

Token Vault protects against:

  1. Compromised Database: AES-256-GCM encryption-at-rest
  2. Memory Dump Attacks: Zeroization with zeroize crate
  3. Password Brute Force: Argon2id with high memory/time cost
  4. SQL Injection: Parameterized queries only

See threat_model for detailed analysis.

Key Derivation Parameters

  • Algorithm: Argon2id
  • Time Cost: 3 iterations
  • Memory Cost: 256 MiB (262,144 KiB)
  • Parallelism: 4 lanes
  • Output: 256-bit key

Encryption

  • Algorithm: AES-256-GCM
  • Nonce: 96-bit (random per encryption)
  • Authentication: GCM auth tag (128-bit)

๐ŸŽฏ Use Cases

// 1. Application Configuration
let config = AppConfig::new("config.db", "password")?;
let db_url = config.get_database_url()?;

// 2. API Key Storage
vault.store("stripe_secret", "sk_live_...", None)?;
vault.store("github_token", "ghp_...", None)?;

// 3. Database Credentials
vault.store("db_password", "secure_password", Some("production"))?;

// 4. Service Tokens
vault.store("jwt_secret", "jwt_signing_key", None)?;

๐Ÿ“ฆ CLI Tools

Token Vault includes three CLI tools:

Server (token-vault-server)

token-vault-server
# Starts HTTP server on 0.0.0.0:8080
# TODO: Full implementation coming soon

Client (token-vault-client)

token-vault-client get <token>
token-vault-client set <token> <value>
token-vault-client list
# TODO: Full implementation coming soon

Admin (token-vault-admin)

token-vault-admin init <db-path>
token-vault-admin backup <db-path> <backup-file>
token-vault-admin restore <backup-file> <db-path>
# TODO: Full implementation coming soon

๐Ÿงช Testing

# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific test
cargo test test_store_and_retrieve

๐Ÿ“š Examples

See the examples/ directory for complete examples:

Run examples:

cargo run --example basic_vault
cargo run --example custom_integration

๐Ÿ”ง Installation

cargo install token-vault

Or add to your Cargo.toml:

[dependencies]
token-vault = "0.1"

๐Ÿ“Š Performance

  • Store: O(1) - Single INSERT with indexed lookup
  • Retrieve: O(1) - Single SELECT with index
  • Encrypt: ~1ยตs per 1KB (AES-256-GCM hardware accelerated)
  • Decrypt: ~1ยตs per 1KB (AES-256-GCM hardware accelerated)

๐Ÿค Integration

With Privox (PII Redaction)

// TODO: Add privox integration example
// Use privox to redact PII in audit logs

๐Ÿ“ License

Licensed under either of:

at your option.

๐Ÿ™ Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ”— Related Projects

๐Ÿ“ฎ Contact

๐ŸŒŸ Used By


Made with โค๏ธ by the SuperInstance team

โฌ† Back to top

About

Secure token storage system with AES-256-GCM encryption-at-rest for API keys, secrets, and credentials

Topics

Resources

License

MIT and 2 other licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages