-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using pure python code to download and verify gpg encrypted files/messages #3692
Merged
conorsch
merged 2 commits into
freedomofpress:tbb-0.9.0
from
kushaldas:3687-create-gpg-for-everything
Aug 8, 2018
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ py | |
pytest | ||
pytest-cov | ||
pytest-mock | ||
requests[socks] | ||
selenium | ||
tbselenium | ||
pyvirtualdisplay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import time | ||
import os | ||
import random | ||
import requests | ||
|
||
from os.path import abspath, realpath, dirname, join | ||
|
||
|
@@ -51,19 +52,19 @@ def return_downloaded_content(self, url, cookies): | |
:param cookies: the cookies to access | ||
:return: Content of the URL | ||
""" | ||
temp_cookie_file = tempfile.NamedTemporaryFile('w', delete=False) | ||
data = {'url': url, 'cookies': cookies} | ||
json.dump(data, temp_cookie_file) | ||
temp_cookie_file.close() | ||
|
||
cmd_path = abspath(join(dirname(realpath(__file__)), | ||
'download_content.py')) | ||
# Now call the external program to handle the download | ||
cmd = 'python {0} {1}'.format(cmd_path, temp_cookie_file.name) | ||
if '.onion' in url: | ||
cmd = 'nc -x 127.0.0.1:9150 ' + cmd | ||
raw_content = self.system(cmd).strip() | ||
return raw_content | ||
proxies = None | ||
if ".onion" in url: | ||
proxies = { | ||
'http': 'socks5h://127.0.0.1:9150', | ||
'https': 'socks5h://127.0.0.1:9150' | ||
} | ||
r = requests.get(url, cookies=cookies, proxies=proxies, stream=True) | ||
if r.status_code != 200: | ||
raise Exception("Failed to download the data.") | ||
data = b"" | ||
for chunk in r.iter_content(1024): | ||
data += chunk | ||
return data | ||
|
||
def _input_text_in_login_form(self, username, password, token): | ||
self.driver.get(self.journalist_location + "/login") | ||
|
@@ -640,14 +641,13 @@ def _journalist_downloads_message(self): | |
|
||
# Downloading files with Selenium is tricky because it cannot automate | ||
# the browser's file download dialog. We can directly request the file | ||
# using urllib2, but we need to pass the cookies for the logged in user | ||
# using requests, but we need to pass the cookies for the logged in user | ||
# for Flask to allow this. | ||
def cookie_string_from_selenium_cookies(cookies): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this function name is now misleading so we should update it since now it's returning a dict for |
||
cookie_strs = [] | ||
result = {} | ||
for cookie in cookies: | ||
cookie_str = "=".join([cookie['name'], cookie['value']]) + ';' | ||
cookie_strs.append(cookie_str) | ||
return ' '.join(cookie_strs) | ||
result[cookie['name']] = cookie['value'] | ||
return result | ||
|
||
cks = cookie_string_from_selenium_cookies(self.driver.get_cookies()) | ||
raw_content = self.return_downloaded_content(file_url, cks) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for updating this 👍