[Koha-patches] [PATCH 2/4] bug 3204: followup to fix AWS request signing
Galen Charlton
gmcharlt at gmail.com
Thu Aug 13 15:27:02 CEST 2009
[1] There were some ersataz spaces in the string
being signed.
[2] AWS expects a trailing '=' in the Base64 signature
---
C4/External/Amazon.pm | 24 ++++++++++--------------
1 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/C4/External/Amazon.pm b/C4/External/Amazon.pm
index d6145b3..bb72af7 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 {
--
1.5.6.5
More information about the Koha-patches
mailing list