A complete TLS (Transport Layer Security) client-server implementation in Python with mutual authentication. This project demonstrates secure communication using TLS protocols with certificate-based authentication.
Author: Yaxploit
Version: 1.0
License: MIT
TLS (Transport Layer Security) is a cryptographic protocol designed to provide secure communication over a computer network. It ensures:
- Confidentiality: Data is encrypted and cannot be read by third parties
- Integrity: Data cannot be modified without detection
- Authentication: Both parties can verify each other's identity
- Client Hello: Client sends supported TLS versions and cipher suites
- Server Hello: Server selects TLS version and cipher suite
- Certificate Exchange: Server sends its certificate, client may send its certificate
- Key Exchange: Pre-master secret is exchanged using asymmetric cryptography
- Session Keys: Both sides derive symmetric session keys from the pre-master secret
- Secure Communication: Encrypted data exchange begins using symmetric encryption
yaxploit-tls/
├── tls_server_yaxploit.py    # TLS Server Implementation
├── tls_client_yaxploit.py    # TLS Client Implementation
├── server.crt               # Server Certificate (auto-generated)
├── server.key               # Server Private Key (auto-generated)
├── client.crt               # Client Certificate (auto-generated)
├── client.key               # Client Private Key (auto-generated)
└── README.md               # This file
- Python 3.6 or higher
- OpenSSL (usually pre-installed on most systems)
- 
Clone or download the project files # Create project directory mkdir yaxploit-tls cd yaxploit-tls # Save the provided Python files in this directory 
- 
Verify Python installation python --version # Should show Python 3.6+
python tls_server_yaxploit.pyExpected Output:
==================================================
Yaxploit TLS Secure Server
Author: Yaxploit
==================================================
[Yaxploit] Generating self-signed certificates for testing...
[Yaxploit] Certificates generated successfully:
  - server.crt (Server Certificate)
  - server.key (Server Private Key)
  - client.crt (Client Certificate)
  - client.key (Client Private Key)
[Yaxploit] SSL context configured successfully
[Yaxploit] TLS Server started on localhost:8443
[Yaxploit] Waiting for client connections...
[Yaxploit] Server is using mutual TLS authentication
[Yaxploit] Press Ctrl+C to stop the server
Option A: Interactive Mode
python tls_client_yaxploit.pyOption B: Single Command Mode
python tls_client_yaxploit.py "echo Hello TLS"
python tls_client_yaxploit.py status
python tls_client_yaxploit.py helpMain server class that handles TLS connections and client management.
- generate_self_signed_certificates(): Creates RSA certificates for testing
- setup_ssl_context(): Configures TLS security settings and cipher suites
- handle_client_connection(): Manages individual client sessions
- start_server(): Main server loop accepting connections
- TLS 1.2+ only (disables older insecure versions)
- Mutual certificate authentication
- Secure cipher suites (ECDHE, AES-GCM, CHACHA20)
- 2048-bit RSA keys for certificates
Client class for establishing secure connections to the server.
- setup_ssl_context(): Configures client-side TLS settings
- connect_to_server(): Establishes secure TLS connection
- interactive_session(): Command-line interface for user interaction
- single_command_mode(): Send single commands to server
- Interactive Mode: Real-time chat-like interface
- Single Command Mode: Execute one command and exit
- Host: localhost
- Port: 8443
- Key Size: 2048-bit RSA
- Certificate Validity: 365 days
Edit these lines in both files to change settings:
Server:
server = YaxploitTLSServer(host='localhost', port=8443)Client:
client = YaxploitTLSClient(host='localhost', port=8443)Once connected, you can use these commands:
| Command | Description | Example | 
|---|---|---|
| echo <message> | Echo back your message | echo Hello World | 
| status | Check server status | status | 
| help | Show available commands | help | 
| quit | Disconnect from server | quit | 
- Automatically creates self-signed X.509 certificates
- Uses RSA 2048-bit encryption
- Certificates include organization details
- Valid for 1 year from generation
- Protocol: TLSv1.2+ only
- Cipher Suites: ECDHE+AESGCM, ECDHE+CHACHA20, DHE+AESGCM
- Authentication: Mutual TLS (client and server certificates)
- Key Exchange: Ephemeral Diffie-Hellman for perfect forward secrecy
- SSLv2, SSLv3, TLSv1.0, TLSv1.1
- Weak ciphers (RC4, 3DES, MD5, DSS)
- NULL and anonymous ciphers
- 
"Connection refused" error - Ensure server is running before starting client
- Check if port 8443 is available
 
- 
Certificate errors - Delete existing .crtand.keyfiles to regenerate
- Ensure OpenSSL is installed
 
- Delete existing 
- 
"SSL handshake failed" - Check if system time is correct
- Verify certificates are not corrupted
 
- 
Port already in use # Find process using port 8443 lsof -i :8443 # Kill the process if needed kill -9 <PID> 
For detailed SSL debugging, add this to both files:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context- Start server in one terminal
- Run client in another terminal
- Test various commands
- Verify encrypted communication
# Test server with OpenSSL client
openssl s_client -connect localhost:8443 -cert client.crt -key client.key
# Check certificate details
openssl x509 -in server.crt -text -nooutThis implementation demonstrates:
- TLS Handshake Process: Complete certificate exchange and key derivation
- Socket Programming: Raw socket manipulation with TLS wrapping
- Threading: Multi-client server architecture
- Cryptography: Certificate generation and validation
- Network Security: Practical implementation of security principles
- Replace self-signed certificates with CA-signed certificates
- Enable certificate validation in client (verify_mode = ssl.CERT_REQUIRED)
- Implement proper hostname verification
- Use stronger key sizes (4096-bit RSA or ECDSA)
- Add certificate revocation checking
- Implement proper logging and monitoring
- Self-signed certificates for testing only
- No certificate revocation checking
- Basic error handling for educational purposes
- No persistence or database integration
- Educational Purposes: Learn TLS internals and Python networking
- Testing Environments: Secure communication in development
- Prototyping: Base for more complex secure applications
- Research: Experiment with different TLS configurations
MIT License - Feel free to use this code for educational and development purposes.
Author: Yaxploit
Last Updated: 2025