This post is more than 5 years old
18 Posts
0
9290
July 3rd, 2012 22:00
Error 1032 while executing REST API Calls
Hi,
Sorry if this is a repost, but I could not find a solution from any thread I hit on earlier.
I know that the procedure I use to get x-emc-signature is correct, however I get the following while executing any httpmethod.
1032
This is what I do to get the x-emc-signature:
- Use gmtime() function to get time in UTC format
- Create hash string as follows
HTTPRequestMethod + '\n' +
ContentType + '\n' +
Range + '\n' +
Date + '\n' +
CanonicalizedResource + '\n' +
CanonicalizedEMCHeaders
3. decode_base64($SecretKey)
4. encode_base64(hmac_sha1($HashString,decode_base64($SecretKey))
My account is enabled and on a portal, there is a link that tests the subtenant by running a POST object and DELETE object calls. This test was successful, and I used the timestamp from that request, keyed it into my code and compared the signatures, they match, and that is why I think my signatures are correct.
However when I run my perl program, I get the error mentioned.
Just for confirmation, following is the format of date I put in after reordering the output of gmtime();
Tue, 4 Jul 2012 04:27:53 GMT
In canonicalized EMCHeaders, i use x-emc-uid alone.
Following is my $HashString
POST
application/octet-stream
Wed, 4 Jul 2012 04:27:53 GMT
/rest/objects
x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin
Following is my signature:
BQ5tLNWDF9iTmpyZTzqu26NN2uM=
Following is my call:
`curl -v --basic -u "$Account:$Passwd" -H "Accept:*/*" -H "Content-type:Application/octet-stream" -H "Host:$Host" -H "Date:$Date" -H "x-emc-uid:$UserID" -H "x-emc-signature:$EMCSignature" -X POST $Host/rest/objects`;
Please help, I am not quite sure what I am missing.



sadimadh2
18 Posts
0
July 13th, 2012 02:00
This is not listening on 443, I get a positive connection on port 80
$ perl staas_test.pl
Fri, 13 Jul 2012 09:17:13 GMT
POST
application/octet-stream
Fri, 13 Jul 2012 09:17:13 GMT
/rest/objects
x-emc-date:Fri, 13 Jul 2012 09:17:13 GMT
x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin
EKXTzn4OdDHdaN4BrgesohdpMVI=* getaddrinfo(3) failed for 0s:80
* Couldn't resolve host '0s'
* Closing connection #0
curl: (6) Couldn't resolve host '0s'
* About to connect() to 135.21.93.176 port 443 (#0)
* Trying 135.21.93.176...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
rbala1
222 Posts
0
July 13th, 2012 06:00
Can you post or send a complete, minimal example of code that we can run ourselves that generates the same condition?
BrianOlson
13 Posts
0
July 13th, 2012 08:00
When does the 2 minute wait occur? Its not apparent from your included traces.
To troubleshoot, you might try setting Content-Length to zero to ensure your object is being successfully created with no signature mismatches or invalid request errors.
Anyway, now it seems like you're seeing a 403 Forbidden error first?
You might find the XCLOUD tool helpful... it has a '-M' option that will show the actual HTTP header request and reply traffic for any Atmos data-access operation. You can find XCLOUD here: http://code.google.com/p/xcloudtool/
Here's what XCLOUD shows when creating a 200-byte object for AT&T Synaptic:
* Connected to ssl://storage.synaptic.att.com:443
POST /rest/objects HTTP/1.1
User-Agent: XCLOUD
Content-Type: application/octet-stream
X-Emc-Uid: ssssssssssssssssssssssssssssssss/uuuuuuuuuu
Date: Fri, 13 Jul 2012 15:08:29 +0000
X-Emc-Signature: zzzzzzzzzzzzzzzzzzzzzzzzzzzz
Host: storage.synaptic.att.com
Accept-Encoding: gzip, deflate
Content-Length: 200
200 byte(s) sent
HTTP/1.1 201 Created
date: Fri, 13 Jul 2012 15:08:31 GMT
server: Apache
x-emc-policy: default
x-emc-delta: 200
location: /rest/objects/4a08bf2eac1f2e0e04fe3c1e8534110500039ef23a7e
content-length: 0
x-cnection: close
content-type: text/plain; charset=UTF-8
sadimadh2
18 Posts
0
July 13th, 2012 10:00
no matter what I do, I hit the signature mismatch error. I used curl and firefox rest api client.
Also, when I run a test from the portal, I check the signature that the portal is sending and it matches the signature I would send for that time stamp, for that method. Yet the portal gets a 200 response and my program gets a 1032 response.
sadimadh2
18 Posts
0
July 13th, 2012 10:00
Bala,
Please find my code below:
You cannot connect to my host, but you can use it to another host with another uid ofcourse.
#!/usr/bin/perl
use strict;
use Time::Local;
use MIME::Base64;
use Digest::SHA qw(hmac_sha1);
sub _MyUTCTime(){
my @Time=split(" ",scalar gmtime());
my ($Wkday,$Mon,$Day,$time,$year) = @Time;
my $UTCTime = $Wkday . ", " . $Day . " $Mon" . " $year " . $time . " GMT";
return $UTCTime;
}
my $UserID='x../y';
my $SharedSecret = 'x...=';
my $HTTPRequestMethod = 'POST';
my $ContentType = "application/octet-stream";
my $Range = "";
my $Date= _MyUTCTime;
my $CanonicalizedResource = '/rest/objects';
my $CanonicalizedEMCHeaders = 'x-emc-date:'.$Date."\n".'x-emc-uid:'.$UserID;
$CanonicalizedResource . "\n" . $CanonicalizedEMCHeaders;
my $HashString = $HTTPRequestMethod . "\n" . $ContentType . "\n" . $Range . "\n". $Date."\n".$CanonicalizedResource . "\n" . $CanonicalizedEMCHeaders;
my $DecodedSharedSecret = decode_base64($SharedSecret);
my $digest=hmac_sha1($HashString,$DecodedSharedSecret);
my $EMCSignature= encode_base64($digest);
my $cmd = `curl -k -s -v -H "accept:*/*" -H "content-type:application/octet-stream" -H "content-length:200" -H "host:135.21.93.176" -H "x-emc-date:$Date" -H "x-emc-uid:$UserID" -H "x-emc-signature:$EMCSignature" -X POST 135.21.93.176/rest/objects/`;
print $cmd;
sadimadh2
18 Posts
0
July 13th, 2012 19:00
That Fixed it!!! Thanks a lot Jason, Bala and Brian
$ perl staas_test_1.pl
StringToSign:
POST
application/octet-stream
/rest/objects
x-emc-date:Sat, 14 Jul 2012 02:56:21 GMT
x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin
* About to connect() to 135.21.93.176 port 80 (#0)
* Trying 135.21.93.176...
* connected
* Connected to 135.21.93.176 (135.21.93.176) port 80 (#0)
> POST /rest/objects HTTP/1.1
> User-Agent: curl/7.24.0 (i686-pc-cygwin) libcurl/7.24.0 OpenSSL/1.0.1 zlib/1.2 .5 libidn/1.22 libssh2/1.4.0
> Host: 135.21.93.176
> Accept: */*
> Content-Type:application/octet-stream
> Content-Length:0
> x-emc-date:Sat, 14 Jul 2012 02:56:21 GMT
> x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin
> x-emc-signature:evVHxpWlsBnJAUJi2GcLXbv2+/4=
>
< HTTP/1.1 201 Created
< Date: Sat, 14 Jul 2012 02:56:22 GMT
< Server: Apache
< x-emc-policy: default
< x-emc-delta: 0
< location: /rest/objects/4ea588a2a2411d7004ea5aceee005d05000dfd6458e4
< Content-Length: 0
< Connection: close
< Content-Type: text/plain; charset=UTF-8
<
* Closing connection #0
sadimadh2
18 Posts
0
July 13th, 2012 20:00
To summarize, following was what was corrected:
1) content-type value should have been in lower case in request and in hash-string
2) content-length header was not present
3) encode_base64 was adding a new line until an empty string was passed as its second argument
4) request need not explicitly add Accept and Host headers