Sign responses as well

This commit is contained in:
Ian Gulliver
2023-06-03 21:12:48 -07:00
parent 4da068ed5c
commit 8c8133ff52
2 changed files with 31 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ import (
"time"
"github.com/dchest/uniuri"
"github.com/samber/lo"
)
// TODO: Ensure promotion takes longer than demotion
@@ -141,12 +142,12 @@ func (c *Candidate) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
js = lo.Must(json.Marshal(c.resp))
w.Header().Set("Content-Type", "application/json")
// TODO: Sign responses
w.Header().Set("Signature", mac(js, c.signingKey))
enc := json.NewEncoder(w)
err = enc.Encode(c.resp)
_, err = w.Write(js)
if err != nil {
http.Error(
w,