This system enables serverless, secure messaging with hybrid online/offline capabilities using direct secure chat, store-and-forward, and automatic cleanup. Below is a detailed technical explanation of each component.
1. Direct Secure Chat
Handles real-time messaging when sender and recipient are online.
- Encryption: Messages are encrypted end-to-end using AES-256 for the payload and RSA or Diffie-Hellman for key exchange. Only the recipient’s private key can decrypt the message.
- P2P Connection: Uses protocols like WebRTC (with STUN/TURN for NAT traversal) or custom UDP/TCP for direct communication, avoiding central servers.
- Authentication: Public-key cryptography verifies sender identity via digital signatures, preventing impersonation.
- Process:
- Sender and recipient authenticate using public/private key pairs.
- Sender encrypts message with recipient’s public key.
- Message is sent directly via P2P channel.
- Recipient decrypts and verifies message integrity.
2. Store-and-Forward Mechanism
Manages message delivery when the recipient is offline.
- Encrypted Envelope: Message is encrypted with recipient’s public key, including payload, metadata (timestamp, recipient ID), and unique message ID. Envelope is unreadable without the private key.
- Peer Selection: Sender identifies nearby peers using distributed hash tables (DHTs) or gossip protocols, based on proximity, reliability, and storage capacity.
- Message Distribution: Encrypted envelope is sent to one or more peers for temporary storage. Redundancy (e.g., replication or erasure coding) ensures availability.
- Security: Peers cannot decrypt the envelope. Digital signatures verify authenticity and prevent tampering.
- Dynamic Handover: If a peer goes offline, the envelope is handed to another peer, maintaining availability.
- Process:
- Sender detects recipient is offline.
- Message is encrypted into an envelope.
- Envelope is distributed to selected peers.
- Peers store envelope until recipient is online or message expires.
3. Delivery and Cleanup
Ensures message delivery and removes stored copies.
- Retrieval: Recipient, upon coming online, polls the network or receives a notification (e.g., via P2P push) to retrieve the encrypted envelope from a peer.
- Decryption: Recipient decrypts the envelope using their private key and verifies integrity with checksums or signatures.
- Acknowledgment (ACK): Recipient sends an ACK to the network, confirming receipt. ACK is propagated to all peers holding the envelope.
- Cleanup: Peers delete stored envelope copies upon receiving ACK.
- Expiration: Undelivered messages expire after a set period (e.g., 24 hours or 7 days). Peers automatically delete expired envelopes.
- Process:
- Recipient retrieves envelope from a peer.
- Decrypts and verifies message.
- Sends ACK to network.
- Peers delete envelope copies.
- Expired messages are deleted if undelivered.
Technical Details
- Protocols: WebRTC for P2P, AES-256 for encryption, RSA/Diffie-Hellman for key exchange, SHA-256 for signatures/checksums.
- Network: Decentralized P2P network using DHTs or gossip protocols for peer discovery and routing.
- Redundancy: Erasure coding or replication to ensure message availability.
- Storage: Peers use local storage (e.g., in-memory or disk) for temporary envelope holding, with size limits to prevent overload.
- Scalability: Dynamic peer selection and cleanup minimize resource usage.
Challenges
- Peer Reliability: Malicious or unreliable peers may drop messages. Mitigated by reputation systems or cryptographic verification.
- Storage Overhead: Redundant storage consumes resources. Optimized with erasure coding or storage-aware peer selection.
- Latency: Store-and-forward delays delivery. Improved with efficient routing and peer proximity.
- Key Management: Secure key exchange and storage are critical. System must handle key revocation and rotation.
Use Cases
- Secure messaging in intermittent networks (e.g., rural areas, disaster zones).
- Censorship-resistant communication for privacy-critical applications.
- IoT device communication without central servers.
This system provides secure, serverless messaging with robust online/offline support, leveraging encryption, P2P networks, and automatic cleanup for privacy and efficiency.