Skip to content

Commit

Permalink
Windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Apr 14, 2015
1 parent 1056a74 commit 44caa01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 4 additions & 3 deletions syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ def setup_widgets(self):
self[limitmenu].show_all()

if not old_gtk:
if not Gtk.IconTheme.get_default().has_icon(self["edit-menu-icon"].get_icon_name()[0]):
# If requested icon is not found in default theme, replace it with emblem-system-symbolic
self["edit-menu-icon"].set_from_icon_name("emblem-system-symbolic", self["edit-menu-icon"].get_icon_name()[1])
if not self["edit-menu-icon"] is None:
if not Gtk.IconTheme.get_default().has_icon(self["edit-menu-icon"].get_icon_name()[0]):
# If requested icon is not found in default theme, replace it with emblem-system-symbolic
self["edit-menu-icon"].set_from_icon_name("emblem-system-symbolic", self["edit-menu-icon"].get_icon_name()[1])

# Set window title in way that even Gnome can understand
self["window"].set_title(_("Syncthing GTK"))
Expand Down
23 changes: 17 additions & 6 deletions syncthing_gtk/iddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, app, device_id):
self.app = app
self.device_id = device_id
self.setup_widgets()
self.ssl_ctx = create_ssl_context()
self.load_data()

def __getitem__(self, name):
Expand Down Expand Up @@ -53,7 +54,7 @@ def load_data_urllib(self):
""" Loads QR code from Syncthing daemon """
uri = "%s/qr/?text=%s" % (self.app.daemon.get_webui_url(), self.device_id)
api_key = self.app.daemon.get_api_key()
opener = urllib2.build_opener(DummyHTTPSHandler())
opener = urllib2.build_opener(DummyHTTPSHandler(self.ssl_ctx))
if not api_key is None:
opener.addheaders = [("X-API-Key", api_key)]
a = opener.open(uri)
Expand Down Expand Up @@ -93,19 +94,29 @@ def cb_syncthing_qr(self, io, results, *a):
finally:
del io

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
def create_ssl_context():
""" May return NULL if ssl is not available """
if hasattr(ssl, "create_default_context"):
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
else:
log.warning("SSL is not available, cannot verify server certificate.")

class DummyHTTPSHandler(urllib2.HTTPSHandler):
"""
Dummy HTTPS handler that ignores certificate errors. This in unsafe,
but used ONLY for QR code images.
"""
def __init__(self):
def __init__(self, ctx):
urllib2.HTTPSHandler.__init__(self)
self.ctx = ctx

def https_open(self, req):
return self.do_open(self.getConnection, req)

def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, context=ctx)
if not self.ctx is None:
return httplib.HTTPSConnection(host, context=ctx)
return True

0 comments on commit 44caa01

Please sign in to comment.