mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-12-04 02:23:59 +00:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
922e762273 | ||
|
|
4c48e992da | ||
|
|
76aaa7d214 | ||
|
|
3047ba97a2 | ||
|
|
c894e38ffa | ||
|
|
72893efd83 | ||
|
|
5cec707d76 | ||
|
|
793733853b | ||
|
|
b0471904fa | ||
|
|
53e921aa80 | ||
|
|
f08dd36635 | ||
|
|
792d7210a7 | ||
|
|
fcf8f3d71f | ||
|
|
4361d96c52 |
No files matched your search
@@ -25,8 +25,8 @@ body:
|
|||||||
id: version
|
id: version
|
||||||
attributes:
|
attributes:
|
||||||
label: 版本号
|
label: 版本号
|
||||||
description: 页面上的版本,或发布包名里的版本,例如 0.4.13。
|
description: 页面上的版本,或发布包名里的版本,例如 0.4.15。
|
||||||
placeholder: "0.4.13"
|
placeholder: "0.4.15"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ body:
|
|||||||
id: version
|
id: version
|
||||||
attributes:
|
attributes:
|
||||||
label: 版本号
|
label: 版本号
|
||||||
description: 例如 0.4.13。不确定就写获取方式。
|
description: 例如 0.4.15。不确定就写获取方式。
|
||||||
placeholder: "0.4.13"
|
placeholder: "0.4.15"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
|
|||||||
@@ -1,22 +1,10 @@
|
|||||||
## 更新内容
|
## v0.4.15
|
||||||
|
|
||||||
- 蓝奏文件页识别 `ajaxfiles.php`(#310):
|
- 浏览器与服务端以相同的 UTF-8 密钥字节处理临时认证,兼容 16、24 和 32 字节的密钥。
|
||||||
- 单文件页 iframe 里的下载 ajax 写成了 `/ajaxfiles.php`。解析器原来只认 `ajaxm.php` 和 `ajaxfile.php`,匹配不上就报「获取失败0, 可能分享已失效」。表单字段没有改。
|
- 临时认证不再使用发行包里的公共密钥。未手动配置的服务实例每次启动生成随机密钥,只记录来源和指纹。保留旧发行包配置的实例也会自动迁移。
|
||||||
- `https://njkn.lanzouw.com/winx123`(无密码)没有失效。修复后本机完整下载 1,197,569 字节,`unzip -t` 无错误。
|
- 捐赠池默认关闭。显式启用后,受支持的网盘使用服务端选号,不再向前端提供捐赠账号。已保存的捐赠记录不会删除。
|
||||||
- 另外三个同样改成 `ajaxfiles.php` 的对照只各下载了 1 MiB Range,返回 206,文件头分别是 7z、zip、zip,没有做完整下载:
|
- 清理网页和文档中的公共密钥。需要网页个人认证、外部客户端或多实例共享密钥的自建站,须显式配置和安全分发 `server.authEncryptKey`。
|
||||||
- `wwn.lanzouy.com/ihLkw1gezutg`
|
|
||||||
- b66477 目录下的 `pan.lanzoui.com/io4y41i3zq5e`
|
|
||||||
- 密码目录 `b00yaejvte` 里的子文件 `w1.lanzn.com/i4VjZ332qzwh`
|
|
||||||
- 带密码的单文件分享没有找到公开样例,没有实测。
|
|
||||||
- 目录按已加载文件名筛选(#311):
|
|
||||||
- 分享目录浏览器和首页解析后的目录共用目录树。两套视图以及独立的 `list.html` 按文件名做大小写不敏感的子串匹配,只筛已经加载的行,不把后续页自动拉完。
|
|
||||||
- 目录树底部「全选 / 取消全选」只作用于当前关键字命中的、已经加载的可选文件。不勾选被筛掉的项,不拉取未加载分页,也不清掉范围外原来的选择。
|
|
||||||
- 分页仍走现有的 `nextCursor` / `pageCursor`。
|
|
||||||
- 界面验收跑在本机开发服务和本机夹具,不是线上分享页。
|
|
||||||
|
|
||||||
## 限制
|
### 升级提醒
|
||||||
|
|
||||||
- 没有把这次界面验收当成线上分享页或全站界面已验。
|
旧公共密钥生成的 `auth` 参数不再兼容。升级后请核对部署配置,并视部署情况清理过往解析缓存和轮换捐赠凭据。
|
||||||
- 三个对照链接只验证了 1 MiB Range,不能据此说这些文件已经完整下载并核对。
|
|
||||||
- 带密码的单文件分享未测。
|
|
||||||
- 本机访问部分蓝奏下载域时连接时好时坏。winx123 曾连续超时,重试后完整下载成功。
|
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
# 一款网盘分享链接云解析快速下载服务
|
# 一款网盘分享链接云解析快速下载服务
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> 如果在线解析失败,可以试试 [NFD Client](https://github.com/qaiu/nfd-client-parser),在本机解析网盘分享链接。[下载安装包](https://github.com/qaiu/nfd-client-parser/releases/latest)
|
||||||
|
|
||||||
QQ交流群:1017480890
|
QQ交流群:1017480890
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/qaiu/netdisk-fast-download/actions/workflows/maven.yml"><img src="https://img.shields.io/github/actions/workflow/status/qaiu/netdisk-fast-download/build.yml?branch=main&style=flat"></a>
|
<a href="https://github.com/qaiu/netdisk-fast-download/actions/workflows/maven.yml"><img src="https://img.shields.io/github/actions/workflow/status/qaiu/netdisk-fast-download/build.yml?branch=main&style=flat"></a>
|
||||||
@@ -159,14 +163,13 @@ GET /json/getFileList?url={分享链接}&pwd={密码}
|
|||||||
- `your_host` 替换为您的域名或 IP
|
- `your_host` 替换为您的域名或 IP
|
||||||
|
|
||||||
### 认证参数(v0.2.1+)
|
### 认证参数(v0.2.1+)
|
||||||
[可以使用在线认证参数加密](https://qaiu.top/nfd-auth.html)
|
|
||||||
部分网盘需要登录后的 Cookie 或 Authorization 才能下载。可通过 `auth` 参数传递认证信息:
|
部分网盘需要登录后的 Cookie 或 Authorization 才能下载。可通过 `auth` 参数传递认证信息:
|
||||||
|
|
||||||
**参数格式**:`auth` 参数值为 AES 加密后的 JSON 字符串,经过 Base64 编码和 URL 编码
|
**参数格式**:`auth` 参数值为 AES 加密后的 JSON 字符串,经过 Base64 编码和 URL 编码
|
||||||
|
|
||||||
**加密方式**:
|
**加密方式**:
|
||||||
- 算法:AES/ECB/PKCS5Padding
|
- 算法:AES/ECB/PKCS5Padding
|
||||||
- 密钥:`nfd_auth_key2026`(16字节)
|
- 密钥:由自建服务显式配置并通过安全渠道交给可信客户端(无公共默认值)
|
||||||
- 流程:JSON → AES加密 → Base64 → URL编码
|
- 流程:JSON → AES加密 → Base64 → URL编码
|
||||||
|
|
||||||
**JSON 结构**:
|
**JSON 结构**:
|
||||||
@@ -195,14 +198,20 @@ GET /json/getFileList?url={分享链接}&pwd={密码}
|
|||||||
GET /parser?url={分享链接}&pwd={密码}&auth={加密后的认证参数}
|
GET /parser?url={分享链接}&pwd={密码}&auth={加密后的认证参数}
|
||||||
```
|
```
|
||||||
|
|
||||||
> 💡 提示:Web 界面已内置认证配置功能,可自动处理加密过程,无需手动构造参数。
|
> 💡 提示:自建站的可信客户端可在网页中填写其显式配置的服务认证密钥;网页不会获取或保存服务端密钥。
|
||||||
> [可以使用在线认证参数加密](https://qaiu.top/nfd-auth.html)
|
> 不要在不受信任的站点输入服务密钥或网盘凭据。
|
||||||
|
|
||||||
|
#### 升级与捐赠开关
|
||||||
|
|
||||||
|
- 没有手动配置密钥(包括升级后仍保留旧发布包默认配置)的实例,在每次启动时自动生成进程随机密钥。启动日志只记录来源和指纹,不输出原文。重启后,之前用进程密钥生成的认证参数会失效。
|
||||||
|
- 要让可信浏览器、外部工具或多实例使用同一密钥,显式配置 `server.authEncryptKey`,通过安全渠道分发;不要使用旧发布包默认值。
|
||||||
|
- 捐赠默认关闭。仅设置 `server.enableDonatedAccounts: true` 且启用数据库后,才允许提交和服务端选用捐赠账号。关闭不删除已有记录。旧的浏览器取号接口已移除。仅 123 云盘、小飞机和蓝奏优享可使用服务端捐赠池;需要在下载响应携带账号请求头的网盘暂不开放。
|
||||||
|
|
||||||
#### 密钥作用说明
|
#### 密钥作用说明
|
||||||
|
|
||||||
- `server.authEncryptKey`
|
- `server.authEncryptKey`
|
||||||
- 作用:用于 `auth` 参数的 AES 加解密
|
- 作用:用于 `auth` 参数的 AES 加解密
|
||||||
- 要求:16位(AES-128)
|
- 要求:16、24 或 32 个 UTF-8 字节
|
||||||
|
|
||||||
- `server.donatedAccountFailureTokenSignKey`
|
- `server.donatedAccountFailureTokenSignKey`
|
||||||
- 作用:用于“捐赠账号失败计数 token”的 HMAC 签名/验签
|
- 作用:用于“捐赠账号失败计数 token”的 HMAC 签名/验签
|
||||||
@@ -470,7 +479,7 @@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtow
|
|||||||
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
||||||
```shell
|
```shell
|
||||||
cd ~
|
cd ~
|
||||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.13/netdisk-fast-download-linux-amd64.zip
|
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.15/netdisk-fast-download-linux-amd64.zip
|
||||||
unzip netdisk-fast-download.zip
|
unzip netdisk-fast-download.zip
|
||||||
cd netdisk-fast-download
|
cd netdisk-fast-download
|
||||||
bash service-install.sh
|
bash service-install.sh
|
||||||
@@ -599,3 +608,14 @@ Core模块集成Vert.x实现类似spring的注解式路由API
|
|||||||
<a href="https://www.dkdun.cn/aff/WDBRYKGH" target="_blank">
|
<a href="https://www.dkdun.cn/aff/WDBRYKGH" target="_blank">
|
||||||
<img src="https://www.dkdun.cn/themes/web/www/upload/local68c2dbb2ab148.png" width="200">
|
<img src="https://www.dkdun.cn/themes/web/www/upload/local68c2dbb2ab148.png" width="200">
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
### 代理资源支持
|
||||||
|
|
||||||
|
<a href="https://proxy-seller.com/?partner=5799A39425654D33">
|
||||||
|
<img src="https://raw.githubusercontent.com/wujunwei928/parse-video-py/main/resources/proxy-seller-logo.png" alt="Proxy-Seller" width="120">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
感谢 [Proxy-Seller](https://proxy-seller.com/?partner=5799A39425654D33) 提供代理 IP 支持,其香港 IP 可用于本项目。
|
||||||
|
|
||||||
|
[Proxy-Seller 优惠链接](https://proxy-seller.com/?partner=5799A39425654D33) · 专属折扣码:`BJSBDD_664959`
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
[English](#security-policy) | [简体中文](#安全政策)
|
||||||
|
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
Thank you for helping keep netdisk-fast-download (NFD) and its users safe.
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Security fixes are provided for the latest stable release. Older releases are not actively maintained and generally do not receive security backports. Users are strongly encouraged to upgrade to the latest stable release.
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| --- | --- |
|
||||||
|
| Latest stable release | ✅ |
|
||||||
|
| Older releases | ❌ |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Please report suspected security vulnerabilities privately through [GitHub Private Vulnerability Reporting](https://github.com/qaiu/netdisk-fast-download/security/advisories/new). Do not disclose unpatched vulnerabilities in public Issues, Pull Requests, Discussions, or other public channels.
|
||||||
|
|
||||||
|
Please include the following information where possible:
|
||||||
|
|
||||||
|
- Affected version or commit
|
||||||
|
- Vulnerability description, affected component, and potential impact
|
||||||
|
- Reproduction steps or a minimal proof of concept
|
||||||
|
- Relevant configuration, logs, and deployment details, with sensitive information redacted
|
||||||
|
|
||||||
|
Do not include real credentials, authentication keys, API tokens, or personal data in your report. Test only systems you own or are authorized to test.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This policy applies to security vulnerabilities in the official NFD project, including authentication, authorization, credential handling, and other security-sensitive functionality.
|
||||||
|
|
||||||
|
Ordinary bugs, upstream API changes, and compatibility issues without a security impact should be reported through [GitHub Issues](https://github.com/qaiu/netdisk-fast-download/issues). Issues caused solely by third-party services, unofficial modifications, or unsafe deployment configurations are generally outside the scope of this policy. However, vulnerabilities in NFD's default configuration or its handling of third-party services remain in scope.
|
||||||
|
|
||||||
|
## Security Response and Disclosure
|
||||||
|
|
||||||
|
Security reports are handled on a best-effort basis, taking into account severity, impact, and maintainer availability. We aim to assess reports, develop appropriate fixes or mitigations, and coordinate public disclosure with reporters where possible. No fixed response or remediation timeframe is guaranteed.
|
||||||
|
|
||||||
|
## Security Best Practices
|
||||||
|
|
||||||
|
- Keep NFD and its dependencies up to date.
|
||||||
|
- Use HTTPS and restrict access to sensitive administrative interfaces.
|
||||||
|
- Protect authentication keys, API tokens, and cloud-drive credentials; never expose them in public logs, frontend bundles, or diagnostic reports.
|
||||||
|
- Enable only the services and optional features you need.
|
||||||
|
- Revoke or rotate potentially compromised credentials promptly.
|
||||||
|
|
||||||
|
## Security Advisories
|
||||||
|
|
||||||
|
For published vulnerabilities, affected versions, fixes, and mitigation guidance, see [GitHub Security Advisories](https://github.com/qaiu/netdisk-fast-download/security/advisories) and [Release Notes](https://github.com/qaiu/netdisk-fast-download/releases).
|
||||||
|
|
||||||
|
## Acknowledgments
|
||||||
|
|
||||||
|
We appreciate everyone who responsibly reports vulnerabilities and helps improve the security of NFD.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 安全政策
|
||||||
|
|
||||||
|
感谢你帮助维护 netdisk-fast-download(NFD)及其用户的安全。
|
||||||
|
|
||||||
|
## 支持的版本
|
||||||
|
|
||||||
|
安全修复面向最新稳定版本。历史版本不再主动维护,原则上不提供安全补丁回移。强烈建议用户及时升级至最新稳定版本。
|
||||||
|
|
||||||
|
| 版本 | 是否支持 |
|
||||||
|
| --- | --- |
|
||||||
|
| 最新稳定版 | ✅ |
|
||||||
|
| 历史版本 | ❌ |
|
||||||
|
|
||||||
|
## 漏洞报告
|
||||||
|
|
||||||
|
请通过 [GitHub 私密漏洞报告](https://github.com/qaiu/netdisk-fast-download/security/advisories/new) 渠道提交疑似安全漏洞。请勿在公开 Issue、Pull Request、Discussion 或其他公开渠道披露尚未修复的漏洞。
|
||||||
|
|
||||||
|
请尽可能提供以下信息:
|
||||||
|
|
||||||
|
- 受影响的版本或提交
|
||||||
|
- 漏洞描述、受影响组件及潜在影响
|
||||||
|
- 复现步骤或最小概念验证
|
||||||
|
- 相关配置、日志及部署信息(请先脱敏)
|
||||||
|
|
||||||
|
请勿在报告中包含真实账号凭据、认证密钥、API 令牌或个人数据。请仅在自己拥有或已获得授权的环境中进行安全测试。
|
||||||
|
|
||||||
|
## 适用范围
|
||||||
|
|
||||||
|
本政策适用于 NFD 官方项目中的安全漏洞,包括身份认证、访问控制、凭据处理及其他涉及安全的功能。
|
||||||
|
|
||||||
|
不涉及安全影响的普通缺陷、上游接口变更及兼容性问题,请通过 [GitHub Issues](https://github.com/qaiu/netdisk-fast-download/issues) 反馈。仅由第三方服务、非官方修改或不安全部署配置引起的问题,原则上不属于本政策的适用范围。但 NFD 默认配置或第三方服务处理逻辑中存在的安全漏洞仍在适用范围内。
|
||||||
|
|
||||||
|
## 安全响应与披露
|
||||||
|
|
||||||
|
维护者将根据漏洞严重程度、影响范围及可用时间尽力处理安全报告,包括漏洞评估、制定修复或缓解措施,并尽可能与报告人协调公开披露。不承诺固定的响应或修复时限。
|
||||||
|
|
||||||
|
## 安全最佳实践
|
||||||
|
|
||||||
|
- 及时更新 NFD 及其依赖组件。
|
||||||
|
- 使用 HTTPS,并限制敏感管理接口的访问权限。
|
||||||
|
- 妥善保管认证密钥、API 令牌及网盘凭据,切勿通过公开日志、前端构建产物或诊断报告泄露。
|
||||||
|
- 仅启用实际需要的服务及可选功能。
|
||||||
|
- 及时撤销或轮换可能泄露的凭据。
|
||||||
|
|
||||||
|
## 安全公告
|
||||||
|
|
||||||
|
已公开的漏洞、影响版本、修复及缓解措施,请参阅 [GitHub 安全公告](https://github.com/qaiu/netdisk-fast-download/security/advisories) 和 [版本发布说明](https://github.com/qaiu/netdisk-fast-download/releases)。
|
||||||
|
|
||||||
|
## 致谢
|
||||||
|
|
||||||
|
感谢所有负责任地报告漏洞并帮助提升 NFD 安全性的研究人员与社区成员。
|
||||||
+4
-4
@@ -4,26 +4,26 @@ NFD 解析器模块:聚合各类网盘/分享页解析,统一输出文件列
|
|||||||
|
|
||||||
- 语言:Java 17
|
- 语言:Java 17
|
||||||
- 构建:Maven
|
- 构建:Maven
|
||||||
- 模块版本:10.2.5
|
- 模块版本:10.2.7
|
||||||
|
|
||||||
## 依赖(Maven Central)
|
## 依赖(Maven Central)
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.qaiu</groupId>
|
<groupId>cn.qaiu</groupId>
|
||||||
<artifactId>parser</artifactId>
|
<artifactId>parser</artifactId>
|
||||||
<version>10.2.5</version>
|
<version>10.2.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
- Gradle Groovy DSL:
|
- Gradle Groovy DSL:
|
||||||
```groovy
|
```groovy
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'cn.qaiu:parser:10.2.5'
|
implementation 'cn.qaiu:parser:10.2.7'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- Gradle Kotlin DSL:
|
- Gradle Kotlin DSL:
|
||||||
```kotlin
|
```kotlin
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("cn.qaiu:parser:10.2.5")
|
implementation("cn.qaiu:parser:10.2.7")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
**加密方式**:
|
**加密方式**:
|
||||||
- 算法:AES/ECB/PKCS5Padding
|
- 算法:AES/ECB/PKCS5Padding
|
||||||
- 密钥:`nfd_auth_key2026`(16字节)
|
- 密钥:由自建服务显式配置并通过安全渠道交给可信客户端(无公共默认值)
|
||||||
- 流程:JSON → AES加密 → Base64 → URL编码
|
- 流程:JSON → AES加密 → Base64 → URL编码
|
||||||
|
|
||||||
**JSON 结构**:
|
**JSON 结构**:
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ URL解码 → Base64解码 → AES解密 → JSON对象
|
|||||||
### 加密配置
|
### 加密配置
|
||||||
|
|
||||||
- **加密算法**: AES/ECB/PKCS5Padding
|
- **加密算法**: AES/ECB/PKCS5Padding
|
||||||
- **密钥长度**: 16位(128位)
|
- **密钥长度**: 16、24 或 32 个 UTF-8 字节
|
||||||
- **默认密钥**: `nfd_auth_key2026`(可在 `app-dev.yml` 中通过 `server.authEncryptKey` 配置)
|
- **密钥**: 没有公共默认值。需要对接的可信客户端应使用自建服务显式配置的 `server.authEncryptKey`。
|
||||||
|
|
||||||
### 密钥作用说明(重要)
|
### 密钥作用说明(重要)
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ URL解码 → Base64解码 → AES解密 → JSON对象
|
|||||||
1. `server.authEncryptKey`
|
1. `server.authEncryptKey`
|
||||||
- 用途:加解密 `auth` 参数(前端/调用方传入的认证信息)
|
- 用途:加解密 `auth` 参数(前端/调用方传入的认证信息)
|
||||||
- 影响范围:`/parser`、`/json/parser`、`/v2/linkInfo` 等接口中的 `auth` 参数
|
- 影响范围:`/parser`、`/json/parser`、`/v2/linkInfo` 等接口中的 `auth` 参数
|
||||||
- 注意:这是 **AES 对称加密密钥**,要求 16 位
|
- 注意:这是 **AES 对称加密密钥**,要求 16、24 或 32 字节
|
||||||
|
|
||||||
2. `server.donatedAccountFailureTokenSignKey`
|
2. `server.donatedAccountFailureTokenSignKey`
|
||||||
- 用途:签名和验签“捐赠账号失败计数 token”(用于防伪造、失败计数)
|
- 用途:签名和验签“捐赠账号失败计数 token”(用于防伪造、失败计数)
|
||||||
@@ -194,7 +194,7 @@ AuthParam decoded = AuthParamCodec.decode(encrypted);
|
|||||||
// 使用 CryptoJS 库
|
// 使用 CryptoJS 库
|
||||||
const CryptoJS = require('crypto-js');
|
const CryptoJS = require('crypto-js');
|
||||||
|
|
||||||
const AUTH_KEY = 'nfd_auth_key2026';
|
const AUTH_KEY = process.env.NFD_AUTH_ENCRYPT_KEY;
|
||||||
|
|
||||||
// 加密
|
// 加密
|
||||||
function encodeAuthParam(authObj) {
|
function encodeAuthParam(authObj) {
|
||||||
@@ -234,7 +234,8 @@ from urllib.parse import quote, unquote
|
|||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
from Crypto.Util.Padding import pad, unpad
|
from Crypto.Util.Padding import pad, unpad
|
||||||
|
|
||||||
AUTH_KEY = b'nfd_auth_key2026'
|
import os
|
||||||
|
AUTH_KEY = os.environ['NFD_AUTH_ENCRYPT_KEY'].encode('utf-8')
|
||||||
|
|
||||||
def encode_auth_param(auth_obj):
|
def encode_auth_param(auth_obj):
|
||||||
"""加密认证参数"""
|
"""加密认证参数"""
|
||||||
@@ -323,8 +324,8 @@ if (auths != null) {
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
server:
|
server:
|
||||||
# auth参数加密密钥(16位AES密钥)
|
# auth参数加密密钥(16、24 或 32 字节)
|
||||||
authEncryptKey: 'your_custom_key16'
|
# authEncryptKey: "" # 仅在可信客户端或多实例需共享密钥时显式配置
|
||||||
|
|
||||||
# 捐赠账号失败计数token签名密钥(HMAC)
|
# 捐赠账号失败计数token签名密钥(HMAC)
|
||||||
# 建议使用较长随机字符串,并与 authEncryptKey 不同
|
# 建议使用较长随机字符串,并与 authEncryptKey 不同
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
## 使用说明
|
## 使用说明
|
||||||
|
|
||||||
1. **编码流程**: JSON对象 → AES加密 → Base64编码 → URL编码
|
1. **编码流程**: JSON对象 → AES加密 → Base64编码 → URL编码
|
||||||
2. **加密配置**: AES/ECB/PKCS5Padding, 密钥: `nfd_auth_key2026` (16位)
|
2. **加密配置**: AES/ECB/PKCS5Padding, 密钥: 自建服务配置值(无公共默认值)
|
||||||
3. **接口调用**: `GET /parser?url={分享链接}&pwd={提取码}&auth={加密认证参数}`
|
3. **接口调用**: `GET /parser?url={分享链接}&pwd={提取码}&auth={加密认证参数}`
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -423,6 +423,38 @@ public class LzTool extends PanBase {
|
|||||||
return "/" + ajax.group(1);
|
return "/" + ajax.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 分享页 / iframe 里的文件 ajax 表单;提取不到时返回 null。 */
|
||||||
|
static Map<String, String> fileAjaxForm(String html, String pwd) {
|
||||||
|
AjaxCall call = extractAjaxFromHtml(html, pwd);
|
||||||
|
return call == null ? null : call.form();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件 ajax 头。官方页把下载 POST 打到 apifile / apifile2 等跨站主机,
|
||||||
|
* 浏览器会带 Origin 且 Sec-Fetch-Site=cross-site;写 same-origin 与 Referer 矛盾,部分出口会被 ESA 拦。
|
||||||
|
*/
|
||||||
|
static MultiMap fileAjaxHeaders(String pageUrl, String ajaxTarget) {
|
||||||
|
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
|
||||||
|
String page = pageUrl == null ? "" : pageUrl.trim();
|
||||||
|
if (!page.isEmpty()) {
|
||||||
|
headers.set("referer", page);
|
||||||
|
}
|
||||||
|
String pageOrigin = normalizeOrigin(originOf(page, ""));
|
||||||
|
String ajaxOrigin = originFromAjaxTarget(ajaxTarget);
|
||||||
|
if (ajaxOrigin.isEmpty()) {
|
||||||
|
ajaxOrigin = pageOrigin;
|
||||||
|
}
|
||||||
|
if (!pageOrigin.isEmpty()) {
|
||||||
|
headers.set("origin", pageOrigin);
|
||||||
|
}
|
||||||
|
if (!ajaxOrigin.isEmpty() && !ajaxOrigin.equalsIgnoreCase(pageOrigin)) {
|
||||||
|
headers.set("Sec-Fetch-Site", "cross-site");
|
||||||
|
} else {
|
||||||
|
headers.set("Sec-Fetch-Site", "same-origin");
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
private static void addAjaxOrigin(List<String> origins, String origin) {
|
private static void addAjaxOrigin(List<String> origins, String origin) {
|
||||||
if (origin != null && origin.contains("://") && !origins.contains(origin)) {
|
if (origin != null && origin.contains("://") && !origins.contains(origin)) {
|
||||||
origins.add(origin);
|
origins.add(origin);
|
||||||
@@ -814,13 +846,12 @@ public class LzTool extends PanBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getDownURL(String referer, AjaxCall call) {
|
private void getDownURL(String referer, AjaxCall call) {
|
||||||
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
|
// 文件 ajax 优先用页面里的绝对地址(常见 apifile / apifile2)。
|
||||||
// 文件 ajax 优先用页面里的绝对地址(常见 apifile.lanzouw.com)。
|
|
||||||
// 页面源站空响应再换 FILE_AJAX_FALLBACK_ORIGINS,wwww 仍在最后。
|
// 页面源站空响应再换 FILE_AJAX_FALLBACK_ORIGINS,wwww 仍在最后。
|
||||||
// iframe / 分享页的 Referer 保持原主机,不把页面 GET 改写到 wwww。
|
// iframe / 分享页的 Referer 保持原主机,不把页面 GET 改写到 wwww。
|
||||||
String page = referer != null && !referer.isBlank() ? referer : resolveShareUrl();
|
String page = referer != null && !referer.isBlank() ? referer : resolveShareUrl();
|
||||||
headers.set("referer", page);
|
|
||||||
String target = call.absoluteUrl() != null ? call.absoluteUrl() : call.path();
|
String target = call.absoluteUrl() != null ? call.absoluteUrl() : call.path();
|
||||||
|
MultiMap headers = fileAjaxHeaders(page, target);
|
||||||
postAjaxAt(fileAjaxOrigins(page, target), 0, call, headers, this::handleAjaxDownResponse, null);
|
postAjaxAt(fileAjaxOrigins(page, target), 0, call, headers, this::handleAjaxDownResponse, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,12 @@ import java.util.zip.CRC32;
|
|||||||
import static cn.qaiu.util.RandomStringGenerator.gen36String;
|
import static cn.qaiu.util.RandomStringGenerator.gen36String;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 123盘解析器 v2 - 使用Android平台API
|
* 123盘解析器。
|
||||||
* 支持账号密码或token配置
|
* 分享单文件走分享域名:先 POST /api/share/download/traffic/check,
|
||||||
|
* 再 POST /api/v2/share/download/info。platform web,App-Version 149。
|
||||||
|
* 域名只由 shareKey 解码出的数字 uid 组成,不使用调用方提供的任意 host。
|
||||||
|
* 文件夹打包下载仍走 App-Version 55 的 batch_download_share_info。
|
||||||
|
* 支持账号密码或 token 配置。
|
||||||
*
|
*
|
||||||
* @author <a href="https://qaiu.top">QAIU</a>
|
* @author <a href="https://qaiu.top">QAIU</a>
|
||||||
*/
|
*/
|
||||||
@@ -41,9 +45,13 @@ public class Ye2Tool extends PanBase {
|
|||||||
|
|
||||||
private static final String API_BASE = "https://api.123278.com";
|
private static final String API_BASE = "https://api.123278.com";
|
||||||
private static final String GET_SHARE_INFO_URL = API_BASE + "/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey={shareKey}&SharePwd={pwd}&ParentFileId={ParentFileId}&Page=1";
|
private static final String GET_SHARE_INFO_URL = API_BASE + "/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey={shareKey}&SharePwd={pwd}&ParentFileId={ParentFileId}&Page=1";
|
||||||
private static final String DOWNLOAD_API_URL = API_BASE + "/b/api/file/download_info";
|
/** 分享页脚本把 /share/download/traffic/check 加上 /api 前缀,发到当前分享域名。 */
|
||||||
private static final String DOWNLOAD_API_V2_BASE = "https://api.123278.com";
|
static final String SHARE_TRAFFIC_CHECK_PATH = "/api/share/download/traffic/check";
|
||||||
private static final String DOWNLOAD_API_V2_PATH = "/b/api/v2/share/download/info";
|
/** 分享页脚本把 /v2/share/download/info 加上 /api 前缀,不是 api.123278.com/b/api。 */
|
||||||
|
static final String SHARE_DOWNLOAD_INFO_PATH = "/api/v2/share/download/info";
|
||||||
|
static final String SHARE_PLATFORM = "web";
|
||||||
|
/** 当前分享页静态资源里的 App-Version。个人文件接口 App-Version 55 会返回 5066。 */
|
||||||
|
static final String SHARE_WEB_APP_VERSION = "149";
|
||||||
private static final String BATCH_DOWNLOAD_API_URL = API_BASE + "/b/api/file/batch_download_share_info";
|
private static final String BATCH_DOWNLOAD_API_URL = API_BASE + "/b/api/file/batch_download_share_info";
|
||||||
private static final String LOGIN_URL = "https://login.123pan.com/api/user/sign_in";
|
private static final String LOGIN_URL = "https://login.123pan.com/api/user/sign_in";
|
||||||
|
|
||||||
@@ -126,28 +134,25 @@ public class Ye2Tool extends PanBase {
|
|||||||
return TokenCache.isExpired(cacheKey);
|
return TokenCache.isExpired(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String crc32(String data) {
|
|
||||||
CRC32 crc32 = new CRC32();
|
|
||||||
crc32.update(data.getBytes());
|
|
||||||
long value = crc32.getValue();
|
|
||||||
return String.format("%08x", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long hexToInt(String hexStr) {
|
|
||||||
return Long.parseLong(hexStr, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String encode123(String url, String way, String version, String timestamp) {
|
private String encode123(String url, String way, String version, String timestamp) {
|
||||||
Random random = new Random();
|
return signQuery(url, way, version, Long.parseLong(timestamp), nextSignRandom());
|
||||||
int randomInt = random.nextInt(10000000) + 1;
|
}
|
||||||
long a = (10000000L * randomInt) / 10000;
|
|
||||||
|
|
||||||
long timeLong = Long.parseLong(timestamp) / 1000;
|
private static long nextSignRandom() {
|
||||||
|
int randomInt = new Random().nextInt(10000000) + 1;
|
||||||
|
return (10000000L * randomInt) / 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名原文:unix秒|随机数|实际路径|platform|App-Version|时间混淆值。
|
||||||
|
* 分享下载的路径是 /api/...,platform 是 web,版本是 149。
|
||||||
|
*/
|
||||||
|
static String signMaterial(String url, String way, String version, long timeMillis, long randomA) {
|
||||||
|
long timeLong = timeMillis / 1000;
|
||||||
java.time.LocalDateTime dateTime = java.time.Instant.ofEpochSecond(timeLong)
|
java.time.LocalDateTime dateTime = java.time.Instant.ofEpochSecond(timeLong)
|
||||||
.atZone(java.time.ZoneId.systemDefault())
|
.atZone(java.time.ZoneId.systemDefault())
|
||||||
.toLocalDateTime();
|
.toLocalDateTime();
|
||||||
String timeStr = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
|
String timeStr = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
|
||||||
|
|
||||||
StringBuilder g = new StringBuilder();
|
StringBuilder g = new StringBuilder();
|
||||||
for (char c : timeStr.toCharArray()) {
|
for (char c : timeStr.toCharArray()) {
|
||||||
int digit = Character.getNumericValue(c);
|
int digit = Character.getNumericValue(c);
|
||||||
@@ -157,11 +162,22 @@ public class Ye2Tool extends PanBase {
|
|||||||
g.append(CHAR_MAP.charAt(digit - 1));
|
g.append(CHAR_MAP.charAt(digit - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String y = String.valueOf(crc32Decimal(g.toString()));
|
||||||
|
return timeLong + "|" + randomA + "|" + url + "|" + way + "|" + version + "|" + y;
|
||||||
|
}
|
||||||
|
|
||||||
String y = String.valueOf(hexToInt(crc32(g.toString())));
|
static String signQuery(String url, String way, String version, long timeMillis, long randomA) {
|
||||||
String finalCrcInput = String.format("%d|%d|%s|%s|%s|%s", timeLong, a, url, way, version, y);
|
String material = signMaterial(url, way, version, timeMillis, randomA);
|
||||||
String finalCrc = String.valueOf(hexToInt(crc32(finalCrcInput)));
|
String y = material.substring(material.lastIndexOf('|') + 1);
|
||||||
return String.format("?%s=%d-%d-%s", y, timeLong, a, finalCrc);
|
long timeLong = timeMillis / 1000;
|
||||||
|
String finalCrc = String.valueOf(crc32Decimal(material));
|
||||||
|
return "?" + y + "=" + timeLong + "-" + randomA + "-" + finalCrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long crc32Decimal(String data) {
|
||||||
|
CRC32 crc32 = new CRC32();
|
||||||
|
crc32.update(data.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
return crc32.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Future<String> parse() {
|
public Future<String> parse() {
|
||||||
@@ -210,15 +226,14 @@ public class Ye2Tool extends PanBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JsonObject fileInfo = data.getJsonArray("InfoList").getJsonObject(0);
|
JsonObject fileInfo = data.getJsonArray("InfoList").getJsonObject(0);
|
||||||
if (token.equals("nologin")) {
|
|
||||||
fail(loginRequiredDownloadMessage(false, null));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileInfo.getInteger("Type", 0) == 1) {
|
if (fileInfo.getInteger("Type", 0) == 1) {
|
||||||
|
if (!hasUsableToken(token)) {
|
||||||
|
fail(loginRequiredDownloadMessage(false, null));
|
||||||
|
return;
|
||||||
|
}
|
||||||
getZipDownUrl(client, fileInfo);
|
getZipDownUrl(client, fileInfo);
|
||||||
} else {
|
} else {
|
||||||
getDownUrl(client, fileInfo);
|
getDownUrl(fileInfo, token);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.onFailure(this.handleFail(GET_SHARE_INFO_URL));
|
.onFailure(this.handleFail(GET_SHARE_INFO_URL));
|
||||||
@@ -317,112 +332,55 @@ public class Ye2Tool extends PanBase {
|
|||||||
return promise.future();
|
return promise.future();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDownUrl(WebClient client, JsonObject fileInfo) {
|
/**
|
||||||
|
* 分享单文件:流量预检通过后走分享域名 v2。不回退个人文件接口,也不创建订单。
|
||||||
|
*/
|
||||||
|
private void getDownUrl(JsonObject fileInfo, String token) {
|
||||||
setFileInfo(fileInfo);
|
setFileInfo(fileInfo);
|
||||||
|
|
||||||
String normalizedShareKey = YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey());
|
String normalizedShareKey = YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey());
|
||||||
if (StringUtils.isNotEmpty(normalizedShareKey)) {
|
applyResolvedShareKey(shareLinkInfo, normalizedShareKey);
|
||||||
JsonObject v2Body = new JsonObject()
|
Integer fileId = fileInfo.getInteger("FileId");
|
||||||
.put("ShareKey", normalizedShareKey)
|
if (!usableShareKey(normalizedShareKey) || fileId == null) {
|
||||||
.put("FileID", fileInfo.getInteger("FileId"))
|
fail("123网盘公开下载参数缺少分享标识");
|
||||||
.put("S3keyFlag", fileInfo.getString("S3KeyFlag"))
|
|
||||||
.put("Size", fileInfo.getLong("Size"))
|
|
||||||
.put("Etag", fileInfo.getString("Etag"));
|
|
||||||
requestShareV2Download(normalizedShareKey, v2Body).onSuccess(v2Url -> {
|
|
||||||
if (StringUtils.isNotEmpty(v2Url)) {
|
|
||||||
complete(v2Url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
requestLegacyDownUrl(client, fileInfo);
|
|
||||||
}).onFailure(err -> {
|
|
||||||
log.warn("Ye2 v2分享下载接口失败,回退旧接口: {}", err.getMessage());
|
|
||||||
requestLegacyDownUrl(client, fileInfo);
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long size = fileInfo.getLong("Size") == null ? 0L : fileInfo.getLong("Size");
|
||||||
requestLegacyDownUrl(client, fileInfo);
|
requestShareDownload(normalizedShareKey, fileId, fileInfo.getString("S3KeyFlag"), size,
|
||||||
|
fileInfo.getString("Etag"), token).onSuccess(this::complete)
|
||||||
|
.onFailure(err -> fail(err.getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestLegacyDownUrl(WebClient client, JsonObject fileInfo) {
|
private Future<String> requestShareDownload(String shareKey, long fileId, String s3keyFlag, long size,
|
||||||
JsonObject jsonObject = new JsonObject();
|
String etag, String token) {
|
||||||
jsonObject.put("driveId", 0);
|
return executeShareFileDownload(this::postShareJson, new ShareFileRequest(
|
||||||
jsonObject.put("etag", fileInfo.getString("Etag"));
|
shareLinkInfo.getShareUrl(),
|
||||||
jsonObject.put("fileId", fileInfo.getInteger("FileId"));
|
shareLinkInfo.getStandardUrl(),
|
||||||
jsonObject.put("fileName", fileInfo.getString("FileName"));
|
shareKey,
|
||||||
jsonObject.put("s3keyFlag", fileInfo.getString("S3KeyFlag"));
|
shareLinkInfo.getSharePassword(),
|
||||||
jsonObject.put("size", fileInfo.getLong("Size"));
|
fileId,
|
||||||
jsonObject.put("type", 0);
|
s3keyFlag,
|
||||||
|
size,
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
etag,
|
||||||
String encryptedParams = encode123("/b/api/file/download_info", "android", "55", timestamp);
|
token,
|
||||||
String apiUrl = DOWNLOAD_API_URL + encryptedParams;
|
System.currentTimeMillis(),
|
||||||
|
nextSignRandom()));
|
||||||
log.info("Ye2 API URL: {}", apiUrl);
|
|
||||||
|
|
||||||
HttpRequest<Buffer> bufferHttpRequest = client.postAbs(apiUrl);
|
|
||||||
bufferHttpRequest.putHeader("platform", "android");
|
|
||||||
bufferHttpRequest.putHeader("App-Version", "55");
|
|
||||||
bufferHttpRequest.putHeader("Authorization", "Bearer " + TokenCache.getToken(cacheKey));
|
|
||||||
bufferHttpRequest.putHeader("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36");
|
|
||||||
bufferHttpRequest.putHeader("Content-Type", "application/json");
|
|
||||||
|
|
||||||
bufferHttpRequest
|
|
||||||
.sendJsonObject(jsonObject)
|
|
||||||
.onSuccess(res2 -> handleDownloadUrlResponse(client, asJson(res2), "Ye2"))
|
|
||||||
.onFailure(err -> fail("下载接口失败: " + err.getMessage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<String> requestShareV2Download(String shareKey, JsonObject body) {
|
private Future<JsonObject> postShareJson(ShareHttpCall call) {
|
||||||
Promise<String> promise = Promise.promise();
|
Promise<JsonObject> promise = Promise.promise();
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
HttpRequest<Buffer> request = client.postAbs(call.url());
|
||||||
String encryptedParams = encode123(DOWNLOAD_API_V2_PATH, "web", "3", timestamp);
|
call.headers.forEach(entry -> request.putHeader(entry.getKey(), entry.getValue()));
|
||||||
String apiUrl = DOWNLOAD_API_V2_BASE + DOWNLOAD_API_V2_PATH + encryptedParams;
|
request.sendJsonObject(call.body)
|
||||||
String shareOrigin = resolveYeShareOrigin(shareKey);
|
.onSuccess(resp -> promise.complete(asJson(resp)))
|
||||||
String shareReferer = buildShareReferer(shareOrigin, shareKey, shareLinkInfo.getSharePassword());
|
.onFailure(promise::fail);
|
||||||
|
|
||||||
HttpRequest<Buffer> request = client.postAbs(apiUrl);
|
|
||||||
request.putHeader("Accept", "*/*");
|
|
||||||
request.putHeader("Authorization", "Bearer " + TokenCache.getToken(cacheKey));
|
|
||||||
request.putHeader("App-Version", "3");
|
|
||||||
request.putHeader("platform", "web");
|
|
||||||
request.putHeader("Origin", shareOrigin);
|
|
||||||
request.putHeader("Referer", shareReferer);
|
|
||||||
request.putHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36");
|
|
||||||
request.putHeader("Content-Type", "application/json;charset=UTF-8");
|
|
||||||
|
|
||||||
request.sendJsonObject(body).onSuccess(resp -> {
|
|
||||||
JsonObject json = asJson(resp);
|
|
||||||
if (json == null || json.getInteger("code", -1) != 0) {
|
|
||||||
promise.fail("v2接口返回异常: " + (json == null ? "null" : json.encode()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JsonObject data = json.getJsonObject("data", new JsonObject());
|
|
||||||
JsonArray dispatchList = data.getJsonArray("dispatchList", new JsonArray());
|
|
||||||
String downloadPath = data.getString("downloadPath");
|
|
||||||
if (StringUtils.isBlank(downloadPath)) {
|
|
||||||
promise.complete("");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String prefix = "";
|
|
||||||
if (dispatchList.size() > 0) {
|
|
||||||
JsonObject firstDispatch = dispatchList.getJsonObject(0);
|
|
||||||
if (firstDispatch != null) {
|
|
||||||
prefix = firstDispatch.getString("prefix", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(prefix)) {
|
|
||||||
promise.complete(downloadPath);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String finalUrl = prefix.endsWith("/") ? prefix.substring(0, prefix.length() - 1) : prefix;
|
|
||||||
finalUrl += downloadPath.startsWith("/") ? downloadPath : "/" + downloadPath;
|
|
||||||
promise.complete(finalUrl);
|
|
||||||
}).onFailure(promise::fail);
|
|
||||||
|
|
||||||
return promise.future();
|
return promise.future();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹打包下载仍使用 App-Version 55 的 /b/api/file/batch_download_share_info。
|
||||||
|
* 分享页脚本已改走 /v2/file/batch_download_share_info,这次不改这条路径。
|
||||||
|
*/
|
||||||
private void getZipDownUrl(WebClient client, JsonObject fileInfo) {
|
private void getZipDownUrl(WebClient client, JsonObject fileInfo) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.put("shareKey", YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey()));
|
jsonObject.put("shareKey", YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey()));
|
||||||
@@ -691,76 +649,322 @@ public class Ye2Tool extends PanBase {
|
|||||||
Future<String> tokenFuture = resolveTokenFuture();
|
Future<String> tokenFuture = resolveTokenFuture();
|
||||||
|
|
||||||
tokenFuture.onSuccess(token -> {
|
tokenFuture.onSuccess(token -> {
|
||||||
if (token.equals("nologin")) {
|
if (hasUsableToken(token)) {
|
||||||
fail(loginRequiredDownloadMessage(false, null));
|
TokenCache.putToken(cacheKey, token);
|
||||||
|
}
|
||||||
|
String normalizedShareKey = resolveDownloadShareKey(paramJson, shareLinkInfo.getShareKey());
|
||||||
|
applyResolvedShareKey(shareLinkInfo, normalizedShareKey);
|
||||||
|
if (!usableShareKey(normalizedShareKey)) {
|
||||||
|
fail("123网盘公开下载参数缺少分享标识");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
long fileId = paramJson.getLong("fileId", paramJson.getLong("FileID", 0L));
|
||||||
String rawShareKey = paramJson.getString("shareKey");
|
String s3keyFlag = firstNonBlank(paramJson, "s3keyFlag", "S3keyFlag", "S3KeyFlag");
|
||||||
if (StringUtils.isBlank(rawShareKey)) {
|
long size = paramJson.getLong("size", paramJson.getLong("Size", 0L));
|
||||||
rawShareKey = paramJson.getString("ShareKey");
|
String etag = firstNonBlank(paramJson, "etag", "Etag");
|
||||||
}
|
requestShareDownload(normalizedShareKey, fileId, s3keyFlag, size, etag, token)
|
||||||
if (StringUtils.isBlank(rawShareKey)) {
|
.onSuccess(this::complete)
|
||||||
rawShareKey = shareLinkInfo.getShareKey();
|
.onFailure(err -> fail(err.getMessage()));
|
||||||
}
|
|
||||||
String normalizedShareKey = YeShareHostUtil.normalizeShareKey(rawShareKey);
|
|
||||||
if (StringUtils.isNotEmpty(normalizedShareKey)) {
|
|
||||||
JsonObject v2Body = new JsonObject()
|
|
||||||
.put("ShareKey", normalizedShareKey)
|
|
||||||
.put("FileID", paramJson.getInteger("fileId", paramJson.getInteger("FileID", 0)))
|
|
||||||
.put("S3keyFlag", paramJson.getString("s3keyFlag", paramJson.getString("S3keyFlag", "")))
|
|
||||||
.put("Size", paramJson.getLong("size", paramJson.getLong("Size", 0L)))
|
|
||||||
.put("Etag", paramJson.getString("etag", paramJson.getString("Etag", "")));
|
|
||||||
requestShareV2Download(normalizedShareKey, v2Body).onSuccess(v2Url -> {
|
|
||||||
if (StringUtils.isNotEmpty(v2Url)) {
|
|
||||||
complete(v2Url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parseByIdLegacy(token, paramJson);
|
|
||||||
}).onFailure(err -> {
|
|
||||||
log.warn("Ye2 parseById v2接口失败,回退旧接口: {}", err.getMessage());
|
|
||||||
parseByIdLegacy(token, paramJson);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
parseByIdLegacy(token, paramJson);
|
|
||||||
}).onFailure(err -> fail("123盘解析异常: " + err.getMessage()));
|
}).onFailure(err -> fail("123盘解析异常: " + err.getMessage()));
|
||||||
|
|
||||||
return promise.future();
|
return promise.future();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseByIdLegacy(String token, JsonObject paramJson) {
|
static final class ShareFileRequest {
|
||||||
if (paramJson.containsKey("FileID") && !paramJson.containsKey("fileId")) {
|
final String shareUrl;
|
||||||
paramJson.put("fileId", paramJson.getValue("FileID"));
|
final String standardUrl;
|
||||||
|
final String shareKey;
|
||||||
|
final String password;
|
||||||
|
final long fileId;
|
||||||
|
final String s3keyFlag;
|
||||||
|
final long size;
|
||||||
|
final String etag;
|
||||||
|
final String token;
|
||||||
|
final long timeMillis;
|
||||||
|
final long randomA;
|
||||||
|
|
||||||
|
ShareFileRequest(String shareUrl, String standardUrl, String shareKey, String password, long fileId,
|
||||||
|
String s3keyFlag, long size, String etag, String token, long timeMillis, long randomA) {
|
||||||
|
this.shareUrl = shareUrl;
|
||||||
|
this.standardUrl = standardUrl;
|
||||||
|
this.shareKey = shareKey;
|
||||||
|
this.password = password;
|
||||||
|
this.fileId = fileId;
|
||||||
|
this.s3keyFlag = s3keyFlag;
|
||||||
|
this.size = size;
|
||||||
|
this.etag = etag;
|
||||||
|
this.token = token;
|
||||||
|
this.timeMillis = timeMillis;
|
||||||
|
this.randomA = randomA;
|
||||||
}
|
}
|
||||||
if (paramJson.containsKey("S3keyFlag") && !paramJson.containsKey("s3keyFlag")) {
|
}
|
||||||
paramJson.put("s3keyFlag", paramJson.getValue("S3keyFlag"));
|
|
||||||
}
|
static final class ShareHttpCall {
|
||||||
if (paramJson.containsKey("Size") && !paramJson.containsKey("size")) {
|
final String origin;
|
||||||
paramJson.put("size", paramJson.getValue("Size"));
|
final String path;
|
||||||
}
|
final String query;
|
||||||
if (paramJson.containsKey("Etag") && !paramJson.containsKey("etag")) {
|
final JsonObject body;
|
||||||
paramJson.put("etag", paramJson.getValue("Etag"));
|
final MultiMap headers;
|
||||||
|
|
||||||
|
ShareHttpCall(String origin, String path, String query, JsonObject body, MultiMap headers) {
|
||||||
|
this.origin = origin;
|
||||||
|
this.path = path;
|
||||||
|
this.query = query;
|
||||||
|
this.body = body;
|
||||||
|
this.headers = headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
String url() {
|
||||||
String encryptedParams = encode123("/b/api/file/download_info", "android", "55", timestamp);
|
return origin + path + query;
|
||||||
String apiUrl = DOWNLOAD_API_URL + encryptedParams;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Ye2 parseById API URL: {}", apiUrl);
|
@FunctionalInterface
|
||||||
|
interface ShareJsonPost {
|
||||||
|
Future<JsonObject> post(ShareHttpCall call);
|
||||||
|
}
|
||||||
|
|
||||||
HttpRequest<Buffer> bufferHttpRequest = client.postAbs(apiUrl);
|
/**
|
||||||
bufferHttpRequest.putHeader("platform", "android");
|
* 分享接口只发到 key 解码出的 https://{uid}.share.123pan.cn。
|
||||||
bufferHttpRequest.putHeader("App-Version", "55");
|
* mshare、/s/ 和调用方写入的其它 host 都不能改变这个目标。
|
||||||
bufferHttpRequest.putHeader("Authorization", "Bearer " + token);
|
*/
|
||||||
bufferHttpRequest.putHeader("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36");
|
static String shareApiOrigin(String shareUrl, String standardUrl, String shareKey) {
|
||||||
bufferHttpRequest.putHeader("Content-Type", "application/json");
|
String uid = YeShareHostUtil.getNumericSubdomainIdByShareKey(shareKey);
|
||||||
|
if (!uid.matches("\\d+")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (hostileShareHost(shareUrl) || hostileShareHost(standardUrl)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return "https://" + uid + ".share.123pan.cn";
|
||||||
|
}
|
||||||
|
|
||||||
bufferHttpRequest
|
/**
|
||||||
.sendJsonObject(paramJson)
|
* 调用方给出的地址如果带了 host,只允许空、普通网页,或与 shareKey 一致的数字分享域名。
|
||||||
.onSuccess(res2 -> handleDownloadUrlResponse(client, asJson(res2), "Ye2"))
|
* 127.0.0.1、云元数据、以及伪装成 123 域名的其它 host 直接拒绝。
|
||||||
.onFailure(err -> fail("下载接口失败: " + err.getMessage()));
|
*/
|
||||||
|
static boolean hostileShareHost(String url) {
|
||||||
|
if (StringUtils.isBlank(url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
java.net.URI uri;
|
||||||
|
try {
|
||||||
|
uri = java.net.URI.create(url.trim());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String host = uri.getHost();
|
||||||
|
if (host == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String scheme = uri.getScheme();
|
||||||
|
if (!"https".equalsIgnoreCase(scheme) && !"http".equalsIgnoreCase(scheme)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (uri.getUserInfo() != null || uri.getPort() > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (host.equalsIgnoreCase("www.123pan.com") || host.equalsIgnoreCase("yun.123pan.com")
|
||||||
|
|| host.equalsIgnoreCase("123pan.com")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !host.matches("(?i)\\d+\\.(?:mshare|share)\\.123pan\\.cn");
|
||||||
|
}
|
||||||
|
|
||||||
|
static JsonObject trafficCheckBody(String shareKey, long fileId) {
|
||||||
|
return new JsonObject()
|
||||||
|
.put("shareKey", shareKey)
|
||||||
|
.put("fileIds", new JsonArray().add(fileId));
|
||||||
|
}
|
||||||
|
|
||||||
|
static JsonObject downloadInfoBody(String shareKey, long fileId, String s3keyFlag, long size, String etag) {
|
||||||
|
return new JsonObject()
|
||||||
|
.put("ShareKey", shareKey)
|
||||||
|
.put("FileID", fileId)
|
||||||
|
.put("S3keyFlag", s3keyFlag == null ? "" : s3keyFlag)
|
||||||
|
.put("Size", size)
|
||||||
|
.put("Etag", etag == null ? "" : etag);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String trafficStopMessage(JsonObject data) {
|
||||||
|
if (data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(data.getBoolean("isBlocked"))) {
|
||||||
|
return "123网盘限制了这个分享的下载。解析器不会自动下单或选择付费流量。";
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(data.getBoolean("isPay"))) {
|
||||||
|
return "123网盘这个文件需要付费后下载。解析器不会自动下单或选择付费流量。";
|
||||||
|
}
|
||||||
|
if (Boolean.TRUE.equals(data.getBoolean("isTrafficExceeded"))) {
|
||||||
|
return "123网盘分享提取流量不足。解析器不会自动购买或选择付费流量。";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String joinDownloadUrl(String downloadPath, String prefix) {
|
||||||
|
if (StringUtils.isBlank(downloadPath)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String path = downloadPath.trim();
|
||||||
|
if (path.startsWith("//")) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (isAbsoluteHttp(path)) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(prefix) || !isAbsoluteHttp(prefix.trim())) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String normalizedPrefix = prefix.trim();
|
||||||
|
if (normalizedPrefix.endsWith("/") && path.startsWith("/")) {
|
||||||
|
return normalizedPrefix.substring(0, normalizedPrefix.length() - 1) + path;
|
||||||
|
}
|
||||||
|
if (!normalizedPrefix.endsWith("/") && !path.startsWith("/")) {
|
||||||
|
return normalizedPrefix + "/" + path;
|
||||||
|
}
|
||||||
|
return normalizedPrefix + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isAbsoluteHttp(String value) {
|
||||||
|
return value.startsWith("https://") || value.startsWith("http://");
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<String> executeShareFileDownload(ShareJsonPost post, ShareFileRequest request) {
|
||||||
|
String origin = shareApiOrigin(request.shareUrl, request.standardUrl, request.shareKey);
|
||||||
|
if (origin == null || !usableShareKey(request.shareKey)) {
|
||||||
|
return Future.failedFuture("123网盘公开下载参数缺少可识别的分享域名");
|
||||||
|
}
|
||||||
|
String referer = origin + "/123pan/" + YeShareHostUtil.normalizeShareKey(request.shareKey);
|
||||||
|
if (StringUtils.isNotBlank(request.password)) {
|
||||||
|
referer = referer + "?pwd=" + request.password;
|
||||||
|
}
|
||||||
|
MultiMap headers = shareHeaders(origin, referer, request.token);
|
||||||
|
ShareHttpCall traffic = new ShareHttpCall(
|
||||||
|
origin,
|
||||||
|
SHARE_TRAFFIC_CHECK_PATH,
|
||||||
|
signQuery(SHARE_TRAFFIC_CHECK_PATH, SHARE_PLATFORM, SHARE_WEB_APP_VERSION,
|
||||||
|
request.timeMillis, request.randomA),
|
||||||
|
trafficCheckBody(request.shareKey, request.fileId),
|
||||||
|
headers);
|
||||||
|
ShareHttpCall download = new ShareHttpCall(
|
||||||
|
origin,
|
||||||
|
SHARE_DOWNLOAD_INFO_PATH,
|
||||||
|
signQuery(SHARE_DOWNLOAD_INFO_PATH, SHARE_PLATFORM, SHARE_WEB_APP_VERSION,
|
||||||
|
request.timeMillis, request.randomA),
|
||||||
|
downloadInfoBody(request.shareKey, request.fileId, request.s3keyFlag, request.size, request.etag),
|
||||||
|
headers);
|
||||||
|
return post.post(traffic).compose(json -> {
|
||||||
|
if (json == null || json.getInteger("code", -1) != 0) {
|
||||||
|
return Future.failedFuture(shareV2FailureMessage(json, request.token));
|
||||||
|
}
|
||||||
|
String stop = trafficStopMessage(json.getJsonObject("data"));
|
||||||
|
if (stop != null) {
|
||||||
|
return Future.failedFuture(stop);
|
||||||
|
}
|
||||||
|
return post.post(download);
|
||||||
|
}).compose(json -> {
|
||||||
|
if (json == null || json.getInteger("code", -1) != 0) {
|
||||||
|
return Future.failedFuture(shareV2FailureMessage(json, request.token));
|
||||||
|
}
|
||||||
|
JsonObject data = json.getJsonObject("data", new JsonObject());
|
||||||
|
JsonArray dispatchList = data.getJsonArray("dispatchList", new JsonArray());
|
||||||
|
String prefix = "";
|
||||||
|
if (!dispatchList.isEmpty() && dispatchList.getJsonObject(0) != null) {
|
||||||
|
prefix = dispatchList.getJsonObject(0).getString("prefix", "");
|
||||||
|
}
|
||||||
|
String url = joinDownloadUrl(data.getString("downloadPath"), prefix);
|
||||||
|
if (StringUtils.isBlank(url)) {
|
||||||
|
return Future.failedFuture("123网盘公开下载接口未返回下载链接");
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MultiMap shareHeaders(String origin, String referer, String token) {
|
||||||
|
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||||
|
headers.set("Accept", "*/*");
|
||||||
|
headers.set("App-Version", SHARE_WEB_APP_VERSION);
|
||||||
|
headers.set("platform", SHARE_PLATFORM);
|
||||||
|
headers.set("Origin", origin);
|
||||||
|
headers.set("Referer", referer);
|
||||||
|
headers.set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36");
|
||||||
|
headers.set("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
String authorization = bearerAuthorization(token);
|
||||||
|
if (authorization != null) {
|
||||||
|
headers.set("Authorization", authorization);
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String firstNonBlank(JsonObject json, String... keys) {
|
||||||
|
if (json == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
for (String key : keys) {
|
||||||
|
String value = json.getString(key);
|
||||||
|
if (StringUtils.isNotBlank(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
static String resolveDownloadShareKey(JsonObject paramJson, String fallbackShareKey) {
|
||||||
|
String shareKey = paramJson == null ? null : paramJson.getString("shareKey");
|
||||||
|
if (StringUtils.isBlank(shareKey) && paramJson != null) {
|
||||||
|
shareKey = paramJson.getString("ShareKey");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(shareKey)) {
|
||||||
|
shareKey = fallbackShareKey;
|
||||||
|
}
|
||||||
|
return YeShareHostUtil.normalizeShareKey(shareKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean usableShareKey(String shareKey) {
|
||||||
|
return StringUtils.isNotBlank(shareKey) && !"-".equals(shareKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getFileDownInfo / redirectUrl 用 shareKey="-" 占位,错误文案会变成 /s/-。
|
||||||
|
* 目录参数里已有真实 shareKey 时,只替换这个占位地址。
|
||||||
|
*/
|
||||||
|
static void applyResolvedShareKey(ShareLinkInfo info, String shareKey) {
|
||||||
|
if (info == null || !usableShareKey(shareKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
info.setShareKey(shareKey);
|
||||||
|
String rebuilt = "https://www.123pan.com/s/" + shareKey;
|
||||||
|
if (isPlaceholderYeShareUrl(info.getShareUrl())) {
|
||||||
|
info.setShareUrl(rebuilt);
|
||||||
|
}
|
||||||
|
if (isPlaceholderYeShareUrl(info.getStandardUrl())) {
|
||||||
|
info.setStandardUrl(rebuilt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isPlaceholderYeShareUrl(String url) {
|
||||||
|
return StringUtils.isNotBlank(url) && (url.endsWith("/s/-") || url.endsWith("/s/-.html"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static String bearerAuthorization(String token) {
|
||||||
|
return hasUsableToken(token) ? "Bearer " + token : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* v2 非 0 的说明。5112 仍用现有登录提示;5113、5066 原样留在 v2 错误里,不再改写成个人文件接口的文案。
|
||||||
|
*/
|
||||||
|
static String shareV2FailureMessage(JsonObject json, String token) {
|
||||||
|
Integer code = json == null ? null : json.getInteger("code");
|
||||||
|
String message = json == null ? null : json.getString("message");
|
||||||
|
if (isYeLoginRequired(code, message)) {
|
||||||
|
return loginRequiredDownloadMessage(hasUsableToken(token), message);
|
||||||
|
}
|
||||||
|
return "v2接口返回异常: " + (json == null ? "null" : json.encode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasUsableToken(String token) {
|
||||||
|
return StringUtils.isNotBlank(token) && !"nologin".equals(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFileTimes(JsonObject item, FileInfo fileInfo) {
|
private void setFileTimes(JsonObject item, FileInfo fileInfo) {
|
||||||
|
|||||||
@@ -92,7 +92,17 @@ public class HttpResponseHelper {
|
|||||||
|
|
||||||
// -------------------- Buffer 转换 --------------------
|
// -------------------- Buffer 转换 --------------------
|
||||||
private static Buffer toBuffer(HttpResponse<?> res) {
|
private static Buffer toBuffer(HttpResponse<?> res) {
|
||||||
return res.body() instanceof Buffer ? (Buffer) res.body() : Buffer.buffer(res.bodyAsString());
|
Object raw = res.body();
|
||||||
|
if (raw instanceof Buffer buf) {
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
// 407/空 body 时 body() 与 bodyAsString() 都可能是 null,Buffer.buffer(null) 会 NPE,
|
||||||
|
// 最终被当成「ajax 返回非JSON: 空响应」。
|
||||||
|
if (raw == null) {
|
||||||
|
return Buffer.buffer();
|
||||||
|
}
|
||||||
|
String text = res.bodyAsString();
|
||||||
|
return text == null ? Buffer.buffer() : Buffer.buffer(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureBodyLimit(Buffer body) {
|
private static void ensureBodyLimit(Buffer body) {
|
||||||
|
|||||||
@@ -237,4 +237,51 @@ public class LzToolShareUrlTest {
|
|||||||
assertEquals("https://wwww.lanzoux.com", origins.get(origins.size() - 1));
|
assertEquals("https://wwww.lanzoux.com", origins.get(origins.size() - 1));
|
||||||
assertFalse(origins.get(0).contains("wwww"));
|
assertFalse(origins.get(0).contains("wwww"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void passwordPageUsesApifile2AndIsngisSign() {
|
||||||
|
String html = """
|
||||||
|
<div class="passwddiv-btn" onclick="down_p();"></div>
|
||||||
|
<input id="pwd" />
|
||||||
|
<script type="text/javascript">
|
||||||
|
function down_p(){
|
||||||
|
var kdns =1;
|
||||||
|
var isngis = '';
|
||||||
|
var isngis = 'SIGNVALUEFROMISNGIS';
|
||||||
|
var pwd =document.getElementById('pwd').value;
|
||||||
|
$.ajax({
|
||||||
|
type : 'post',
|
||||||
|
url : 'https://apifile2.woozooo.com/ajaxfile.php?file=333149117',
|
||||||
|
data : { 'action':'downprocess','sign':isngis,'kd':kdns,'p':pwd, },
|
||||||
|
dataType : 'json'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
""";
|
||||||
|
String target = LzTool.fileAjaxTarget(html);
|
||||||
|
assertEquals("https://apifile2.woozooo.com/ajaxfile.php?file=333149117", target);
|
||||||
|
Map<String, String> form = LzTool.fileAjaxForm(html, "1t54");
|
||||||
|
assertEquals("downprocess", form.get("action"));
|
||||||
|
assertEquals("SIGNVALUEFROMISNGIS", form.get("sign"));
|
||||||
|
assertEquals("1", form.get("kd"));
|
||||||
|
assertEquals("1t54", form.get("p"));
|
||||||
|
List<String> origins = LzTool.fileAjaxOrigins("https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
|
||||||
|
assertEquals("https://apifile2.woozooo.com", origins.get(0));
|
||||||
|
|
||||||
|
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
|
||||||
|
"https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
|
||||||
|
assertEquals("https://wwaov.lanzouw.com/iNUOu4hbih4h", headers.get("referer"));
|
||||||
|
assertEquals("https://wwaov.lanzouw.com", headers.get("origin"));
|
||||||
|
assertEquals("cross-site", headers.get("Sec-Fetch-Site"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sameOriginFileAjaxKeepsSameSiteFetchMetadata() {
|
||||||
|
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
|
||||||
|
"https://apifile.lanzouw.com/fn?x", "/ajaxfile.php?file=1");
|
||||||
|
assertEquals("same-origin", headers.get("Sec-Fetch-Site"));
|
||||||
|
assertEquals("https://apifile.lanzouw.com", headers.get("origin"));
|
||||||
|
assertEquals("https://apifile.lanzouw.com/fn?x", headers.get("referer"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,8 @@ public class Ye2LoginHintTest {
|
|||||||
assertTrue(Ye2Tool.isYeLoginRequired(0, "需要登录才能下载"));
|
assertTrue(Ye2Tool.isYeLoginRequired(0, "需要登录才能下载"));
|
||||||
assertFalse(Ye2Tool.isYeLoginRequired(0, "ok"));
|
assertFalse(Ye2Tool.isYeLoginRequired(0, "ok"));
|
||||||
assertFalse(Ye2Tool.isYeLoginRequired(null, null));
|
assertFalse(Ye2Tool.isYeLoginRequired(null, null));
|
||||||
|
assertFalse(Ye2Tool.isYeLoginRequired(5113, "分享方提取流量包不足"));
|
||||||
|
assertFalse(Ye2Tool.isYeLoginRequired(5066, "该文件暂不支持在当前版本下载"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -0,0 +1,410 @@
|
|||||||
|
package cn.qaiu.parser.impl;
|
||||||
|
|
||||||
|
import cn.qaiu.entity.ShareLinkInfo;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.json.JsonArray;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 123 分享单文件下载规则。不访问网络。
|
||||||
|
* mvn -pl parser -DskipTests=false -Dtest=Ye2ToolTest,Ye2LoginHintTest test
|
||||||
|
*/
|
||||||
|
public class Ye2ToolTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void downloadUsesShareKeyEncodedInDirectoryFileParameter() {
|
||||||
|
JsonObject directoryFileParameter = new JsonObject()
|
||||||
|
.put("shareKey", "iaKtVv-6OECd.html?from=dir")
|
||||||
|
.put("fileId", 123);
|
||||||
|
|
||||||
|
assertEquals("iaKtVv-6OECd",
|
||||||
|
Ye2Tool.resolveDownloadShareKey(directoryFileParameter, "-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void downloadFallsBackToParserShareKeyWhenParameterHasNone() {
|
||||||
|
assertEquals("iaKtVv-6OECd",
|
||||||
|
Ye2Tool.resolveDownloadShareKey(new JsonObject(), "iaKtVv-6OECd.html"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void downloadAcceptsCapitalShareKeyFromParameter() {
|
||||||
|
JsonObject directoryFileParameter = new JsonObject()
|
||||||
|
.put("ShareKey", "iaKtVv-r4aCd");
|
||||||
|
|
||||||
|
assertEquals("iaKtVv-r4aCd",
|
||||||
|
Ye2Tool.resolveDownloadShareKey(directoryFileParameter, "-"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void anonymous123RequestsDoNotSendFakeBearerTokens() {
|
||||||
|
assertNull(Ye2Tool.bearerAuthorization(null));
|
||||||
|
assertNull(Ye2Tool.bearerAuthorization(""));
|
||||||
|
assertNull(Ye2Tool.bearerAuthorization("nologin"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void configured123TokenKeepsExistingBearerAuthentication() {
|
||||||
|
assertEquals("Bearer configured-token",
|
||||||
|
Ye2Tool.bearerAuthorization("configured-token"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shareDownloadUsesCurrentWebAppVersion() {
|
||||||
|
assertEquals("149", Ye2Tool.SHARE_WEB_APP_VERSION);
|
||||||
|
assertTrue(Ye2Tool.usableShareKey("iaKtVv-r4aCd"));
|
||||||
|
assertFalse(Ye2Tool.usableShareKey("-"));
|
||||||
|
assertFalse(Ye2Tool.usableShareKey(""));
|
||||||
|
assertFalse(Ye2Tool.usableShareKey(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void placeholderShareUrlIsReplacedWithShareKeyFromFileParameter() {
|
||||||
|
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||||
|
.type("ye")
|
||||||
|
.shareKey("-")
|
||||||
|
.shareUrl("https://www.123pan.com/s/-")
|
||||||
|
.standardUrl("https://www.123pan.com/s/-")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||||
|
|
||||||
|
assertEquals("iaKtVv-r4aCd", info.getShareKey());
|
||||||
|
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getShareUrl());
|
||||||
|
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void realShareUrlIsKeptWhenResolvingDirectoryFile() {
|
||||||
|
String original = "https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd";
|
||||||
|
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||||
|
.type("ye")
|
||||||
|
.shareKey("iaKtVv-r4aCd")
|
||||||
|
.shareUrl(original)
|
||||||
|
.standardUrl("https://www.123pan.com/s/iaKtVv-r4aCd")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||||
|
|
||||||
|
assertEquals(original, info.getShareUrl());
|
||||||
|
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void placeholderStandardUrlDoesNotReplaceOriginalShareUrl() {
|
||||||
|
String original = "https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd";
|
||||||
|
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||||
|
.type("ye")
|
||||||
|
.shareKey("-")
|
||||||
|
.shareUrl(original)
|
||||||
|
.standardUrl("https://www.123pan.com/s/-")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||||
|
|
||||||
|
assertEquals(original, info.getShareUrl());
|
||||||
|
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void anonymousV2LoginCodeUsesExistingLoginHint() {
|
||||||
|
JsonObject json = new JsonObject()
|
||||||
|
.put("code", 5112)
|
||||||
|
.put("message", "您需要注册登录或付费后下载");
|
||||||
|
|
||||||
|
String msg = Ye2Tool.shareV2FailureMessage(json, "nologin");
|
||||||
|
|
||||||
|
assertTrue(msg.contains("auths.ye.authorization"));
|
||||||
|
assertTrue(msg.contains("上游信息: 您需要注册登录或付费后下载"));
|
||||||
|
assertFalse(msg.contains("downURLJson"));
|
||||||
|
assertFalse(msg.contains("download_info"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loggedInV2TrafficShortageStaysOnV2Error() {
|
||||||
|
JsonObject json = new JsonObject()
|
||||||
|
.put("code", 5113)
|
||||||
|
.put("message", "分享方提取流量包不足");
|
||||||
|
|
||||||
|
String msg = Ye2Tool.shareV2FailureMessage(json, "configured-token");
|
||||||
|
|
||||||
|
assertTrue(msg.startsWith("v2接口返回异常:"));
|
||||||
|
assertTrue(msg.contains("5113"));
|
||||||
|
assertTrue(msg.contains("分享方提取流量包不足"));
|
||||||
|
assertFalse(msg.contains("downURLJson"));
|
||||||
|
assertFalse(msg.contains("download_info"));
|
||||||
|
assertFalse(msg.contains("auths.ye.authorization"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void oldClientErrorIsNotRewrittenAsPersonalFileApiFailure() {
|
||||||
|
JsonObject json = new JsonObject()
|
||||||
|
.put("code", 5066)
|
||||||
|
.put("message", "该文件暂不支持在当前版本下载");
|
||||||
|
|
||||||
|
String msg = Ye2Tool.shareV2FailureMessage(json, "configured-token");
|
||||||
|
|
||||||
|
assertTrue(msg.startsWith("v2接口返回异常:"));
|
||||||
|
assertTrue(msg.contains("5066"));
|
||||||
|
assertFalse(msg.contains("downURLJson"));
|
||||||
|
assertFalse(Ye2Tool.isYeLoginRequired(5066, "该文件暂不支持在当前版本下载"));
|
||||||
|
assertFalse(Ye2Tool.isYeLoginRequired(5113, "分享方提取流量包不足"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void signatureUsesActualSharePathPlatformAndVersion() {
|
||||||
|
long time = 1_700_000_000_000L;
|
||||||
|
long randomA = 42L;
|
||||||
|
String traffic = Ye2Tool.signMaterial(
|
||||||
|
Ye2Tool.SHARE_TRAFFIC_CHECK_PATH, Ye2Tool.SHARE_PLATFORM, Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA);
|
||||||
|
String download = Ye2Tool.signMaterial(
|
||||||
|
Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, Ye2Tool.SHARE_PLATFORM, Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA);
|
||||||
|
|
||||||
|
assertTrue(traffic.contains("|/api/share/download/traffic/check|web|149|"));
|
||||||
|
assertTrue(download.contains("|/api/v2/share/download/info|web|149|"));
|
||||||
|
assertFalse(traffic.contains("/b/api/"));
|
||||||
|
assertFalse(download.contains("/b/api/"));
|
||||||
|
assertEquals(Ye2Tool.signQuery(
|
||||||
|
Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, "web", "149", time, randomA),
|
||||||
|
Ye2Tool.signQuery(Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, Ye2Tool.SHARE_PLATFORM,
|
||||||
|
Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mshareAndPlainSharePageUseDecodedShareHost() {
|
||||||
|
String host = "https://1815268665.share.123pan.cn";
|
||||||
|
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||||
|
"https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd",
|
||||||
|
"https://www.123pan.com/s/iaKtVv-r4aCd",
|
||||||
|
"iaKtVv-r4aCd"));
|
||||||
|
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||||
|
"https://1815268665.share.123pan.cn/123pan/iaKtVv-r4aCd?notoken=1",
|
||||||
|
null,
|
||||||
|
"iaKtVv-r4aCd"));
|
||||||
|
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||||
|
"https://www.123pan.com/s/iaKtVv-r4aCd",
|
||||||
|
"https://yun.123pan.com/s/iaKtVv-r4aCd",
|
||||||
|
"iaKtVv-r4aCd"));
|
||||||
|
assertFalse(host.contains("mshare"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void maliciousHostIsNotCalled() {
|
||||||
|
AtomicInteger calls = new AtomicInteger();
|
||||||
|
Future<String> blocked = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||||
|
}, sampleRequest("http://127.0.0.1/latest/meta-data", "iaKtVv-r4aCd", "configured-token"));
|
||||||
|
Future<String> disguised = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||||
|
}, sampleRequest("https://1815268665.share.123pan.cn.evil.com/123pan/iaKtVv-r4aCd",
|
||||||
|
"iaKtVv-r4aCd", "configured-token"));
|
||||||
|
Future<String> unknownKey = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||||
|
}, sampleRequest("https://evil.example/123pan/not-a-real-key", "not-a-real-key", "configured-token"));
|
||||||
|
|
||||||
|
assertEquals(0, calls.get());
|
||||||
|
assertTrue(blocked.failed());
|
||||||
|
assertTrue(disguised.failed());
|
||||||
|
assertTrue(unknownKey.failed());
|
||||||
|
assertTrue(blocked.cause().getMessage().contains("分享域名"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void successChecksTrafficThenDownloadsOnShareHost() {
|
||||||
|
List<Ye2Tool.ShareHttpCall> seen = new ArrayList<>();
|
||||||
|
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
seen.add(call);
|
||||||
|
if (seen.size() == 1) {
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject()
|
||||||
|
.put("isBlocked", false)
|
||||||
|
.put("isTrafficExceeded", false)
|
||||||
|
.put("isPay", false)));
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject()
|
||||||
|
.put("downloadPath", "/123/file.zip")
|
||||||
|
.put("dispatchList", new JsonArray()
|
||||||
|
.add(new JsonObject().put("prefix", "https://cdn-a.example/"))
|
||||||
|
.add(new JsonObject().put("prefix", "https://cdn-b.example/")))));
|
||||||
|
}, sampleRequest("https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd",
|
||||||
|
"iaKtVv-r4aCd", "configured-token"));
|
||||||
|
|
||||||
|
assertTrue(result.succeeded());
|
||||||
|
assertEquals("https://cdn-a.example/123/file.zip", result.result());
|
||||||
|
assertEquals(2, seen.size());
|
||||||
|
|
||||||
|
Ye2Tool.ShareHttpCall traffic = seen.get(0);
|
||||||
|
Ye2Tool.ShareHttpCall download = seen.get(1);
|
||||||
|
assertEquals("https://1815268665.share.123pan.cn", traffic.origin);
|
||||||
|
assertEquals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH, traffic.path);
|
||||||
|
assertEquals(Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, download.path);
|
||||||
|
assertEquals(traffic.origin, download.origin);
|
||||||
|
assertFalse(traffic.url().contains("api.123278.com"));
|
||||||
|
assertFalse(traffic.url().contains("/b/api/"));
|
||||||
|
assertEquals(Ye2Tool.signQuery(traffic.path, "web", "149", 1_700_000_000_000L, 42L), traffic.query);
|
||||||
|
assertEquals(Ye2Tool.signQuery(download.path, "web", "149", 1_700_000_000_000L, 42L), download.query);
|
||||||
|
|
||||||
|
assertEquals("149", traffic.headers.get("App-Version"));
|
||||||
|
assertEquals("web", traffic.headers.get("platform"));
|
||||||
|
assertEquals("Bearer configured-token", traffic.headers.get("Authorization"));
|
||||||
|
assertEquals("application/json;charset=UTF-8", traffic.headers.get("Content-Type"));
|
||||||
|
assertEquals("https://1815268665.share.123pan.cn", traffic.headers.get("Origin"));
|
||||||
|
assertEquals("https://1815268665.share.123pan.cn/123pan/iaKtVv-r4aCd", traffic.headers.get("Referer"));
|
||||||
|
assertEquals("iaKtVv-r4aCd", traffic.body.getString("shareKey"));
|
||||||
|
assertEquals(Long.valueOf(2468L), traffic.body.getJsonArray("fileIds").getLong(0));
|
||||||
|
assertFalse(traffic.body.containsKey("payType"));
|
||||||
|
|
||||||
|
assertEquals("iaKtVv-r4aCd", download.body.getString("ShareKey"));
|
||||||
|
assertEquals(Long.valueOf(2468L), download.body.getLong("FileID"));
|
||||||
|
assertEquals("etag-flag", download.body.getString("S3keyFlag"));
|
||||||
|
assertEquals(Long.valueOf(6915371L), download.body.getLong("Size"));
|
||||||
|
assertEquals("abcetag", download.body.getString("Etag"));
|
||||||
|
assertFalse(download.body.containsKey("OrderId"));
|
||||||
|
assertFalse(download.body.containsKey("payType"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void directoryDownloadUsesShareKeyHostNotPlaceholderPage() {
|
||||||
|
List<Ye2Tool.ShareHttpCall> seen = new ArrayList<>();
|
||||||
|
Ye2Tool.ShareFileRequest request = sampleRequest(
|
||||||
|
"https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token");
|
||||||
|
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
seen.add(call);
|
||||||
|
if (seen.size() == 1) {
|
||||||
|
return Future.succeededFuture(openTraffic());
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject()
|
||||||
|
.put("downloadPath", "folder/file.bin")
|
||||||
|
.put("dispatchList", new JsonArray().add(
|
||||||
|
new JsonObject().put("prefix", "https://cdn.example/root")))));
|
||||||
|
}, request);
|
||||||
|
|
||||||
|
assertTrue(result.succeeded());
|
||||||
|
assertEquals("https://cdn.example/root/folder/file.bin", result.result());
|
||||||
|
assertEquals("https://1815268665.share.123pan.cn", seen.get(0).origin);
|
||||||
|
assertFalse(seen.get(0).url().contains("www.123pan.com"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void absoluteDownloadPathIsKept() {
|
||||||
|
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||||
|
return Future.succeededFuture(openTraffic());
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject()
|
||||||
|
.put("downloadPath", "https://cdn.example/already.zip")
|
||||||
|
.put("dispatchList", new JsonArray().add(
|
||||||
|
new JsonObject().put("prefix", "https://ignored.example/")))));
|
||||||
|
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||||
|
|
||||||
|
assertEquals("https://cdn.example/already.zip", result.result());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockedPayAndMissingLinkDoNotContinue() {
|
||||||
|
Future<String> blocked = downloadAfterTraffic(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject().put("isBlocked", true).put("isPay", false)));
|
||||||
|
Future<String> pay = downloadAfterTraffic(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject().put("isPay", true)));
|
||||||
|
Future<String> missing = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||||
|
return Future.succeededFuture(openTraffic());
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(new JsonObject().put("code", 0).put("data", new JsonObject()));
|
||||||
|
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||||
|
|
||||||
|
Future<String> exceeded = downloadAfterTraffic(new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject().put("isTrafficExceeded", true)));
|
||||||
|
|
||||||
|
assertTrue(blocked.cause().getMessage().contains("不会自动下单"));
|
||||||
|
assertTrue(pay.cause().getMessage().contains("不会自动下单"));
|
||||||
|
assertTrue(exceeded.cause().getMessage().contains("不会自动购买"));
|
||||||
|
assertTrue(missing.cause().getMessage().contains("未返回下载链接"));
|
||||||
|
assertFalse(blocked.cause().getMessage().contains("OrderId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loginAndTrafficErrorsStayOnTheStepThatReturnedThem() {
|
||||||
|
AtomicInteger calls = new AtomicInteger();
|
||||||
|
Future<String> login = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 5112)
|
||||||
|
.put("message", "您需要注册登录或付费后下载"));
|
||||||
|
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "nologin"));
|
||||||
|
Future<String> traffic = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||||
|
assertNull(call.headers.get("Authorization"));
|
||||||
|
return Future.succeededFuture(openTraffic());
|
||||||
|
}
|
||||||
|
return Future.succeededFuture(new JsonObject()
|
||||||
|
.put("code", 5113)
|
||||||
|
.put("message", "分享方提取流量包不足"));
|
||||||
|
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "nologin"));
|
||||||
|
|
||||||
|
assertEquals(3, calls.get());
|
||||||
|
assertTrue(login.cause().getMessage().contains("auths.ye.authorization"));
|
||||||
|
assertTrue(traffic.cause().getMessage().contains("5113"));
|
||||||
|
assertFalse(traffic.cause().getMessage().contains("downURLJson"));
|
||||||
|
assertFalse(traffic.cause().getMessage().contains("download_info"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Future<String> downloadAfterTraffic(JsonObject trafficJson) {
|
||||||
|
AtomicInteger calls = new AtomicInteger();
|
||||||
|
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return Future.succeededFuture(trafficJson);
|
||||||
|
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||||
|
assertEquals(1, calls.get());
|
||||||
|
assertTrue(result.failed());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject openTraffic() {
|
||||||
|
return new JsonObject()
|
||||||
|
.put("code", 0)
|
||||||
|
.put("data", new JsonObject()
|
||||||
|
.put("isBlocked", false)
|
||||||
|
.put("isTrafficExceeded", false)
|
||||||
|
.put("isPay", false));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Ye2Tool.ShareFileRequest sampleRequest(String shareUrl, String shareKey, String token) {
|
||||||
|
return new Ye2Tool.ShareFileRequest(
|
||||||
|
shareUrl,
|
||||||
|
"https://www.123pan.com/s/" + shareKey,
|
||||||
|
shareKey,
|
||||||
|
"",
|
||||||
|
2468L,
|
||||||
|
"etag-flag",
|
||||||
|
6915371L,
|
||||||
|
"abcetag",
|
||||||
|
token,
|
||||||
|
1_700_000_000_000L,
|
||||||
|
42L);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>0.4.13</revision>
|
<revision>0.4.15</revision>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
<slf4j.version>2.0.16</slf4j.version>
|
<slf4j.version>2.0.16</slf4j.version>
|
||||||
<commons-lang3.version>3.18.0</commons-lang3.version>
|
<commons-lang3.version>3.18.0</commons-lang3.version>
|
||||||
<commons-beanutils2.version>2.0.0</commons-beanutils2.version>
|
<commons-beanutils2.version>2.0.0</commons-beanutils2.version>
|
||||||
<parserVersion>10.2.5</parserVersion>
|
<parserVersion>10.2.7</parserVersion>
|
||||||
<jackson.version>2.18.9</jackson.version>
|
<jackson.version>2.18.9</jackson.version>
|
||||||
<!-- Logback 最新稳定版 -->
|
<!-- Logback 最新稳定版 -->
|
||||||
<logback.version>1.5.34</logback.version>
|
<logback.version>1.5.34</logback.version>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nfd-web",
|
"name": "nfd-web",
|
||||||
"version": "0.4.13",
|
"version": "0.4.15",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
<el-icon><Key /></el-icon>
|
<el-icon><Key /></el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
<el-tooltip content="捐赠网盘账号" placement="bottom">
|
<el-tooltip v-if="donatedAccountsEnabled" content="捐赠网盘账号" placement="bottom">
|
||||||
<el-button circle size="small" type="warning" @click="showDonateDialog = true">
|
<el-button circle size="small" type="warning" @click="showDonateDialog = true">
|
||||||
<el-icon><Present /></el-icon>
|
<el-icon><Present /></el-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
@@ -319,6 +319,10 @@
|
|||||||
width="550px"
|
width="550px"
|
||||||
:close-on-click-modal="false">
|
:close-on-click-modal="false">
|
||||||
<el-form :model="authConfig" label-width="100px" size="default">
|
<el-form :model="authConfig" label-width="100px" size="default">
|
||||||
|
<el-form-item label="服务认证密钥">
|
||||||
|
<el-input v-model="serverAuthKey" type="password" show-password
|
||||||
|
autocomplete="off" placeholder="自建站已配置的 authEncryptKey(仅本页内存)" />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="网盘类型" required>
|
<el-form-item label="网盘类型" required>
|
||||||
<el-select v-model="authConfig.panType" placeholder="请选择网盘类型" style="width: 100%" @change="onPanTypeChange">
|
<el-select v-model="authConfig.panType" placeholder="请选择网盘类型" style="width: 100%" @change="onPanTypeChange">
|
||||||
<el-option-group label="必须认证">
|
<el-option-group label="必须认证">
|
||||||
@@ -573,10 +577,6 @@
|
|||||||
<el-form :model="donateConfig" label-width="100px" size="default">
|
<el-form :model="donateConfig" label-width="100px" size="default">
|
||||||
<el-form-item label="网盘类型" required>
|
<el-form-item label="网盘类型" required>
|
||||||
<el-select v-model="donateConfig.panType" placeholder="请选择网盘类型" style="width: 100%" @change="onDonatePanTypeChange">
|
<el-select v-model="donateConfig.panType" placeholder="请选择网盘类型" style="width: 100%" @change="onDonatePanTypeChange">
|
||||||
<el-option-group label="必须认证">
|
|
||||||
<el-option label="夸克网盘 (QK)" value="QK" />
|
|
||||||
<el-option label="UC网盘 (UC)" value="UC" />
|
|
||||||
</el-option-group>
|
|
||||||
<el-option-group label="大文件需认证">
|
<el-option-group label="大文件需认证">
|
||||||
<el-option label="小飞机网盘 (FJ)" value="FJ" />
|
<el-option label="小飞机网盘 (FJ)" value="FJ" />
|
||||||
<el-option label="蓝奏优享 (IZ)" value="IZ" />
|
<el-option label="蓝奏优享 (IZ)" value="IZ" />
|
||||||
@@ -712,8 +712,10 @@ export default {
|
|||||||
},
|
},
|
||||||
// 所有网盘的认证配置 { panType: config }
|
// 所有网盘的认证配置 { panType: config }
|
||||||
allAuthConfigs: {},
|
allAuthConfigs: {},
|
||||||
|
serverAuthKey: '',
|
||||||
|
|
||||||
// 捐赠账号相关
|
// 捐赠账号相关
|
||||||
|
donatedAccountsEnabled: false,
|
||||||
showDonateDialog: false,
|
showDonateDialog: false,
|
||||||
donateSubmitting: false,
|
donateSubmitting: false,
|
||||||
donateConfig: {
|
donateConfig: {
|
||||||
@@ -979,6 +981,10 @@ export default {
|
|||||||
|
|
||||||
// 保存认证配置
|
// 保存认证配置
|
||||||
saveAuthConfig() {
|
saveAuthConfig() {
|
||||||
|
if (![16, 24, 32].includes(new TextEncoder().encode(this.serverAuthKey).length)) {
|
||||||
|
this.$message.warning('个人认证需要自建站配置的服务认证密钥(16、24 或 32 个 UTF-8 字节)')
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!this.authConfig.panType) {
|
if (!this.authConfig.panType) {
|
||||||
this.$message.warning('请先选择网盘类型')
|
this.$message.warning('请先选择网盘类型')
|
||||||
return
|
return
|
||||||
@@ -1021,6 +1027,7 @@ export default {
|
|||||||
ext5: ''
|
ext5: ''
|
||||||
}
|
}
|
||||||
this.allAuthConfigs = {}
|
this.allAuthConfigs = {}
|
||||||
|
this.serverAuthKey = ''
|
||||||
localStorage.removeItem('nfd_auth_configs')
|
localStorage.removeItem('nfd_auth_configs')
|
||||||
this.$message.success('所有认证配置已清除')
|
this.$message.success('所有认证配置已清除')
|
||||||
this.showAuthConfigDialog = false
|
this.showAuthConfigDialog = false
|
||||||
@@ -1040,31 +1047,15 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 生成加密的 auth 参数(优先使用个人配置,否则从后端随机获取捐赠账号)
|
// 个人认证由可信客户端使用自建服务显式配置的密钥编码;捐赠凭据只在服务端使用。
|
||||||
async generateAuthParam() {
|
async generateAuthParam() {
|
||||||
const panType = this.getCurrentPanType()
|
const panType = this.getCurrentPanType()
|
||||||
if (!panType) return ''
|
if (!panType) return ''
|
||||||
|
const config = this.allAuthConfigs[panType]
|
||||||
let config = null
|
if (!config) return ''
|
||||||
|
const key = this.serverAuthKey
|
||||||
// 优先使用个人配置
|
if (![16, 24, 32].includes(new TextEncoder().encode(key).length)) return ''
|
||||||
if (this.allAuthConfigs[panType]) {
|
|
||||||
config = this.allAuthConfigs[panType]
|
|
||||||
} else {
|
|
||||||
// 从后端随机获取捐赠账号(后端已加密,直接使用 encryptedAuth)
|
|
||||||
try {
|
|
||||||
const response = await axios.get(`${this.baseAPI}/v2/randomAuth`, { params: { panType } })
|
|
||||||
const encryptedAuth = response.data?.data?.encryptedAuth
|
|
||||||
if (encryptedAuth) {
|
|
||||||
return encryptedAuth
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// no available donated account
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// 个人配置:本地 AES 加密
|
|
||||||
const authObj = {}
|
const authObj = {}
|
||||||
if (config.authType) authObj.authType = config.authType
|
if (config.authType) authObj.authType = config.authType
|
||||||
if (config.username) authObj.username = config.username
|
if (config.username) authObj.username = config.username
|
||||||
@@ -1079,7 +1070,7 @@ export default {
|
|||||||
if (config.ext5) authObj.ext5 = config.ext5
|
if (config.ext5) authObj.ext5 = config.ext5
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const encrypted = this.aesEncrypt(JSON.stringify(authObj), 'nfd_auth_key2026')
|
const encrypted = this.aesEncrypt(JSON.stringify(authObj), key)
|
||||||
return encodeURIComponent(encrypted)
|
return encodeURIComponent(encrypted)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('生成认证参数失败:', e)
|
console.error('生成认证参数失败:', e)
|
||||||
@@ -1719,7 +1710,11 @@ export default {
|
|||||||
token: isPasswordAuth ? '' : (this.donateConfig.token || ''),
|
token: isPasswordAuth ? '' : (this.donateConfig.token || ''),
|
||||||
remark: this.donateConfig.remark || ''
|
remark: this.donateConfig.remark || ''
|
||||||
}
|
}
|
||||||
await axios.post(`${this.baseAPI}/v2/donateAccount`, payload)
|
const response = await axios.post(`${this.baseAPI}/v2/donateAccount`, payload)
|
||||||
|
if (response.data?.code !== 200) {
|
||||||
|
this.$message.error(response.data?.msg || '捐赠失败')
|
||||||
|
return
|
||||||
|
}
|
||||||
this.$message.success(`已捐赠 ${this.getPanDisplayName(this.donateConfig.panType)} 账号,感谢您的贡献!`)
|
this.$message.success(`已捐赠 ${this.getPanDisplayName(this.donateConfig.panType)} 账号,感谢您的贡献!`)
|
||||||
|
|
||||||
// 重置表单
|
// 重置表单
|
||||||
@@ -1749,6 +1744,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data && typeof data === 'object') {
|
if (data && typeof data === 'object') {
|
||||||
|
this.donatedAccountsEnabled = data.enabled === true
|
||||||
// 兼容新结构: { active: {...}, inactive: {...} }
|
// 兼容新结构: { active: {...}, inactive: {...} }
|
||||||
if (data.active && data.inactive) {
|
if (data.active && data.inactive) {
|
||||||
if (data.active.total === undefined) {
|
if (data.active.total === undefined) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.qaiu.db.pool.JDBCPoolInit;
|
|||||||
import cn.qaiu.lz.common.cache.CacheConfigLoader;
|
import cn.qaiu.lz.common.cache.CacheConfigLoader;
|
||||||
import cn.qaiu.lz.common.cache.CacheManager;
|
import cn.qaiu.lz.common.cache.CacheManager;
|
||||||
import cn.qaiu.lz.common.interceptorImpl.RateLimiter;
|
import cn.qaiu.lz.common.interceptorImpl.RateLimiter;
|
||||||
|
import cn.qaiu.lz.common.util.AuthParamCodec;
|
||||||
import cn.qaiu.lz.web.config.PlaygroundConfig;
|
import cn.qaiu.lz.web.config.PlaygroundConfig;
|
||||||
import cn.qaiu.lz.web.service.DbService;
|
import cn.qaiu.lz.web.service.DbService;
|
||||||
import cn.qaiu.lz.web.service.impl.ShoutServiceImpl;
|
import cn.qaiu.lz.web.service.impl.ShoutServiceImpl;
|
||||||
@@ -90,6 +91,7 @@ public class AppMain {
|
|||||||
* @param jsonObject 配置
|
* @param jsonObject 配置
|
||||||
*/
|
*/
|
||||||
private static void exec(JsonObject jsonObject) {
|
private static void exec(JsonObject jsonObject) {
|
||||||
|
AuthParamCodec.configure(jsonObject.getJsonObject(ConfigConstant.SERVER));
|
||||||
WebClientVertxInit.init(VertxHolder.getVertxInstance());
|
WebClientVertxInit.init(VertxHolder.getVertxInstance());
|
||||||
DatabindCodec.mapper().registerModule(new JavaTimeModule());
|
DatabindCodec.mapper().registerModule(new JavaTimeModule());
|
||||||
// 演练场配置要先加载,后续启动流程才能按开关决定是否注册动态解析器。
|
// 演练场配置要先加载,后续启动流程才能按开关决定是否注册动态解析器。
|
||||||
|
|||||||
@@ -3,13 +3,18 @@ package cn.qaiu.lz.common.util;
|
|||||||
import cn.qaiu.lz.web.model.AuthParam;
|
import cn.qaiu.lz.web.model.AuthParam;
|
||||||
import cn.qaiu.util.AESUtils;
|
import cn.qaiu.util.AESUtils;
|
||||||
import cn.qaiu.util.Base64Decoder;
|
import cn.qaiu.util.Base64Decoder;
|
||||||
import cn.qaiu.vx.core.util.SharedDataUtil;
|
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.HexFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认证参数编解码工具类
|
* 认证参数编解码工具类
|
||||||
@@ -24,34 +29,56 @@ import java.nio.charset.StandardCharsets;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class AuthParamCodec {
|
public class AuthParamCodec {
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认加密密钥(16位)
|
|
||||||
*/
|
|
||||||
private static final String DEFAULT_ENCRYPT_KEY = "nfd_auth_key2026";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置中的密钥路径
|
|
||||||
*/
|
|
||||||
private static final String CONFIG_KEY_PATH = "authEncryptKey";
|
private static final String CONFIG_KEY_PATH = "authEncryptKey";
|
||||||
|
// 识别升级时保留下来的旧发行版配置;不再使用旧密钥。
|
||||||
|
private static final String RETIRED_KEY_SHA256 = "b2c23dd4619534db9831db32be8e699412f1de60138ac37234eaae827ff1bcf4";
|
||||||
|
private static final String PROCESS_RANDOM_KEY = generateKey();
|
||||||
|
private static volatile String encryptKey = PROCESS_RANDOM_KEY;
|
||||||
|
|
||||||
private AuthParamCodec() {
|
private AuthParamCodec() {
|
||||||
// 工具类禁止实例化
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static void configure(JsonObject serverConfig) {
|
||||||
* 获取加密密钥
|
String configuredKey = serverConfig.getString(CONFIG_KEY_PATH);
|
||||||
* 优先从配置文件读取,如果未配置则使用默认密钥
|
encryptKey = selectKey(configuredKey);
|
||||||
*/
|
log.info("authEncryptKey: source={}, fingerprint(SHA-256)={}",
|
||||||
public static String getEncryptKey() {
|
encryptKey == PROCESS_RANDOM_KEY ? "generated (this process only)" : "configured",
|
||||||
try {
|
fingerprint(encryptKey).substring(0, 12));
|
||||||
String configKey = SharedDataUtil.getJsonStringForServerConfig(CONFIG_KEY_PATH);
|
}
|
||||||
if (StringUtils.isNotBlank(configKey)) {
|
|
||||||
return configKey;
|
static String selectKey(String configuredKey) {
|
||||||
}
|
if (StringUtils.isBlank(configuredKey) || RETIRED_KEY_SHA256.equals(fingerprint(configuredKey))) {
|
||||||
} catch (Exception e) {
|
return PROCESS_RANDOM_KEY;
|
||||||
log.debug("从配置读取加密密钥失败,使用默认密钥: {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
return DEFAULT_ENCRYPT_KEY;
|
int length = configuredKey.getBytes(StandardCharsets.UTF_8).length;
|
||||||
|
if (length != 16 && length != 24 && length != 32) {
|
||||||
|
throw new IllegalArgumentException("server.authEncryptKey must be 16, 24, or 32 UTF-8 bytes");
|
||||||
|
}
|
||||||
|
return configuredKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String generateKey() {
|
||||||
|
byte[] random = new byte[24];
|
||||||
|
new SecureRandom().nextBytes(random);
|
||||||
|
return Base64.getUrlEncoder().withoutPadding().encodeToString(random);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String fingerprint(String value) {
|
||||||
|
try {
|
||||||
|
return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256")
|
||||||
|
.digest(value.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException("SHA-256 unavailable", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SecretKeySpec asAesKey(String key) {
|
||||||
|
// Match CryptoJS: AES key lengths and values are defined by the full UTF-8 bytes.
|
||||||
|
return new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getEncryptKey() {
|
||||||
|
return encryptKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +96,7 @@ public class AuthParamCodec {
|
|||||||
* 解码认证参数(指定密钥)
|
* 解码认证参数(指定密钥)
|
||||||
*
|
*
|
||||||
* @param encryptedAuth 加密后的认证参数字符串
|
* @param encryptedAuth 加密后的认证参数字符串
|
||||||
* @param key AES密钥(16位)
|
* @param key AES 密钥(16、24 或 32 个 UTF-8 字节)
|
||||||
* @return AuthParam 对象,解码失败返回 null
|
* @return AuthParam 对象,解码失败返回 null
|
||||||
*/
|
*/
|
||||||
public static AuthParam decode(String encryptedAuth, String key) {
|
public static AuthParam decode(String encryptedAuth, String key) {
|
||||||
@@ -85,15 +112,13 @@ public class AuthParamCodec {
|
|||||||
}
|
}
|
||||||
// 兼容 query 参数中 '+' 被还原为空格的情况
|
// 兼容 query 参数中 '+' 被还原为空格的情况
|
||||||
normalized = normalized.replace(' ', '+');
|
normalized = normalized.replace(' ', '+');
|
||||||
log.debug("认证参数规范化结果: {}", normalized);
|
|
||||||
|
|
||||||
// Step 2: Base64解码
|
// Step 2: Base64解码
|
||||||
byte[] base64Decoded = Base64Decoder.decode(normalized);
|
byte[] base64Decoded = Base64Decoder.decode(normalized);
|
||||||
log.debug("Base64解码成功,长度: {}", base64Decoded.length);
|
log.debug("Base64解码成功,长度: {}", base64Decoded.length);
|
||||||
|
|
||||||
// Step 3: AES解密
|
// Step 3: AES解密
|
||||||
String jsonStr = AESUtils.decryptByAES(base64Decoded, key);
|
String jsonStr = AESUtils.decryptByAES(base64Decoded, asAesKey(key));
|
||||||
log.debug("AES解密结果: {}", jsonStr);
|
|
||||||
|
|
||||||
// Step 4: JSON解析
|
// Step 4: JSON解析
|
||||||
JsonObject json = new JsonObject(jsonStr);
|
JsonObject json = new JsonObject(jsonStr);
|
||||||
@@ -102,9 +127,9 @@ public class AuthParamCodec {
|
|||||||
return authParam;
|
return authParam;
|
||||||
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.warn("认证参数Base64解码失败: {}", e.getMessage());
|
log.warn("认证参数格式无效");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("认证参数解码失败: {}", e.getMessage());
|
log.warn("认证参数解码失败");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -124,7 +149,7 @@ public class AuthParamCodec {
|
|||||||
* 编码认证参数(指定密钥)
|
* 编码认证参数(指定密钥)
|
||||||
*
|
*
|
||||||
* @param authParam 认证参数对象
|
* @param authParam 认证参数对象
|
||||||
* @param key AES密钥(16位)
|
* @param key AES 密钥(16、24 或 32 个 UTF-8 字节)
|
||||||
* @return 加密后的字符串,编码失败返回 null
|
* @return 加密后的字符串,编码失败返回 null
|
||||||
*/
|
*/
|
||||||
public static String encode(AuthParam authParam, String key) {
|
public static String encode(AuthParam authParam, String key) {
|
||||||
@@ -135,15 +160,12 @@ public class AuthParamCodec {
|
|||||||
try {
|
try {
|
||||||
// Step 1: 转换为JSON
|
// Step 1: 转换为JSON
|
||||||
String jsonStr = authParam.toJsonObject().encode();
|
String jsonStr = authParam.toJsonObject().encode();
|
||||||
log.debug("JSON字符串: {}", jsonStr);
|
|
||||||
|
|
||||||
// Step 2: AES加密 + Base64编码
|
// Step 2: AES加密 + Base64编码
|
||||||
String base64Encoded = AESUtils.encryptBase64ByAES(jsonStr, key);
|
String base64Encoded = AESUtils.encryptBase64ByAES(jsonStr, asAesKey(key));
|
||||||
log.debug("AES+Base64编码结果: {}", base64Encoded);
|
|
||||||
|
|
||||||
// Step 3: URL编码
|
// Step 3: URL编码
|
||||||
String urlEncoded = java.net.URLEncoder.encode(base64Encoded, StandardCharsets.UTF_8);
|
String urlEncoded = java.net.URLEncoder.encode(base64Encoded, StandardCharsets.UTF_8);
|
||||||
log.debug("URL编码结果: {}", urlEncoded);
|
|
||||||
|
|
||||||
return urlEncoded;
|
return urlEncoded;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cn.qaiu.lz.web.service.DbService;
|
|||||||
import cn.qaiu.parser.ParserCreate;
|
import cn.qaiu.parser.ParserCreate;
|
||||||
import cn.qaiu.vx.core.util.ConfigConstant;
|
import cn.qaiu.vx.core.util.ConfigConstant;
|
||||||
import cn.qaiu.vx.core.util.VertxHolder;
|
import cn.qaiu.vx.core.util.VertxHolder;
|
||||||
|
import cn.qaiu.vx.core.util.SharedDataUtil;
|
||||||
import io.vertx.core.Future;
|
import io.vertx.core.Future;
|
||||||
import io.vertx.core.MultiMap;
|
import io.vertx.core.MultiMap;
|
||||||
import io.vertx.core.http.HttpServerRequest;
|
import io.vertx.core.http.HttpServerRequest;
|
||||||
@@ -88,7 +89,7 @@ public class ParserAuthUtil {
|
|||||||
|
|
||||||
public static void recordDonatedAccountFailureIfNeeded(DbService dbService, JsonObject otherParam,
|
public static void recordDonatedAccountFailureIfNeeded(DbService dbService, JsonObject otherParam,
|
||||||
Throwable cause) {
|
Throwable cause) {
|
||||||
if (!isLikelyAuthFailure(cause) || otherParam == null) {
|
if (otherParam == null || !isLikelyAuthFailure(cause) || !isDonatedAccountsEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String donatedAccountToken = otherParam.getString("donatedAccountToken");
|
String donatedAccountToken = otherParam.getString("donatedAccountToken");
|
||||||
@@ -101,7 +102,7 @@ public class ParserAuthUtil {
|
|||||||
|
|
||||||
public static void recordAutoDonatedFailureIfNeeded(DbService dbService, ShareLinkInfo shareLinkInfo,
|
public static void recordAutoDonatedFailureIfNeeded(DbService dbService, ShareLinkInfo shareLinkInfo,
|
||||||
Throwable cause) {
|
Throwable cause) {
|
||||||
if (shareLinkInfo == null || !isLikelyAuthFailure(cause)) {
|
if (shareLinkInfo == null || !isLikelyAuthFailure(cause) || !isDonatedAccountsEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object tokenObj = shareLinkInfo.getOtherParam().get(DONATED_ACCOUNT_TOKEN);
|
Object tokenObj = shareLinkInfo.getOtherParam().get(DONATED_ACCOUNT_TOKEN);
|
||||||
@@ -112,14 +113,31 @@ public class ParserAuthUtil {
|
|||||||
.onFailure(e -> log.warn("记录自动捐赠账号失败次数失败", e));
|
.onFailure(e -> log.warn("记录自动捐赠账号失败次数失败", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDonatedAccountsEnabled() {
|
||||||
|
return isDonatedAccountsEnabled(SharedDataUtil.getJsonConfig(ConfigConstant.SERVER));
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isDonatedAccountsEnabled(JsonObject server) {
|
||||||
|
return server != null && Boolean.TRUE.equals(server.getValue("enableDonatedAccounts"))
|
||||||
|
&& Boolean.TRUE.equals(server.getValue("enableDatabase"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只启用已检查解析结果不会携带捐赠账号下载请求头的网盘。
|
||||||
|
public static boolean supportsServerSideDonation(String type) {
|
||||||
|
return "ye".equalsIgnoreCase(type) || "fj".equalsIgnoreCase(type) || "iz".equalsIgnoreCase(type);
|
||||||
|
}
|
||||||
|
|
||||||
private static Future<Void> applyDonatedAccountFallback(ParserCreate parserCreate, DbService dbService) {
|
private static Future<Void> applyDonatedAccountFallback(ParserCreate parserCreate, DbService dbService) {
|
||||||
|
if (!isDonatedAccountsEnabled()) {
|
||||||
|
return Future.succeededFuture();
|
||||||
|
}
|
||||||
ShareLinkInfo shareLinkInfo = parserCreate.getShareLinkInfo();
|
ShareLinkInfo shareLinkInfo = parserCreate.getShareLinkInfo();
|
||||||
Map<String, Object> otherParam = shareLinkInfo.getOtherParam();
|
Map<String, Object> otherParam = shareLinkInfo.getOtherParam();
|
||||||
if (Boolean.TRUE.equals(otherParam.get(TEMP_AUTH_ADDED))) {
|
if (Boolean.TRUE.equals(otherParam.get(TEMP_AUTH_ADDED))) {
|
||||||
return Future.succeededFuture();
|
return Future.succeededFuture();
|
||||||
}
|
}
|
||||||
String type = shareLinkInfo.getType();
|
String type = shareLinkInfo.getType();
|
||||||
if (StringUtils.isBlank(type) || hasUsableStaticAuthConfig(type)) {
|
if (!supportsServerSideDonation(type) || hasUsableStaticAuthConfig(type)) {
|
||||||
return Future.succeededFuture();
|
return Future.succeededFuture();
|
||||||
}
|
}
|
||||||
return dbService.getRandomDonatedAccount(type.toUpperCase())
|
return dbService.getRandomDonatedAccount(type.toUpperCase())
|
||||||
|
|||||||
@@ -770,11 +770,18 @@ public class ParserApi {
|
|||||||
*/
|
*/
|
||||||
@RouteMapping(value = "/donateAccount", method = RouteMethod.POST)
|
@RouteMapping(value = "/donateAccount", method = RouteMethod.POST)
|
||||||
public Future<JsonObject> donateAccount(RoutingContext ctx) {
|
public Future<JsonObject> donateAccount(RoutingContext ctx) {
|
||||||
|
if (!ParserAuthUtil.isDonatedAccountsEnabled()) {
|
||||||
|
return Future.succeededFuture(JsonResult.error("捐赠账号功能未启用").toJsonObject());
|
||||||
|
}
|
||||||
JsonObject body = ctx.body().asJsonObject();
|
JsonObject body = ctx.body().asJsonObject();
|
||||||
if (body == null || StringUtils.isBlank(body.getString("panType"))
|
if (body == null || StringUtils.isBlank(body.getString("panType"))
|
||||||
|| StringUtils.isBlank(body.getString("authType"))) {
|
|| StringUtils.isBlank(body.getString("authType"))) {
|
||||||
return Future.succeededFuture(JsonResult.error("panType and authType are required").toJsonObject());
|
return Future.succeededFuture(JsonResult.error("panType and authType are required").toJsonObject());
|
||||||
}
|
}
|
||||||
|
if (!ParserAuthUtil.supportsServerSideDonation(body.getString("panType"))) {
|
||||||
|
return Future.succeededFuture(JsonResult.error("该网盘暂不支持服务端捐赠池").toJsonObject());
|
||||||
|
}
|
||||||
|
body.put("panType", body.getString("panType").toUpperCase(java.util.Locale.ROOT));
|
||||||
String ip = ctx.request().remoteAddress().host();
|
String ip = ctx.request().remoteAddress().host();
|
||||||
body.put("ip", ip);
|
body.put("ip", ip);
|
||||||
return dbService.saveDonatedAccount(body);
|
return dbService.saveDonatedAccount(body);
|
||||||
@@ -785,23 +792,16 @@ public class ParserApi {
|
|||||||
*/
|
*/
|
||||||
@RouteMapping(value = "/donateAccountCounts", method = RouteMethod.GET)
|
@RouteMapping(value = "/donateAccountCounts", method = RouteMethod.GET)
|
||||||
public Future<JsonObject> getDonateAccountCounts() {
|
public Future<JsonObject> getDonateAccountCounts() {
|
||||||
return dbService.getDonatedAccountCounts();
|
if (!ParserAuthUtil.isDonatedAccountsEnabled()) {
|
||||||
}
|
return Future.succeededFuture(JsonResult.data(new JsonObject().put("enabled", false)).toJsonObject());
|
||||||
|
}
|
||||||
/**
|
return dbService.getDonatedAccountCounts().map(result -> {
|
||||||
* 随机获取指定网盘类型的捐赠账号(内部使用,返回加密后的 auth 参数)
|
JsonObject data = result.getJsonObject("data");
|
||||||
*/
|
if (data != null) {
|
||||||
@RouteMapping(value = "/randomAuth", method = RouteMethod.GET)
|
data.put("enabled", true);
|
||||||
public Future<JsonObject> getRandomAuth(String panType) {
|
|
||||||
return dbService.getRandomDonatedAccount(panType).map(res -> {
|
|
||||||
if (Integer.valueOf(200).equals(res.getInteger("code")) && res.getJsonObject("data") != null) {
|
|
||||||
JsonObject data = res.getJsonObject("data");
|
|
||||||
String encryptedAuth = AuthParamCodec.encode(data);
|
|
||||||
JsonObject safeData = new JsonObject();
|
|
||||||
safeData.put("encryptedAuth", encryptedAuth);
|
|
||||||
res.put("data", safeData);
|
|
||||||
}
|
}
|
||||||
return res;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ public class DbServiceImpl implements DbService {
|
|||||||
private static final long FAILURE_TOKEN_TTL_MILLIS = 10 * 60 * 1000L;
|
private static final long FAILURE_TOKEN_TTL_MILLIS = 10 * 60 * 1000L;
|
||||||
private static final String HMAC_ALGORITHM = "HmacSHA256";
|
private static final String HMAC_ALGORITHM = "HmacSHA256";
|
||||||
private static final String DONATED_ACCOUNT_TOKEN_SIGN_KEY_CONFIG = "donatedAccountFailureTokenSignKey";
|
private static final String DONATED_ACCOUNT_TOKEN_SIGN_KEY_CONFIG = "donatedAccountFailureTokenSignKey";
|
||||||
private static final String DONATED_ACCOUNT_TOKEN_SIGN_KEY_FALLBACK = "nfd_donate_fail_token_sign_2026";
|
private static final String DONATED_ACCOUNT_TOKEN_SIGN_KEY_FALLBACK = java.util.UUID.randomUUID().toString() + java.util.UUID.randomUUID();
|
||||||
@Override
|
@Override
|
||||||
public Future<JsonObject> sayOk(String data) {
|
public Future<JsonObject> sayOk(String data) {
|
||||||
log.info("say ok1 -> wait...");
|
log.info("say ok1 -> wait...");
|
||||||
@@ -574,7 +574,7 @@ public class DbServiceImpl implements DbService {
|
|||||||
return configKey;
|
return configKey;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("读取捐赠账号失败计数签名密钥失败,使用默认值: {}", e.getMessage());
|
log.debug("读取捐赠账号失败计数签名密钥失败,使用进程随机值: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
return DONATED_ACCOUNT_TOKEN_SIGN_KEY_FALLBACK;
|
return DONATED_ACCOUNT_TOKEN_SIGN_KEY_FALLBACK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ server:
|
|||||||
# domainName: http://127.0.0.1:6401
|
# domainName: http://127.0.0.1:6401
|
||||||
# 预览服务URL
|
# 预览服务URL
|
||||||
previewURL: https://nfd-parser.github.io/nfd-preview/preview.html?src=
|
previewURL: https://nfd-parser.github.io/nfd-preview/preview.html?src=
|
||||||
# auth参数加密密钥(16位AES密钥)
|
# 未配置时每次启动自动生成随机密钥;多实例或外部客户端可配置共享密钥。
|
||||||
authEncryptKey: 'nfd_auth_key2026'
|
# authEncryptKey: ""
|
||||||
|
# 捐赠默认关闭;开启后凭据仅供服务端选用。
|
||||||
|
enableDonatedAccounts: false
|
||||||
|
|
||||||
# 反向代理服务器配置路径(不用加后缀)
|
# 反向代理服务器配置路径(不用加后缀)
|
||||||
proxyConf: server-proxy
|
proxyConf: server-proxy
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import cn.qaiu.util.AESUtils;
|
|||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -21,7 +23,64 @@ import static org.junit.Assert.*;
|
|||||||
public class AuthParamCodecTest {
|
public class AuthParamCodecTest {
|
||||||
|
|
||||||
// 测试用的固定密钥
|
// 测试用的固定密钥
|
||||||
private static final String TEST_KEY = "nfd_auth_key2026";
|
private static final String TEST_KEY = "dummy-test-key16";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void usesOneRandomKeyPerProcessAndSupportsExplicitConfiguration() {
|
||||||
|
String generated = AuthParamCodec.selectKey(null);
|
||||||
|
assertEquals(32, generated.getBytes(StandardCharsets.UTF_8).length);
|
||||||
|
assertSame(generated, AuthParamCodec.selectKey(""));
|
||||||
|
assertSame(generated, AuthParamCodec.selectKey(" "));
|
||||||
|
assertNotEquals(AuthParamCodec.generateKey(), AuthParamCodec.generateKey());
|
||||||
|
assertEquals(TEST_KEY, AuthParamCodec.selectKey(TEST_KEY));
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> AuthParamCodec.selectKey("invalid length"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generatedKeyRoundTripsSyntheticAuth() {
|
||||||
|
AuthParam auth = AuthParam.builder().authType("token").token("synthetic-only").build();
|
||||||
|
String key = AuthParamCodec.selectKey(null);
|
||||||
|
assertEquals("synthetic-only",
|
||||||
|
AuthParamCodec.decode(AuthParamCodec.encode(auth, key), key).getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void interoperatesWithBrowserCryptoJsUsingFullUtf8Key() throws Exception {
|
||||||
|
// CryptoJS 4.2.0: AES-ECB/PKCS7, Utf8.parse(key),
|
||||||
|
// plaintext {"authType":"token","token":"synthetic-认证"}.
|
||||||
|
String[][] browserVectors = {
|
||||||
|
{"0123456789abcdef", "VxQ8JVsWso0Fhf76r82AjtWhuqKaDUtBWPUJcD+Oc1lGwDq001J2N8LJH3RSFBcA"},
|
||||||
|
{"0123456789abcdefghijklmn", "kCYuDyekW7KZf8rlLqIR0Rcwp7QWcFYn5X6tsGd6XUqlGf9RoJyFzogOgU26JJNS"},
|
||||||
|
{"0123456789abcdefghijklmnopqrstuv", "FB94nNibPhLIh+oMcnJW0Iuu3O3xSPK0WVHXCiwnvbblwSfe++oPk3RZmw6/7OqX"},
|
||||||
|
{"密钥测试甲乙丙丁", "cg0YzgNOQxws0chQxDOnepm1Ht+Pkgo7Am9McLXjkUcC35QcRiyHELm0/g4WQm2e"}
|
||||||
|
};
|
||||||
|
for (String[] vector : browserVectors) {
|
||||||
|
String key = vector[0];
|
||||||
|
AuthParam decoded = AuthParamCodec.decode(URLEncoder.encode(vector[1], StandardCharsets.UTF_8), key);
|
||||||
|
assertNotNull("browser ciphertext should decode with " + key.getBytes(StandardCharsets.UTF_8).length + "-byte key", decoded);
|
||||||
|
assertEquals("token", decoded.getAuthType());
|
||||||
|
assertEquals("synthetic-认证", decoded.getToken());
|
||||||
|
|
||||||
|
String encoded = AuthParamCodec.encode(decoded, key);
|
||||||
|
assertNotNull(encoded);
|
||||||
|
Cipher peer = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||||
|
peer.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"));
|
||||||
|
String base64 = URLDecoder.decode(encoded, StandardCharsets.UTF_8);
|
||||||
|
JsonObject plaintext = new JsonObject(new String(peer.doFinal(Base64.getDecoder().decode(base64)), StandardCharsets.UTF_8));
|
||||||
|
assertEquals("synthetic-认证", plaintext.getString("token"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void donatedAccountsRequireExplicitOptInAndDatabase() {
|
||||||
|
JsonObject server = new JsonObject().put("enableDatabase", true);
|
||||||
|
assertFalse(ParserAuthUtil.isDonatedAccountsEnabled(server));
|
||||||
|
assertTrue(ParserAuthUtil.isDonatedAccountsEnabled(server.put("enableDonatedAccounts", true)));
|
||||||
|
assertFalse(ParserAuthUtil.isDonatedAccountsEnabled(server.put("enableDatabase", false)));
|
||||||
|
assertTrue(ParserAuthUtil.supportsServerSideDonation("YE"));
|
||||||
|
assertFalse(ParserAuthUtil.supportsServerSideDonation("QK"));
|
||||||
|
assertFalse(ParserAuthUtil.supportsServerSideDonation("UC"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthParamModel() {
|
public void testAuthParamModel() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.util.Base64;
|
|||||||
*/
|
*/
|
||||||
public class AuthParamCodecTestMain {
|
public class AuthParamCodecTestMain {
|
||||||
|
|
||||||
private static final String TEST_KEY = "nfd_auth_key2026";
|
private static final String TEST_KEY = "dummy-test-key16";
|
||||||
private static int passCount = 0;
|
private static int passCount = 0;
|
||||||
private static int failCount = 0;
|
private static int failCount = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -214,7 +214,7 @@
|
|||||||
|
|
||||||
<div class="info-box">
|
<div class="info-box">
|
||||||
<p><strong>加密算法:</strong> AES/ECB/PKCS5Padding</p>
|
<p><strong>加密算法:</strong> AES/ECB/PKCS5Padding</p>
|
||||||
<p><strong>默认密钥:</strong> nfd_auth_key2026 (16位)</p>
|
<p><strong>密钥:</strong> 自建服务配置的认证密钥(仅在可信本地环境使用)</p>
|
||||||
<p><strong>编码流程:</strong> JSON对象 → AES加密 → Base64编码 → URL编码</p>
|
<p><strong>编码流程:</strong> JSON对象 → AES加密 → Base64编码 → URL编码</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -268,8 +268,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="encryptKey">加密密钥 (可选,默认: nfd_auth_key2026)</label>
|
<label for="encryptKey">加密密钥(必填)</label>
|
||||||
<input type="text" id="encryptKey" placeholder="留空使用默认密钥" value="nfd_auth_key2026">
|
<input type="password" id="encryptKey" autocomplete="off" placeholder="本地服务配置的密钥">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
@@ -368,7 +368,10 @@
|
|||||||
|
|
||||||
// AES 加密
|
// AES 加密
|
||||||
try {
|
try {
|
||||||
const encryptKey = document.getElementById('encryptKey').value.trim() || 'nfd_auth_key2026';
|
const encryptKey = document.getElementById('encryptKey').value;
|
||||||
|
if (![16, 24, 32].includes(new TextEncoder().encode(encryptKey).length)) {
|
||||||
|
throw new Error('密钥必须为 16、24 或 32 个 UTF-8 字节');
|
||||||
|
}
|
||||||
const encrypted = encryptAuthParam(JSON.stringify(authParam), encryptKey);
|
const encrypted = encryptAuthParam(JSON.stringify(authParam), encryptKey);
|
||||||
|
|
||||||
document.getElementById('encryptedResult').textContent = encrypted;
|
document.getElementById('encryptedResult').textContent = encrypted;
|
||||||
@@ -389,11 +392,6 @@
|
|||||||
|
|
||||||
// AES 加密函数
|
// AES 加密函数
|
||||||
function encryptAuthParam(jsonString, key) {
|
function encryptAuthParam(jsonString, key) {
|
||||||
// 确保密钥是16位
|
|
||||||
if (key.length !== 16) {
|
|
||||||
throw new Error('密钥必须是16位字符');
|
|
||||||
}
|
|
||||||
|
|
||||||
// AES 加密 (ECB 模式, PKCS5Padding)
|
// AES 加密 (ECB 模式, PKCS5Padding)
|
||||||
const encrypted = CryptoJS.AES.encrypt(
|
const encrypted = CryptoJS.AES.encrypt(
|
||||||
jsonString,
|
jsonString,
|
||||||
|
|||||||
Reference in new issue
Block a user