|
|
@@ -12,13 +12,13 @@ class SignatureMiddleware
|
|
12
|
12
|
// 1. 获取加密签名
|
|
13
|
13
|
$sign = $request->header('X-Sign');
|
|
14
|
14
|
if (!$sign) {
|
|
15
|
|
- return $this->reject('Missing signature', 401);
|
|
|
15
|
+ return $this->reject('缺少签名', 401);
|
|
16
|
16
|
}
|
|
17
|
17
|
|
|
18
|
18
|
// 2. 读取私钥
|
|
19
|
19
|
$privateKey = file_get_contents(env('RSA_PRIVATE_KEY_PATH'));
|
|
20
|
20
|
if (!$privateKey) {
|
|
21
|
|
- return $this->reject('Server key error', 500);
|
|
|
21
|
+ return $this->reject('服务器密钥错误', 500);
|
|
22
|
22
|
}
|
|
23
|
23
|
|
|
24
|
24
|
// 3. 解密数据
|
|
|
@@ -26,7 +26,7 @@ class SignatureMiddleware
|
|
26
|
26
|
openssl_private_decrypt(base64_decode($sign), $decrypted, $privateKey);
|
|
27
|
27
|
|
|
28
|
28
|
if (!$decrypted || !strpos($decrypted, ':')) {
|
|
29
|
|
- return $this->reject('Invalid signature', 403);
|
|
|
29
|
+ return $this->reject('无效签名', 403);
|
|
30
|
30
|
}
|
|
31
|
31
|
|
|
32
|
32
|
// 4. 分离随机数和时间戳
|
|
|
@@ -34,13 +34,13 @@ class SignatureMiddleware
|
|
34
|
34
|
|
|
35
|
35
|
// 5. 验证时间有效性(5分钟内)
|
|
36
|
36
|
if (abs(time() - $timestamp / 1000) > 300) {
|
|
37
|
|
- return $this->reject('Request expired', 403);
|
|
|
37
|
+ return $this->reject('请求已过期', 403);
|
|
38
|
38
|
}
|
|
39
|
39
|
|
|
40
|
40
|
// 6. 防重放攻击(检查nonce唯一性)
|
|
41
|
41
|
$cacheKey = 'nonce_' . $nonce;
|
|
42
|
42
|
if (Cache::has($cacheKey)) {
|
|
43
|
|
- return $this->reject('Repeated request', 403);
|
|
|
43
|
+ return $this->reject('重复请求', 403);
|
|
44
|
44
|
}
|
|
45
|
45
|
Cache::set($cacheKey, 1, 300); // 5分钟缓存
|
|
46
|
46
|
|