Skip to content

Commit

Permalink
Fix: SSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphwetzel authored and ralphwetzel committed Jan 6, 2017
1 parent 62201ce commit 773ba39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions theonionbox/theonionbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,15 +1874,16 @@ def shutdown(self):
# https://fgallaire.github.io/wsgiserver/
class WSGIserver(ServerAdapter):

server = None
# server = None

def run(self, handler):
from tob.wsgiserver import WSGIServer
self.server = WSGIServer(handler, host=self.host, port=self.port)
self.server = WSGIServer(handler, self.host, self.port, **self.options)
self.server.start()

def shutdown(self):
self.server.stop()
if self.server is not None:
self.server.stop()


# This job runs at midnight to add a notification to the log
Expand Down Expand Up @@ -2060,19 +2061,19 @@ def exit_procedure(quit=True):
# good time to launch the housekeeping for the first time!
session_housekeeping()

boxLog.notice('Ready to listen on http://{}:{}/'.format(tob_server.host, tob_server.port))
http_or_https = 'http' if box_ssl is False else 'https'
boxLog.notice('Ready to listen on {}://{}:{}/'.format(http_or_https, tob_server.host, tob_server.port))

try:
if box_debug is True:
run(theonionbox, server=tob_server, host=box_host, port=box_port)
else:
run(theonionbox, server=tob_server, host=box_host, port=box_port, quiet=True)
except KeyboardInterrupt:
# print('Here we are!')
pass
except Exception as exc:
print(exc)
raise exc
finally:
exit_procedure(False)
# boxLog.notice("Fine!")


8 changes: 4 additions & 4 deletions theonionbox/tob/wsgiserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,9 +1776,9 @@ def __init__(self, certfile, keyfile, ca_certs=None):
if hasattr(ssl, 'create_default_context'):
self.context = ssl.create_default_context(
purpose=ssl.Purpose.CLIENT_AUTH,
cafile=certificate_chain
cafile=self.certificate_chain
)
self.context.load_cert_chain(certificate, private_key)
self.context.load_cert_chain(self.certificate, self.private_key)

def bind(self, sock):
"""Wrap and return the given socket."""
Expand All @@ -1804,10 +1804,10 @@ def wrap(self, sock):
# the 'ping' isn't SSL.
return None, {}
elif e.errno == ssl.SSL_ERROR_SSL:
if e.args[1].endswith('http request'):
if e.args[1].find('http request') > 0:
# The client is speaking HTTP to an HTTPS server.
raise NoSSLError
elif e.args[1].endswith('unknown protocol'):
elif e.args[1].find('unknown protocol') > 0:
# The client is speaking some non-HTTP protocol.
# Drop the conn.
return None, {}
Expand Down

0 comments on commit 773ba39

Please sign in to comment.