rust-license-key
A production-grade Rust library for creating and validating offline software licenses using Ed25519 cryptography.
Features
- Asymmetric Cryptography - Licenses signed with Ed25519; clients only need the public key
- Offline Validation - No network calls required for license verification
- Rich Constraints - Expiration, features, hostnames, versions, connection limits, and custom data
- Tamper-Proof - Any modification invalidates the cryptographic signature
- Human-Readable - JSON-based format for easy debugging
- Type-Safe - Strongly typed API with comprehensive error handling
- No Panics - All operations return
Resultfor safe error handling
Installation
Add to your Cargo.toml:
[]
= "0.1"
= "0.4"
Quick Start
Generate a Key Pair
use *;
let key_pair = generate?;
// Store the private key securely (publisher only)
println!;
// Embed the public key in your application
println!;
Create a License (Publisher Side)
use *;
use Duration;
let key_pair = from_private_key_base64?;
let license = new
.license_id
.customer_id
.customer_name
.expires_in
.allowed_features
.max_connections
.build_and_sign_to_json?;
// Send `license` to your customer
Validate a License (Client Side)
use *;
// Public key embedded in your application
const PUBLIC_KEY: &str = "your-public-key";
let result = validate_license?;
if result.is_valid else
Quick Validation Helpers
use *;
// Simple validity check
if is_license_valid
// Check specific feature
if is_feature_allowed
License Constraints
| Constraint | Description |
|---|---|
expires_at / expires_in |
License expiration date |
valid_from / valid_after |
Delayed activation date |
allowed_features |
Whitelist of permitted features |
denied_features |
Blacklist of forbidden features |
max_connections |
Maximum concurrent connections/seats |
allowed_hostnames |
Permitted server hostnames |
allowed_machine_ids |
Permitted machine identifiers |
minimum_version |
Minimum software version required |
maximum_version |
Maximum software version allowed |
custom_constraints |
Application-specific key-value data |
Validation Context
Validate against runtime environment:
use *;
use Version;
let context = new
.with_hostname
.with_machine_id
.with_software_version
.with_connection_count
.with_feature;
let result = validate_license?;
Security Model
┌─────────────────────────────────────┐
│ PUBLISHER (Secure) │
│ Private Key → Sign → License │
└──────────────────┬──────────────────┘
│ (distribute license)
▼
┌─────────────────────────────────────┐
│ CLIENT (Untrusted) │
│ Public Key → Verify → Valid/Invalid│
└─────────────────────────────────────┘
- Private key: Never leaves your secure environment
- Public key: Safely embedded in distributed applications
- Signatures: Ed25519 with 128-bit security level
- No encryption: Payload is readable but tamper-proof
Documentation
- Getting Started - Installation and first steps
- User Guide - Complete usage documentation
- API Reference - Full API documentation
- Examples - Practical code examples
- Security Guide - Security best practices
- Architecture - Technical design documentation
- Contributing - Contribution guidelines
Example License Output
Decoded payload:
Minimum Rust Version
Rust 1.70 or later.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please read our Contributing Guide before submitting a PR.
Acknowledgments
Built with:
- ed25519-dalek - Ed25519 signatures
- serde - Serialization framework
- chrono - Date and time handling