Hmac fix, maybe.
This commit is contained in:
@@ -88,13 +88,27 @@ func SignPayload(data interface{}) string {
|
|||||||
if psk == "" {
|
if psk == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes, err := json.Marshal(data)
|
// First marshal the struct to JSON
|
||||||
|
raw, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Round-trip through a generic interface so json.Marshal
|
||||||
|
// will sort map keys alphabetically, matching the Python
|
||||||
|
// manager's json.dumps(sort_keys=True) canonicalization.
|
||||||
|
var canonical interface{}
|
||||||
|
if err := json.Unmarshal(raw, &canonical); err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
sorted, err := json.Marshal(canonical)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
h := hmac.New(sha256.New, []byte(psk))
|
h := hmac.New(sha256.New, []byte(psk))
|
||||||
h.Write(bytes)
|
h.Write(sorted)
|
||||||
return hex.EncodeToString(h.Sum(nil))
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user