Skip to content

Commit

Permalink
first code review pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ioerror committed Feb 18, 2013
1 parent a0bddfc commit bfe97f4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
54 changes: 32 additions & 22 deletions torbrowser-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import os, sys, subprocess, locale, urllib2, gobject, time

# XXX: I guess gettext would be a good import
# I also assume it would make sense to use _("") for all strings?

import pygtk
pygtk.require('2.0')
import gtk
Expand Down Expand Up @@ -40,25 +43,25 @@ class TorBrowserLauncher:
# not installed
else:
# save the current version to the file
open(self.paths['file']['version'], 'w').write(self.current_tbb_version)
open(self.paths['file']['version'], 'w').write(self.current_tbb_version) # XXX: We arbitrarily truncate or squash this file - is that safe?

# are the tarball and sig already downloaded?
if os.path.isfile(self.paths['file']['tarball']) and os.path.isfile(self.paths['file']['tarball_sig']):
# start the gui with verify
self.set_gui('task', "You already have Tor Browser Bundle downloaded, but it isn't installed yet.", ['verify', 'extract', 'run'])
self.set_gui('task', "You already have Tor Browser Bundle downloaded, but it isn't installed yet.", ['verify', 'extract', 'run']) # XXX: Why ask?

# first run
else:
self.set_gui('task', "The first time you run the Tor Browser Launcher you need to download the Tor Browser Bundle. Click Start to download it now from https://www.torproject.org/.", ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run'])
self.set_gui('task', "The first time you run the Tor Browser Launcher you need to download the Tor Browser Bundle. Click Start to download it now from https://www.torproject.org/.", ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run']) # XXX: Why ask?

if launch_gui:
self.build_ui()
gtk.main()

# discover the architecture and language
def discover_arch_lang(self):
# figure out the architecture
self.architecture = subprocess.check_output(['arch']).strip('\n')
self.architecture = subprocess.check_output(['arch']).strip('\n') #XXX: Why not uname? Is `arch` portable?

# figure out the language
available_languages = ['en-US', 'ar', 'de', 'es-ES', 'fa', 'fr', 'it', 'ko', 'nl', 'pl', 'pt-PT', 'ru', 'vi', 'zh-CN']
Expand All @@ -72,10 +75,11 @@ class TorBrowserLauncher:
# if language isn't available, default to english
if self.language not in available_languages:
self.language = 'en-US'
# XXX: Wouldn't this be a nice survey data point? "Request TBB in your language!"

# build all relevant paths
def build_paths(self):
tbb_data = os.getenv('HOME')+'/.torbrowser'
tbb_data = os.getenv('HOME')+'/.torbrowser' # XXX: What happens if HOME is not set?
tarball_filename = 'tor-browser-gnu-linux-'+self.architecture+'-'+self.current_tbb_version+'-dev-'+self.language+'.tar.gz'

self.paths = {
Expand Down Expand Up @@ -125,7 +129,7 @@ class TorBrowserLauncher:

# set up the window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Tor Browser Launcher")
self.window.set_title("Tor Browser Launcher") # XXX: Perhaps just Tor Browser?
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_border_width(10)
self.window.connect("delete_event", self.delete_event)
Expand All @@ -136,11 +140,13 @@ class TorBrowserLauncher:

if self.gui == 'error':
# labels
self.label1 = gtk.Label( self.gui_message );
self.label1 = gtk.Label( self.gui_message );
self.label1.set_line_wrap(True)
self.box.pack_start(self.label1, True, True, 0)
self.label1.show()

# XXX: No formats?
# v v v v v
self.label2 = gtk.Label("You can fix the problem by deleting:\n"+self.paths['dir']['data']+"\n\nHowever, you will lose all your bookmarks and other Tor Browser preferences.");
self.label2.set_line_wrap(True)
self.box.pack_start(self.label2, True, True, 0)
Expand All @@ -157,11 +163,11 @@ class TorBrowserLauncher:

elif self.gui == 'task':
# label
self.label = gtk.Label( self.gui_message );
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()

# progress bar
self.progressbar = gtk.ProgressBar(adjustment=None)
self.progressbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
Expand Down Expand Up @@ -203,15 +209,15 @@ class TorBrowserLauncher:
# start running tasks
self.gui_task_i = 0
self.run_task()

# run the next task in the task list
def run_task(self):
if self.gui_task_i >= len(self.gui_tasks):
self.destroy(False)
return

task = self.gui_tasks[self.gui_task_i]

# get ready for the next task
self.gui_task_i += 1

Expand All @@ -234,29 +240,29 @@ class TorBrowserLauncher:
elif task == 'run':
print 'Running '+self.paths['file']['start']
self.run()

elif task == 'start_over':
print 'Starting download over again'
self.start_over()


def download(self, name, url, path):
# initialize the progress bar
self.progressbar.set_fraction(0)
self.progressbar.set_fraction(0)
self.progressbar.set_text('Downloading '+name)
self.progressbar.show()

# start the download
# start the download XXX: Should be over Tor if Tor is available on the system, no?
self.dl_response = urllib2.urlopen(url); # XXX SSL/TLS MITM
self.dl_total_size = self.dl_response.info().getheader('Content-Length').strip()
self.dl_total_size = int(self.dl_total_size)
self.dl_total_size = int(self.dl_total_size) # XXX: Sanity check this?
self.dl_bytes_so_far = 0

# set a timer to download more chunks
self.timer = gobject.timeout_add(1, self.download_chunk, name)

# open a file to write to
self.file_download = open(path, 'w')
self.file_download = open(path, 'w') # XXX: shouldn't we be extra careful and use tempfile here?

def download_chunk(self, name):
# download 10kb a time
Expand All @@ -274,7 +280,7 @@ class TorBrowserLauncher:
self.progressbar.set_fraction(percent)
percent = round(percent*100, 2)
self.progressbar.set_text("Downloaded %d%% of %s" % (percent, name))

sys.stdout.write("Downloaded %d of %d bytes (%0.2f%%)\r" % (self.dl_bytes_so_far, self.dl_total_size, percent))

if self.dl_bytes_so_far >= self.dl_total_size:
Expand All @@ -284,16 +290,18 @@ class TorBrowserLauncher:

def verify(self):
# initialize the progress bar
self.progressbar.set_fraction(0)
self.progressbar.set_fraction(0)
self.progressbar.set_text('Verifying Signature')
self.progressbar.show()

p = subprocess.Popen([self.paths['file']['verify'], self.paths['dir']['gpg'], self.paths['file']['tarball_sig']], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.pulse_until_process_exits(p)
# XXX: No return code checking?
# XXX: What happens if there are two signatures in the tarball_sig file? say, one good and one bad?

output = p.stdout.read()
if 'Good signature' in output:

if 'Good signature' in output: #XXX - what happens if the sig has the name "Goog Signature" in it?
self.run_task();
else:
self.progressbar.hide()
Expand All @@ -308,6 +316,7 @@ class TorBrowserLauncher:
self.progressbar.set_text('Installing')
self.progressbar.show()

# XXX: We should depend on tar or make this mode general - on OS X it is a .zip file
p = subprocess.Popen(['tar', '-xf', self.paths['file']['tarball'], '-C', self.paths['dir']['tbb']], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.pulse_until_process_exits(p)

Expand All @@ -333,7 +342,7 @@ class TorBrowserLauncher:
self.gui_tasks = ['download_tarball', 'download_tarball_sig', 'verify', 'extract', 'run']
self.gui_task_i = 0
self.start(None)

# exit
def delete_event(self, widget, event, data=None):
return False
Expand All @@ -347,6 +356,7 @@ class TorBrowserLauncher:
if __name__ == "__main__":
print 'Tor Browser Launcher'
print 'https://github.com/micahflee/torbrowser-launcher'
# XXX: Might make sense to print the TBL launcher version and lots of other useful debug info here

current_tbb_version = '2.3.25-2'
app = TorBrowserLauncher(current_tbb_version)
Expand Down
3 changes: 3 additions & 0 deletions verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ rm -rf $GPG_TMP_DIR
mkdir -p $GPG_TMP_DIR
chmod 700 $GPG_TMP_DIR

# XXX: Wouldn't it be better to have a system wide processed GnuPG trust db
# and then the user's account won't, say, accidentally subvert the trusted
# directory or even need to initalize anything?
# import erinn's public key
gpg --homedir $GPG_TMP_DIR --import /usr/share/torbrowser-launcher/erinn.asc

Expand Down

0 comments on commit bfe97f4

Please sign in to comment.