Crate turbomcp_dpop

Crate turbomcp_dpop 

Source
Expand description

§TurboMCP DPoP Implementation

RFC 9449 compliant Demonstration of Proof-of-Possession (DPoP) implementation

This crate provides production-grade DPoP support for TurboMCP, implementing the full RFC 9449 specification with enterprise-ready security features:

§Core Features

  • RFC 9449 Compliance - Full specification implementation
  • Cryptographic Security - RSA, ECDSA P-256, and PSS support
  • Token Binding - Prevents stolen token usage
  • Replay Protection - Nonce tracking and timestamp validation
  • Enterprise Ready - HSM integration, audit logging, key rotation

§Quick Start

use turbomcp_dpop::{DpopKeyManager, DpopProofGenerator, DpopAlgorithm};

// Generate key pair for DPoP
let key_manager = DpopKeyManager::new_memory().await?;
let key_pair = key_manager.generate_key_pair(DpopAlgorithm::ES256).await?;

// Create DPoP proof for HTTP request
let proof_gen = DpopProofGenerator::new(key_manager.into());
let proof = proof_gen.generate_proof(
    "POST",
    "https://api.example.com/oauth/token",
    None, // No access token for initial request
).await?;

println!("DPoP Header: {}", proof.to_jwt_string());

§Integration with TurboMCP OAuth

// Example OAuth integration (requires turbomcp crate)
// let config = OAuth2Config {
//     // ... existing OAuth configuration  
//     security_level: SecurityLevel::Enhanced, // 🔒 Enables DPoP
//     // ... rest unchanged
// };

§Architecture

┌─────────────────────┐    ┌─────────────────────┐    ┌─────────────────────┐
│   Application       │    │   TurboMCP OAuth    │    │   OAuth Provider    │
│   + DPoP Client     │    │   + DPoP Support    │    │   (GitHub/Google)   │
└─────────┬───────────┘    └─────────┬───────────┘    └─────────┬───────────┘
          │                          │                          │
          │ 1. Generate DPoP proof   │                          │
          │                          │                          │
          │ 2. OAuth + DPoP header ──┼──────────────────────────▶│
          │                          │                          │
          │                          │ 3. Validate DPoP proof   │
          │                          │                          │
          │◄─────────────────────────┼──────────────────────────┤
          │    4. Ephemeral token    │         bound to DPoP    │
          │       (cryptographically bound)                     │

§Security Properties

§Token Binding

  • Access tokens are cryptographically bound to client key pairs
  • Stolen tokens are unusable without the corresponding private key
  • Each token is tied to a specific client instance

§Replay Attack Prevention

  • JWT timestamps prevent token replay beyond time windows
  • Nonce tracking ensures each proof is used only once
  • HTTP method and URI binding prevents cross-endpoint attacks

§Forward Security

  • Key rotation support for long-lived applications
  • Ephemeral tokens with short lifespans (1 hour maximum)
  • Secure key material destruction on cleanup

Re-exports§

pub use errors::*;
pub use keys::*;
pub use proof::*;
pub use types::*;

Modules§

errors
DPoP error types and conversions
hsm
Hardware Security Module (HSM) integration for DPoP key management
keys
DPoP key management and cryptographic operations
proof
DPoP proof generation and validation
types
Core DPoP types and data structures

Constants§

DEFAULT_PROOF_LIFETIME_SECONDS
Default proof lifetime (60 seconds)
DPOP_JWT_TYPE
DPoP JWT header type as defined in RFC 9449
MAX_CLOCK_SKEW_SECONDS
Maximum clock skew tolerance (5 minutes)
MAX_PROOF_LIFETIME_SECONDS
Maximum proof lifetime (5 minutes)
VERSION
Current crate version

Type Aliases§

Result
DPoP result type