Telegram Bot as a Secure File Backend

2022-03-05MODULE: backend_infrastructure

Serving files directly through Telegram's servers offers an efficient file hosting mechanism, but doing so directly on a public-facing website typically exposes the raw bot token. To mitigate this security vulnerability, I developed the Telegram File Backend proxy.

Architecture

Source repository: telegram-file-backend.

System Specifications

  • Core Protocol: A proxy server written in Go designed to interface with the Telegram Bot API.
  • Cryptography: Employs AES encryption to obfuscate the Telegram bot token, ensuring it is never exposed in plain text to the public or client-side applications.
  • Data Store: Integrates with a Redis instance for high-performance caching and state management.
  • Language Stack: Go (Primary backend service), Python (Encryption utility scripts).

Execution Protocol

Deployment requires a multi-stage initialization to ensure cryptographic security.

  1. Token Encryption: Utilize the provided Python encryption utility to generate an AES-encrypted variant of the bot token.
    python encryptor/encrypt.py 'YOUR_BOT_TOKEN' # Output: encrypted token hash
    
  2. Infrastructure: Provision and run a Redis instance.
  3. Proxy Initialization: Execute the Go proxy server.
  4. Endpoint Access: Files are subsequently requested via the proxy endpoint utilizing the encrypted token and target file ID.
    http://localhost:4627/<ENCRYPTED_BOT_TOKEN>/<FILE_ID>
    

By employing this proxy, applications can leverage Telegram's robust infrastructure as a zero-cost file backend without compromising operational security.

> SYSTEM_ARCHITECTURE_ACCESS_

the underlying technology used to scale clothshift and handle 400,000+ users on past exits is available as a boilerplate.

the 'operator_arsenal' and 'root_system' packages include a built-in backend wallet and transaction system fully synchronized across mobile and frontend out of the box.