From b8a87ca2569c905983c53e8df7ae8b80ecc9cb61 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 13 Aug 2009 08:55:25 -0400 Subject: [PATCH] bug 3204: followup to fix AWS request signing [1] There were some ersataz spaces in the string being signed. [2] AWS expects a trailing '=' in the Base64 signature Signed-off-by: Galen Charlton --- C4/External/Amazon.pm | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm index d6145b342b..bb72af71c9 100644 --- a/C4/External/Amazon.pm +++ b/C4/External/Amazon.pm @@ -132,7 +132,7 @@ sub get_amazon_details { my %hformat = ( a => 'Books', g => 'Video', j => 'Music' ); my $search_index = $hformat{ substr($record->leader(),6,1) } || 'Books'; - my $parameters={Service=>"AWSECommerceService" , + my $parameters={Service=>"AWSECommerceService" , "AWSAccessKeyId"=> C4::Context->preference('AWSAccessKeyID') , "Operation"=>"ItemLookup", "AssociateTag"=> C4::Context->preference('AmazonAssocTag') , @@ -141,12 +141,12 @@ sub get_amazon_details { "IdType"=>$id_type, "ResponseGroup"=> join( ',', @aws ), "Timestamp"=>strftime("%Y-%m-%dT%H:%M:%SZ", gmtime) - }; - $$parameters{"SearchIndex"} = $search_index if $id_type ne 'ASIN'; - my @params; - while (my ($key,$value)=each %$parameters){ - push @params, qq{$key=}.uri_escape($value, "^A-Za-z0-9\-_.~" ); - } + }; + $$parameters{"SearchIndex"} = $search_index if $id_type ne 'ASIN'; + my @params; + while (my ($key,$value)=each %$parameters){ + push @params, qq{$key=}.uri_escape($value, "^A-Za-z0-9\-_.~" ); + } my $url =qq{http://webservices.amazon}. get_amazon_tld(). "/onca/xml?".join("&",sort @params).qq{&Signature=}.uri_escape(SignRequest(@params),"^A-Za-z0-9\-_.~" ); @@ -162,14 +162,10 @@ sub get_amazon_details { } sub SignRequest{ - my @params=@_; + my @params=@_; my $tld=get_amazon_tld(); - my $string = qq{ -GET -webservices.amazon$tld -/onca/xml -}.join("&",sort @params); - return hmac_sha256_base64($string,C4::Context->preference('AWSPrivateKey')); + my $string = qq{GET\nwebservices.amazon$tld\n/onca/xml\n} . join("&",sort @params); + return hmac_sha256_base64($string,C4::Context->preference('AWSPrivateKey')) . '='; } sub check_search_inside { -- 2.39.5