[Pkg-privacy-commits] [torbrowser-launcher] 17/39: Make downloading over Tor work

Roger Shimizu rosh at debian.org
Tue Mar 27 15:41:52 UTC 2018


This is an automated email from the git hooks/post-receive script.

rosh pushed a commit to branch rosh/experimental
in repository torbrowser-launcher.

commit 0195e489917f970e13e645f90daa0d50a9e44ba7
Author: Micah Lee <micah at micahflee.com>
Date:   Fri Mar 23 12:49:52 2018 -0700

    Make downloading over Tor work
---
 BUILD.md                        |  4 ++--
 torbrowser_launcher/common.py   |  7 ++++++-
 torbrowser_launcher/launcher.py | 41 +++++++++++++++++++++++------------------
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/BUILD.md b/BUILD.md
index 79833cd..e4c7194 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -12,7 +12,7 @@ Then install dependencies, build a package, and install:
 ### Debian, Ubuntu, Linux Mint, etc.
 
 ```sh
-sudo apt-get install build-essential dh-python python3-all python3-stdeb python3-qt5 python3-gpg python3-requests tor
+sudo apt-get install build-essential dh-python python3-all python3-stdeb python3-qt5 python3-gpg python3-requests python3-socks tor
 ./build_deb.sh
 sudo dpkg -i deb_dist/torbrowser-launcher_*.deb
 ```
@@ -20,7 +20,7 @@ sudo dpkg -i deb_dist/torbrowser-launcher_*.deb
 ### Red Hat, Fedora, CentOS, etc.
 
 ```sh
-sudo dnf install rpm-build python3-qt5 python3-gpg python3-requests tor
+sudo dnf install rpm-build python3-qt5 python3-gpg python3-requests python3-pysocks tor
 ./build_rpm.sh
 sudo yum install dist/torbrowser-launcher-*.rpm
 ```
diff --git a/torbrowser_launcher/common.py b/torbrowser_launcher/common.py
index 5642f4d..abf8628 100644
--- a/torbrowser_launcher/common.py
+++ b/torbrowser_launcher/common.py
@@ -305,7 +305,7 @@ class Common(object):
             'tbl_version': self.tbl_version,
             'installed': False,
             'download_over_tor': False,
-            'tor_socks_address': 'tcp:127.0.0.1:9050',
+            'tor_socks_address': '127.0.0.1:9050',
             'mirror': self.default_mirror,
             'force_en-US': False,
         }
@@ -323,6 +323,11 @@ class Common(object):
                     settings[setting] = default_settings[setting]
                     resave = True
 
+            # make sure tor_socks_address doesn't start with 'tcp:'
+            if settings['tor_socks_address'].startswith('tcp:'):
+                settings['tor_socks_address'] = settings['tor_socks_address'][4:]
+                resave = True
+
             # make sure the version is current
             if settings['tbl_version'] != self.tbl_version:
                 settings['tbl_version'] = self.tbl_version
diff --git a/torbrowser_launcher/launcher.py b/torbrowser_launcher/launcher.py
index b09f087..959a2ac 100644
--- a/torbrowser_launcher/launcher.py
+++ b/torbrowser_launcher/launcher.py
@@ -37,8 +37,8 @@ import threading
 import re
 import unicodedata
 import requests
+import socks
 import gpg
-import OpenSSL
 import xml.etree.ElementTree as ET
 
 from PyQt5 import QtCore, QtWidgets, QtGui
@@ -81,16 +81,6 @@ class Launcher(QtWidgets.QMainWindow):
 
         # If Tor Browser is not installed, detect latest version, download, and install
         if not self.common.settings['installed'] or not self.check_min_version():
-            # If downloading over Tor, include txsocksx
-            if self.common.settings['download_over_tor']:
-                try:
-                    import txsocksx
-                    print(_('Downloading over Tor'))
-                except ImportError:
-                    Alert(self.common, _("The python-txsocksx package is missing, downloads will not happen over tor"))
-                    self.common.settings['download_over_tor'] = False
-                    self.common.save_settings()
-
             # Different message if downloading for the first time, or because your installed version is too low
             download_message = ""
             if not self.common.settings['installed']:
@@ -109,6 +99,9 @@ class Launcher(QtWidgets.QMainWindow):
                           'extract',
                           'run'])
 
+            if self.common.settings['download_over_tor']:
+                print(_('Downloading over Tor'))
+
         else:
             # Tor Browser is already installed, so run
             self.run(False)
@@ -283,12 +276,10 @@ class Launcher(QtWidgets.QMainWindow):
         # Initialize the progress bar
         self.progress_bar.setValue(0)
         self.progress_bar.setMaximum(100)
-        self.progress_bar.setFormat(_('Downloading') + ' {0}, %p%'.format(name))
-
         if self.common.settings['download_over_tor']:
-            # TODO: make requests work over SOCKS5 proxy
-            # this is the proxy to use: self.common.settings['tor_socks_address']
-            pass
+            self.progress_bar.setFormat(_('Downloading') + ' {0} '.format(name) + _('(over Tor)') + ', %p%')
+        else:
+            self.progress_bar.setFormat(_('Downloading') + ' {0}, %p%'.format(name))
 
         def progress_update(total_bytes, bytes_so_far):
             percent = float(bytes_so_far) / float(total_bytes)
@@ -300,7 +291,9 @@ class Launcher(QtWidgets.QMainWindow):
                     amount /= float(size)
                     break
 
-            message = _('Downloaded')+(' %2.1f%% (%2.1f %s)' % ((percent * 100.0), amount, units))
+            message = _('Downloaded') + (' %2.1f%% (%2.1f %s)' % ((percent * 100.0), amount, units))
+            if self.common.settings['download_over_tor']:
+                message += ' ' + _('(over Tor)')
 
             self.progress_bar.setMaximum(total_bytes)
             self.progress_bar.setValue(bytes_so_far)
@@ -484,11 +477,23 @@ class DownloadThread(QtCore.QThread):
         self.url = url
         self.path = path
 
+        # Use tor socks5 proxy, if enabled
+        if self.common.settings['download_over_tor']:
+            socks5_address = 'socks5://{}'.format(self.common.settings['tor_socks_address'])
+            self.proxies = {
+                'https': socks5_address,
+                'http': socks5_address
+            }
+        else:
+            self.proxies = None
+
     def run(self):
         with open(self.path, "wb") as f:
             try:
                 # Start the request
-                r = requests.get(self.url, headers={'User-Agent': 'torbrowser-launcher'}, stream=True)
+                r = requests.get(self.url,
+                                 headers={'User-Agent': 'torbrowser-launcher'},
+                                 stream=True, proxies=self.proxies)
 
                 # If status code isn't 200, something went wrong
                 if r.status_code != 200:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/torbrowser-launcher.git



More information about the Pkg-privacy-commits mailing list