Skip to content

Commit 039fd8d

Browse files
committed
fix(auth): Update Sign function signature to include Iteration context for improved HMAC signing
1 parent b8321d0 commit 039fd8d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

core/dbio/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ type APIStateAuth struct {
262262
Headers map[string]string `json:"-"` // to inject
263263
ExpiresAt int64 `json:"expires_at,omitempty"` // Unix timestamp when auth expires
264264

265-
Sign func(context.Context, *http.Request, []byte) error `json:"-"` // for AWS Sigv4
266-
Mutex *sync.Mutex `json:"-" yaml:"-"` // Mutex for auth operations
265+
Sign func(*Iteration, *http.Request, []byte) error `json:"-"` // for AWS Sigv4, HMAC
266+
Mutex *sync.Mutex `json:"-" yaml:"-"` // Mutex for auth operations
267267
}
268268

269269
var bracketRegex = regexp.MustCompile(`\{([^\{\}]+)\}`)

core/dbio/api/auth.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ func (a *AuthenticatorAWSSigV4) Authenticate(ctx context.Context, state *APIStat
816816
return g.Error(err, "could not make AWS config for authentication")
817817
}
818818

819-
ac.State.Auth.Sign = func(ctx context.Context, req *http.Request, bodyBytes []byte) error {
819+
ac.State.Auth.Sign = func(iter *Iteration, req *http.Request, bodyBytes []byte) error {
820820
// Calculate the SHA256 hash of the request body.
821821
hasher := sha256.New()
822822
hasher.Write(bodyBytes)
@@ -825,13 +825,13 @@ func (a *AuthenticatorAWSSigV4) Authenticate(ctx context.Context, state *APIStat
825825
// Create a new signer.
826826
signer := v4.NewSigner()
827827

828-
creds, err := cfg.Credentials.Retrieve(ctx)
828+
creds, err := cfg.Credentials.Retrieve(iter.context.Ctx)
829829
if err != nil {
830830
return g.Error(err, "could not retrieve AWS creds signing request")
831831
}
832832

833833
// Sign the request, which adds the 'Authorization' and other necessary headers.
834-
return signer.SignHTTP(ctx, creds, req, payloadHash, awsService, awsRegion, time.Now())
834+
return signer.SignHTTP(iter.context.Ctx, creds, req, payloadHash, awsService, awsRegion, time.Now())
835835
}
836836

837837
return
@@ -853,7 +853,7 @@ func (a *AuthenticatorHMAC) Authenticate(ctx context.Context, state *APIStateAut
853853
a.Algorithm = "sha256"
854854
}
855855

856-
state.Sign = func(ctx context.Context, req *http.Request, bodyBytes []byte) error {
856+
state.Sign = func(iter *Iteration, req *http.Request, bodyBytes []byte) error {
857857
var signature string
858858

859859
// Fixed timestamp for consistency
@@ -945,7 +945,7 @@ func (a *AuthenticatorHMAC) Authenticate(ctx context.Context, state *APIStateAut
945945
case "sha256":
946946
stringToSign := g.Rm(a.SigningString, templateMap)
947947

948-
stringToSign, err = a.conn.renderString(stringToSign)
948+
stringToSign, err = iter.renderString(stringToSign)
949949
if err != nil {
950950
return g.Error(err, "could not render string for HMAC signer")
951951
}
@@ -957,7 +957,7 @@ func (a *AuthenticatorHMAC) Authenticate(ctx context.Context, state *APIStateAut
957957
case "sha512":
958958
stringToSign := g.Rm(a.SigningString, templateMap)
959959

960-
stringToSign, err = a.conn.renderString(stringToSign)
960+
stringToSign, err = iter.renderString(stringToSign)
961961
if err != nil {
962962
return g.Error(err, "could not render string for HMAC signer")
963963
}
@@ -976,7 +976,7 @@ func (a *AuthenticatorHMAC) Authenticate(ctx context.Context, state *APIStateAut
976976
// Add headers
977977
for key, value := range a.ReqHeaders {
978978
value = g.Rm(value, templateMap)
979-
value, err = a.conn.renderString(value)
979+
value, err = iter.renderString(value)
980980
if err != nil {
981981
return g.Error(err, "could not render string for HMAC header: %s", key)
982982
}

0 commit comments

Comments
 (0)