Skip to content

Commit

Permalink
Switch from SHA-1 to SHA-384 for signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Mar 1, 2024
1 parent da266e8 commit 53058c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions transloadit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/hmac"
"crypto/sha1"
"crypto/sha512"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -104,14 +105,16 @@ func (client *Client) sign(params map[string]interface{}) (string, string, error
// Add a random nonce to make signatures unique and prevent error about
// signature reuse: https://github.com/transloadit/go-sdk/pull/35
params["nonce"] = client.random.Int()
b, err := json.Marshal(params)
contentToSign, err := json.Marshal(params)
if err != nil {
return "", "", fmt.Errorf("unable to create signature: %s", err)
}

hash := hmac.New(sha1.New, []byte(client.config.AuthSecret))
hash.Write(b)
return string(b), hex.EncodeToString(hash.Sum(nil)), nil
hash := hmac.New(sha512.New384, []byte(client.config.AuthSecret))
hash.Write(contentToSign)
signature := "sha384:" + hex.EncodeToString(hash.Sum(nil))

return string(contentToSign), signature, nil
}

func (client *Client) doRequest(req *http.Request, result interface{}) error {
Expand Down

0 comments on commit 53058c3

Please sign in to comment.