From ca32b91a9ca48b5d4109179207438eab43f68114 Mon Sep 17 00:00:00 2001 From: Ray Brown Date: Mon, 26 Nov 2012 21:07:56 -0800 Subject: [PATCH] Linux port With this change all unit tests pass on the Linux platform (tested on Ubuntu 12.04.1 LTS). demux/__init__.py has been adjusted temporarily so as to load the routing demux on Linux until the osnet demux is ready. Testing on Linux exposed an issue where comparison of the ssl object value from cookie callbacks failed to compare equal to the value stored in the SSLConnection callback object. This was because the callback function signature of c_void_p for this parameter produced a 64-bit value if the 32nd bit was set (as opposed to producing a negative integer 32-bit value). Changing the signature from c_void_p to c_int for this parameter fixes the issue. --- dtls/demux/__init__.py | 3 ++- dtls/openssl.py | 4 ++-- dtls/test/unit.py | 12 ++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/dtls/demux/__init__.py b/dtls/demux/__init__.py index 4c88f1a..ee53ba6 100644 --- a/dtls/demux/__init__.py +++ b/dtls/demux/__init__.py @@ -21,6 +21,7 @@ import sys if sys.platform.startswith('win') or sys.platform.startswith('cygwin'): from router import UDPDemux else: - from osnet import UDPDemux + #from osnet import UDPDemux + from router import UDPDemux __all__ = ["UDPDemux"] diff --git a/dtls/openssl.py b/dtls/openssl.py index 519d587..0c63d1f 100644 --- a/dtls/openssl.py +++ b/dtls/openssl.py @@ -616,9 +616,9 @@ def SSL_CTX_set_read_ahead(ctx, m): # Returns the previous value of m _SSL_CTX_ctrl(ctx, SSL_CTRL_SET_READ_AHEAD, m, None) -_rint_voidp_ubytep_uintp = CFUNCTYPE(c_int, c_void_p, POINTER(c_ubyte), +_rint_voidp_ubytep_uintp = CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), POINTER(c_uint)) -_rint_voidp_ubytep_uint = CFUNCTYPE(c_int, c_void_p, POINTER(c_ubyte), c_uint) +_rint_voidp_ubytep_uint = CFUNCTYPE(c_int, c_int, POINTER(c_ubyte), c_uint) def SSL_CTX_set_cookie_cb(ctx, generate, verify): def py_generate_cookie_cb(ssl, cookie, cookie_len): diff --git a/dtls/test/unit.py b/dtls/test/unit.py index b585889..8cedc39 100644 --- a/dtls/test/unit.py +++ b/dtls/test/unit.py @@ -154,10 +154,14 @@ class BasicSocketTests(unittest.TestCase): # something unexpected like TypeError. s = socket.socket(AF_INET4_6, socket.SOCK_DGRAM) ss = ssl.wrap_socket(s) - self.assertRaises(socket.error, ss.recv, 1) - self.assertRaises(socket.error, ss.recv_into, bytearray(b'x')) - self.assertRaises(socket.error, ss.recvfrom, 1) - self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), 1) + if os.name != "posix": + # On Linux, unconnected, unbound datagram sockets can receive and + # the following calls will therefore block + self.assertRaises(socket.error, ss.recv, 1) + self.assertRaises(socket.error, ss.recv_into, bytearray(b'x')) + self.assertRaises(socket.error, ss.recvfrom, 1) + self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), + 1) self.assertRaises(socket.error, ss.send, b'x') self.assertRaises(socket.error, ss.sendto, b'x', ('0.0.0.0', 0) if AF_INET4_6 == socket.AF_INET else