| 302 | |
| 303 | |
| 304 | def resolve_request_checksum_algorithm( |
| 305 | request, |
| 306 | operation_model, |
| 307 | params, |
| 308 | supported_algorithms=None, |
| 309 | ): |
| 310 | # If the header is already set by the customer, skip calculation |
| 311 | if has_checksum_header(request): |
| 312 | return |
| 313 | |
| 314 | checksum_context = request["context"].get("checksum", {}) |
| 315 | request_checksum_calculation = request["context"][ |
| 316 | "client_config" |
| 317 | ].request_checksum_calculation |
| 318 | http_checksum = operation_model.http_checksum |
| 319 | request_checksum_required = ( |
| 320 | operation_model.http_checksum_required |
| 321 | or http_checksum.get("requestChecksumRequired") |
| 322 | ) |
| 323 | algorithm_member = http_checksum.get("requestAlgorithmMember") |
| 324 | if algorithm_member and algorithm_member in params: |
| 325 | # If the client has opted into using flexible checksums and the |
| 326 | # request supports it, use that instead of checksum required |
| 327 | if supported_algorithms is None: |
| 328 | supported_algorithms = _SUPPORTED_CHECKSUM_ALGORITHMS |
| 329 | |
| 330 | algorithm_name = params[algorithm_member].lower() |
| 331 | if algorithm_name not in supported_algorithms: |
| 332 | raise FlexibleChecksumError( |
| 333 | error_msg=f"Unsupported checksum algorithm: {algorithm_name}" |
| 334 | ) |
| 335 | elif request_checksum_required or ( |
| 336 | algorithm_member and request_checksum_calculation == "when_supported" |
| 337 | ): |
| 338 | # Don't use a default checksum for presigned requests. |
| 339 | if request["context"].get("is_presign_request"): |
| 340 | return |
| 341 | algorithm_name = DEFAULT_CHECKSUM_ALGORITHM.lower() |
| 342 | algorithm_member_header = _get_request_algorithm_member_header( |
| 343 | operation_model, request, algorithm_member |
| 344 | ) |
| 345 | if algorithm_member_header is not None: |
| 346 | checksum_context["request_algorithm_header"] = { |
| 347 | "name": algorithm_member_header, |
| 348 | "value": DEFAULT_CHECKSUM_ALGORITHM, |
| 349 | } |
| 350 | else: |
| 351 | return |
| 352 | |
| 353 | location_type = "header" |
| 354 | if ( |
| 355 | operation_model.has_streaming_input |
| 356 | and urlparse(request["url"]).scheme == "https" |
| 357 | ): |
| 358 | if request["context"]["client_config"].signature_version != 's3': |
| 359 | # Operations with streaming input must support trailers. |
| 360 | # We only support unsigned trailer checksums currently. As this |
| 361 | # disables payload signing we'll only use trailers over TLS. |