From 36285db2cae08a11d4aa8de6e11c095bea9820c5 Mon Sep 17 00:00:00 2001 From: Arthur Date: Wed, 1 Nov 2023 07:41:26 -0700 Subject: [PATCH] 14132 fix --- netbox/extras/webhooks.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 netbox/extras/webhooks.py diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py new file mode 100644 index 000000000..a48a8038b --- /dev/null +++ b/netbox/extras/webhooks.py @@ -0,0 +1,14 @@ +import hashlib +import hmac + + +def generate_signature(request_body, secret): + """ + Return a cryptographic signature that can be used to verify the authenticity of webhook data. + """ + hmac_prep = hmac.new( + key=secret.encode('utf8'), + msg=request_body, + digestmod=hashlib.sha512 + ) + return hmac_prep.hexdigest()