Ejemplo n.º 1
0
func setChecksumError(r *aws.Request, format string, args ...interface{}) {
	r.Retryable = true
	r.Error = &aws.APIError{
		StatusCode: r.HTTPResponse.StatusCode,
		Code:       "InvalidChecksum",
		Message:    fmt.Sprintf(format, args...),
	}
}
Ejemplo n.º 2
0
func validateCRC32(r *aws.Request) {
	if r.Error != nil {
		return // already have an error, no need to verify CRC
	}

	// Checksum validation is off, skip
	if r.Service.Config.DisableComputeChecksums {
		return
	}

	// Try to get CRC from response
	header := r.HTTPResponse.Header.Get("X-Amz-Crc32")
	if header == "" {
		return // No header, skip
	}

	expected, err := strconv.ParseUint(header, 10, 32)
	if err != nil {
		return // Could not determine CRC value, skip
	}

	buf, err := drainBody(r.HTTPResponse.Body)
	if err != nil { // failed to read the response body, skip
		return
	}

	// Reset body for subsequent reads
	r.HTTPResponse.Body = ioutil.NopCloser(bytes.NewReader(buf.Bytes()))

	// Compute the CRC checksum
	crc := crc32.ChecksumIEEE(buf.Bytes())

	if crc != uint32(expected) {
		// CRC does not match, set a retryable error
		r.Retryable = true
		r.Error = &aws.APIError{
			Code:    "CRC32CheckFailed",
			Message: "CRC32 integrity check failed",
		}
	}
}