Skip to content

Commit c81eae9

Browse files
committed
use fips-compliant sha256 hash
On-behalf-of: SAP <[email protected]> Signed-off-by: Simon Bein <[email protected]>
1 parent c9f5d61 commit c81eae9

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/controller/utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package controller
22

33
import (
4-
"crypto/sha1"
4+
"crypto/sha256"
55
"encoding/base32"
66
"reflect"
77
"strings"
@@ -10,15 +10,16 @@ import (
1010
)
1111

1212
const (
13-
maxLength int = 63
14-
Base32EncodeStdLowerCase = "abcdefghijklmnopqrstuvwxyz234567"
13+
Base32EncodeStdLowerCase = "abcdefghijklmnopqrstuvwxyz234567"
1514
)
1615

17-
// K8sNameHash takes any number of string arguments and computes a hash out of it, which is then base32-encoded to be a valid k8s resource name.
16+
// K8sNameHash takes any number of string arguments and computes a hash out of it, which is then base32-encoded to be a valid DNS1123Subdomain k8s resource name
1817
// The arguments are joined with '/' before being hashed.
1918
func K8sNameHash(ids ...string) string {
2019
name := strings.Join(ids, "/")
21-
h := sha1.New()
20+
// since we are not worried about length-extension attacks (in fact we are not even using hashing for
21+
// any security purposes), use sha2 for better performance compared to sha3
22+
h := sha256.New()
2223
_, _ = h.Write([]byte(name))
2324
// we need base32 encoding as some base64 (even url safe base64) characters are not supported by k8s
2425
// see https://kubernetes.io/docs/concepts/overview/working-with-objects/names/

pkg/controller/utils_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ func TestK8sNameHash(t *testing.T) {
1414
}{
1515
{
1616
[]string{"test1"},
17-
"wrckybtbh7enmn4vx2nnbpvpkuarsnvm",
17+
"dnhq5gcrs4mzrzzsa6cujsllg3b5ahhn67fkgmrvtvxr3a2woaka",
1818
},
1919
{
2020
// check that the same string produces the same hash
2121
[]string{"test1"},
22-
"wrckybtbh7enmn4vx2nnbpvpkuarsnvm",
22+
"dnhq5gcrs4mzrzzsa6cujsllg3b5ahhn67fkgmrvtvxr3a2woaka",
2323
},
2424
{
2525
[]string{"bla"},
26-
"76tha37scj5hjglta4tvn6b4kmxeh3ic",
26+
"jxz4h5upzsb3e7u5ileqimnhesm7c6dvzanftg2wnsmitoljm4bq",
2727
},
2828
{
2929
[]string{"some other test", "this is a very, very long string"},
30-
"fkkzqgh27xym6tqbswyql3wy4atsf6pt",
30+
"rjphpfjbmwn6qqydv6xhtmj3kxrlzepn2tpwy4okw2ypoc3nlffq",
3131
},
3232
}
3333

0 commit comments

Comments
 (0)