ForcePilot/backend/package/yuxi/channels/adapters/bluebubbles/webhook_auth.py
Kris 6aa1d52a8b feat(bluebubbles): 实现完整的BlueBubbles适配器基础组件
新增BlueBubbles适配器全套核心工具类与服务,包含会话管理、消息去重、Webhook验证、缓存系统、账号配置解析、聊天消息处理等完整功能模块,支持iMessage消息收发、群管理、反应特效、语音合成等能力,提供完善的健康检查与配置校验流程。
2026-05-12 00:42:57 +08:00

30 lines
682 B
Python

from __future__ import annotations
import hashlib
import hmac
def verify_webhook_signature(
secret: str,
body: bytes,
signature_header: str,
) -> bool:
if not secret or not signature_header:
return False
expected = hmac.new(
secret.encode("utf-8"),
body,
hashlib.sha256,
).hexdigest()
received = signature_header.replace("sha256=", "").strip()
return hmac.compare_digest(expected, received)
def extract_signature(headers: dict[str, str]) -> str | None:
for key, value in headers.items():
if key.lower() in ("x-bluebubbles-signature", "x-hub-signature-256"):
return value
return None