Compare commits

..

12 Commits

Author SHA1 Message Date
inpos f4237f9bf6 local import 2017-12-18 10:22:46 +03:00
inpos 6e662a291a import from local dir 2017-12-18 10:15:22 +03:00
inpos a511463f67 py3 support errors 2017-12-18 09:12:23 +03:00
inpos 26b0e5ca8f py3 support errors 2017-12-18 09:09:38 +03:00
inpos a3242f2749 py3 support errors 2017-12-18 09:07:35 +03:00
inpos d218d92d2f py3 support errors 2017-12-18 09:06:38 +03:00
inpos b9da8c1323 py3 support errors 2017-12-18 09:04:57 +03:00
inpos 9d0be7fcdc ssl 1.0.2 2017-12-17 19:02:06 +03:00
hades 85391e63ea execfile not available in Python 3, replacing with exec alternative 2017-08-14 13:41:58 +02:00
hades 4f90714df1 Setup.py/Python 3 fails as expects a byte stream instead of str 2017-08-14 13:40:24 +02:00
hades a89dc6533a Setup.py install fails as README.rst does not exist. Using README.md file as fallback instead 2017-08-14 13:09:59 +02:00
Ray 41a71fccd9 Merge branch 'incoming' 2017-04-27 14:14:32 -07:00
12 changed files with 82 additions and 81 deletions

View File

@ -48,7 +48,7 @@ def _prep_bins():
prebuilt_path = path.join(package_root, "prebuilt", platform + bit_suffix) prebuilt_path = path.join(package_root, "prebuilt", platform + bit_suffix)
config = {"MANIFEST_DIR": prebuilt_path} config = {"MANIFEST_DIR": prebuilt_path}
try: try:
execfile(path.join(prebuilt_path, "manifest.pycfg"), config) exec(compile(open(path.join(prebuilt_path, "manifest.pycfg"), "rb").read()), config)
except IOError: except IOError:
return # there are no prebuilts for this platform - nothing to do return # there are no prebuilts for this platform - nothing to do
files = map(lambda x: path.join(prebuilt_path, x), config["FILES"]) files = map(lambda x: path.join(prebuilt_path, x), config["FILES"])
@ -60,6 +60,6 @@ def _prep_bins():
_prep_bins() # prepare before module imports _prep_bins() # prepare before module imports
from patch import do_patch from .patch import do_patch
from sslconnection import SSLContext, SSL, SSLConnection from .sslconnection import SSLContext, SSL, SSLConnection
from demux import force_routing_demux, reset_default_demux from .demux import force_routing_demux, reset_default_demux

View File

@ -38,9 +38,9 @@ import socket
from logging import getLogger from logging import getLogger
from os import path from os import path
from datetime import timedelta from datetime import timedelta
from err import openssl_error from .err import openssl_error
from err import SSL_ERROR_NONE from .err import SSL_ERROR_NONE
from util import _EC_KEY, _BIO from .util import _EC_KEY, _BIO
import ctypes import ctypes
from ctypes import CDLL from ctypes import CDLL
from ctypes import CFUNCTYPE from ctypes import CFUNCTYPE
@ -65,8 +65,8 @@ if sys.platform.startswith('win'):
libcrypto = CDLL(cryptodll_path) libcrypto = CDLL(cryptodll_path)
libssl = CDLL(ssldll_path) libssl = CDLL(ssldll_path)
else: else:
libcrypto = CDLL("libcrypto.so.1.0.0") libcrypto = CDLL("libcrypto.so.1.0.2")
libssl = CDLL("libssl.so.1.0.0") libssl = CDLL("libssl.so.1.0.2")
# #
# Integer constants - exported # Integer constants - exported

View File

