Common Access Token (CAT) for Rust
A Rust implementation of the Common Access Token (CAT) specification with HMAC signatures.
What is CAT?
Common Access Token (CAT) is a token format designed for authorization and authentication in distributed systems, particularly for media and content delivery applications. It provides a secure, compact, and efficient way to represent claims and authorization information between parties.
CAT is built on established standards:
- Based on CBOR Web Token (CWT) format
- Uses CBOR Object Signing and Encryption (COSE) for cryptographic operations
- Provides a binary alternative to JWT with smaller token sizes and more efficient processing
Overview
This library provides a complete implementation for generating and validating Common Access Tokens (CAT) using HMAC signatures. It is designed to be interoperable with other implementations like node-cat.
Key benefits of using CAT tokens:
- Compact: Binary format results in smaller token sizes compared to text-based formats
- Efficient: CBOR encoding/decoding is faster and requires less processing power
- Secure: Built on established cryptographic standards
- Extensible: Supports custom claims and extensions
Features
-
Token Operations:
- Generate CAT tokens with HMAC signatures (HS256)
- Validate CAT tokens with comprehensive security checks
- Support for token expiration and time-based validation
-
Claims Support:
- Standard CWT claims (issuer, subject, audience, expiration, etc.)
- CAT-specific claims (version, renewal, usage, data, authorization)
- Custom claim extension capability
-
Integration:
- Interoperability with other CAT implementations
- Easy integration with Rust applications
- Comprehensive documentation and examples
Installation
Add this to your Cargo.toml
:
[]
= "0.1"
Usage
Token Generation
This example demonstrates how to create a CAT token with standard claims:
use ;
use HashMap;
Using CAT-specific Claims
CAT extends the standard CWT claims with additional fields for specific use cases:
use ;
use HashMap;
Token Validation
This example shows how to validate a CAT token and extract its claims:
use ;
use HashMap;
Examples
The library includes several ready-to-use examples in the examples/
directory:
- generate.rs: Demonstrates basic token generation with standard claims
- validate.rs: Shows how to validate tokens and extract claims
- interop.rs: Tests interoperability with the NodeJS implementation
- cat_claims.rs: Demonstrates using CAT-specific claims for advanced use cases
To run an example:
# Generate a token
# Validate a token (replace <token> with an actual token)
# Test interoperability with NodeJS implementation
# Use CAT-specific claims
Security Considerations
When using CAT tokens in your applications, keep these security best practices in mind:
-
Key Management:
- Store signing keys securely
- Rotate keys periodically
- Use different keys for different environments
-
Token Validation:
- Always validate tokens before trusting their contents
- Check expiration times
- Verify the issuer and audience claims
-
Token Lifetime:
- Use short-lived tokens when possible
- For longer sessions, consider refresh token patterns
-
Claims:
- Only include necessary information in tokens
- Be cautious with sensitive data in claims
Compatibility
This library is designed to be interoperable with other CAT implementations:
- node-cat: The NodeJS reference implementation
- Other implementations that follow the CAT specification
Roadmap
Future development plans include:
- Support for additional signature algorithms (RSA, EdDSA)
- Encryption support for sensitive claims
- Performance optimizations
- Additional utility functions for common use cases
Contributing
Contributions are welcome! Here's how you can help:
- Report Issues: File bugs or feature requests on the issue tracker
- Submit PRs: Code contributions are appreciated
- Documentation: Improvements to docs and examples
- Testing: Additional test cases and interoperability testing
Please follow the existing code style and include tests for new features.
License
This project is licensed under the MIT License - see the LICENSE file for details.