This project implements a secure client-server file transfer application using Python's built-in socket and ssl libraries.
Unlike standard file transfers (like basic FTP) that send data in cleartext, this application establishes an encrypted SSL/TLS tunnel before transmitting any file data. It demonstrates the implementation of Server-Authenticated TLS, where the client verifies the server's identity using a digital certificate.
- Network Programming: TCP Socket communication (binding, listening, accepting connections).
- Applied Cryptography: Implementing SSL/TLS contexts for data encryption in transit.
- Public Key Infrastructure (PKI): Handling X.509 certificates (
.crt) and private keys (.key). - Client-Server Architecture: Building a distinct server listener and client initiator.
- File I/O: Binary reading and writing of files.
The repository contains the following essential files:
server.py: The server script. It binds to port 8443, wraps the socket in SSL using the private key/cert, and listens for requests.client.py: The client script. It connects to the server, verifies the server's certificate, and requests the file.server.crt: The public SSL Certificate (used by the server to prove identity, and by the client to verify it).server.key: The server's Private Key (used to decrypt the handshake).textfile.txt: The sample file to be transferred.
Prerequisites: Python 3. (No external pip installs required).
Ensure all files (server.py, client.py, keys, and textfile.txt) are in the same directory.
Open a terminal in the project directory and run:
python server.pyOpen a separate terminal window in the same directory and run:
python client.pyClient Terminal: You will see Downloaded file successfully. for file textfile.txt.
Server Terminal: You will see Connection from... and Server has sent the file....
Directory: A new file named downloaded_textfile.txt will appear in your folder.
Encryption: All data transferred is encrypted using TLS. If a packet sniffer (like Wireshark) intercepted the traffic, the file contents would be unreadable.
Authentication: The client code uses context.load_verify_locations('server.crt'). This ensures the client is connecting to the intended server and not a "Man-in-the-Middle" attacker.
Secure Context: The server creates an SSL context with ssl.create_default_context(ssl.Purpose.CLIENT_AUTH), ensuring modern security protocols are used for the handshake.
Educational Use Only: This repository includes the server.key (Private Key) for demonstration purposes so the code can be run immediately. In a real-world deployment, the private key must remain secret and never be uploaded to a version control system (GitHub).