tordam

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

commit 2e02e951df8b4bb89560d1fdc0116d9231290d63
parent 4f05f88997bce535ef0cc782633172330ac16c11
Author: parazyd <parazyd@dyne.org>
Date:   Sun, 10 Dec 2017 13:50:27 +0100

More robustness in dam-dir

Diffstat:
Mcmd/dam-client/main.go | 6+++---
Mcmd/dam-dir/main.go | 32+++++++++++++++++++++++++++-----
Mpkg/lib/helpers.go | 2+-
3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go @@ -38,9 +38,9 @@ func announce(dir string, vals map[string]string, privkey *rsa.PrivateKey) (bool return false, err } - if dir == "localhost" { + if dir == "localhost" || dir == "127.0.0.1" { // Modify the string if we are authenticating to ourself. - dir = "localhost:49371" + dir += ":49371" } log.Println("Announcing keypair to:", dir) @@ -180,7 +180,7 @@ func main() { var ann = 0 // Track of how many successful authentications - dirs := []string{"qvhgzxjkdchj2jl5.onion", "localhost"} + dirs := []string{"3mb6b3exknytbqdg.onion", "localhost"} var wg sync.WaitGroup for _, i := range dirs { diff --git a/cmd/dam-dir/main.go b/cmd/dam-dir/main.go @@ -45,7 +45,7 @@ type nodeStruct struct { } func startRedis() { - log.Println("Staring up redis-server...") + log.Println("Starting up redis-server...") cmd := exec.Command("redis-server", "/usr/local/share/tor-dam/redis.conf") err := cmd.Start() lib.CheckError(err) @@ -57,14 +57,24 @@ func startRedis() { } func handlePost(rw http.ResponseWriter, request *http.Request) { + if request.Method != "POST" || request.Header["Content-Type"][0] != "application/json" { + return + } + decoder := json.NewDecoder(request.Body) var n nodeStruct err := decoder.Decode(&n) - lib.CheckError(err) + if err != nil { + log.Println("Failed decoding request:", err) + return + } decSig, err := base64.StdEncoding.DecodeString(n.Signature) - lib.CheckError(err) + if err != nil { + log.Println("Failed decoding signature:", err) + return + } req := map[string]string{ "nodetype": n.Nodetype, @@ -86,7 +96,14 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { pkey, valid := lib.ValidateReq(req, pub) if !(valid) && pkey == nil { - log.Fatalln("Request is not valid.") + ret := map[string]string{ + "secret": "Request is not valid.", + } + jsonVal, err := json.Marshal(ret) + lib.CheckError(err) + rw.Header().Set("Content-Type", "application/json") + rw.Write(jsonVal) + return } else if !(valid) && pkey != nil { // We couldn't get a descriptor. ret := map[string]string{ @@ -213,6 +230,11 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { } } +func handleElse(rw http.ResponseWriter, request *http.Request) { + // noop for anything that isn't /announce. + return +} + func main() { var wg sync.WaitGroup @@ -220,7 +242,6 @@ func main() { err := os.Mkdir(Cwd, 0700) lib.CheckError(err) } - log.Println("Chdir to", Cwd) err := os.Chdir(Cwd) lib.CheckError(err) @@ -230,6 +251,7 @@ func main() { } http.HandleFunc("/announce", handlePost) + http.HandleFunc("/", handleElse) wg.Add(1) go http.ListenAndServe(ListenAddress, nil) diff --git a/pkg/lib/helpers.go b/pkg/lib/helpers.go @@ -36,7 +36,7 @@ func FetchHSPubkey(addr string) string { log.Println("Fetching pubkey for:", addr) - cmd := exec.Command("dirauth.py", addr) + cmd := exec.Command("damauth.py", addr) cmd.Stdout = &outb cmd.Stderr = &errb err := cmd.Start()