Skip to content

c0d3d3m0n/IPSec

Repository files navigation

Unified Cross-Platform IPsec Framework

License: MIT Python 3.10+ FastAPI Docker

A professional, enterprise-grade framework designed to standardize, automate, and orchestrate IPsec tunnel configurations across heterogeneous operating systems (Windows, Linux, and macOS).


πŸ— Architecture & Flow

graph TD
    subgraph "External Control"
        Admin[System Admin] --> Swagger[Swagger UI / API Docs]
    end

    subgraph "Cloud Infrastructure (Render/Docker)"
        Swagger --> Orchestrator[FastAPI Orchestrator]
        Orchestrator --> DB[(PostgreSQL)]
    end

    subgraph "Local Endpoints"
        AgentWin[Windows Agent] -- "Polls Policy (REST)" --> Orchestrator
        AgentLin[Linux Agent] -- "Polls Policy (REST)" --> Orchestrator
        
        AgentWin --> DriverWin[Windows Driver]
        DriverWin --> WFP[Windows Filtering Platform]
        
        AgentLin --> DriverLin[strongSwan Driver]
        DriverLin --> IPsec[Linux IPsec Stack]
    end

    style Orchestrator fill:#f9f,stroke:#333,stroke-width:2px
    style DB fill:#66f,stroke:#333,stroke-width:2px
    style Swagger fill:#dfd,stroke:#333,stroke-width:2px
Loading

πŸ“‹ Project Status

  • Core Orchestrator: FastAPI backend with PostgreSQL persistence
  • Containerization: Full Docker support for cloud deployment (Render, Vercel)
  • Platform Drivers: Native Windows (PowerShell) and Linux (strongSwan) support
  • Admin Dashboard: React.js frontend with policy management
  • Phase 1 - Compliance & Telemetry (βœ… Complete):
    • Heartbeat monitoring (device health & connectivity)
    • Compliance reporting (policy adherence verification)
    • Security Association (SA) monitoring (IPsec tunnel tracking)
    • Leak detection (unauthorized data flow alerts)
    • Audit logs with immutable chain integrity (SHA-512)
  • Phase 2 - Full Zero Trust Security (βœ… Complete):
    • Internal Certificate Authority (CA) for device certificates
    • mTLS communication (mutual TLS authentication)
    • Device fingerprint attestation (HMAC-SHA512)
    • JWT token management with automatic rotation
    • Admin TOTP MFA (Time-based One-Time Passwords)
    • Behavioral trust scoring (continuous device evaluation)
    • Zero Trust middleware (threshold-based access control)
    • Rate limiting on all endpoints (DoS protection)
  • Phase 3 - Policy Routing & Driver Dispatch (βœ… Complete):
    • Policy parser with alias normalization and validation
    • Per-OS policy config generation (Linux / Windows / macOS)
    • OS-specific device config delivery
    • Native driver dispatch on agents
  • macOS Support: Upcoming integration with native IPsec APIs

Completed Changes So Far

  • Windows policy application now uses a staged PowerShell driver flow with explicit step logging.
  • PSK IKEv2 Windows tunnels now skip Phase 2 auth set creation when it is not applicable.
  • Quick mode proposal generation now uses Windows-supported parameters only.
  • The policy parser now normalizes crypto values into Windows-accepted names before dispatch.
  • The documentation set now includes the Windows runbook, policy routing guide, and a navigation index.

πŸš€ Quick Start

1. Cloud Deployment (The "Brain")

Deploy the Central Orchestrator to Render in minutes:

2. Local Setup (The "Hands")

Set up agents on your local machines:

3. Security & Advanced Topics

4. Windows Driver Notes (Completed)

  • Windows dispatcher now applies tunnel policy using a staged PowerShell flow with explicit step logging.
  • For PSK IKEv2 tunnels, Phase 2 auth set creation is skipped.
  • Quick mode proposal uses Windows-supported parameters (Encapsulation, ESPHash, Encryption).
  • Rule creation enforces inbound and outbound security requirements.
  • See AGENT_WINDOWS_RUNBOOK.txt for exact terminal commands and verification steps.

πŸ’» Tech Stack

Backend & Core

  • Framework: Python 3.10+, FastAPI 0.100+, SQLAlchemy ORM
  • Database: PostgreSQL (cloud deployments), SQLite (local dev)
  • Deployment: Docker, Render, Vercel
  • API Docs: OpenAPI/Swagger at /docs

Security (Phase 1 & 2)

  • Encryption: AES-GCM-256 (IPsec), AES-256-GCM (TLS), RSA-4096 (device certs)
  • Hashing: SHA-512 (audit trail, fingerprints), SHA-256 (JWT)
  • Authentication:
  • Admin: Username + Password + TOTP MFA
  • Devices: Fingerprint + HMAC-SHA512 + X.509 certificate
  • mTLS: Client certificate verification on all device endpoints
  • Rate Limiting: slowapi (DoS protection on all endpoints)
  • Token Management: RS256 JWT (15-min access + 7-day refresh)
  • Password Security: bcrypt with work factor 12

Agent

  • Lightweight: Python residents with minimal dependencies
  • Platforms: Windows (PowerShell), Linux (strongSwan)
  • Compliance: Heartbeat, SA monitoring, leak detection, OS-specific policy enforcement
  • Communication: mTLS client with automatic retry + backoff

Frontend

  • Dashboard: React.js with Vite bundler
  • UI Framework: Modern responsive design
  • Features:
  • Device management and enrollment
  • Policy creation and assignment
  • Real-time monitoring (heartbeat, SA status)
  • Compliance dashboard
  • Audit log viewer
  • Admin security settings (TOTP MFA setup)

πŸ“‚ Directory Structure

β”œβ”€β”€ agent/                  # Device Agent logic
β”‚   β”œβ”€β”€ client.py          # Orchestrator API client
β”‚   β”œβ”€β”€ main.py            # Agent main loop with mTLS support
β”‚   β”œβ”€β”€ config.py          # Environment-driven configuration
β”‚   β”œβ”€β”€ security/          # Security modules
β”‚   β”‚   β”œβ”€β”€ device_fingerprint.py  # Device identity & attestation
β”‚   β”‚   └── mtls_client.py         # Secure mTLS HTTP client
β”‚   β”œβ”€β”€ verification/      # Compliance verification
β”‚   β”‚   └── sa_monitor.py  # IPsec SA monitoring & leak detection
β”‚   β”œβ”€β”€ platforms/         # OS-specific drivers
β”‚   β”‚   β”œβ”€β”€ base.py        # Base platform interface
β”‚   β”‚   β”œβ”€β”€ windows.py     # Windows PowerShell integration
β”‚   β”‚   └── linux.py       # Linux strongSwan integration
β”‚   └── utils/             # Utility functions
β”‚
β”œβ”€β”€ orchestrator/          # Central Orchestrator service
β”‚   β”œβ”€β”€ main.py           # FastAPI app initialization
β”‚   β”œβ”€β”€ models.py         # SQLAlchemy ORM models
β”‚   β”œβ”€β”€ schemas.py        # Pydantic request/response schemas
β”‚   β”œβ”€β”€ auth.py           # Authentication & authorization
β”‚   β”œβ”€β”€ config.py         # Configuration management
β”‚   β”œβ”€β”€ database.py       # Database connection pooling
β”‚   β”œβ”€β”€ security/         # Security modules
β”‚   β”‚   β”œβ”€β”€ certificate_authority.py  # Internal CA for device certs
β”‚   β”‚   β”œβ”€β”€ token_manager.py          # JWT access & refresh tokens
β”‚   β”‚   β”œβ”€β”€ totp_manager.py           # Admin TOTP MFA
β”‚   β”‚   └── trust_evaluator.py        # Zero Trust scoring
β”‚   β”œβ”€β”€ middleware/       # Request middleware
β”‚   β”‚   └── zero_trust.py # mTLS verification & trust enforcement
β”‚   β”œβ”€β”€ routers/          # API endpoint handlers
β”‚   β”‚   β”œβ”€β”€ auth.py       # User authentication endpoints
β”‚   β”‚   β”œβ”€β”€ devices.py    # Device enrollment & management
β”‚   β”‚   β”œβ”€β”€ policies.py   # IPsec policy management
β”‚   β”‚   └── compliance.py # Compliance & monitoring endpoints
β”‚   β”œβ”€β”€ services/         # Business logic services
β”‚   β”œβ”€β”€ models/           # Database model extensions
β”‚   β”‚   └── certificate.py # Device certificate ORM tables
β”‚   β”œβ”€β”€ schemas/          # Extended Pydantic schemas
β”‚   β”‚   └── compliance.py # Compliance request/response schemas
β”‚   β”œβ”€β”€ frontend/         # React.js admin dashboard
β”‚   β”‚   β”œβ”€β”€ src/          # React components
β”‚   β”‚   β”œβ”€β”€ index.html    # HTML entry point
β”‚   β”‚   β”œβ”€β”€ package.json  # Node dependencies
β”‚   β”‚   └── vite.config.js # Vite build config
β”‚   └── generate_keys.py  # Key pair generation utility
β”‚
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ INDEX.md                    # Documentation navigation index
β”‚   β”œβ”€β”€ USAGE_GUIDE.md              # Complete usage guide (START HERE)
β”‚   β”œβ”€β”€ ZERO_TRUST_SETUP.md         # Zero Trust architecture deep dive
β”‚   β”œβ”€β”€ COMPLIANCE_AND_MONITORING.md # Phase 1 telemetry & monitoring
β”‚   β”œβ”€β”€ SECURITY_ARCHITECTURE.md    # Cryptography & threat models
β”‚   β”œβ”€β”€ POLICY_ROUTING_AND_DRIVERS.md # Policy parser and native driver behavior
β”‚   β”œβ”€β”€ API_TESTING_GUIDE.md        # API validation and endpoint testing
β”‚   β”œβ”€β”€ AGENT_REGISTRATION.md       # Device enrollment guide
β”‚   β”œβ”€β”€ AGENT_WINDOWS_RUNBOOK.txt   # Windows agent env vars and command sequence
β”‚   β”œβ”€β”€ DEPLOYMENT_LINUX.md         # Linux deployment instructions
β”‚   └── DEPLOYMENT_VERCEL.md        # Vercel/Render deployment
β”‚
β”œβ”€β”€ keys/                  # Cryptographic keys (not in repo)
β”‚   β”œβ”€β”€ ca.crt            # CA public certificate
β”‚   └── ca.key            # CA private key (KEEP SECURE!)
β”‚
β”œβ”€β”€ shared/                # Shared utilities
β”œβ”€β”€ Dockerfile             # Container definition for Orchestrator
β”œβ”€β”€ render.yaml            # Render infrastructure-as-code
β”œβ”€β”€ LICENSE                # MIT License
β”œβ”€β”€ README.md              # This file
└── TEST_PLAN.md           # Comprehensive test strategies

🀝 Contributing

Contributions are welcome! Please follow the standard fork/PR workflow.

πŸ“„ License

Distributed under the MIT License. See LICENSE for details.

About

A Python-based framework to standardize and automate IPsec tunnel configuration across heterogeneous environments (Windows, Linux, macOS).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors