End-to-end encryption middleware for FastAPI
Project description
rossetta-fastapi
End-to-end encryption middleware for FastAPI applications.
Installation
pip install rossetta-fastapi
Usage
Add the middleware to your FastAPI application with a single line:
from fastapi import FastAPI
from rossetta_fastapi import RossettaMiddleware
app = FastAPI()
# Add the middleware - that's it!
app.add_middleware(RossettaMiddleware)
# All your existing routes now have e2e encryption
@app.get("/api/data")
async def get_data():
return {"message": "This response is automatically encrypted!"}
@app.post("/api/submit")
async def submit_data(data: dict):
# Request is automatically decrypted
return {"received": data}
Features
- Zero Code Changes: Add middleware and all routes are automatically protected
- Transparent Encryption: Works with existing FastAPI code
- Automatic Key Exchange: ECDH key exchange handled automatically
- Replay Attack Prevention: Built-in timestamp and nonce validation
- Session Management: Automatic session lifecycle management
Configuration
app.add_middleware(
RossettaMiddleware,
session_duration=3600, # Session duration in seconds (default: 1 hour)
max_timestamp_drift=300, # Max timestamp drift in seconds (default: 5 minutes)
)
How It Works
- Client initiates ECDH key exchange via
/__rossetta_handshake__endpoint - Middleware derives shared secret from key exchange
- All subsequent requests are encrypted with the shared session key
- Middleware decrypts requests, validates nonce/timestamp
- Processes request through normal FastAPI handlers
- Encrypts response before sending back to client
Requirements
- Python 3.8+
- FastAPI 0.100.0+
- cryptography 41.0.0+
Client Compatibility
Works with rossetta-client npm package for JavaScript/TypeScript clients.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rossetta_fastapi-0.2.0.tar.gz
(13.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rossetta_fastapi-0.2.0.tar.gz.
File metadata
- Download URL: rossetta_fastapi-0.2.0.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7af0e5ac1ee794a53b84ae36148750b4b6c5a88436fe12ccca5a59b719734bd
|
|
| MD5 |
6d0f152da80f910d1b9d2f6db2200dee
|
|
| BLAKE2b-256 |
b8958a708389f0a58a373bc026888dc6a6e9c39ef9e31983ede6a90a121c7cd8
|
File details
Details for the file rossetta_fastapi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: rossetta_fastapi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90094cea44cfa8f61648bd9f06d16658ce4013347d99eb10c12b2ea7faca0931
|
|
| MD5 |
dd1cdbd09a41f111df3222521aa9b7d2
|
|
| BLAKE2b-256 |
5cb511bb4e8ddb891a8dd0e24542bd137537fccf3692fe783ffc7ee1fb3f84da
|