Skip to content

[Bug] - The XAmzContentSHA256Mismatch error should include ClientComputedContentSHA256 and S3ComputedContentSHA256. #2043

@niksis02

Description

@niksis02

Describe the bug
The XAmzContentSHA256Mismatch error should include ClientComputedContentSHA256 and S3ComputedContentSHA256 in the xml response.

To Reproduce

package main

import (
	"bytes"
	"context"
	"fmt"
	"io"
	"log"
	"net/http"
	"time"

	"github.com/aws/aws-sdk-go-v2/aws"
	v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
)

const (
	accessKeyId = "user"
	secretAccessKey = "pass"
)

func main(){
	signer := v4.NewSigner()
	req, err := http.NewRequest(http.MethodPut, "http://127.0.0.1:7070/test/obj", bytes.NewReader([]byte("body")))
	if err != nil {
		log.Fatalf("failed to create the request: %v", err)
	}

	req.Header.Add("x-amz-content-sha256", "1ff263b5c58d2112708bf6102036e014c4c7acea463704226ebc8026fb3ffd00")

	err = signer.SignHTTP(context.Background(), aws.Credentials{
		AccessKeyID:    accessKeyId,
		SecretAccessKey: secretAccessKey,
	}, req, "1ff263b5c58d2112708bf6102036e014c4c7acea463704226ebc8026fb3ffd00","s3", "us-east-1", time.Now())
	if err != nil {
		log.Fatalf("failed to sign the request: %v", err)
	}

	httpclient := &http.Client{}
	resp, err := httpclient.Do(req)
	if err != nil {
		log.Fatalf("failed to send the request: %v", err)
	}

	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("failed to read the request body: %v", err)
	}

	fmt.Println(string(body))
}

Expected behavior
The above script should print out something like:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>XAmzContentSHA256Mismatch</Code><Message>The provided 'x-amz-content-sha256' header does not match what was computed.</Message><ClientComputedContentSHA256>1ff263b5c58d2112708bf6102036e014c4c7acea463704226ebc8026fb3ffd00</ClientComputedContentSHA256><S3ComputedContentSHA256>230d8358dc8e8890b4c58deeb62912ee2f20357ae92a5cc861b98e68fe31acb5</S3ComputedContentSHA256><RequestId>WCF351Q2KFWS76WQ</RequestId><HostId>OM+sTDVxxjiPn3DDP/ifznClig51o56Shby96nhbj28GEJSKiCkEJECzk12h/TP8zTnbvzUEpoLFKDaUWay/DjRZrybdUolUxQg0+BPFUMQ=</HostId></Error>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions