Skip to content

Commit 0bd8a35

Browse files
Merge pull request #340 from mritunjaysharma394/hash256
use sha256 sum for idempotency token
2 parents 66583e0 + d9461d2 commit 0bd8a35

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/aws/pca.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package aws
1919
import (
2020
"bytes"
2121
"context"
22-
"crypto/md5"
22+
"crypto/sha256"
2323
"encoding/pem"
2424
"fmt"
2525
"strings"
@@ -91,8 +91,9 @@ func NewProvisioner(config aws.Config, arn string) (p *PCAProvisioner) {
9191
// idempotencyToken is limited to 64 ASCII characters, so make a fixed length hash.
9292
// @see: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html
9393
func idempotencyToken(cr *cmapi.CertificateRequest) string {
94-
token := []byte(cr.ObjectMeta.Namespace + "/" + cr.ObjectMeta.Name)
95-
return fmt.Sprintf("%x", md5.Sum(token))
94+
token := []byte(cr.ObjectMeta.Namespace + "/" + cr.ObjectMeta.Name)
95+
fullHash := fmt.Sprintf("%x", sha256.Sum256(token))
96+
return fullHash[:36] // Truncate to 36 characters
9697
}
9798

9899
// Sign takes a certificate request and signs it using PCA

pkg/aws/pca_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,9 @@ func TestIdempotencyToken(t *testing.T) {
325325
Namespace: "fake-namespace",
326326
},
327327
},
328-
expected: "f331cbfd0cc6569f58c12c3dbb238a4f",
328+
expected: "63e69830270b95081942a3d85034fdc97bb9", // Truncated SHA-256 hash
329329
},
330+
330331
}
331332

332333
for name, tc := range tests {

0 commit comments

Comments
 (0)