How sonertari/sslproxy works
Project Type and Purpose
• SSLproxy is an open-source network proxy tool (not a full-stack web app) written in C.
• It transparently intercepts (diverts) SSL/TLS and TCP traffic, decrypts it, feeds it to external “listening” programs for deep inspection or modification, then re-encrypts and forwards to the original destination.
• It uses NAT engines (pf/ipfw/netfilter/TPROXY) for transparent redirection and supports extensive filtering, certificate forging, user authentication, logging, and protocol validation.
File-Structure Analysis
• Top level: build scripts (Mk/, GNUmakefile, BSDmakefile), configuration (src/sslproxy.conf{.5}), and documentation (README.md, man pages).
• src/ – C source code:
• main.c, opts.c (CLI & config parser)
• proxy*.c (core loop, connection management, threading)
• filter.c (filter rules engine)
• ssl.c, cert.c (OpenSSL integration, on-the-fly certificate generation)
• proto*.c (per-protocol handlers: HTTP, SMTP, POP3, passthrough, TCP)
• cache*.c (session/session key caching)
• privsep.c (privilege separation)
• log*.c (logging and pcap/mirror support)
• nat.c (abstraction over OS NAT/divert mechanisms)
• extra/ – helper scripts; tests/ – unit & end-to-end test harness; xnu/ – OS headers for Mac PF compatibility.
Key Architectural Insights from README
• Mode of operation: client packets → OS NAT engine → SSLproxy → decrypt → divert to listening program → get back → encrypt → server → response reverse path.
• Core is event-driven (libevent), lock-free threading, modular protocol plug-ins, flexible “proxyspec” and filtering rule engine.
• External dependencies: OpenSSL, libevent, libpcap/libnet (for mirroring), sqlite3 (for user auth).
Components
a. Network Entities
• Client Application (e.g., browser, mail client)
• Original Server (e.g., HTTPS server)
• External “Listening” Programs (e.g., UTM services, virus scanner)
• OS Kernel with NAT/Divert subsystem (pf, iptables+TPROXY, ipfw)
b. SSLproxy Process
• CLI & Configuration Parser
• Event Loop & Thread Manager (libevent)
• Packet Redirector (nat abstraction)
• Filter Engine (filter.c, kbtree + aho-corasick)
• Protocol Handlers (proto*.c modules)
• SSL/TLS Handler & Certificate Forge (ssl.c, cert.c)
• Cache Manager (session caching)
• Privilege Separation Module
• Logging Subsystem (connect/content logs, pcap, mirror)
• UserAuth Module (sqlite3 interaction, ARP cache check)
c. External Dependencies (shown as libraries or services)
• OpenSSL
• libevent
• libpcap / libnet (optional)
• sqlite3 (optional)
d. Data Stores and Config
• Configuration File (sslproxy.conf) & Command-line options
• SQLite3 Users Database (for UserAuth)
• Log Files / PCAP files
Relationships and Data Flows
1. Client → OS NAT Redirect → SSLproxy
2. SSLproxy decrypts (OpenSSL) → Protocol Handler → Filter Engine → Divert
3. Divert → External Program
4. External Program → (unencrypted) SSLproxy → Encrypt → Destination Server
5. Response: reverse order back to Client
• Control-flow interactions:
• SSLproxy ↔ SQLite3 for user authentication
• SSLproxy ↔ file system for config, logs, certificates
• SSLproxy ↔ OS kernel modules via nat.c abstraction
Architectural Patterns and Principles
• Event-driven, non-blocking I/O (libevent)
• Lock-free core with thread manager (pxythrmgr)
• Modular protocol plug-ins (proto*.c) and filter rules engine
• Privilege separation (privsep) for sensitive operations
• Caching of SSL session data to improve performance
• Separation of concerns: network I/O, SSL processing, divert logic, logging, config parsing