sadimadh2

updated

14 years ago

S

sadimadh2

18 Posts

0

9599

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.

  • JasonCwik

    1 Rookie

    •

    281 Posts

    3646

    0

    Posted 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

  • rbala1

    1 Rookie

    •

    222 Posts

    2861

    1

    Posted 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?

  • JasonCwik

    1 Rookie

    •

    281 Posts

    2861

    1

    Posted 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.

  • sadimadh2

    18 Posts

    2862

    0

    Posted 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).

  • sadimadh2

    18 Posts

    2862

    0

    Posted 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

  • sadimadh2

    18 Posts

    2862

    0

    Posted 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

  • sadimadh2

    18 Posts

    2862

    0

    Posted July 6th, 2012 03:00

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

  • JasonCwik

    1 Rookie

    •

    281 Posts

    2862

    0

    Posted 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?

  • sadimadh2

    18 Posts

    2862

    0

    Posted July 6th, 2012 09:00

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

  • sadimadh2

    18 Posts

    2862

    0

    Posted 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