tordam

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

commit a35a59a7538832581d0f5b6ec1f4ca7e9837a7a4
parent 83c3511e48ef77cda6298b2e98c710a421cb2b1b
Author: parazyd <parazyd@dyne.org>
Date:   Thu,  7 Dec 2017 20:59:16 +0100

Implement secret encryption in ddir.

This expands the handshake protocol by encrypting a random string
with the requester's public key and returning it to them through
the POST response via JSON.

Diffstat:
Mgo/ddir/ddir.go | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go @@ -18,6 +18,7 @@ type nodeStruct struct { Address string Message string Signature string + Secret string } func handlePost(rw http.ResponseWriter, request *http.Request) { @@ -32,12 +33,35 @@ func handlePost(rw http.ResponseWriter, request *http.Request) { "address": n.Address, "message": n.Message, "signature": n.Signature, + "secret": n.Secret, } - if lib.ValidateReq(req) != true { + pkey, valid := lib.ValidateReq(req) + if !(valid) { log.Fatalln("Request is not valid.") } + pubkey, err := lib.ParsePubkey(pkey) + lib.CheckError(err) + + if len(req["secret"]) != 64 { + randString, err := lib.GenRandomASCII(64) + lib.CheckError(err) + + secret, err := lib.EncryptMsg([]byte(randString), pubkey) + lib.CheckError(err) + + ret := map[string]string{ + "secret": string(secret), + } + 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() {