125 lines
4.3 KiB
Markdown
125 lines
4.3 KiB
Markdown
# DCAuth 客户端
|
||
|
||
三个系统共用的设备认证客户端,通过 `dcauth://` 协议被浏览器唤起。
|
||
|
||
## 运行方式
|
||
|
||
- **Windows**:GUI 常驻程序。启动后进入系统托盘,通过协议唤起时只出现一个登录确认窗口;成功后在托盘气泡中提示,不再连续弹多个消息框。
|
||
- **macOS**:后台常驻进程,使用系统图形对话框确认登录。重复执行命令会转发给已有进程,不会叠加实例。
|
||
|
||
## 构建
|
||
|
||
Windows x64:
|
||
|
||
```bash
|
||
cd apps/dcauth
|
||
x86_64-w64-mingw32-windres --codepage=65001 versioninfo.rc \
|
||
-O coff -o versioninfo_windows_amd64.syso
|
||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 \
|
||
go build -trimpath -ldflags "-H windowsgui -s -w" \
|
||
-o dist/DCAuth.exe .
|
||
```
|
||
|
||
版本号统一在 `main.go` 的 `clientVersion` 和 `versioninfo.rc` 中维护。`DCAuth.exe` 右键“属性 → 详细信息”会显示文件版本和产品版本,托盘菜单、设备信息及确认窗口也会显示当前版本。
|
||
|
||
Windows ARM64:
|
||
|
||
```bash
|
||
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 \
|
||
go build -trimpath -ldflags "-H windowsgui -s -w" \
|
||
-o dist/DCAuth-arm64.exe .
|
||
```
|
||
|
||
macOS 通用二进制:
|
||
|
||
```bash
|
||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 \
|
||
go build -trimpath -ldflags "-s -w" -o /tmp/DCAuth-macos-arm64 .
|
||
|
||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 \
|
||
go build -trimpath -ldflags "-s -w" -o /tmp/DCAuth-macos-amd64 .
|
||
|
||
lipo -create -output dist/DCAuth-macos \
|
||
/tmp/DCAuth-macos-arm64 /tmp/DCAuth-macos-amd64
|
||
|
||
chmod +x dist/DCAuth-macos
|
||
codesign --force --sign - dist/DCAuth-macos
|
||
```
|
||
|
||
## Windows 首次运行
|
||
|
||
直接运行一次 `DCAuth.exe`:
|
||
|
||
- 注册 `dcauth://` 协议到当前 Windows 用户。
|
||
- 生成 Ed25519 设备密钥,使用 Windows DPAPI 加密保存在 `%LOCALAPPDATA%\DCAuth\device.key`。
|
||
- 进入系统托盘后台运行,不弹设备信息窗口。
|
||
|
||
托盘操作:
|
||
|
||
- 双击图标:查看设备码和机器码,并复制到剪贴板。
|
||
- 右键菜单:查看设备码、退出 DCAuth。
|
||
- 浏览器登录:只弹出一个确认窗口;点击“确定”后显示成功气泡,点击“取消”则拒绝。
|
||
- 再次唤起协议:第二个进程会把请求转交给常驻进程,然后立即退出。
|
||
|
||
## macOS 开发调试
|
||
|
||
登录页在开发模式会显示一条 `dcauth://...` 链接。复制后在终端执行:
|
||
|
||
```bash
|
||
cd apps/dcauth
|
||
./dist/DCAuth-macos "dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=http%3A%2F%2Flocalhost"
|
||
```
|
||
|
||
首次执行会启动后台进程并显示图形确认框;命令本身会立即返回。后续协议请求会转发给这个后台进程。
|
||
|
||
停止后台进程:
|
||
|
||
```bash
|
||
./dist/DCAuth-macos --exit
|
||
```
|
||
|
||
macOS 当前仍是开发版:私钥明文保存在用户配置目录的 `DCAuth/device.key`,且浏览器不会自动拉起程序,需要从登录页复制命令执行。
|
||
|
||
如果只是测后台业务,不想每次都走短信和设备验证,可以在“后台用户”里把测试账号设为 **技术测试**。该账号只使用账号密码登录;正式账号仍必须走短信 + DCAuth。
|
||
|
||
## 浏览器联动
|
||
|
||
登录页创建 challenge 后跳转:
|
||
|
||
```text
|
||
dcauth://authorize?app=order_site&challenge_id=...&challenge=...&api=https%3A%2F%2Forder.khhao.com
|
||
```
|
||
|
||
客户端校验 app 和 api 白名单后,弹出一次确认框,签名并提交到:
|
||
|
||
```text
|
||
POST /api/dcauth/authorize
|
||
```
|
||
|
||
浏览器轮询 challenge 状态,拿到一次性 ticket 后完成登录。
|
||
|
||
## 支持的应用
|
||
|
||
| app | 生产入口 |
|
||
|---|---|
|
||
| `order_site` | `https://order.khhao.com` |
|
||
| `live_hub` | `https://live.khhao.com` |
|
||
| `affiliate_dash` | `https://skin.khhao.com` |
|
||
|
||
本地开发入口已内置在 `main.go` 的 `appRegistry` 中,包括 `http://localhost`、`http://localhost/`、`http://127.0.0.1`、`http://192.168.10.6` 及对应 Vite 端口。
|
||
|
||
## 验证
|
||
|
||
```bash
|
||
go test ./...
|
||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "-H windowsgui -s -w" -o dist/DCAuth.exe .
|
||
```
|
||
|
||
## 安全说明
|
||
|
||
- 私钥不离开本机,Windows 使用 DPAPI 保护。
|
||
- 服务端只保存公钥和机器码哈希/脱敏值。
|
||
- 机器码采集主板 UUID、MachineGuid、主板/BIOS/系统盘序列号、CPU ID,不上传原始序列号。
|
||
- 正式分发前建议使用代码签名证书,避免 SmartScreen 和杀毒软件误报。
|
||
- 如果要做到 token 也不能复制,需要后续让 exe 对每次 API 请求签名,或把 exe 作为唯一客户端。
|