Skip to content

Commit a246ebb

Browse files
committed
Convert to SHA256 signatures for the invoke command
This is a convenience option for invoking functions along with a signature, if a function accepts one. They should all have been moved to sha256 now if they were even using it Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 2bf121e commit a246ebb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

commands/invoke.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package commands
55

66
import (
77
"bytes"
8+
"crypto"
89
"encoding/hex"
910
"fmt"
1011
"io"
@@ -14,7 +15,7 @@ import (
1415
"runtime"
1516
"strings"
1617

17-
"github.com/alexellis/hmac"
18+
"github.com/alexellis/hmac/v2"
1819
"github.com/openfaas/faas-cli/stack"
1920
"github.com/openfaas/faas-cli/version"
2021
"github.com/spf13/cobra"
@@ -205,10 +206,10 @@ func runInvoke(cmd *cobra.Command, args []string) error {
205206
}
206207

207208
func generateSignature(message []byte, key string) string {
208-
hash := hmac.Sign(message, []byte(key))
209+
hash := hmac.Sign(message, []byte(key), crypto.SHA256.New)
209210
signature := hex.EncodeToString(hash)
210211

211-
return fmt.Sprintf(`%s=%s`, "sha1", string(signature[:]))
212+
return fmt.Sprintf(`%s=%s`, "sha256", string(signature[:]))
212213
}
213214

214215
func missingSignFlag(header string, key string) bool {

commands/invoke_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ func Test_generateHeader(t *testing.T) {
9898
name: "Empty key",
9999
message: []byte("This is a message"),
100100
key: "",
101-
want: "sha1=cdefd604e685e5c8b31fbcf6621a6e8282770dfe",
101+
want: "sha256=7fb67a61acd7a9fa2541bbde51cef1bd4086a5a3acec0a0c821b40e06e824cfc",
102102
},
103103
{
104104
name: "Key with empty message",
105105
message: []byte(""),
106106
key: "KeySet",
107-
want: "sha1=33dcd94ffaf13fce58615585c030c1a39d100b3c",
107+
want: "sha256=51846d8900847a40a129743c98742c83a56c3cbc4f5aec188d7eb2de629d11df",
108108
},
109109
{
110110
name: "Empty key and message",
111111
message: []byte(""),
112112
key: "",
113-
want: "sha1=fbdb1d1b18aa6c08324b7d64b71fb76370690e1d",
113+
want: "sha256=b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad",
114114
},
115115
}
116116
for _, test := range tests {

0 commit comments

Comments
 (0)