Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

9042

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

        There was a mismatch between the signature in the request and t                                                                                                                           he signature computed by the server.

This is what I do to get the x-emc-signature:

  1. Use gmtime() function to get time in UTC format
  2. 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.

281 Posts

July 13th, 2012 11:00

I believe the problem is that Perl's "encode_base64" function appends a newline to its output value.  You need to suppress this behavior by adding an empty string as the second argument.

The 2-minute delay you were seeing was because you specified Content-Length:200 but didn't send any data.  The server was waiting until it timed out.  You should either set Content-Length:0 or use --data-binary=@filename to send a file.

Here's my updated code.  I also removed the extra $Date from the signature and just kept the newline.

#!/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='6/c';

my $SharedSecret = 'wA=';

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;

my $HashString = $HTTPRequestMethod . "\n" . $ContentType . "\n" . $Range . "\n". "\n".$CanonicalizedResource . "\n" . $CanonicalizedEMCHeaders;

print "StringToSign:\n$HashString\n";

my $DecodedSharedSecret = decode_base64($SharedSecret);

my $digest=hmac_sha1($HashString,$DecodedSharedSecret);

my $EMCSignature= encode_base64($digest, "");

my $cmd =  `curl -k -s -v -H "Content-Type:$ContentType" -H "Content-Length:0" -H "x-emc-date:$Date" -H "x-emc-uid:$UserID" -H "x-emc-signature:$EMCSignature" -X POST api.atmosonline.com/rest/objects`;

print $cmd;

And the output:

~$ ./atmostest.pl

StringToSign:

POST

application/octet-stream

/rest/objects

x-emc-date:Fri, 13 Jul 2012 17:52:11 GMT

x-emc-uid:6c91fae4fc1f427a9b101ae92d35b0b7/A13067272264222607fc

* About to connect() to api.atmosonline.com port 80 (#0)

*   Trying 74.112.146.139... connected

> POST /rest/objects HTTP/1.1

> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3

> Host: api.atmosonline.com

> Accept: */*

> Content-Type:application/octet-stream

> Content-Length:0

> x-emc-date:Fri, 13 Jul 2012 17:52:11 GMT

> x-emc-uid:6c91fae4fc1f427a9b101ae92d35b0b7/A13067272264222607fc

> x-emc-signature:jMsuseufdo/2XB+y0rzD48uMjos=

>

< HTTP/1.1 201 Created

< Server: Apache

< Content-Type: text/plain; charset=UTF-8

< Date: Fri, 13 Jul 2012 17:52:11 GMT

< location: /rest/objects/4ee696e4a31f549804f0b909b451ee05000604bf202b

< x-emc-delta: 0

< x-emc-policy: default

< Connection: Keep-Alive

< Content-Length: 0

<

* Connection #0 to host api.atmosonline.com left intact

* Closing connection #0

222 Posts

July 5th, 2012 00:00

Have you considered using one of our language bindings if you're using Java, .NET, PHP, Ruby, etc?  The bindings perform request signing, sending, parsing, etc. 

Can you post a Wireshark trace of the HTTP request so that we can look at what's actually being sent over the wire?

281 Posts

July 5th, 2012 07:00

I think the problem is that in your signature string you have:

application/octet-stream

But your curl command line has:

-H "Content-type:Application/octet-stream"

Try changing Application to lowercase on the curl command.

What language are you using?  As Raj mentioned, we recommend using one of our exising APIs.

18 Posts

July 6th, 2012 02:00

Jason,

Thank you for your response. If  I change the header to lower case, I get a 1002 error (invalid header).

18 Posts

July 6th, 2012 02:00

Bala and Jason,

I am more comfortable working with perl, I did not find a link for a binding in Perl. Will reply with the wireshark op soon

18 Posts

July 6th, 2012 02:00

This is the message captured by wireshark.

Since I am working on a windows platform, I see that the carriage return is implemented as \r\n. But in my signature, there would only be \n

Let me check it on a linux machine and come back

Hypertext Transfer Protocol

POST /rest/objects HTTP/1.1\r\n

Authorization: Basic YXRtb3N1Z3JAc2E3MjRwLmluOnVzaTEyMzQ1\r\n

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/Accept:*/*\r\n

Content-type:Application/octet-stream\r\n

Host:135.21.93.176\r\n

Date:Fri, 6 Jul 2012 09:41:55 GMT\r\n

x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin\r\n

x-emc-signature:d1DwpdhQj7NBH+N+2V2oNxRUoXk=\n

\r\n

18 Posts

July 6th, 2012 03:00

no change from linux as well...over to you

281 Posts

July 6th, 2012 06:00

It's definitely the "A" in "Application/octet-stream".  Can you make that lowercase and then wireshark the result if you still get the invalid header?

18 Posts

July 6th, 2012 09:00

Invalid header was my mistake earlier may be, but I still hit the signature mismatch

18 Posts

July 6th, 2012 09:00

The request and error:

$ perl staas_test.pl

POST

application/octet-stream

Fri, 6 Jul 2012 16:36:31 GMT

/rest/objects

x-emc-date:Fri, 6 Jul 2012 16:36:31 GMT

x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

iM5wF6SCNGCQsVPufOsU0wJIaCE=

* 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)

* Server auth using Basic with user 'atmosugr@sa724p.in'

> POST /rest/objects HTTP/1.1

> Authorization: Basic YXRtb3N1Z3JAc2E3MjRwLmluOnVzaTEyMzQ1

> 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

