john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

s3 cumulus authentication hash creation

import hmac
import base64
try:
    from hashlib import sha1 as sha
    from hashlib import sha256 as sha256
except ImportError:
    import sha

import boto
import boto.utils



def get_auth_hash(key, method, path, headers, uri):

    sub_resources = ["?acl", "?location", "?logging", "?torrent"]
    for sr in sub_resources:
        ndx = uri.find(sr)
        if ndx > 0:
            path = path + sr

    myhmac = hmac.new(key, digestmod=sha)
    c_string = boto.utils.canonical_string(method, path, headers, provider=boto.provider.get_default())
    print c_string

    myhmac.update(c_string)
    auth_hash = base64.encodestring(myhmac.digest()).strip()
    return auth_hash



if __name__ == '__main__':
    authkey = '9XprLpeV3SYIW8hTge3IyCJpaMGsCNLLgu667A4SwM'
    method = 'GET'
    path = '/Files/img/emoticons/cry.png'
    headers = dict()
    headers['x-amz-date'] = 'Wed, 15 Jan 2014 22:51:25 GMT'
    uri = '/Files/img/emoticons/cry.png?Signature=%2FWm9mKl%2Fq%2FLqCj%2Bt96SZWUfBvFI%3D&Expires=1389829871&AWSAccessKeyId=ByTUlL54RzaP0asoNY7NA'

    signature = get_auth_hash( authkey, method, path, headers, uri )
    print 'signature: ', signature

  # note it does not use expiration


# sudo pip install Wheel; sudo apt-get install sqlite3
# /home/ubuntu/nimbus/cumulus/cumulus-install.sh /opt/cumulus; /opt/setup_s3.sh; /etc/init.d/cumulus restart

  • « Chef install and knife
  • twisted trial test single file tempfile remove »

Published

Apr 11, 2014

Category

python

~113 words

Tags

  • authentication 4
  • creation 2
  • cumulus 2
  • hash 7
  • python 180
  • s3 17