@ -34,18 +34,19 @@ has the following effects:
PROTOCOL_DTLSv1 for the parameter ssl_version is supported PROTOCOL_DTLSv1 for the parameter ssl_version is supported
""" """
from socket import socket, getaddrinfo, _delegate_methods, error as socket_error # from socket import socket, getaddrinfo, _delegate_methods, error as socket_error
from socket import socket, getaddrinfo, error as socket_error
from socket import AF_INET, SOCK_STREAM, SOCK_DGRAM from socket import AF_INET, SOCK_STREAM, SOCK_DGRAM
from ssl import PROTOCOL_SSLv23, CERT_NONE from ssl import PROTOCOL_SSLv23, CERT_NONE
from types import MethodType from types import MethodType
from weakref import proxy from weakref import proxy
import errno import errno
from sslconnection import SSLConnection, PROTOCOL_DTLS, PROTOCOL_DTLSv1, PROTOCOL_DTLSv1_2 from .sslconnection import SSLConnection, PROTOCOL_DTLS, PROTOCOL_DTLSv1, PROTOCOL_DTLSv1_2
from sslconnection import DTLS_OPENSSL_VERSION_NUMBER, DTLS_OPENSSL_VERSION, DTLS_OPENSSL_VERSION_INFO from .sslconnection import DTLS_OPENSSL_VERSION_NUMBER, DTLS_OPENSSL_VERSION, DTLS_OPENSSL_VERSION_INFO
from sslconnection import SSL_BUILD_CHAIN_FLAG_NONE, SSL_BUILD_CHAIN_FLAG_UNTRUSTED, \ from .sslconnection import SSL_BUILD_CHAIN_FLAG_NONE, SSL_BUILD_CHAIN_FLAG_UNTRUSTED, \
SSL_BUILD_CHAIN_FLAG_NO_ROOT, SSL_BUILD_CHAIN_FLAG_CHECK, SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR, SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR SSL_BUILD_CHAIN_FLAG_NO_ROOT, SSL_BUILD_CHAIN_FLAG_CHECK, SSL_BUILD_CHAIN_FLAG_IGNORE_ERROR, SSL_BUILD_CHAIN_FLAG_CLEAR_ERROR
from err import raise_as_ssl_module_error, patch_ssl_errors from .err import raise_as_ssl_module_error, patch_ssl_errors
def do_patch(): def do_patch():
@ -158,11 +159,11 @@ def _SSLSocket_init(self, sock=None, keyfile=None, certfile=None,
else: else:
socket.__init__(self, _sock=sock.get_socket(True)._sock) socket.__init__(self, _sock=sock.get_socket(True)._sock)
# Copy instance initialization from SSLSocket class # Copy instance initialization from SSLSocket class
for attr in _delegate_methods: #for attr in _delegate_methods:
try: # try:
delattr(self, attr) # delattr(self, attr)
except AttributeError: # except AttributeError:
pass # pass
if certfile and not keyfile: if certfile and not keyfile:
keyfile = certfile keyfile = certfile
@ -170,7 +171,7 @@ def _SSLSocket_init(self, sock=None, keyfile=None, certfile=None,
# see if it's connected # see if it's connected
try: try:
socket.getpeername(self) socket.getpeername(self)
except socket_error, e: except socket_error as e:
if e.errno != errno.ENOTCONN: if e.errno != errno.ENOTCONN:
raise raise
# no, no connection yet # no, no connection yet

View File

@ -50,17 +50,17 @@ from os import urandom
from select import select from select import select
from weakref import proxy from weakref import proxy
from err import openssl_error, InvalidSocketError from .err import openssl_error, InvalidSocketError
from err import raise_ssl_error from .err import raise_ssl_error
from err import SSL_ERROR_WANT_READ, SSL_ERROR_SYSCALL from .err import SSL_ERROR_WANT_READ, SSL_ERROR_SYSCALL
from err import ERR_WRONG_VERSION_NUMBER, ERR_COOKIE_MISMATCH, ERR_NO_SHARED_CIPHER from .err import ERR_WRONG_VERSION_NUMBER, ERR_COOKIE_MISMATCH, ERR_NO_SHARED_CIPHER
from err import ERR_NO_CIPHER, ERR_HANDSHAKE_TIMEOUT, ERR_PORT_UNREACHABLE from .err import ERR_NO_CIPHER, ERR_HANDSHAKE_TIMEOUT, ERR_PORT_UNREACHABLE
from err import ERR_READ_TIMEOUT, ERR_WRITE_TIMEOUT from .err import ERR_READ_TIMEOUT, ERR_WRITE_TIMEOUT
from err import ERR_BOTH_KEY_CERT_FILES, ERR_BOTH_KEY_CERT_FILES_SVR, ERR_NO_CERTS from .err import ERR_BOTH_KEY_CERT_FILES, ERR_BOTH_KEY_CERT_FILES_SVR, ERR_NO_CERTS
from x509 import _X509, decode_cert from .x509 import _X509, decode_cert
from tlock import tlock_init from .tlock import tlock_init
from openssl import * from .openssl import *
from util import _Rsrc, _BIO from .util import _Rsrc, _BIO
_logger = getLogger(__name__) _logger = getLogger(__name__)

View File

@ -56,13 +56,13 @@ def main():
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
if peer_address: if peer_address:
print "Completed listening for peer: %s" % str(peer_address) print("Completed listening for peer: %s" % str(peer_address))
break break
print "Accepting..." print("Accepting...")
conn = scn.accept()[0] conn = scn.accept()[0]
sck.settimeout(5) sck.settimeout(5)
conn.get_socket(True).settimeout(5) conn.get_socket(True).settimeout(5)
@ -70,26 +70,26 @@ def main():
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Handshake invocation: %d" % cnt print("Handshake invocation: %d" % cnt)
try: try:
conn.do_handshake() conn.do_handshake()
except SSLError as err: except SSLError as err:
if err.errno == 504: if err.errno == 504:
continue continue
raise raise
print "Completed handshaking with peer" print("Completed handshaking with peer")
break break
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Read invocation: %d" % cnt print("Read invocation: %d" % cnt)
try: try:
message = conn.read() message = conn.read()
except SSLError as err: except SSLError as err:
@ -98,16 +98,16 @@ def main():
if err.args[0] == SSL_ERROR_ZERO_RETURN: if err.args[0] == SSL_ERROR_ZERO_RETURN:
break break
raise raise
print message print(message)
conn.write("Back to you: " + message) conn.write("Back to you: " + message)
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Shutdown invocation: %d" % cnt print("Shutdown invocation: %d" % cnt)
try: try:
s = conn.shutdown() s = conn.shutdown()
s.shutdown(socket.SHUT_RDWR) s.shutdown(socket.SHUT_RDWR)

View File

@ -10,6 +10,6 @@ cert_path = path.join(path.abspath(path.dirname(__file__)), "certs")
sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM), cert_reqs=ssl.CERT_REQUIRED, ca_certs=path.join(cert_path, "ca-cert.pem")) sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM), cert_reqs=ssl.CERT_REQUIRED, ca_certs=path.join(cert_path, "ca-cert.pem"))
sock.connect(('localhost', 28000)) sock.connect(('localhost', 28000))
sock.send('Hi there') sock.send('Hi there')
print sock.recv() print(sock.recv())
sock.unwrap() sock.unwrap()
sock.shutdown(SHUT_RDWR) sock.shutdown(SHUT_RDWR)

