Selovanth
Selovanth

Reputation: 31

Python DTLS - Server Will Not Accept Connections

I have been learning, through a veil of many tears, the concepts of network programming. I started with a simple UDP client/server pair, moved to TCP, and then secured the TCP stream successfully using TLS. Now I am trying to "defeat the final boss", and secure UDP communication using DTLS.

I put together a very simple UDP client/server pair using DTLS to attempt and successfully exchange encrypted communications. Let me break down the problem into the client and server.

DTLS Client

import socket
import ssl
from dtls import do_patch
do_patch()

serverAddress, serverPort = "IP Address", 12345
addr = (serverAddress, serverPort)

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
SSLSocket = ssl.wrap_socket(s, '.\key.pem', '\cert.pem', server_side=False)

SSLSocket.connect(addr)
clientMessage = bytes(('I am the UDP client').encode('utf-8'))

SSLSocket.send(clientMessage)

Client Hello is successfully seen in Wireshark using the DTLS protocol.

DTLS Server

import ssl
from socket import socket, AF_INET, SOCK_DGRAM
from dtls import do_patch
do_patch()

##### Server and Socket Parameters #####
serverAddress, serverPort = "192.168.1.158", 12345
addr = (serverAddress, serverPort)

s = socket(AF_INET, SOCK_DGRAM)
sock = ssl.wrap_socket(s, '.\key.pem', '.\cert.pem', server_side=True)
sock.bind(addr)
sock.listen(2)
clientSocket, addr = sock.accept()
print("Connection established")

Server program runs successfully, however the client does not seem to be able to connect. The server never acknowledges the Client Hello, and this is reflected by the client retransmitting its hello message at regular intervals.

I could not get a Print() statement in the server after sock.listen(2). I'm not 100% sure what this could mean. Either the server is listening and waiting, the Print() statement not executing, or something else that is not causing a runtime error.

Regardless, sock.accept() never gets reached, and the client is stuck sending Hello messages forever. I'm not sure what the issue is, and would greatly appreciate some feedback on the matter.

Upvotes: 1

Views: 320

Answers (0)

Related Questions