mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
Return ErrContentSHA256Mismatch when sha256sum is invalid (#5188)
This commit is contained in:
parent
67f66c40c1
commit
2a0a62b78d
@ -289,7 +289,7 @@ func doesPresignedSignatureMatch(hashedPayload string, r *http.Request, region s
|
|||||||
/// Verify finally if signature is same.
|
/// Verify finally if signature is same.
|
||||||
|
|
||||||
// Get canonical request.
|
// Get canonical request.
|
||||||
presignedCanonicalReq := getCanonicalRequest(extractedSignedHeaders, unsignedPayload, encodedQuery, req.URL.Path, req.Method)
|
presignedCanonicalReq := getCanonicalRequest(extractedSignedHeaders, hashedPayload, encodedQuery, req.URL.Path, req.Method)
|
||||||
|
|
||||||
// Get string to sign from canonical request.
|
// Get string to sign from canonical request.
|
||||||
presignedStringToSign := getStringToSign(presignedCanonicalReq, t, pSignValues.Credential.getScope())
|
presignedStringToSign := getStringToSign(presignedCanonicalReq, t, pSignValues.Credential.getScope())
|
||||||
|
@ -26,6 +26,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var errNestedReader = errors.New("Nesting of Reader detected, not allowed")
|
||||||
|
|
||||||
// Reader writes what it reads from an io.Reader to an MD5 and SHA256 hash.Hash.
|
// Reader writes what it reads from an io.Reader to an MD5 and SHA256 hash.Hash.
|
||||||
// Reader verifies that the content of the io.Reader matches the expected checksums.
|
// Reader verifies that the content of the io.Reader matches the expected checksums.
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
@ -40,17 +42,17 @@ type Reader struct {
|
|||||||
// SHA256 sum (if set) of the provided io.Reader at EOF.
|
// SHA256 sum (if set) of the provided io.Reader at EOF.
|
||||||
func NewReader(src io.Reader, size int64, md5Hex, sha256Hex string) (*Reader, error) {
|
func NewReader(src io.Reader, size int64, md5Hex, sha256Hex string) (*Reader, error) {
|
||||||
if _, ok := src.(*Reader); ok {
|
if _, ok := src.(*Reader); ok {
|
||||||
return nil, errors.New("Nesting of Reader detected, not allowed")
|
return nil, errNestedReader
|
||||||
}
|
}
|
||||||
|
|
||||||
sha256sum, err := hex.DecodeString(sha256Hex)
|
sha256sum, err := hex.DecodeString(sha256Hex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, SHA256Mismatch{}
|
||||||
}
|
}
|
||||||
|
|
||||||
md5sum, err := hex.DecodeString(md5Hex)
|
md5sum, err := hex.DecodeString(md5Hex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, BadDigest{}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sha256Hash hash.Hash
|
var sha256Hash hash.Hash
|
||||||
|
@ -114,26 +114,30 @@ func TestHashReaderInvalidArguments(t *testing.T) {
|
|||||||
size int64
|
size int64
|
||||||
md5hex, sha256hex string
|
md5hex, sha256hex string
|
||||||
success bool
|
success bool
|
||||||
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
// Invalid md5sum NewReader() will fail.
|
// Invalid md5sum NewReader() will fail.
|
||||||
{
|
{
|
||||||
src: bytes.NewReader([]byte("abcd")),
|
src: bytes.NewReader([]byte("abcd")),
|
||||||
size: 4,
|
size: 4,
|
||||||
md5hex: "invalid-md5",
|
md5hex: "invalid-md5",
|
||||||
success: false,
|
success: false,
|
||||||
|
expectedErr: BadDigest{},
|
||||||
},
|
},
|
||||||
// Invalid sha256 NewReader() will fail.
|
// Invalid sha256 NewReader() will fail.
|
||||||
{
|
{
|
||||||
src: bytes.NewReader([]byte("abcd")),
|
src: bytes.NewReader([]byte("abcd")),
|
||||||
size: 4,
|
size: 4,
|
||||||
sha256hex: "invalid-sha256",
|
sha256hex: "invalid-sha256",
|
||||||
success: false,
|
success: false,
|
||||||
|
expectedErr: SHA256Mismatch{},
|
||||||
},
|
},
|
||||||
// Nested hash reader NewReader() will fail.
|
// Nested hash reader NewReader() will fail.
|
||||||
{
|
{
|
||||||
src: &Reader{src: bytes.NewReader([]byte("abcd"))},
|
src: &Reader{src: bytes.NewReader([]byte("abcd"))},
|
||||||
size: 4,
|
size: 4,
|
||||||
success: false,
|
success: false,
|
||||||
|
expectedErr: errNestedReader,
|
||||||
},
|
},
|
||||||
// Expected inputs, NewReader() will succeed.
|
// Expected inputs, NewReader() will succeed.
|
||||||
{
|
{
|
||||||
@ -151,5 +155,8 @@ func TestHashReaderInvalidArguments(t *testing.T) {
|
|||||||
if err == nil && !testCase.success {
|
if err == nil && !testCase.success {
|
||||||
t.Errorf("Test %d: Expected error, but got success", i+1)
|
t.Errorf("Test %d: Expected error, but got success", i+1)
|
||||||
}
|
}
|
||||||
|
if err != testCase.expectedErr {
|
||||||
|
t.Errorf("Test %d: Expected error %v, but got %v", i+1, testCase.expectedErr, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user