View File

@ -84,7 +84,7 @@ fill = urandom(CHUNK_SIZE)
def transfer_out(sock, listen_sock=None, marker=False): def transfer_out(sock, listen_sock=None, marker=False):
max_i_len = 10 max_i_len = 10
start_char = "t" if marker else "s" start_char = "t" if marker else "s"
for i in xrange(CHUNKS): for i in range(CHUNKS):
prefix = start_char + str(i) + ":" prefix = start_char + str(i) + ":"
pad_prefix = prefix + "b" * (max_i_len - len(prefix)) pad_prefix = prefix + "b" * (max_i_len - len(prefix))
message = pad_prefix + fill[:CHUNK_SIZE - max_i_len - 1] + "e" message = pad_prefix + fill[:CHUNK_SIZE - max_i_len - 1] + "e"
@ -106,7 +106,7 @@ def transfer_out(sock, listen_sock=None, marker=False):
if not i % CHUNKS_PER_DOT: if not i % CHUNKS_PER_DOT:
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
print print()
def transfer_in(sock, listen_sock=None): def transfer_in(sock, listen_sock=None):
drops = 0 drops = 0
@ -168,7 +168,7 @@ def transfer_in(sock, listen_sock=None):
sys.stdout.flush() sys.stdout.flush()
i += 1 i += 1
drops += CHUNKS - 1 - pack_seq drops += CHUNKS - 1 - pack_seq
print print()
return drops return drops
# #
@ -260,7 +260,7 @@ def make_client_manager():
# Create the global client manager class in servers configured as client # Create the global client manager class in servers configured as client
# managers # managers
class ClientManager(object): class ClientManager(object):
from Queue import Queue from queue import Queue
queue = Queue() queue = Queue()
clients = -1 # creator does not count clients = -1 # creator does not count
@ -324,16 +324,16 @@ def remote_client(manager_address):
manager = Manager(manager_address, COMM_KEY) manager = Manager(manager_address, COMM_KEY)
manager.connect() manager.connect()
queue = manager.get_queue() queue = manager.get_queue()
print "Client connected; waiting for job..." print("Client connected; waiting for job...")
while True: while True:
command = queue.get() command = queue.get()
if command == "STOP": if command == "STOP":
break break
command = command[:-1] + [(manager_address[0], command[-1][1])] command = command[:-1] + [(manager_address[0], command[-1][1])]
print "Starting job: " + str(command) print("Starting job: " + str(command))
drops = client(*command) drops = client(*command)
print "%d drops" % drops print("%d drops" % drops)
print "Job completed; waiting for next job..." print("Job completed; waiting for next job...")
# #
# Test runner # Test runner
@ -349,7 +349,7 @@ def run_test(server_args, client_args, port):
# bind to loopback only, for local clients # bind to loopback only, for local clients
listen_addr = 'localhost', port listen_addr = 'localhost', port
svr = iter(server(*server_args, listen_addr=listen_addr)) svr = iter(server(*server_args, listen_addr=listen_addr))
listen_addr = svr.next() listen_addr = next(svr)
listen_addr = 'localhost', listen_addr[1] listen_addr = 'localhost', listen_addr[1]
client_args = list(client_args) client_args = list(client_args)
client_args.append(listen_addr) client_args.append(listen_addr)
@ -360,19 +360,19 @@ def run_test(server_args, client_args, port):
proc.start() proc.start()
in_size = CHUNK_SIZE * CHUNKS / 2**20 in_size = CHUNK_SIZE * CHUNKS / 2**20
out_size = CHUNK_SIZE * CHUNKS / 2**20 out_size = CHUNK_SIZE * CHUNKS / 2**20
print "Starting inbound: %dMiB" % in_size print("Starting inbound: %dMiB" % in_size)
svr_in_time, drops = svr.next() svr_in_time, drops = next(svr)
print "Inbound: %.3f seconds, %dMiB/s, %d drops" % ( print("Inbound: %.3f seconds, %dMiB/s, %d drops" % (
svr_in_time, in_size / svr_in_time, drops) svr_in_time, in_size / svr_in_time, drops))
print "Starting outbound: %dMiB" % out_size print("Starting outbound: %dMiB" % out_size)
svr_out_time = svr.next() svr_out_time = next(svr)
print "Outbound: %.3f seconds, %dMiB/s" % ( print("Outbound: %.3f seconds, %dMiB/s" % (
svr_out_time, out_size / svr_out_time) svr_out_time, out_size / svr_out_time))
if not QUEUE: if not QUEUE:
proc.join() proc.join()
print "Combined: %.3f seconds, %dMiB/s" % ( print("Combined: %.3f seconds, %dMiB/s" % (
svr_out_time + svr_in_time, svr_out_time + svr_in_time,
(in_size + out_size) / (svr_in_time + svr_out_time)) (in_size + out_size) / (svr_in_time + svr_out_time)))
# #
# Main entry point # Main entry point
@ -419,16 +419,16 @@ if __name__ == "__main__":
} }
do_patch() do_patch()
while True: while True:
print "\nSelect protocol:\n" print("\nSelect protocol:\n")
for key in sorted(selector): for key in sorted(selector):
print "\t" + str(key) + ": " + selector[key] print("\t" + str(key) + ": " + selector[key])
try: try:
choice = raw_input("\nProtocol: ") choice = input("\nProtocol: ")
choice = int(choice) choice = int(choice)
if choice < 0 or choice >= len(selector): if choice < 0 or choice >= len(selector):
raise ValueError("Invalid selection input") raise ValueError("Invalid selection input")
except (ValueError, OverflowError): except (ValueError, OverflowError):
print "Invalid selection input" print("Invalid selection input")
continue continue
except EOFError: except EOFError:
break break

View File

@ -59,7 +59,7 @@ class BasicTests(unittest.TestCase):
# A crude test for the legacy API # A crude test for the legacy API
try: try:
ssl.sslwrap_simple(socket.socket(AF_INET4_6, socket.SOCK_DGRAM)) ssl.sslwrap_simple(socket.socket(AF_INET4_6, socket.SOCK_DGRAM))
except IOError, e: except IOError as e:
if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
pass pass
else: else:
@ -67,7 +67,7 @@ class BasicTests(unittest.TestCase):
try: try:
ssl.sslwrap_simple(socket.socket(AF_INET4_6, ssl.sslwrap_simple(socket.socket(AF_INET4_6,
socket.SOCK_DGRAM)._sock) socket.SOCK_DGRAM)._sock)
except IOError, e: except IOError as e:
if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
pass pass
else: else:
@ -281,7 +281,7 @@ class NetworkedTests(unittest.TestCase):
count += 1 count += 1
s.do_handshake() s.do_handshake()
break break
except ssl.SSLError, err: except ssl.SSLError as err:
if err.args[0] == ssl.SSL_ERROR_WANT_READ: if err.args[0] == ssl.SSL_ERROR_WANT_READ:
while True: while True:
to = s.get_timeout() to = s.get_timeout()
@ -601,7 +601,7 @@ class AsyncoreEchoServer(threading.Thread):
def _do_ssl_handshake(self): def _do_ssl_handshake(self):
try: try:
self.socket.do_handshake() self.socket.do_handshake()
except ssl.SSLError, err: except ssl.SSLError as err:
if err.args[0] in (ssl.SSL_ERROR_WANT_READ, if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE, ssl.SSL_ERROR_WANT_WRITE,
ssl.SSL_ERROR_SSL): ssl.SSL_ERROR_SSL):
@ -609,7 +609,7 @@ class AsyncoreEchoServer(threading.Thread):
elif err.args[0] == ssl.SSL_ERROR_EOF: elif err.args[0] == ssl.SSL_ERROR_EOF:
return self.handle_close() return self.handle_close()
raise raise
except socket.error, err: except socket.error as err:
if err.args[0] == errno.ECONNABORTED: if err.args[0] == errno.ECONNABORTED:
return self.handle_close() return self.handle_close()
else: else:
@ -861,10 +861,10 @@ def bad_cert_test(certfile):
certfile=certfile, certfile=certfile,
ssl_version=ssl.PROTOCOL_DTLSv1) ssl_version=ssl.PROTOCOL_DTLSv1)
s.connect((HOST, server.port)) s.connect((HOST, server.port))
except ssl.SSLError, x: except ssl.SSLError as x:
if test_support.verbose: if test_support.verbose:
sys.stdout.write("\nSSLError is %s\n" % x[1]) sys.stdout.write("\nSSLError is %s\n" % x[1])
except socket.error, x: except socket.error as x:
if test_support.verbose: if test_support.verbose:
sys.stdout.write("\nsocket.error is %s\n" % x[1]) sys.stdout.write("\nsocket.error is %s\n" % x[1])
else: else:

View File

@ -25,7 +25,7 @@ threading support. It does not have client-visible components.
""" """
from logging import getLogger from logging import getLogger
from openssl import * from .openssl import *
try: try:
import threading import threading

View File

@ -35,10 +35,10 @@ from logging import getLogger
import ssl import ssl
import socket import socket
from patch import do_patch from .patch import do_patch
do_patch() do_patch()
from sslconnection import SSLContext, SSL from .sslconnection import SSLContext, SSL
import err as err_codes import .err as err_codes
_logger = getLogger(__name__) _logger = getLogger(__name__)

View File

@ -31,8 +31,8 @@ interpreter.
""" """
from logging import getLogger from logging import getLogger
from openssl import * from .openssl import *
from util import _Rsrc, _BIO from .util import _Rsrc, _BIO
_logger = getLogger(__name__) _logger = getLogger(__name__)

View File

@ -49,10 +49,10 @@ if __name__ == "__main__":
from pypandoc import convert from pypandoc import convert
long_description = convert("README.md", "rst")\ long_description = convert("README.md", "rst")\
.translate({ord("\r"): None}) .translate({ord("\r"): None})
with open("README.rst", "wb") as readme: with open("README.rst", "w") as readme:
readme.write(long_description) readme.write(long_description)
else: else:
long_description = open("README.rst").read() long_description = open("README.md").read()
top_package_plat_files_file = "dtls_package_files" top_package_plat_files_file = "dtls_package_files"
if dist: if dist:
if plat_dist: if plat_dist: