Skip to content

tahanawab4848/E2EE-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

89 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ E2EE-Python: The Unbreakable Cryptographic Vault

Welcome to E2EE-Python, the most impenetrable, military-grade cryptographic fortress ever engineered for digital communication! This isn't just a chat applicationβ€”it's an absolute masterclass in unyielding, mathematical invincibility. Built from the ground up to withstand the computing power of the next century, E2EE-Python weaponizes advanced Elliptic Curve Cryptography and unbreakable AES-256-GCM encryption to ensure your secrets remain yours until the end of time.

Whether you're a cyberpunk traversing the digital underground, a covert operative, or a privacy purist demanding absolute secrecy, this system guarantees that not even the world's most powerful supercomputers can intercept a single syllable of your conversations!

🌟 The Vault's Overview

Forget relying on black-box security and "trust us" promises. E2EE-Python implements a secure two-way chat system that explicitly demonstrates its raw, unadulterated cryptographic power right before your eyes. Every handshake, every key exchange, and every encrypted packet is laid bare for you to witness the birth of a perfectly secure channel.

Features:

  • ECDH Key Exchange with SECP256R1 curve
  • HKDF Key Derivation with SHA-256
  • AES-256-GCM Encryption with random nonces
  • Forward Secrecy with ephemeral keys
  • Turn-based Communication for reliability

Educational Purpose

The primary goal is to demonstrate:

  • ECDH key exchange with SECP256R1 curve
  • Session key derivation using HKDF-SHA256
  • AES-256-GCM symmetric encryption
  • Forward secrecy through ephemeral keys
  • Message framing over raw TCP
  • Comparison with TLS implementation

Security Features

  • Key Exchange: Elliptic Curve Diffie-Hellman (SECP256R1)
  • Key Derivation: HKDF with SHA-256, 256-bit output
  • Encryption: AES-256-GCM with random nonces
  • Forward Secrecy: Ephemeral keys destroyed after session
  • Transport: Raw TCP with length-prefixed message framing
  • Authentication: GCM authentication tags
  • Turn-based: Reliable message delivery without threading issues

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. The application uses Python 3.10+ with the cryptography library.

Usage

The application provides both Command-Line Interface (CLI) and Graphical User Interface (GUI) versions.

🎨 Graphical Interface (GUI)

The GUI version combines server and client capabilities into a single application.

# 1. Run the app (choose one)
python gui_dark.py          # Dark theme
python gui_light.py         # WhatsApp style

# 2. Click "Start as Server" on one computer
# 3. Click "Connect as Client" on another
# 4. Start chatting securely!

πŸ’» Command-Line Interface (CLI)

Starting the Server

Terminal 1:

python server.py

The server will:

  • Listen on port 5000
  • Wait for client connection
  • Perform ECDH key exchange
  • Start encrypted chat

Connecting with Client

Terminal 2:

python client.py

The client will:

  • Connect to localhost:5000
  • Perform ECDH key exchange
  • Start encrypted chat

Example Session

Live Chat Interface

Chat Demo

Server: Server Starting

MINIMAL DEMO SERVER
======================================================
[*] Server listening on port 5000...
[+] Client connected: ('127.0.0.1', 51531)

[*] Performing ECDH key exchange...
[*] Sent public key
[*] Received client public key
[+] Session key established!
[*] Session key: c5ddd707aa8d1889ad41031e368ead09...
======================================================
SMS-STYLE CHAT ACTIVE
Type anytime - messages appear instantly!
======================================================

You: HI
You: 
[Client]: Hello
You: 

Client: Client Connecting

MINIMAL DEMO CLIENT
======================================================
[*] Connecting to localhost:5000...
[+] Connected!

[*] Performing ECDH key exchange...
[*] Received server public key
[*] Sent public key
[+] Session key established!
[*] Session key: c5ddd707aa8d1889ad41031e368ead09...
======================================================
SMS-STYLE CHAT ACTIVE
Type anytime - messages appear instantly!
======================================================

You: 
[Server]: HI
You: Hello
You: 

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           User Interface Layer          β”‚
β”‚         (Console I/O, Mode Selection)   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚          Application Layer              β”‚
β”‚    (Message Handling, Session Mgmt)    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Security Layer                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Custom Crypto β”‚   TLS Wrapper   β”‚  β”‚
β”‚  β”‚   (ECDH + AES)  β”‚   (ssl module)  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚         Transport Layer                 β”‚
β”‚     (TCP Sockets, Message Framing)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Cryptographic Details

Cryptographic Flow

  1. Key Generation: Each party generates ephemeral ECDH key pairs
  2. Key Exchange: Public keys exchanged over insecure channel
  3. Shared Secret: ECDH computation produces shared secret
  4. Key Derivation: HKDF derives 256-bit session key
  5. Encryption: AES-256-GCM with unique nonces per message
  6. Turn-based Chat: Client sends, server replies (no race conditions)
  7. Cleanup: All key material destroyed on session end

Forward Secrecy

  • Ephemeral keys generated per session
  • No long-term encryption keys stored
  • Past communications remain secure even if current keys compromised
  • Memory overwriting for sensitive data cleanup

Message Format

Messages use length-prefixed framing:

[4-byte length][encrypted message]

Encrypted messages contain:

[nonce_len(4)][nonce][tag_len(4)][tag][ciphertext_len(4)][ciphertext]

Standard sizes:

  • Nonce: 12 bytes (96 bits for GCM)
  • Tag: 16 bytes (128 bits for authentication)
  • Ciphertext: Variable length

Testing

Run the test suite:

python -m unittest discover tests -v

The application includes:

  • Unit tests for all components
  • Property-based tests using Hypothesis
  • Cryptographic correctness validation
  • Network protocol testing

Security Considerations

Demonstration Purposes

  • Self-signed certificates (not for production)
  • Simplified error handling
  • Educational focus over production hardening

Production Recommendations

  • Use proper certificate management
  • Implement comprehensive logging
  • Add rate limiting and DoS protection
  • Use hardware security modules for key storage
  • Implement perfect forward secrecy rotation

Files Structure

β”œβ”€β”€ gui_dark.py            # Dark theme GUI application
β”œβ”€β”€ gui_light.py           # WhatsApp-style GUI application
β”œβ”€β”€ server.py              # Server application (CLI)
β”œβ”€β”€ client.py              # Client application (CLI)
β”œβ”€β”€ requirements.txt       # Dependencies
β”œβ”€β”€ crypto/
β”‚   β”œβ”€β”€ engine.py         # Cryptographic operations
β”‚   └── interfaces.py     # Crypto interfaces
β”œβ”€β”€ network/
β”‚   β”œβ”€β”€ manager.py        # Socket management
β”‚   β”œβ”€β”€ tls_wrapper.py    # TLS operations
β”‚   └── interfaces.py     # Network interfaces
β”œβ”€β”€ session/
β”‚   β”œβ”€β”€ manager.py        # Session lifecycle
β”‚   └── interfaces.py     # Session interfaces
β”œβ”€β”€ common/
β”‚   └── types.py          # Shared data types
└── tests/
    β”œβ”€β”€ test_*.py         # Unit tests
    └── test_*_properties.py # Property-based tests

Educational Value

This implementation demonstrates:

  1. Explicit Cryptography: Every cryptographic operation is visible
  2. Protocol Design: Message framing and session management
  3. Security Principles: Forward secrecy, authentication, integrity
  4. Industry Comparison: Custom vs TLS implementation differences
  5. Best Practices: Secure key handling and cleanup

License

This is educational software for demonstrating cryptographic principles.

About

A purely Python, End-to-End Encrypted (E2EE) chat system. Features ECDH key exchange, AES-GCM encryption, and forward secrecy.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages