feat: AI PRO 离线凭证激活与统一门禁
默认不激活 AI PRO,需服务方离线下发 Ed25519 签名凭证后在本地执行 hose-aipro login 激活。凭证只含 sub / exp / maxVersion 等业务字段, 校验完全在本地完成,不联网。 约束仅两条: - 当前二进制版本不得高于 maxVersion(三段数字比较,忽略 -dev 后缀) - 当前时间不得晚于 exp(绝对到期时间;不做时长上限、不做时钟防篡改) 实现要点: - src/cli/aipro-license.ts 单文件承载验签、版本比较、0600 凭证落盘、 门禁与 login;公钥内嵌源码,私钥由签发方离线保管、绝不进仓库 - src/aipro-cli.ts 分发层 12 行统一门禁;login 在门禁前分流且不进命令 注册表。以后新增任何 AI PRO 命令只需照常注册,自动受门禁管辖, 授权代码零侵入 - scripts/license/issue.ts 离线签发,私钥只读本地文件或环境变量, exp 想签多久签多久,脚本不施加任何天数限制 - 放行 status / help / version 等自省命令,其余业务命令未激活一律拦截 - 测试用进程内依赖注入临时密钥对,不引入环境变量后门 - skills/hose-aipro/SKILL.md 补充激活说明 校验:bun test 1094 pass / 0 fail,bun run check 通过; 端到端冒烟(未激活拦截 → 签发 → login → 版本超限拒绝)全通过。
This commit is contained in:
1 parent
19d8fd3c59
commit
957cb04324
6 files changed
+502
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
handleSaasPlatformRedirect,
|
||||
} from "./cli/aipro-registry.js";
|
||||
import { handleAiProHelp } from "./cli/commands/aipro/status.js";
|
||||
import { assertAiProEnabled, handleAiProLogin } from "./cli/aipro-license.js";
|
||||
import type { AiProExecutionContext } from "./cli/commands/aipro/types.js";
|
||||
|
||||
export async function runAiProCli(
|
||||
@@ -97,11 +98,22 @@ async function runAiProCliOnce(rawArgs: string[]): Promise<{ stdout: string; std
|
||||
};
|
||||
|
||||
try {
|
||||
if (command === "login" || command === "activate") {
|
||||
return handleAiProLogin(rawArgs, jsonMode);
|
||||
}
|
||||
if (booleanOption(parsed.options, ["version", "v"])) {
|
||||
const versionDef = findAiProCommand("version");
|
||||
if (versionDef) return await versionDef.handler(ctx);
|
||||
}
|
||||
|
||||
// 统一门禁:除只读自省命令外,其余 AI PRO 命令一律要求有效凭证。
|
||||
// 以后新增命令只需照常注册,自动被此处拦截,无需改动授权代码。
|
||||
const readOnly = new Set(["status", "whoami", "context", "info", "help", "version", "v"]);
|
||||
if (!readOnly.has(command)) {
|
||||
const licenseGate = assertAiProEnabled(jsonMode);
|
||||
if (licenseGate) return licenseGate;
|
||||
}
|
||||
|
||||
const commandDef = findAiProCommand(command);
|
||||
if (commandDef) {
|
||||
return await commandDef.handler(ctx);
|
||||
|
||||
Reference in new issue
Block a user