Initial V2 commit 4

This commit is contained in:
Hamza-Ayed
2026-04-22 23:16:23 +03:00
parent 3269a836a2
commit 3f4afd0f5c
47 changed files with 456 additions and 72 deletions

View File

@@ -8,16 +8,16 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
/**
* HMAC Signature Validation Middleware
* وسيط التحقق من التوقيع الرقمي (HMAC Validation Middleware)
*
* Validates every API request using HMAC-SHA256 signatures.
* Prevents: Replay attacks, Man-in-the-Middle, Tampering.
* الغرض من الملف:
* توفير طبقة أمان إضافية لجميع الطلبات لضمان عدم التلاعب بالبيانات أثناء انتقالها بين التطبيق والخادم.
*
* Required Headers:
* X-API-Key: unique per user (stored in DB)
* X-Timestamp: Unix timestamp (must be within TOLERANCE window)
* X-Signature: HMAC-SHA256(timestamp|api_key|request_body, api_secret)
* X-Nonce: unique per request (prevents replay attacks)
* كيفية العمل:
* 1. يتطلب وجود "توقيع" (Signature) في رأس الطلب (Headers).
* 2. يقوم الخادم بإعادة حساب التوقيع باستخدام مفتاح سري (API Secret) ومقارنته بالتوقيع المرسل.
* 3. يحمي من هجمات "إعادة الإرسال" (Replay Attacks) عن طريق التحقق من الـ Nonce والـ Timestamp.
* 4. يضمن أن البيانات لم تتغير في الطريق (Data Integrity).
*/
class HmacAuthMiddleware
{