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
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.1.5.tar.gz.
File metadata
- Download URL: rossetta_fastapi-0.1.5.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44ee3351dad7de9b2ff005cfb7ed87c10027c99163b626eb4e832706da8fd9c2
|
|
| MD5 |
bc8b5d2be37908e5c728e0b176259116
|
|
| BLAKE2b-256 |
4fd763770f6bdc707e4fdcf7f0e2cf6eca46e246f6d9f1c711cc11fc4b9b04a2
|
File details
Details for the file rossetta_fastapi-0.1.5-py3-none-any.whl.
File metadata
- Download URL: rossetta_fastapi-0.1.5-py3-none-any.whl
- Upload date:
- Size: 8.5 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 |
d4c917bfc2e451fa90a00e526b1ee8dcf08b0f8661666c09d2f69168be99f5c6
|
|
| MD5 |
6024a6cb6072fbeb09b9859b0f0c444c
|
|
| BLAKE2b-256 |
22f8f047e32875df3b76d71d47c70273b6f001dba6e95807370d6280f228cbd2
|