Unsolved
This post is more than 5 years old
222 Posts
0
2137
January 5th, 2011 16:00
HTTP Request Signing using Python with Atmos
Here's a complete example of the Atmos request signing process using Python.
#!/usr/bin/env python
import hmac, base64, hashlib
key = "LJLuryj6zs8ste6Y3jTGQp71xq0=" # base64 encoded shared secret
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"
decodedkey = base64.b64decode(key) # Be sure to base64 decode the shared secret before you use HMAC on the request
hash = hmac.new(decodedkey, test_headers, hashlib.sha1).digest() # Compute the HMAC-SHA1 algorithm on the request using the decoded shared secret
hashout = base64.encodestring(hash).strip() # base64 encode the hash and strip the trailing new line character
print "The headers are:\n\n%s" % test_headers
print "\nThe signature is: %s" % hashout # Expecting WHJo1MFevMnK4jCthJ974L3YHoo= as the signature


