Skip to main content

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

  1. Client initiates ECDH key exchange via /__rossetta_handshake__ endpoint
  2. Middleware derives shared secret from key exchange
  3. All subsequent requests are encrypted with the shared session key
  4. Middleware decrypts requests, validates nonce/timestamp
  5. Processes request through normal FastAPI handlers
  6. 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.1.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rossetta_fastapi-0.1.5-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

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

Hashes for rossetta_fastapi-0.1.5.tar.gz
Algorithm Hash digest
SHA256 44ee3351dad7de9b2ff005cfb7ed87c10027c99163b626eb4e832706da8fd9c2
MD5 bc8b5d2be37908e5c728e0b176259116
BLAKE2b-256 4fd763770f6bdc707e4fdcf7f0e2cf6eca46e246f6d9f1c711cc11fc4b9b04a2

See more details on using hashes here.

File details

Details for the file rossetta_fastapi-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for rossetta_fastapi-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d4c917bfc2e451fa90a00e526b1ee8dcf08b0f8661666c09d2f69168be99f5c6
MD5 6024a6cb6072fbeb09b9859b0f0c444c
BLAKE2b-256 22f8f047e32875df3b76d71d47c70273b6f001dba6e95807370d6280f228cbd2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page