TokenShield is a prototype PCI compliance gateway demonstrating credit card tokenization using modern proxy technologies. This is an educational/demonstration project showing how HAProxy, Squid, and a unified Go tokenization service can work together to intercept and tokenize sensitive data transparently.
Client → HAProxy → Unified Tokenizer → Your App
↓
MySQL Database
↓
Your App → Squid → Unified Tokenizer → Payment Gateway
↓
Management API (REST)
↓
GUI Dashboard & CLI Tool
- Go: Unified tokenizer service (HTTP + ICAP + REST API)
- HAProxy: Incoming traffic interception and tokenization
- Squid: Outgoing traffic interception and detokenization
- MySQL: Token and metadata storage
- HTML/CSS/JS: Web GUI dashboard
- React + TypeScript: Modern React GUI with Material-UI
- Go + Cobra: CLI management tool
- Docker: Complete containerization
- Nginx: Web server for GUI
-
Unified Tokenizer Service (
unified-tokenizer/main.go)- HTTP tokenization server (port 8080)
- ICAP detokenization server (port 1344)
- REST management API (port 8090)
- KEK/DEK encryption support with AES-GCM
- Configurable token formats (prefix:
tok_or Luhn-valid:9999xxxx) - CORS middleware for browser API access
-
Database Schema (
database/schema.sql)- Credit card tokens storage
- API keys management
- Request activity logging
- KEK/DEK encryption keys tables
- Key rotation logging
- User management and sessions
- Two-tier audit logging (user actions + security events)
-
Proxy Configuration
- HAProxy config with Lua tokenization script (
haproxy/) - Squid proxy with ICAP integration (
squid/) - SSL/TLS certificate generation (
certs/)
- HAProxy config with Lua tokenization script (
-
Demo Applications
- Dummy e-commerce app with HTTP tracing (
dummy-app/) - Payment gateway simulator (
dummy-gateway/) - Card distributor API (
card-distributor/)
- Dummy e-commerce app with HTTP tracing (
-
REST API (Management API on port 8090)
- API key management (create, list, revoke)
- Token management (list, search, revoke)
- Activity monitoring
- System statistics
- Version and health endpoints
- KEK/DEK key management (when enabled)
- User management and authentication
-
CLI Tool (
cli/)- Complete Go CLI using Cobra framework
- Token management commands
- API key operations
- Activity monitoring
- Statistics viewing
- Docker support and cross-platform builds
-
Web GUI Dashboard (
gui/)- Modern HTML/CSS/JavaScript interface
- Real-time system statistics
- Token management (view, search, revoke)
- API key management (create, list, revoke)
- Activity monitoring with filtering
- Settings configuration
- Responsive design for mobile/desktop
- Docker deployment with Nginx
-
React GUI Dashboard (
gui-react/)- Modern React 19 + TypeScript + Material-UI v5
- Theme management with light/dark modes
- Dynamic API configuration
- Complete feature parity with legacy GUI
- Docker deployment on port 8082
- Modern development workflow with Vite
-
Security Enhancements
- Rate limiting for authentication endpoints (5 attempts per 15 minutes)
- Two-tier audit logging (user actions + security events)
- Session security with configurable timeouts and concurrent limits
- Automatic session cleanup and background monitoring
- PCI DSS v4.0 compliant password requirements (12+ characters)
-
Docker Integration
- Complete docker-compose.yml with all services
- Multi-stage builds for Go applications
- Health checks and service dependencies
- Volume management for data persistence
TOKEN_FORMAT: "prefix" (default) or "luhn" for Luhn-valid tokensUSE_KEK_DEK: "true" to enable KEK/DEK encryption (default: false)ENCRYPTION_KEY: Base64 encoded encryption keyADMIN_SECRET: Admin secret for privileged operations (default: "change-this-admin-secret")SESSION_TIMEOUT: Absolute session timeout (default: 24h)SESSION_IDLE_TIMEOUT: Idle session timeout (default: 4h)MAX_CONCURRENT_SESSIONS: Maximum sessions per user (default: 5)
- 80/443: HAProxy (HTTP/HTTPS traffic)
- 8080: Unified tokenizer HTTP service
- 1344: Unified tokenizer ICAP service
- 8090: Management REST API
- 8081: Legacy GUI web dashboard
- 8082: React GUI web dashboard
- 3306: MySQL database
- 3128/3129: Squid proxy (HTTP/HTTPS)
- 8000: Dummy app
- 9000: Payment gateway
- 5001: Card distributor
- 8404: HAProxy stats
credit_cards: Token storage with metadataapi_keys: API key managementtoken_requests: Activity loggingencryption_keys: KEK/DEK keys (when enabled)key_rotation_log: Key rotation historyusers: User accounts and authenticationuser_sessions: Session managementuser_audit_log: User action loggingsecurity_audit_log: Security event logging
- Tokens stored with card type, last 4 digits, creation time
- Activity includes source IP, request type, timestamps
- API keys have permissions and usage tracking
- Sessions include timeout, idle tracking, and concurrent limits
- Audit logs capture both user actions and security events
docker-compose up -dcd cli && ./build.shcurl -X POST http://localhost:8090/api/v1/api-keys \
-H "Content-Type: application/json" \
-H "X-Admin-Secret: change-this-admin-secret" \
-d '{"client_name":"Test","permissions":["read","write","admin"]}'- Legacy GUI Dashboard: http://localhost:8081
- React GUI Dashboard: http://localhost:8082
- Demo App: http://localhost
- API: http://localhost:8090
docker-compose logs -f unified-tokenizer
docker-compose logs -f dummy-appUnifiedTokenizerstruct: Main service with HTTP, ICAP, and API serversKeyManager: KEK/DEK encryption management- HTTP handlers: Tokenization endpoints
- ICAP handlers: Detokenization for Squid integration
- API handlers: Management REST endpoints
- CORS middleware: Browser compatibility
- Rate limiting: Authentication protection
- Session management: Security and timeouts
- Audit logging: User actions and security events
index.html: Main interface structuresrc/App.tsx: Main React application with theme providersrc/contexts/ThemeContext.tsx: Theme management systemsrc/components/: Feature-specific React componentsDockerfile: Nginx-based container with Vite buildnginx.conf: Web server configuration
- Cobra-based command structure
- API client with authentication
- Commands for all major operations
- Configuration file support
- Cross-platform build support
- HTTP Tracing: Added comprehensive request/response logging to dummy-app
- Token Formats: Implemented configurable token formats (prefix vs Luhn-valid)
- KEK/DEK: Added enterprise-grade key encryption with rotation
- REST API: Built complete management API for GUI/CLI consumption
- CLI Tool: Created full-featured command-line interface
- GUI Dashboard: Developed modern web interface with all management features
- CORS Support: Added browser compatibility for GUI-API communication
- React Migration: Built modern React GUI with TypeScript and Material-UI
- Theme System: Implemented comprehensive light/dark theme management
- Security Hardening: Added rate limiting, audit logging, and session security
- Session Security: Implemented configurable timeouts, concurrent limits, and cleanup
- Visa: 4532015112830366
- Mastercard: 5425233430109903
- Amex: 378282246310005
- Discover: 6011111111111117
- Admin Secret:
change-this-admin-secret - MySQL: pciproxy/pciproxy123
- Database: tokenshield
- Prototype quality code
- Self-signed certificates
- Basic error handling
- No production security features
- Limited input validation
- HSM/KMS integration
- Comprehensive audit logging
- Rate limiting and DDoS protection
- Advanced monitoring and alerting
- PCI DSS compliance controls
- Production-grade authentication
- Network security hardening
- Rate Limiting: 5 login attempts per 15 minutes per IP
- Session Security: Configurable timeouts (24h absolute, 4h idle)
- Concurrent Sessions: Maximum 5 sessions per user
- Password Requirements: PCI DSS v4.0 compliant (12+ characters)
- Audit Logging: Two-tier logging (user actions + security events)
- Background Cleanup: Automatic session cleanup every 15 minutes
- Session Invalidation: Manual session termination for security events
- Absolute session timeout (default: 24 hours)
- Idle session timeout (default: 4 hours)
- Concurrent session limits (default: 5 per user)
- Automatic cleanup of expired sessions
- Session invalidation on security events
- Detailed security event logging
- Background monitoring service
- Input validation middleware
- Health checks for dependencies
- Structured logging with security classification
- Database connection pooling optimization
- Multi-factor authentication
- Role-based access control refinements
- Multi-tenant support
- Token format customization
- Webhook notifications
- Backup and recovery procedures
- Performance monitoring
- Load balancing support
- Go 1.21+
- Docker and Docker Compose
- Node.js 18+ (for React GUI)
- MySQL client (for direct DB access)
- Modern web browser (for GUI testing)
- Start with React GUI dashboard for modern experience
- Use CLI for automated operations
- Direct API calls for integration testing
- Log monitoring for debugging and security analysis
- Go: Standard Go formatting, error handling
- TypeScript: Modern ES6+, async/await patterns
- CSS: Custom properties, responsive design
- HTML: Semantic markup, accessibility considerations
- Last Updated: 2024-06-04
- Current Focus: Session security enhancements completed
- Recent Work:
- Implemented session security with configurable timeouts
- Added concurrent session limits and cleanup
- Enhanced validateSession with idle timeout checks
- Added background session cleanup service
- Implemented session invalidation functions
- Completed Security Features:
- Rate limiting for authentication endpoints
- Two-tier audit logging system
- Session security with timeouts and limits
- Background session monitoring and cleanup