def generate_oauth_signature(self, method, params, url, key=None): """ Generate OAuth Signature """ string_to_sign = self.get_signature_base_string(method, params, url) if key is None: key = self.get_sign_key(self.consumer_secret) if self.signature_method == 'HMAC-SHA1': hmac_mod = sha1 elif self.signature_method == 'HMAC-SHA256': hmac_mod = sha256 else: raise UserWarning("Unknown signature_method") # print "\nstring_to_sign: %s" % repr(string_to_sign) # print "\nkey: %s" % repr(key) sig = HMAC( bytes(key.encode('utf-8')), bytes(string_to_sign.encode('utf-8')), hmac_mod ) sig_b64 = binascii.b2a_base64(sig.digest())[:-1] # print "\nsig_b64: %s" % sig_b64 return sig_b64
def current_hmac(self, cached = False): """Returns the current hmac of self.fulldata""" data = '' for i in self.headers: log.debug("Adding hmac data %s", repr(i.hmac_data())) if cached: data += i.data else: data += i.hmac_data() for i in self.records: log.debug("Adding hmac data %s", repr(i.hmac_data())) data += i.hmac_data() log.debug("Building hmac with key %s", repr(self.hshkey)) hm = HMAC(self.hshkey, data, sha256_mod) #print hm.hexdigest() log.debug("HMAC %s-%s", repr(hm.hexdigest()), repr(hm.digest())) return hm.digest()
def current_hmac(self, cached=False): """Returns the current hmac of self.fulldata""" data = '' for i in self.headers: log.debug("Adding hmac data %s", repr(i.hmac_data())) if cached: data += i.data else: data += i.hmac_data() for i in self.records: log.debug("Adding hmac data %s", repr(i.hmac_data())) data += i.hmac_data() log.debug("Building hmac with key %s", repr(self.hshkey)) hm = HMAC(self.hshkey, data, sha256_mod) #print hm.hexdigest() log.debug("HMAC %s-%s", repr(hm.hexdigest()), repr(hm.digest())) return hm.digest()
def current_hmac(self, cached = False): """Returns the current hmac of self.fulldata""" data = '' for i in self.headers: log.debug("Adding hmac data %r from %r" % (i.hmac_data(), i.__class__.__name__)) if cached: data += i.data else: data += i.hmac_data() # assert i.data == i.hmac_data(), "Working on %r where %r!=%r" % (i, i.data, i.hmac_data()) for i in self.records: # TODO: Add caching support log.debug("Adding hmac data %r from %r" % (i.hmac_data(), i.__class__.__name__)) data += i.hmac_data() log.debug("Building hmac with key %s", repr(self.hshkey)) hm = HMAC(self.hshkey, data, sha256_mod) # print hm.hexdigest() log.debug("HMAC %s-%s", repr(hm.hexdigest()), repr(hm.digest())) return hm.digest()
def current_hmac(self, cached=False): """Returns the current hmac of self.fulldata""" data = b'' for i in self.headers: log.debug("Adding hmac data %r from %r" % (i.hmac_data(), i.__class__.__name__)) if cached: data += i.data else: data += i.hmac_data() # assert i.data == i.hmac_data(), "Working on %r where %r!=%r" % (i, i.data, i.hmac_data()) for i in self.records: # TODO: Add caching support log.debug("Adding hmac data %r from %r" % (i.hmac_data(), i.__class__.__name__)) data += i.hmac_data() log.debug("Building hmac with key %s", repr(self.hshkey)) hm = HMAC(self.hshkey, data, sha256_mod) # print hm.hexdigest() log.debug("HMAC %s-%s", repr(hm.hexdigest()), repr(hm.digest())) return hm.digest()