def __validate_signature(self, signature, payload): signature_pairs = [pair.split("|") for pair in signature.split("&") if "|" in pair] matching_signature = self.__matching_signature(signature_pairs) payload_signature = Crypto.hmac_hash(self.config.private_key, payload) if not Crypto.secure_compare(payload_signature, matching_signature): raise InvalidSignatureError
def __validate_signature(self, signature, payload): signature_pairs = [ pair.split("|") for pair in signature.split("&") if "|" in pair ] matching_signature = self.__matching_signature(signature_pairs) payload_signature = Crypto.hmac_hash(self.config.private_key, payload) if not Crypto.secure_compare(payload_signature, matching_signature): raise InvalidSignatureError
def tr_data(self, data, redirect_url): data = self.__flatten_dictionary(data) date_string = datetime.utcnow().strftime("%Y%m%d%H%M%S") data["time"] = date_string data["redirect_url"] = redirect_url data["public_key"] = self.config.public_key data["api_version"] = self.config.api_version() tr_content = urllib.urlencode(data) tr_hash = Crypto.hmac_hash(self.config.private_key, tr_content) return tr_hash + "|" + tr_content
def tr_data(data, redirect_url): data = TransparentRedirect.__flatten_dictionary(data) date_string = datetime.utcnow().strftime("%Y%m%d%H%M%S") data["time"] = date_string data["redirect_url"] = redirect_url data["public_key"] = Configuration.public_key data["api_version"] = Configuration.api_version() tr_content = urllib.urlencode(data) tr_hash = Crypto.hmac_hash(Configuration.private_key, tr_content) return tr_hash + "|" + tr_content
def sample_notification(self, kind, id): payload = base64.encodestring(self.__sample_xml(kind, id)) hmac_payload = Crypto.hmac_hash(self.gateway.config.private_key, payload) signature = "%s|%s" % (self.gateway.config.public_key, hmac_payload) return signature, payload
def _is_valid_tr_query_string(self, query_string): content, hash = query_string.split("&hash=") return hash == Crypto.hmac_hash(self.config.private_key, content)
def verify(self, challenge): digest = Crypto.hmac_hash(self.config.private_key, challenge) return "%s|%s" % (self.config.public_key, digest)
def is_valid_tr_query_string(query_string): content, hash = query_string.split("&hash=") return hash == Crypto.hmac_hash(Configuration.private_key, content)