tImplement secret encryption in ddir. - tordam - A library for peer discovery inside the Tor network (HTM) git clone https://git.parazyd.org/tordam (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit a35a59a7538832581d0f5b6ec1f4ca7e9837a7a4 (DIR) parent 83c3511e48ef77cda6298b2e98c710a421cb2b1b (HTM) 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 tthe POST response via JSON. Diffstat: M go/ddir/ddir.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) --- (DIR) diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go t@@ -18,6 +18,7 @@ type nodeStruct struct { Address string Message string Signature string + Secret string } func handlePost(rw http.ResponseWriter, request *http.Request) { t@@ -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() {