Also promote "signature mismatch" from warning to error.
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
+ "encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
mac.Write(payload)
signatureWant := mac.Sum(nil)
+ if !hmac.Equal(signatureGot, signatureWant) {
+ log.Debugf(ctx, "CheckSignature(): got %q, want %q",
+ hex.EncodeToString(signatureGot),
+ hex.EncodeToString(signatureWant))
+ }
+
return hmac.Equal(signatureGot, signatureWant)
}
// Fitbit recommendation: "If signature verification fails, you should
// respond with a 404"
if !fitbit.CheckSignature(ctx, data, r.Header.Get("X-Fitbit-Signature")) {
- log.Warningf(ctx, "signature mismatch")
+ log.Errorf(ctx, "signature mismatch")
w.WriteHeader(http.StatusNotFound)
return nil
}