> Accept:*/*

> Content-type:application/octet-stream

> Host:135.21.93.176

> Date:Fri, 6 Jul 2012 16:36:31 GMT

> x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

> x-emc-signature:iM5wF6SCNGCQsVPufOsU0wJIaCE=

>

>

< HTTP/1.1 403 Forbidden

< Date: Fri, 06 Jul 2012 16:36:33 GMT

< Server: Apache

< Content-Length: 195

< Connection: close

< Content-Type: text/xml

<

{ [data not shown]

* Closing connection #0

        1032

        There was a mismatch between the signature in the request and t                                                                                                                           he signature computed by the server.

Output from Wireshark:

Hypertext Transfer Protocol

    POST /rest/objects HTTP/1.1\r\n

        [Expert Info (Chat/Sequence): POST /rest/objects HTTP/1.1\r\n]

        Request Method: POST

        Request URI: /rest/objects

        Request Version: HTTP/1.1

    Authorization: Basic YXRtb3N1Z3JAc2E3MjRwLmluOnVzaTEyMzQ1\r\n

    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\r\n

    Accept:*/*\r\n

    Content-type:application/octet-stream\r\n

    Host:135.21.93.176\r\n

    Date:Fri, 6 Jul 2012 16:36:31 GMT\r\n

    x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin\r\n

    x-emc-signature:iM5wF6SCNGCQsVPufOsU0wJIaCE=\n

    \r\n

    [Full request URI: http://135.21.93.176/rest/objects]

Hypertext Transfer Protocol

    \r\n

18 Posts

July 6th, 2012 10:00

One more thing is, tenant is at&t storage as a service.

281 Posts

July 6th, 2012 11:00

I see you're using x-emc-date.  Try removing the plain date from your signature string and replace with an empty line, e.g.

POST

application/octet-stream

/rest/objects

x-emc-date:Fri, 6 Jul 2012 16:36:31 GMT

x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

18 Posts

July 6th, 2012 12:00

POST

application/octet-stream

/rest/objects

x-emc-date:Fri, 6 Jul 2012 19:50:14 GMT

x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

EiUsxVN1kSIz7vGPRXxw2kvJGlA=

* 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)

* Server auth using Basic with user 'atmosugr@sa724p.in'

> POST /rest/objects HTTP/1.1

> Authorization: Basic YXRtb3N1Z3JAc2E3MjRwLmluOnVzaTEyMzQ1

> 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

> Accept:*/*

> Content-type:application/octet-stream

> Host:135.21.93.176

> x-emc-date:Fri, 6 Jul 2012 19:50:14 GMT

> x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

> x-emc-signature:EiUsxVN1kSIz7vGPRXxw2kvJGlA=

>

>

< HTTP/1.1 400 Bad Request

< Date: Fri, 06 Jul 2012 19:50:15 GMT

< Server: Apache

< Content-Length: 145

< Connection: close

< Content-Type: text/xml

<

{ [data not shown]

* Closing connection #0

        1002

        One or more arguments in the request was invalid.

Wireshark O/P:

Hypertext Transfer Protocol

    POST /rest/objects HTTP/1.1\r\n

    Authorization: Basic YXRtb3N1Z3JAc2E3MjRwLmluOnVzaTEyMzQ1\r\n

    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\r\n

    Accept:*/*\r\n

    Content-type:application/octet-stream\r\n

    Host:135.21.93.176\r\n

    x-emc-date:Fri, 6 Jul 2012 19:50:14 GMT\r\n

    x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin\r\n

    x-emc-signature:EiUsxVN1kSIz7vGPRXxw2kvJGlA=\n

    \r\n

    [Full request URI: http://135.21.93.176/rest/objects]

Hypertext Transfer Protocol

    \r\n

13 Posts

July 12th, 2012 23:00

Hi,

The 1002 error you're seeing may be because your request is missing the required "Content-Length" http header.   Is curl reading from stdin?   (If so try reading from a file to prove your signatures are correct.)   What size object are you trying to create?

As an aside, I would advise removing the HTTP basic authentication from your request...  Its basically harmless since Atmos ignores it -- instead relying on its own native REST-based authentication -- but its best to remove these from your curl requests.

Are you using on-premise Atmos?  The AT&T Synaptic service doesn't allow port 80, as far as I know.

Are you still seeing the 1032 signature mismatch errors at this point?

18 Posts

July 13th, 2012 02:00

I put the content-length header in, I get the same error, only thing different now is there is a 2minute wait.

POST

application/octet-stream

Fri, 13 Jul 2012 09:12:15 GMT

/rest/objects

x-emc-date:Fri, 13 Jul 2012 09:12:15 GMT

x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

/WnCu9IFA7B+gX+0md5pFpgnFXY=* 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

> accept:*/*

> content-type:application/octet-stream

> content-length:200

> host:135.21.93.176

> x-emc-date:Fri, 13 Jul 2012 09:12:15 GMT

> x-emc-uid:d3ade228823c412b8a3460084e7917e2/atmosugrATsa724pDOTin

> x-emc-signature:/WnCu9IFA7B+gX+0md5pFpgnFXY=

>

% Total% Received % Xferd  Average Speed   TimeTime Time  Current
                             Dload  Upload   Total   SpentLeft  Speed
  0 00 00 0 --:--:--  0:02:00 --:--:-- 0< HTTP/1.1 403 Forbidden

< Date: Fri, 13 Jul 2012 09:12:16 GMT

< Server: Apache

< Content-Length: 195

< Connection: close

< Content-Type: text/xml

<

{ [data not shown]

100   195  100   1950 0  0:03:15  0:02:00  0:01:1544

* Closing connection #0

    1032
    There was a mismatch between the signature in the request and the signature computed by the server.

No Events found!

Top