def authenticate_presign_url_signv2(method, path, headers, data, url, query_params, request_dict): # Calculating Signature aws_request = create_request_object(request_dict) credentials = Credentials(access_key=TEST_AWS_ACCESS_KEY_ID, secret_key=TEST_AWS_SECRET_ACCESS_KEY) auth = HmacV1QueryAuth(credentials=credentials, expires=query_params['Expires'][0]) split = urlsplit(aws_request.url) string_to_sign = auth.get_string_to_sign(method=method, split=split, headers=aws_request.headers) signature = auth.get_signature(string_to_sign=string_to_sign) # Comparing the signature in url with signature we calculated query_sig = urlparse.unquote(query_params['Signature'][0]) if query_sig != signature: return requests_error_response_xml_signature_calculation( code=403, code_string='SignatureDoesNotMatch', aws_access_token=TEST_AWS_ACCESS_KEY_ID, string_to_sign=string_to_sign, signature=signature, message='The request signature we calculated does not match the signature you provided. \ Check your key and signing method.') # Checking whether the url is expired or not if int(query_params['Expires'][0]) < time.time(): return requests_error_response_xml_signature_calculation( code=403, code_string='AccessDenied', message='Request has expired', expires=query_params['Expires'][0] )
def authenticate_presign_url_signv2(method, path, headers, data, url, query_params, request_dict): # Calculating Signature aws_request = create_request_object(request_dict) credentials = Credentials( access_key=TEST_AWS_ACCESS_KEY_ID, secret_key=TEST_AWS_SECRET_ACCESS_KEY, token=query_params.get("X-Amz-Security-Token", None), ) auth = HmacV1QueryAuth(credentials=credentials, expires=query_params["Expires"][0]) split = urlsplit(aws_request.url) string_to_sign = auth.get_string_to_sign(method=method, split=split, headers=aws_request.headers) signature = auth.get_signature(string_to_sign=string_to_sign) # Comparing the signature in url with signature we calculated query_sig = urlparse.unquote(query_params["Signature"][0]) if config.S3_SKIP_SIGNATURE_VALIDATION: if query_sig != signature: LOGGER.warning( "Signatures do not match, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1" ) signature = query_sig if query_sig != signature: return requests_error_response_xml_signature_calculation( code=403, code_string="SignatureDoesNotMatch", aws_access_token=TEST_AWS_ACCESS_KEY_ID, string_to_sign=string_to_sign, signature=signature, message= "The request signature we calculated does not match the signature you provided. \ Check your key and signing method.", ) # Checking whether the url is expired or not if int(query_params["Expires"][0]) < time.time(): if config.S3_SKIP_SIGNATURE_VALIDATION: LOGGER.warning( "Signature is expired, but not raising an error, as S3_SKIP_SIGNATURE_VALIDATION=1" ) else: return requests_error_response_xml_signature_calculation( code=403, code_string="AccessDenied", message="Request has expired", expires=query_params["Expires"][0], )