mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-12 00:24:45 +00:00
Apply gofmt
This commit is contained in:
parent
48061f1508
commit
8d260c6a7e
3 changed files with 89 additions and 89 deletions
42
hook/hook.go
42
hook/hook.go
|
@ -11,8 +11,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"os"
|
"os"
|
||||||
|
@ -131,30 +131,30 @@ func CheckPayloadSignature256(payload []byte, secret string, signature string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckScalrSignature(headers map[string]interface{}, body []byte, signingKey string, checkDate bool) (bool, error) {
|
func CheckScalrSignature(headers map[string]interface{}, body []byte, signingKey string, checkDate bool) (bool, error) {
|
||||||
// Check for the signature and date headers
|
// Check for the signature and date headers
|
||||||
if _, ok := headers["X-Signature"]; !ok {
|
if _, ok := headers["X-Signature"]; !ok {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if _, ok := headers["Date"]; !ok {
|
if _, ok := headers["Date"]; !ok {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
providedSignature := headers["X-Signature"].(string)
|
providedSignature := headers["X-Signature"].(string)
|
||||||
dateHeader := headers["Date"].(string)
|
dateHeader := headers["Date"].(string)
|
||||||
mac := hmac.New(sha1.New, []byte(signingKey))
|
mac := hmac.New(sha1.New, []byte(signingKey))
|
||||||
mac.Write(body)
|
mac.Write(body)
|
||||||
mac.Write([]byte(dateHeader))
|
mac.Write([]byte(dateHeader))
|
||||||
expectedSignature := hex.EncodeToString(mac.Sum(nil))
|
expectedSignature := hex.EncodeToString(mac.Sum(nil))
|
||||||
|
|
||||||
if !hmac.Equal([]byte(providedSignature), []byte(expectedSignature)) {
|
if !hmac.Equal([]byte(providedSignature), []byte(expectedSignature)) {
|
||||||
return false, &SignatureError{providedSignature}
|
return false, &SignatureError{providedSignature}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !checkDate {
|
if !checkDate {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
// Example format: Fri 08 Sep 2017 11:24:32 UTC
|
// Example format: Fri 08 Sep 2017 11:24:32 UTC
|
||||||
date, err := time.Parse("Mon 02 Jan 2006 15:04:05 MST", dateHeader)
|
date, err := time.Parse("Mon 02 Jan 2006 15:04:05 MST", dateHeader)
|
||||||
//date, err := time.Parse(time.RFC1123, dateHeader)
|
//date, err := time.Parse(time.RFC1123, dateHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func CheckScalrSignature(headers map[string]interface{}, body []byte, signingKey
|
||||||
return false, &SignatureError{"outdated"}
|
return false, &SignatureError{"outdated"}
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckIPWhitelist makes sure the provided remote address (of the form IP:port) falls within the provided IP range
|
// CheckIPWhitelist makes sure the provided remote address (of the form IP:port) falls within the provided IP range
|
||||||
// (in CIDR form or a single IP address).
|
// (in CIDR form or a single IP address).
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue