Revisions
-
rcoup revised this gist
Feb 13, 2014 . 3 changed files with 32 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import base64 import hashlib import hmac import time from email.utils import formatdate import requests HOST="somewhere" KEY_ID="gimme" SECRET="ssshhh" ACCEPT="something" def gimme_yo_stuff(path): time = formatdate(localtime=True) requests.get(path, headers={ "Accept": ACCEPT, "Date": time, "Authorization": "%s:%s" % (KEY_ID, signature_for_path(path, 'GET', time), }) def signature_for_path(path, method, time): payload = string_to_sign(method, path, time) h = hmac.new(SECRET, payload, hashlib.sha256) d = h.digest() return base64.b64encode(d) def string_to_sign(method, path, time): return "\n".join([method, HOST, path, time, KEY_ID, ACCEPT, '']) # then call gimme_yo_stuff('/some/path')? This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +0,0 @@ -
NZKoz revised this gist
Feb 13, 2014 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ >>> payload = 'lulz' >>> import hashlib >>> import hmac >>> import base64 >>> h = hmac.new("YOUR SECRET", payload, hashlib.sha256) >>> h = hmac.new("YOUR SECRET", payload, hashlib.sha256) >>> d = h.digest() >>> base64.b64encode(d) 'AKdJyTNPtw+rFru9gl/pb6Wf5OBu/12ycZN/i+quCyU=' -
NZKoz revised this gist
Feb 13, 2014 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,10 @@ def gimme_yo_stuff def signature_for_path(path, method, time) payload = string_to_sign(method, path, time) digest = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret, payload) # this nonsense is base64 encoding, you may or may not have to remove the \n from your # digests, depends how your library works [digest].pack('m').gsub("\n", '') end def string_to_sign(method, path, time) -
NZKoz created this gist
Feb 13, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ def gimme_yo_stuff time = Time.now.httpdate YOUR HTTP LIBRARY.GET(path, :headers=> { "Accept" => ACCEPT, "Date"=>time, "Authorization"=>"#{@key_id}:#{signature_for_path(path, 'GET', time)}" }) end def signature_for_path(path, method, time) payload = string_to_sign(method, path, time) [OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), @secret, payload)].pack('m').gsub("\n", '') end def string_to_sign(method, path, time) [method, HOST, path, time, @key_id, ACCEPT, ''].join("\n") end