-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Implemented '--tor inside' option to run inside of the Tor-connected virtual machine #484
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
Open
yurivict
wants to merge
10
commits into
HelloZeroNet:master
Choose a base branch
from
yurivict:tor-inside
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d602a6
Implemented '--tor inside' option to run inside of the Tor-conneted v…
yurivict 566a949
Forgotten files.
yurivict dc551bf
Corrections.
yurivict abb687c
Removed unnecessary imports.
yurivict 847a6c9
Added HS list randomization.
yurivict fe60345
Randomly reshuffling the list of supplied onions for security.
yurivict 0d7ae72
Changed format of the HS certificate to standard onem, one onion per …
yurivict 9aa324a
Improved handling of the situation when we run out of onions, reject …
yurivict 26dc8bf
Minor adjustments.
yurivict 257fd7e
Fixed testcase failure.
yurivict 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import logging | ||
| import socket | ||
| import random | ||
| import sys | ||
|
|
||
| from Config import config | ||
| from Crypt import CryptRsa | ||
| from Site import SiteManager | ||
|
|
||
| # TorManagerInside is the version of TorManager reduced to the needs of the Tor-connected VM. | ||
|
|
||
| class TorManagerInside: | ||
| def __init__(self, tor_hidden_services_fname): | ||
| self.privatekeys = {} # Onion: Privatekey | ||
| self.site_onions = {} # Site address: Onion | ||
| self.onion_sites = {} # Onion: Site address | ||
| self.log = logging.getLogger("TorManagerInside") | ||
|
|
||
| self.ip, self.port = config.tor_controller.split(":") | ||
| self.port = int(self.port) | ||
|
|
||
| self.hss_all = self.reshuffleList(self.readHiddenServices(tor_hidden_services_fname)) | ||
| self.hss_unused = self.hss_all[:] | ||
|
|
||
| # Add our onions to the black list | ||
| for hs in self.hss_all: | ||
| SiteManager.peer_blacklist.append((hs[0], config.fileserver_port)) | ||
|
|
||
| self.enabled = True | ||
| self.start_onions = True | ||
| self.updateStatus() | ||
|
|
||
| def readHiddenServices(self, fname): | ||
| with open(fname) as f: | ||
| lines = f.readlines() | ||
| hss = [] | ||
| hs = [] | ||
| phase = 'O' | ||
| onion = "" | ||
| key = "" | ||
| for line in lines: | ||
| line = line.strip('\n') | ||
| if line == "": | ||
| continue | ||
| if phase == 'O': | ||
| if not line.endswith(".onion"): | ||
| sys.exit("Onion address is expected in the hidden services file, got the line >%s<" % line) | ||
| onion = line | ||
| phase = 'H' | ||
| elif phase == 'H': | ||
| if line != "-----BEGIN RSA PRIVATE KEY-----": | ||
| sys.exit("Key header is expected in the hidden services file, got the line >%s<" % line) | ||
| phase = 'K' | ||
| elif phase == 'K': | ||
| if line != "-----END RSA PRIVATE KEY-----": | ||
| key = key+line | ||
| else: | ||
| hss.append([onion, key]) | ||
| key = "" | ||
| phase = 'O' | ||
| if phase != 'O': | ||
| sys.exit("Unexpected end of the hidden services file") | ||
| return hss | ||
|
|
||
| def reshuffleList(self, lst): | ||
| idxs = range(0, len(lst)) | ||
| shuf = [] | ||
| while len(idxs) > 0: | ||
| n = random.randrange(0, len(idxs)) | ||
| shuf.append(lst[idxs[n]]) | ||
| del idxs[n] | ||
| return shuf | ||
|
|
||
| def updateStatus(self): | ||
| self.status = u"OK (%s onion used of %s available)" % (len(self.onion_sites), len(self.hss_all)) | ||
|
|
||
| def getPrivatekey(self, address): | ||
| return self.privatekeys[address] | ||
|
|
||
| def getPublickey(self, address): | ||
| return CryptRsa.privatekeyToPublickey(self.privatekeys[address]) | ||
|
|
||
| def haveOnionsAvailable(self): | ||
| return len(self.hss_unused) > 0 | ||
|
|
||
| def numOnions(self): | ||
| return len(self.hss_all) | ||
|
|
||
| def getOnion(self, site_address): | ||
| onion = self.site_onions.get(site_address) | ||
| if onion: | ||
| return onion | ||
| if len(self.hss_unused) == 0: | ||
| sys.exit("TorManager ran out of onions (%u onions were supplied)" % len(self.hss_all)) | ||
| hs_info = self.hss_unused[0] | ||
| del self.hss_unused[0] | ||
| onion = hs_info[0].replace(".onion", "") | ||
| self.site_onions[site_address] = onion | ||
| self.onion_sites[onion] = site_address | ||
| self.privatekeys[onion] = hs_info[1] | ||
| self.log.debug("Using the next onion for the site %s: %s.onion" % (site_address, onion)) | ||
| self.updateStatus() | ||
| return onion | ||
|
|
||
| def delSiteOnion(self, site_address, onion): | ||
| self.log.debug("Deleting the site %s, recycling its onion %s.onion" % (site_address, onion)) | ||
| self.hss_unused.append([onion+".onion", self.privatekeys[onion]]) | ||
| del self.privatekeys[onion] | ||
| del self.site_onions[site_address] | ||
| del self.onion_sites[onion] | ||
| self.updateStatus() | ||
| return True | ||
|
|
||
| def delOnion(self, onion): | ||
| site_address = self.onion_sites[onion] | ||
| return self.delSiteOnion(site_address, onion) | ||
|
|
||
| def delSite(self, site_address): | ||
| onion = self.site_onions[site_address] | ||
| return self.delSiteOnion(site_address, onion) | ||
|
|
||
| def createSocket(self, onion, port): | ||
| self.log.debug("Creating new socket to %s:%s" % (onion, port)) | ||
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| sock.connect((onion, int(port))) | ||
| return sock |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from TorManager import TorManager | ||
| from TorManager import TorManager | ||
| from TorManagerInside import TorManagerInside |
This file contains hidden or 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 hidden or 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
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.
This is unpractical.
servinghere refers to the number of sites visited, not hosted. I would remove that condition completely.