Skip to main content

Ultra-secure terminal-based chat with end-to-end encryption and decentralized networking

Project description

SecureChat

A spy movie style ultra-secure terminal-based bi-directional chatting application with end-to-end encryption, TLS transport security, and support for one-to-one, one-to-many, many-to-one, and many-to-many communication. Designed as a personal ultra-secure communication medium with comprehensive edge case handling.

Features

  • End-to-End Encryption: RSA-based encryption for direct messages with digital signatures
  • TLS Transport Security: All connections secured with SSL/TLS certificates
  • Password-Protected Keys: Private keys encrypted with user passwords
  • Group Chat: Create and join groups for multi-user conversations
  • Offline Message Delivery: Receive unread messages when you log back in
  • Real-time Communication: Instant message delivery with threading
  • Cross-Platform: Works on Windows, Linux, Mac
  • Federation Support: Connect multiple servers for decentralized communication
  • Production-Ready: Robust error handling, connection management, and security

Security Features

Cryptographic Security

  • RSA 2048-bit Keys: Generated per user with secure key derivation
  • AES-GCM Encryption: Symmetric encryption for group messages with PBKDF2 key derivation
  • Digital Signatures: PSS-based signatures for authenticity
  • TLS 1.2+: Transport layer security with certificate validation
  • Password Protection: Keys stored encrypted with strong passwords (8+ chars, mixed case, digits)
  • Replay Prevention: Server-generated timestamps prevent replay attacks
  • Certificate Validation: Automatic expiry checking and hostname validation for federation

Operational Security

  • Rate Limiting: Prevents abuse with message rate controls
  • Input Validation: Sanitized JSON communication with size limits
  • Resource Limits: Maximum clients, message sizes, and connection timeouts
  • Audit Logging: Security events logged to files
  • Key Recovery: Automatic backup and regeneration for corrupted keys
  • Message TTL: Automatic cleanup of old pending messages

Network Security

  • Federation Authentication: Password-protected federation connections
  • Certificate Pinning: SHA256 fingerprint validation for trusted federation servers
  • Connection Timeouts: Prevents hanging connections
  • IP-based Tracking: Basic connection monitoring
  • Graceful Disconnection: Clean shutdown handling

Edge Cases Handled

Security Edge Cases

  • Key Corruption: Automatic backup and regeneration
  • Certificate Expiry: Validation and warning system
  • Replay Attacks: Timestamp-based prevention
  • Man-in-the-Middle: Certificate validation and hostname checking
  • Key Conflicts: Username-based conflict resolution in federation

Network Edge Cases

  • Connection Drops: Automatic reconnection and message queuing
  • Server Crashes: Federation reconnection and state recovery
  • Network Partitions: Message queuing for offline users
  • High Latency: Non-blocking operations with timeouts
  • Concurrent Connections: Thread-safe message handling

Data Integrity Edge Cases

  • Message Corruption: JSON validation and size limits
  • Storage Corruption: Timestamp-based message validation
  • Database Issues: In-memory storage with periodic cleanup
  • Large Messages: Size limits and validation
  • Memory Exhaustion: Resource limits and cleanup threads

User Experience Edge Cases

  • Duplicate Users: Server-side username validation
  • Invalid Input: Comprehensive input sanitization
  • Race Conditions: Thread-safe operations with locks
  • Keyboard Interrupts: Graceful shutdown handling
  • Password Errors: Recovery mechanisms for key loading

Federation Edge Cases

  • Server Conflicts: ID-based conflict prevention
  • Circular Dependencies: Loop detection in federation
  • Partial Failures: Graceful degradation when servers disconnect
  • User Migration: Cross-server user discovery
  • Message Routing: Multi-hop message forwarding

Installation

Install from PyPI:

pip install securechat

Or install from source:

git clone https://github.com/i-soumya18/securechat.git
cd securechat
pip install .

Setup

  1. Generate SSL certificates:
securechat generate-certs
  1. Start the secure server:
securechat server --cert server.crt --key server.key
  1. (Optional) Start additional servers for federation:
securechat server --port 12348 --cert server.crt --key server.key

Usage

Direct Messages (One-to-One)

securechat client localhost:12346 your_username

Then type: to alice: Hello spy!

Group Chat (One-to-Many/Many-to-Many)

  • group create mygroup - Create a new group
  • group join mygroup - Join an existing group
  • group list - List available groups
  • to group:mygroup: Message for all - Send to group

Federation (Cross-Server Communication)

  • federate hostname:port - Connect to another SecureChat server
  • Users from federated servers appear in your user list automatically

Commands

  • list - Show all known users (local + federated)
  • to username: message - Send direct message
  • group create name - Create group
  • group join name - Join group
  • group leave name - Leave group
  • group list - List groups
  • federate host:port - Connect to federated server
  • Ctrl+C to exit

Architecture

  • Server: Multi-threaded SSL server handling connections, message routing, and federation
  • Client: SSL client with real-time message handling, group management, and federation awareness
  • Crypto: RSA for keys, AES for messages, PSS for signatures, certificate validation
  • Groups: Server-managed group membership with broadcast messaging
  • Federation: Server-to-server protocol for decentralized communication
  • Storage: In-memory with periodic cleanup, file-based key storage

Security Best Practices

  1. Use Strong Passwords: At least 8 characters for key encryption
  2. Keep Certificates Updated: Regenerate before expiry
  3. Monitor Logs: Check server logs for security events
  4. Network Security: Run behind firewalls, use VPNs for remote access
  5. Key Backup: Keep backups of key files in secure locations
  6. Regular Updates: Keep dependencies updated for security patches

Troubleshooting

Certificate Issues

  • Regenerate certificates: securechat generate-certs
  • Check expiry: Server logs show certificate status on startup

Connection Issues

  • Verify server is running: Check for "Secure server started" message
  • Check firewall settings for the configured ports
  • Use localhost for local testing, actual hostname/IP for remote

Federation Issues

  • Ensure both servers have valid certificates
  • Check server logs for federation handshake messages
  • Verify ports are open (main port + federation port +1)

Key Issues

  • Delete corrupted key files to regenerate
  • Backups are created automatically for recovery

Perfect for secure communications in any scenario! 🕵️‍♂️🔐 (Windows, Linux, Mac)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

securechat_py-1.0.1.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

securechat_py-1.0.1-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file securechat_py-1.0.1.tar.gz.

File metadata

  • Download URL: securechat_py-1.0.1.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for securechat_py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5f49132d2bcdbdcb63637d3b820edda6cde193433bc307fea33c633249b38f7c
MD5 1485008b893c4ce466acf8ab0e8c11c3
BLAKE2b-256 38f546de803a5de20e56f25c060c20cec5d7d2d7b272e995ef6274846d982d4b

See more details on using hashes here.

File details

Details for the file securechat_py-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: securechat_py-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for securechat_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b57a705a35657ca88ceba9cf51d2a616a811f1b4f879ce33004bdaf40c3b6e7
MD5 4652dcae163044c2ea5a0cf80e0e1a72
BLAKE2b-256 00cef26a85bde8019c8d5f0445bdc34c0738ec0c7c6ef7d4ae6679fe3f68ec67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page