Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Utils): Add signature verification utility function #81

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions frameioclient/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
import sys
import hmac
import xxhash
import hashlib

KB = 1024
MB = KB * KB
Expand Down Expand Up @@ -125,6 +127,27 @@ def format_headers(token, version):
'x-frameio-client': 'python/{}'.format(version)
}

@staticmethod
def verify_signature(curr_time, req_time, signature, body, secret):
"""
Verify webhook/custom action signature

:Args:
curr_time (float): Current epoch time
req_time (float): Request epoch time
signature (str): Signature provided by the frame.io API for the given request
body (str): Webhook body from the received POST
secret (str): The secret for this custom action/webhook that you saved when you first created it
"""
if int(curr_time) - int(req_time) < 500:
message = 'v0:{}:{}'.format(req_time, body)
calculated_signature = 'v0={}'.format(hmac.new(
bytes(secret, 'latin-1'),
msg=bytes(message, 'latin-1'),
digestmod=hashlib.sha256).hexdigest())
if calculated_signature == signature:
return True
return False

class PaginatedResponse(object):
def __init__(self, results=[], limit=None, page_size=0, total=0,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import json
import time
import socket
import platform
import mimetypes
import shutil
import requests
import platform

from math import ceil
from pprint import pprint, pformat
Expand Down
Empty file.