4040from localstack .services .s3 .constants import (
4141 DEFAULT_PRE_SIGNED_ACCESS_KEY_ID ,
4242 DEFAULT_PRE_SIGNED_SECRET_ACCESS_KEY ,
43+ S3_HOST_ID ,
4344 SIGNATURE_V2_PARAMS ,
4445 SIGNATURE_V4_PARAMS ,
4546)
8586 "x-amz-content-sha256" ,
8687]
8788
88- FAKE_HOST_ID = "9Gjjt1m+cjU4OPvX9O9/8RuvnG41MRb/18Oux2o5H5MY7ISNTlXN+Dz9IG62/ILVxhAGI0qyPfg="
89-
9089HOST_COMBINATION_REGEX = r"^(.*)(:[\d]{0,6})"
9190PORT_REPLACEMENT = [":80" , ":443" , f":{ config .GATEWAY_LISTEN [0 ].port } " , "" ]
9291
@@ -156,7 +155,7 @@ def create_signature_does_not_match_sig_v2(
156155 "The request signature we calculated does not match the signature you provided. Check your key and signing method."
157156 )
158157 ex .AWSAccessKeyId = access_key_id
159- ex .HostId = FAKE_HOST_ID
158+ ex .HostId = S3_HOST_ID
160159 ex .SignatureProvided = request_signature
161160 ex .StringToSign = string_to_sign
162161 ex .StringToSignBytes = to_bytes (string_to_sign ).hex (sep = " " , bytes_per_sep = 2 ).upper ()
@@ -299,7 +298,7 @@ def is_valid_sig_v2(query_args: set) -> bool:
299298 LOG .info ("Presign signature calculation failed" )
300299 raise AccessDenied (
301300 "Query-string authentication requires the Signature, Expires and AWSAccessKeyId parameters" ,
302- HostId = FAKE_HOST_ID ,
301+ HostId = S3_HOST_ID ,
303302 )
304303
305304 return True
@@ -317,7 +316,7 @@ def is_valid_sig_v4(query_args: set) -> bool:
317316 LOG .info ("Presign signature calculation failed" )
318317 raise AuthorizationQueryParametersError (
319318 "Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters." ,
320- HostId = FAKE_HOST_ID ,
319+ HostId = S3_HOST_ID ,
321320 )
322321
323322 return True
@@ -351,7 +350,7 @@ def validate_presigned_url_s3(context: RequestContext) -> None:
351350 )
352351 else :
353352 raise AccessDenied (
354- "Request has expired" , HostId = FAKE_HOST_ID , Expires = expires , ServerTime = time .time ()
353+ "Request has expired" , HostId = S3_HOST_ID , Expires = expires , ServerTime = time .time ()
355354 )
356355
357356 auth_signer = HmacV1QueryAuthValidation (credentials = signing_credentials , expires = expires )
@@ -450,7 +449,7 @@ def validate_presigned_url_s3v4(context: RequestContext) -> None:
450449 else :
451450 raise AccessDenied (
452451 "There were headers present in the request which were not signed" ,
453- HostId = FAKE_HOST_ID ,
452+ HostId = S3_HOST_ID ,
454453 HeadersNotSigned = ", " .join (sigv4_context .missing_signed_headers ),
455454 )
456455
@@ -482,7 +481,7 @@ def validate_presigned_url_s3v4(context: RequestContext) -> None:
482481 else :
483482 raise AccessDenied (
484483 "Request has expired" ,
485- HostId = FAKE_HOST_ID ,
484+ HostId = S3_HOST_ID ,
486485 Expires = expiration_time .timestamp (),
487486 ServerTime = time .time (),
488487 X_Amz_Expires = x_amz_expires ,
@@ -714,7 +713,7 @@ def _get_region_from_x_amz_credential(credential: str) -> str:
714713 if not (split_creds := credential .split ("/" )) or len (split_creds ) != 5 :
715714 raise AuthorizationQueryParametersError (
716715 'Error parsing the X-Amz-Credential parameter; the Credential is mal-formed; expecting "<YOUR-AKID>/YYYYMMDD/REGION/SERVICE/aws4_request".' ,
717- HostId = FAKE_HOST_ID ,
716+ HostId = S3_HOST_ID ,
718717 )
719718
720719 return split_creds [2 ]
@@ -775,7 +774,7 @@ def validate_post_policy(
775774 "Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields." ,
776775 ArgumentName = "key" ,
777776 ArgumentValue = "" ,
778- HostId = FAKE_HOST_ID ,
777+ HostId = S3_HOST_ID ,
779778 )
780779
781780 form_dict = {k .lower (): v for k , v in request_form .items ()}
@@ -791,7 +790,7 @@ def validate_post_policy(
791790
792791 if not is_v2 and not is_v4 :
793792 ex : AccessDenied = AccessDenied ("Access Denied" )
794- ex .HostId = FAKE_HOST_ID
793+ ex .HostId = S3_HOST_ID
795794 raise ex
796795
797796 try :
@@ -810,7 +809,7 @@ def validate_post_policy(
810809 if expiration := policy_decoded .get ("expiration" ):
811810 if is_expired (_parse_policy_expiration_date (expiration )):
812811 ex : AccessDenied = AccessDenied ("Invalid according to Policy: Policy expired." )
813- ex .HostId = FAKE_HOST_ID
812+ ex .HostId = S3_HOST_ID
814813 raise ex
815814
816815 # TODO: validate the signature
@@ -832,7 +831,7 @@ def validate_post_policy(
832831 str_condition = str (condition ).replace ("'" , '"' )
833832 raise AccessDenied (
834833 f"Invalid according to Policy: Policy Condition failed: { str_condition } " ,
835- HostId = FAKE_HOST_ID ,
834+ HostId = S3_HOST_ID ,
836835 )
837836
838837
@@ -885,7 +884,7 @@ def _verify_condition(condition: list | dict, form: dict, additional_policy_meta
885884 "Your proposed upload exceeds the maximum allowed size" ,
886885 ProposedSize = size ,
887886 MaxSizeAllowed = end ,
888- HostId = FAKE_HOST_ID ,
887+ HostId = S3_HOST_ID ,
889888 )
890889 else :
891890 return True
@@ -934,7 +933,7 @@ def _is_match_with_signature_fields(
934933 f"Bucket POST must contain a field named '{ argument_name } '. If it is specified, please check the order of the fields." ,
935934 ArgumentName = argument_name ,
936935 ArgumentValue = "" ,
937- HostId = FAKE_HOST_ID ,
936+ HostId = S3_HOST_ID ,
938937 )
939938
940939 return True
0 commit comments