Skip to content

Commit 373c4f8

Browse files
committed
Use sha3 checksum in snapshot-links API request
Signed-off-by: Richard Wall <[email protected]>
1 parent 699a653 commit 373c4f8

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

pkg/internal/cyberark/dataupload/dataupload.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dataupload
33
import (
44
"bytes"
55
"context"
6-
"crypto/sha256"
6+
"crypto/sha3"
77
"crypto/x509"
88
"encoding/hex"
99
"encoding/json"
@@ -64,7 +64,7 @@ func (c *CyberArkClient) PostDataReadingsWithOptions(ctx context.Context, payloa
6464
}
6565

6666
encodedBody := &bytes.Buffer{}
67-
checksum := sha256.New()
67+
checksum := sha3.New256()
6868
if err := json.NewEncoder(io.MultiWriter(encodedBody, checksum)).Encode(payload); err != nil {
6969
return err
7070
}
@@ -107,7 +107,7 @@ func (c *CyberArkClient) retrievePresignedUploadURL(ctx context.Context, checksu
107107

108108
request := struct {
109109
ClusterID string `json:"cluster_id"`
110-
Checksum string `json:"checksum_sha256"`
110+
Checksum string `json:"checksum_sha3"`
111111
AgentVersion string `json:"agent_version"`
112112
}{
113113
ClusterID: opts.ClusterName,

pkg/internal/cyberark/dataupload/mock.go

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

33
import (
4-
"crypto/sha256"
4+
"crypto/sha3"
55
"encoding/hex"
66
"encoding/json"
77
"fmt"
@@ -73,19 +73,15 @@ func (mds *mockDataUploadServer) handlePresignedUpload(w http.ResponseWriter, r
7373
return
7474
}
7575

76-
body, err := io.ReadAll(r.Body)
77-
if err != nil {
78-
http.Error(w, "failed to read post body", http.StatusInternalServerError)
79-
return
80-
}
81-
76+
decoder := json.NewDecoder(r.Body)
8277
var req struct {
8378
ClusterID string `json:"cluster_id"`
84-
Checksum string `json:"checksum_sha256"`
79+
Checksum string `json:"checksum_sha3"`
8580
AgentVersion string `json:"agent_version"`
8681
}
87-
if err := json.Unmarshal(body, &req); err != nil {
88-
http.Error(w, "failed to unmarshal post body", http.StatusInternalServerError)
82+
decoder.DisallowUnknownFields()
83+
if err := decoder.Decode(&req); err != nil {
84+
http.Error(w, `{"error": "Invalid request format"}`, http.StatusBadRequest)
8985
return
9086
}
9187

@@ -141,7 +137,7 @@ func (mds *mockDataUploadServer) handleUpload(w http.ResponseWriter, r *http.Req
141137
return
142138
}
143139

144-
checksum := sha256.New()
140+
checksum := sha3.New256()
145141
_, _ = io.Copy(checksum, r.Body)
146142

147143
if r.URL.Query().Get("checksum") != hex.EncodeToString(checksum.Sum(nil)) {

0 commit comments

Comments
 (0)