commit b6ba0392a41bb6f02bb4986312b3ca569d6de11b
parent e2ed217643e34fff61eeb660a64c248e7689e8f4
Author: parazyd <parazyd@dyne.org>
Date: Thu, 7 Dec 2017 22:03:05 +0100
Handle signature verification in ddir.go
This commit will decode the base64 signature to allow it to be verified
properly.
We now also implement a 500 HTTP return code with a message if we were
unable to fetch the hidden service descriptor. This is to be handled by
dam.go
Diffstat:
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go
@@ -3,6 +3,7 @@ package main
// See LICENSE file for copyright and license details.
import (
+ "encoding/base64"
"encoding/json"
"log"
"net/http"
@@ -28,17 +29,32 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
err := decoder.Decode(&n)
lib.CheckError(err)
+ log.Println(n.Signature)
+ decSig, err := base64.StdEncoding.DecodeString(n.Signature)
+ lib.CheckError(err)
+
req := map[string]string{
"nodetype": n.Nodetype,
"address": n.Address,
"message": n.Message,
- "signature": n.Signature,
+ "signature": string(decSig),
"secret": n.Secret,
}
pkey, valid := lib.ValidateReq(req)
- if !(valid) {
+ if !(valid) && pkey == nil {
log.Fatalln("Request is not valid.")
+ } else if !(valid) && pkey != nil {
+ // We couldn't get a descriptor.
+ ret := map[string]string{
+ "secret": string(pkey),
+ }
+ jsonVal, err := json.Marshal(ret)
+ lib.CheckError(err)
+ rw.Header().Set("Content-Type", "application/json")
+ rw.WriteHeader(500)
+ rw.Write(jsonVal)
+ return
}
pubkey, err := lib.ParsePubkey(pkey)