Skip to content

Commit d4d9692

Browse files
author
奶爸
committed
[fix]Gogs sign verify
1 parent 493e94d commit d4d9692

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

gogs/gogs.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
client "github.com/gogits/go-gogs-client"
1616
"crypto/hmac"
1717
"crypto/sha256"
18+
"encoding/hex"
1819
)
1920

2021
// Webhook instance contains all methods needed to process events
@@ -109,10 +110,14 @@ func (hook Webhook) ParsePayload(w http.ResponseWriter, r *http.Request) {
109110
mac := hmac.New(sha256.New, []byte(hook.secret))
110111
mac.Write(payload)
111112

112-
expectedMAC := mac.Sum(nil)
113+
expectedMAC := hex.EncodeToString(mac.Sum(nil))
113114

114-
if !hmac.Equal([]byte(signature), expectedMAC) {
115+
if !hmac.Equal([]byte(signature), []byte(expectedMAC)) {
115116
webhooks.DefaultLog.Error("HMAC verification failed")
117+
webhooks.DefaultLog.Debug("LocalHMAC:" + expectedMAC)
118+
webhooks.DefaultLog.Debug("RemoteHMAC:" + signature)
119+
webhooks.DefaultLog.Debug("Secret:" + hook.secret)
120+
webhooks.DefaultLog.Debug(string(payload))
116121
http.Error(w, "403 Forbidden - HMAC verification failed", http.StatusForbidden)
117122
return
118123
}

0 commit comments

Comments
 (0)