@@ -17,8 +17,8 @@ package hooks
1717import (
1818 "bytes"
1919 "context"
20- "crypto/md5"
2120 "crypto/rand"
21+ "crypto/sha256"
2222 "encoding/hex"
2323 "math/big"
2424 "strings"
@@ -37,7 +37,7 @@ type HookExecutorMessageBoundaryProtocol struct {
3737}
3838
3939// generateBoundary is a function for creating boundaries that can be mocked
40- var generateBoundary = generateMD5FromRandomString
40+ var generateBoundary = generateRandomBoundary
4141
4242// Execute processes the data received by the SDK.
4343func (e * HookExecutorMessageBoundaryProtocol ) Execute (ctx context.Context , opts HookExecOpts ) (string , error ) {
@@ -100,24 +100,25 @@ func (e *HookExecutorMessageBoundaryProtocol) Execute(ctx context.Context, opts
100100 return buffout .String (), nil
101101}
102102
103- // generateMD5FromRandomString returns the MD5 hash of a randomized string.
103+ // generateRandomBoundary returns the SHA-256 hash of a randomized string for use
104+ // as a message boundary between the CLI and SDK.
104105//
105106// Reference: https://gist.github.com/dopey/c69559607800d2f2f90b1b1ed4e550fb
106- func generateMD5FromRandomString () string {
107+ func generateRandomBoundary () string {
107108 const alphanumericCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
108109 const length = 10
109110
110- randomBytes := make ([]byte , 0 )
111+ randomBytes := make ([]byte , 0 , length )
111112 for range length {
112113 num , err := rand .Int (rand .Reader , big .NewInt (int64 (len (alphanumericCharacters ))))
113114 if err != nil {
114- return "3561f3a3c5576e2ce0dc0d1e268bb9b2" // Return default value to continue execution
115+ // Return default value to continue execution
116+ return "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2"
115117 }
116118 randomBytes = append (randomBytes , alphanumericCharacters [num .Int64 ()])
117119 }
118120
119- MD5Hash := md5 .New ()
120- s := MD5Hash .Sum (randomBytes )
121-
122- return hex .EncodeToString (s )
121+ hash := sha256 .New ()
122+ hash .Write (randomBytes )
123+ return hex .EncodeToString (hash .Sum (nil ))
123124}
0 commit comments