tordam

A library for peer discovery inside the Tor network
git clone https://git.parazyd.org/tordam
Log | Files | Refs | README | LICENSE

commit 1af7f5d90c331d73e3c82dfe51d551e63aba05be
parent 3a9a28e936498bbc49d062d33a9edfa40323ae78
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 12 Dec 2017 18:04:30 +0100

Enable passing the port mapping to damhs.py.

dam-client implements this by using the TorPortMap constant from
damlib/config.go

Diffstat:
Mcmd/dam-client/main.go | 5+++--
Mpkg/damlib/config.go | 7+++++++
Mpython/damhs.py | 34++++++++++++++++------------------
3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go @@ -10,6 +10,7 @@ import ( "log" "os" "os/exec" + "strconv" "sync" "time" @@ -28,7 +29,7 @@ func announce(dir string, vals map[string]string, privkey *rsa.PrivateKey) (bool if dir == "localhost" || dir == "127.0.0.1" { // Modify the string if we are authenticating to ourself. - dir += ":49371" + dir += ":" + strconv.Itoa(lib.DirPort) } log.Println("Announcing keypair to:", dir) @@ -116,7 +117,7 @@ func main() { // Start up the hidden service log.Println("Starting up the hidden service...") - cmd := exec.Command("damhs.py", lib.PrivKeyPath) + cmd := exec.Command("damhs.py", lib.PrivKeyPath, lib.TorPortMap) stdout, err := cmd.StdoutPipe() lib.CheckError(err) diff --git a/pkg/damlib/config.go b/pkg/damlib/config.go @@ -19,3 +19,10 @@ const WelcomeMsg = "Welcome to the DAM network!" // ProxyAddr is the address of our Tor SOCKS port. const ProxyAddr = "127.0.0.1:9050" + +// TorPortMap is a comma-separated string holding the mapping of ports +// to be opened by the Tor Hidden Service. Format is "remote:local". +const TorPortMap = "80:49371" + +// DirPort is the port where dam-dir will be listening. +const DirPort = 49371 diff --git a/python/damhs.py b/python/damhs.py @@ -2,6 +2,11 @@ # See LICENSE file for copyright and license details. """ Controller daemon running the ephemeral hidden service. + +Usage: damhs.py <path_to_private.key> <portmap> + +<portmap> is a comma-separated string of at least one of the +following element: 80:49371 (80 is the remote, 49371 is local) """ from sys import argv, stdout @@ -9,24 +14,11 @@ from time import sleep from stem.control import Controller -# PORTMAP holds the port mapping of our ports. The key is the port that -# is accessible through Tor, and the value is the port opened locally for -# Tor to use. -PORTMAP = { - 80: 49371 -} - - -def start_hs(ctl=None, ktype=None, kcont=None): +def start_hs(ctl=None, ktype=None, kcont=None, portmap=None): """ Function starting our ephemeral hidden service """ - if not ktype or not kcont: - assert False, 'No key data passed.' - if not ctl: - assert False, 'No controller passed.' - - return ctl.create_ephemeral_hidden_service(PORTMAP, key_type=ktype, + return ctl.create_ephemeral_hidden_service(portmap, key_type=ktype, key_content=kcont, await_publication=True) @@ -35,8 +27,14 @@ def main(): """ Main loop """ - controller = Controller.from_port() - controller.authenticate(password='topkek') + ctl = Controller.from_port() + ctl.authenticate(password='topkek') + + portmap = {} + ports = argv[2].split(',') + for i in ports: + tup = i.split(':') + portmap[int(tup[0])] = int(tup[1]) keyfile = argv[1] ktype = 'RSA1024' @@ -45,7 +43,7 @@ def main(): kcont = kcont.replace('-----BEGIN RSA PRIVATE KEY-----', '') kcont = kcont.replace('-----END RSA PRIVATE KEY-----', '') - service = start_hs(ctl=controller, ktype=ktype, kcont=kcont) + service = start_hs(ctl=ctl, ktype=ktype, kcont=kcont, portmap=portmap) stdout.write('Started HS at %s.onion\n' % service.service_id) stdout.flush()