This post is more than 5 years old
2 Posts
0
2575
January 4th, 2011 13:00
Incorrect hash value (for signature) with PHP
I looked at the provided PHP bindings for the REST API but I need something a little different than what it offers. I started a PHP script that talks HTTP with our cloud provider but I'm getting an incorrect signature response.
I understand how to generate the signature, but I'm getting incorrect results. I just realized the documentation (Atmos_REST_API_Reference.pdf section 4, page 57) that we're given an example request and key and the proper results. My code is getting a different result.
My PHP version (standard PHP 5 with Ubuntu 10.04 64-bit):
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$key = "LJLuryj6zs8ste6Y3jTGQp71xq0=";
$test_headers = "POST\n";
$test_headers .= "application/octet-stream\n";
$test_headers .= "\n";
$test_headers .= "Thu, 05 Jun 2008 16:38:19 GMT\n";
$test_headers .= "/rest/objects\n";
$test_headers .= "x-emc-date:Thu, 05 Jun 2008 16:38:19 GMT\n";
$test_headers .= "x-emc-groupacl:other=NONE\n";
$test_headers .= "x-emc-listable-meta:part4/part7/part8=quick\n";
$test_headers .= "x-emc-meta:part1=buy\n";
$test_headers .= "x-emc-uid:6039ac182f194e15b9261d73ce044939/user1\n";
$test_headers .= "x-emc-useracl:john=FULL_CONTROL,mary=WRITE\n";
$hash = hash_init("sha1", HASH_HMAC, base64_decode($key));
hash_update($hash, $test_headers);
echo "Hash: " . base64_encode(hash_final($hash, true)) . "\n";
?>
My resultant hash is 6Lve4+YAS0oyZZiOHG/I7NegsSI= but the documentation said it should be WHJo1MFevMnK4jCthJ974L3YHoo=
Am I missing something?



rbala1
222 Posts
0
January 5th, 2011 07:00
Hey there,
The newline character for the last header needed to be removed. The following code generates the expected hash:
$key = "LJLuryj6zs8ste6Y3jTGQp71xq0=";
$test_headers = "POST\n";
$test_headers .= "application/octet-stream\n";
$test_headers .= "\n";
$test_headers .= "Thu, 05 Jun 2008 16:38:19 GMT\n";
$test_headers .= "/rest/objects\n";
$test_headers .= "x-emc-date:Thu, 05 Jun 2008 16:38:19 GMT\n";
$test_headers .= "x-emc-groupacl:other=NONE\n";
$test_headers .= "x-emc-listable-meta:part4/part7/part8=quick\n";
$test_headers .= "x-emc-meta:part1=buy\n";
$test_headers .= "x-emc-uid:6039ac182f194e15b9261d73ce044939/user1\n";
$test_headers .= "x-emc-useracl:john=FULL_CONTROL,mary=WRITE";
$hash = hash_init("sha1", HASH_HMAC, base64_decode($key));
hash_update($hash, $test_headers);
echo "Hash: " . base64_encode(hash_final($hash, true)) . "\n";
?>
Raj
ripburn
2 Posts
0
January 5th, 2011 08:00
That was such a small oversight. Thank you.
rbala1
222 Posts
0
January 5th, 2011 17:00
No problem. Let us know if you need any other help.
Out of curiosity, why didn't the existing PHP wrapper work for you?