URI:
       tFinalize the second handshake when sending the decrypted secret. - tordam - A library for peer discovery inside the Tor network
  HTML git clone https://git.parazyd.org/tordam
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 98efaf065bf2a9f5e08156b268d41b93bff3739a
   DIR parent eaba10a6c12470b30090d0c9e39e68728316f72d
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Thu,  7 Dec 2017 23:22:33 +0100
       
       Finalize the second handshake when sending the decrypted secret.
       
       Currently it doesn't validate. This will be implemented afterwards,
       using some database backend.
       
       Diffstat:
         M go/dam/dam.go                       |      20 +++++++++++++++++++-
         M go/ddir/ddir.go                     |      27 ++++++++++++++++++++++++++-
       
       2 files changed, 45 insertions(+), 2 deletions(-)
       ---
   DIR diff --git a/go/dam/dam.go b/go/dam/dam.go
       t@@ -78,6 +78,24 @@ func main() {
                        decrypted, err := lib.DecryptMsg([]byte(decodedSecret), key)
                        lib.CheckError(err)
        
       -                log.Println(string(decrypted))
       +                decryptedEncode := base64.StdEncoding.EncodeToString(decrypted)
       +
       +                vals["secret"] = decryptedEncode
       +                jsonVal, err := json.Marshal(vals)
       +                lib.CheckError(err)
       +
       +                log.Println("Sending back decrypted secret.")
       +                resp = lib.HTTPPost("http://localhost:8080/announce", jsonVal)
       +                decoder = json.NewDecoder(resp.Body)
       +                err = decoder.Decode(&m)
       +                lib.CheckError(err)
       +
       +                if resp.StatusCode == 200 {
       +                        log.Println("Successfully authenticated!")
       +                        log.Println("Server replied:", m.Secret)
       +                } else {
       +                        log.Println("Unsuccessful reply from directory.")
       +                        log.Fatalln("Server replied:", m.Secret)
       +                }
                }
        }
   DIR diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go
       t@@ -59,7 +59,8 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
                pubkey, err := lib.ParsePubkey(pkey)
                lib.CheckError(err)
        
       -        if len(req["secret"]) != 64 {
       +        if len(req["secret"]) != 88 {
       +                // Client did not send a decrypted secret.
                        randString, err := lib.GenRandomASCII(64)
                        lib.CheckError(err)
        
       t@@ -81,6 +82,30 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
                        rw.Write(jsonVal)
                        return
                }
       +
       +        if len(req["secret"]) == 88 {
       +                // Client sent a decrypted secret.
       +                decodedSec, err := base64.StdEncoding.DecodeString(req["secret"])
       +                lib.CheckError(err)
       +
       +                // TODO: validate against state
       +                var correct = true
       +
       +                log.Println(string(decodedSec))
       +
       +                if correct {
       +                        ret := map[string]string{
       +                                "secret": "Welcome to the DECODE network!",
       +                        }
       +                        jsonVal, err := json.Marshal(ret)
       +                        lib.CheckError(err)
       +
       +                        rw.Header().Set("Content-Type", "application/json")
       +                        rw.WriteHeader(http.StatusOK)
       +                        rw.Write(jsonVal)
       +                        return
       +                }
       +        }
        }
        
        func main() {