]> git.lizzy.rs Git - torbrowser-launcher.git/blobdiff - torbrowser-launcher
fixes #1
[torbrowser-launcher.git] / torbrowser-launcher
index ae3b48618a9575b1425db1d6cc266f4801c5da9b..e346ad7bcc243ea5451afcac81079a0a73095d3e 100755 (executable)
@@ -27,6 +27,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 """
 
+import sys
+sys.path.append('/usr/share/torbrowser-launcher/lib/')
+
 import gettext
 gettext.install('torbrowser-launcher', '/usr/share/torbrowser-launcher/locale')
 
@@ -38,25 +41,32 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 
-import os, sys, subprocess, locale, urllib2, gobject, time, pickle, json, tarfile, psutil
+import os, subprocess, locale, urllib2, gobject, time, pickle, json, tarfile, psutil
 
-from twisted.web.client import Agent, ResponseDone
+from twisted.web.client import Agent, ResponseDone, ResponseFailed
 from twisted.web.http_headers import Headers
 from twisted.internet.protocol import Protocol
 from twisted.internet.ssl import ClientContextFactory
+from twisted.internet.endpoints import TCP4ClientEndpoint
+
+from txsocksx.client import SOCKS5ClientEndpoint
 
-from OpenSSL.SSL import Context, VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT
-from OpenSSL.crypto import load_certificate, FILETYPE_PEM
+import OpenSSL
+
+class TryStableException(Exception):
+    pass
+class DownloadErrorException(Exception):
+    pass
 
 class VerifyTorProjectCert(ClientContextFactory):
 
     def __init__(self, torproject_pem):
-        self.torproject_ca = load_certificate(FILETYPE_PEM, open(torproject_pem, 'r').read())
+        self.torproject_ca = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(torproject_pem, 'r').read())
 
     def getContext(self, host, port):
         ctx = ClientContextFactory.getContext(self)
         ctx.set_verify_depth(0)
-        ctx.set_verify(VERIFY_PEER | VERIFY_FAIL_IF_NO_PEER_CERT, self.verifyHostname)
+        ctx.set_verify(OpenSSL.SSL.VERIFY_PEER | OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self.verifyHostname)
         return ctx
 
     def verifyHostname(self, connection, cert, errno, depth, preverifyOK):
@@ -607,20 +617,39 @@ class TBLLauncher:
         self.box = gtk.VBox(False, 20)
         self.window.add(self.box)
 
-        if self.gui == 'error':
+        if self.gui == 'error' or self.gui == 'error_try_stable' or self.gui == 'error_try_tor':
             # labels
             self.label = gtk.Label( self.gui_message ) 
             self.label.set_line_wrap(True)
             self.box.pack_start(self.label, True, True, 0)
             self.label.show()
 
+            # button box
+            self.button_box = gtk.HButtonBox()
+            self.button_box.set_layout(gtk.BUTTONBOX_SPREAD)
+            self.box.pack_start(self.button_box, True, True, 0)
+            self.button_box.show()
+
+            if self.gui != 'error':
+                # yes button
+                yes_image = gtk.Image()
+                yes_image.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
+                self.yes_button = gtk.Button("Yes")
+                self.yes_button.set_image(yes_image)
+                if self.gui == 'error_try_stable':
+                    self.yes_button.connect("clicked", self.try_stable, None)
+                elif self.gui == 'error_try_tor':
+                    self.yes_button.connect("clicked", self.try_tor, None)
+                self.button_box.add(self.yes_button)
+                self.yes_button.show()
+
             # exit button
             exit_image = gtk.Image()
             exit_image.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)
             self.exit_button = gtk.Button("Exit")
             self.exit_button.set_image(exit_image)
             self.exit_button.connect("clicked", self.destroy, None)
-            self.box.add(self.exit_button)
+            self.button_box.add(self.exit_button)
             self.exit_button.show()
 
         elif self.gui == 'task':
@@ -723,13 +752,25 @@ class TBLLauncher:
 
     def response_received(self, response):
         class FileDownloader(Protocol):
-            def __init__(self, file, total, progress, done_cb):
+            def __init__(self, language, file, total, progress, done_cb):
                 self.file = file
                 self.total = total
                 self.so_far = 0
                 self.progress = progress
                 self.all_done = done_cb
 
+                if response.code != 200:
+                    try_stable = False
+                    if response.code == 404:
+                        if common.settings['preferred'] == 'alpha' and language != 'en-US':
+                            try_stable = True
+                    
+                    if try_stable:
+                        print 'about to raise TryStableException'
+                        raise TryStableException(_("It looks like the alpha version of Tor Browser Bundle isn't available for your language. Would you like to try the stable version instead?"))
+                    else:
+                        raise DownloadErrorException(_("Error with download: {0} {1}").format(response.code, response.phrase))
+
             def dataReceived(self, bytes):
                 self.file.write(bytes)
                 self.so_far += len(bytes)
@@ -749,8 +790,8 @@ class TBLLauncher:
                 print _('Finished receiving body:'), reason.getErrorMessage()
                 self.all_done(reason)
 
-        dl = FileDownloader(self.file_download, response.length, self.progressbar, self.response_finished)
-        response.deliverBody(dl)
+        dl = FileDownloader(self.common.language, self.file_download, response.length, self.progressbar, self.response_finished)
+        response.deliverBody(dl) 
 
     def response_finished(self, msg):
         if msg.check(ResponseDone):
@@ -763,9 +804,28 @@ class TBLLauncher:
             ## FIXME handle errors
 
     def download_error(self, f):
-        print _("Download error"), f
-        self.set_gui('error', _("Error starting download:\n\n{0}\n\nAre you connected to the internet?").format(f.value), [], False)
-        self.clear_ui()
+        print _("Download error:"), f.value, type(f.value)
+
+        if isinstance(f.value, TryStableException):
+            f.trap(TryStableException)
+            self.set_gui('error_try_stable', str(f.value), [], False)
+        
+        elif isinstance(f.value, DownloadErrorException):
+            f.trap(DownloadErrorException)
+            self.set_gui('error', str(f.value), [], False)
+
+        elif isinstance(f.value, ResponseFailed):
+            for reason in f.value.reasons:
+                if isinstance(reason.value, OpenSSL.SSL.Error):
+                    # TODO: add the ability to report attack by posting bug to trac.torproject.org
+                    if not self.common.settings['update_over_tor']:
+                        self.set_gui('error_try_tor', _('The SSL certificate served by https://www.torproject.org is invalid! You may be under attack. Try the download again using Tor?'), [], False)
+                    else:
+                        self.set_gui('error', _('The SSL certificate served by https://www.torproject.org is invalid! You may be under attack.'), [], False)
+
+        else:
+            self.set_gui('error', _("Error starting download:\n\n{0}\n\nAre you connected to the internet?").format(f.value), [], False)
+        
         self.build_ui()
 
     def download(self, name, url, path):
@@ -786,6 +846,20 @@ class TBLLauncher:
         if not reactor.running:
             reactor.run()
 
+    def try_stable(self, widget, data=None):
+        # change preferred to stable and relaunch TBL
+        self.common.settings['preferred'] = 'stable'
+        self.common.save_settings()
+        p = subprocess.Popen([self.common.paths['tbl_bin']])
+        self.destroy(False)
+
+    def try_tor(self, widget, data=None):
+        # set update_over_tor to true and relaunch TBL
+        self.common.settings['update_over_tor'] = True
+        self.common.save_settings()
+        p = subprocess.Popen([self.common.paths['tbl_bin']])
+        self.destroy(False)
+
     def attempt_update(self):
         # load the update check file
         try:
@@ -842,6 +916,7 @@ class TBLLauncher:
         if p.returncode == 0:
             self.run_task()
         else:
+            # TODO: add the ability to report attack by posting bug to trac.torproject.org
             self.set_gui('task', _("SIGNATURE VERIFICATION FAILED!\n\nYou might be under attack, or there might just be a networking problem. Click Start try the download again."), ['start_over'], False)
             self.clear_ui()
             self.build_ui()