From 11006f4ef3614c83432b77c8345f845b6802be9d Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Thu, 24 Oct 2024 16:24:28 +0200 Subject: [PATCH] implement hmac generation --- act/cacheproxy/handler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/act/cacheproxy/handler.go b/act/cacheproxy/handler.go index 89234c49..69f36fff 100644 --- a/act/cacheproxy/handler.go +++ b/act/cacheproxy/handler.go @@ -1,6 +1,9 @@ package cacheproxy import ( + "crypto/hmac" + "crypto/sha256" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -35,9 +38,10 @@ type Handler struct { cacheServerPort uint16 repositoryName string + cacheKey string } -func StartHandler(repoName string, targetHost string, targetPort uint16, outboundIP string, port uint16, logger logrus.FieldLogger) (*Handler, error) { +func StartHandler(repoName string, targetHost string, targetPort uint16, outboundIP string, port uint16, cacheKey string, logger logrus.FieldLogger) (*Handler, error) { h := &Handler{} if logger == nil { @@ -49,6 +53,7 @@ func StartHandler(repoName string, targetHost string, targetPort uint16, outboun h.logger = logger h.repositoryName = repoName + h.cacheKey = h.cacheKey if outboundIP != "" { h.outboundIP = outboundIP @@ -119,6 +124,13 @@ func (h *Handler) Close() error { return retErr } +func (h *Handler) calculateMAC() string { + mac := hmac.New(sha256.New, []byte(h.cacheKey)) + mac.Write([]byte(h.repositoryName)) + macBytes := mac.Sum(nil) + return hex.EncodeToString(macBytes) +} + // GET /_apis/artifactcache/cache func (h *Handler) find(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { keys := strings.Split(r.URL.Query().Get("keys"), ",")