How aniketc068/ocspmonitorbot works
Project type and purpose
• This is a Python monolithic service exposing two main interfaces:
– A Telegram Bot using python-telegram-bot (async)
– A Flask REST API (/api/certchecker and /cert-count)
• It processes user uploads or API requests, parses certificates, checks OCSP/CRL status, blocks spam, and sends alerts.
Main architectural components
a. Client Interfaces
– Telegram Users & Groups
– HTTP Clients (curl, Postman, other services)
b. Bot Server
– main.py: application entry point
– imports.py: selects web server backend (Waitress or Gunicorn)
– handlers.py: Telegram update handlers (commands, file uploads)
– Flask app: route definitions for /api/certchecker and /cert-count
c. Business Logic Modules
– parse.py: certificate format detection & parsing
– cert_utils.py: OCSP/CRL checking routines, cryptography interactions
– block_utils.py: spam/user-warning/block logic
– config.py: environment variable management (bot token, chat IDs)
d. Data Storage
– JSON files in data/: blocked_users.json, spam_messages.json, user_warnings.json, counter.json, blocked_notices.json
e. Templates
– templates/index.html: optional web UI (if used)
f. External Dependencies
– Telegram Bot API
– OCSP responders (for real-time monitoring)
– CRL distribution points
– Python packages: Flask, python-telegram-bot, cryptography, lxml
Relationships and data flows
User → Telegram Bot API → handlers.py → parse.py / cert_utils.py → OCSP/CRL endpoints → handlers.py → Telegram Bot API → User
– block_utils.py invoked after invalid attempts
– Data read/write to JSON store for counters and blocks
Client → Flask /api/certchecker → parse.py / cert_utils.py → external OCSP/CRL → Flask → Client
Scheduled or long-polling in main.py for Capricorn .pem → cert_utils.py → on-failure alert via handlers.py → Telegram group
• Metrics endpoint:
Flask /cert-count → reads counter.json → returns JSON
Architectural patterns & design principles
• Modular layering: separation of interface (handlers/routes), domain logic (parse/cert_utils/block_utils), and data persistence (JSON files)
• Single process monolith: both Bot and API share the same codebase and runtime
• Externalization of configuration via ENV (config.py)
• Simple file-based storage, replaceable by a database if scaled
– Component boundaries (containers)
– Clear labels (module names, API endpoints, data files)
– Callouts for important Env vars (TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, MONITOR_USER_ID)
– Annotations for scheduled monitoring vs on-demand requests