-
-
Save leroyfal/b847a0c0c0493e29c0824660e9fc6eb6 to your computer and use it in GitHub Desktop.
Simple TLS client and server on python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import ssl | |
from tls_server import HOST as SERVER_HOST | |
from tls_server import PORT as SERVER_PORT | |
HOST = "127.0.0.1" | |
PORT = 60002 | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
client = ssl.wrap_socket(client, keyfile="path/to/keyfile", certfile="path/to/certfile") | |
if __name__ == "__main__": | |
client.bind((HOST, PORT)) | |
client.connect((SERVER_HOST, SERVER_PORT)) | |
while True: | |
from time import sleep | |
client.send("Hello World!".encode("utf-8")) | |
sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import ssl | |
HOST = "127.0.0.1" | |
PORT = 60000 | |
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server = ssl.wrap_socket( | |
server, server_side=True, keyfile="path/to/keyfile", certfile="path/to/certfile" | |
) | |
if __name__ == "__main__": | |
server.bind((HOST, PORT)) | |
server.listen(0) | |
while True: | |
connection, client_address = server.accept() | |
while True: | |
data = connection.recv(1024) | |
if not data: | |
break | |
print(f"Received: {data.decode('utf-8')}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment