commit 98efaf065bf2a9f5e08156b268d41b93bff3739a
parent eaba10a6c12470b30090d0c9e39e68728316f72d
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:
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/go/dam/dam.go b/go/dam/dam.go
@@ -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)
+ }
}
}
diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go
@@ -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)
@@ -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() {