Managed SSH previously tied remote Agent and Runtime artifacts to desktop packaging and Host activation. Settings now manages verified Linux x64 and arm64 .gbagent packages explicitly, with source-aligned download and update plus offline import and export. Each package contains the signed Agent, pinned Node, and compatible OpenCode Runtime, and project activation never downloads one automatically. Dedicated native CI and a protected release workflow publish deterministic, signed cumulative catalogs to GitHub and Beijing OSS without replacing the desktop Latest release. Desktop packaging is metadata-only, remains independent of Agent artifacts and signing credentials, and Linux desktop releases add RPM installers. The managed SSH path also keeps model credentials in Main, enforces Ask as read-only, verifies signed Agent and Runtime inputs, preserves ACP recovery, and reports Host update cancellation and failures accurately. Release note: 远程项目现可在“设置”中手动下载、更新或离线导入签名 Agent 包,桌面安装包与远程组件发布相互独立;Linux 桌面版同时新增 RPM 安装包。
114 lines
2.7 KiB
TypeScript
114 lines
2.7 KiB
TypeScript
import {
|
|
createHmac,
|
|
randomBytes,
|
|
timingSafeEqual
|
|
} from 'node:crypto'
|
|
|
|
const CHALLENGE_DOMAIN = 'goodbuddy-agent-installation-challenge-v1\0'
|
|
|
|
export type InstallationChallenge = {
|
|
serverNonce: string
|
|
expiresAt: number
|
|
}
|
|
|
|
export class InstallationChallengeVerifier {
|
|
readonly #secret: Buffer
|
|
readonly #now: () => number
|
|
readonly #lifetimeMs: number
|
|
readonly #pending = new Map<string, number>()
|
|
|
|
constructor(
|
|
secret: Uint8Array,
|
|
options: { now?: () => number; lifetimeMs?: number } = {}
|
|
) {
|
|
if (secret.byteLength < 32) {
|
|
throw new RangeError('Installation challenge secret is too short')
|
|
}
|
|
this.#secret = Buffer.from(secret)
|
|
this.#now = options.now ?? Date.now
|
|
this.#lifetimeMs = options.lifetimeMs ?? 30_000
|
|
if (!Number.isSafeInteger(this.#lifetimeMs) || this.#lifetimeMs < 1) {
|
|
throw new RangeError('Invalid installation challenge lifetime')
|
|
}
|
|
}
|
|
|
|
issue(): InstallationChallenge {
|
|
this.#purgeExpired()
|
|
const serverNonce = randomBytes(32).toString('hex')
|
|
const expiresAt = this.#now() + this.#lifetimeMs
|
|
this.#pending.set(serverNonce, expiresAt)
|
|
return { serverNonce, expiresAt }
|
|
}
|
|
|
|
createResponse(input: {
|
|
serverNonce: string
|
|
clientNonce: string
|
|
controllerId: string
|
|
}): string {
|
|
return calculateResponse(this.#secret, input)
|
|
}
|
|
|
|
verify(input: {
|
|
serverNonce: string
|
|
clientNonce: string
|
|
controllerId: string
|
|
response: string
|
|
}): boolean {
|
|
const expiresAt = this.#pending.get(input.serverNonce)
|
|
this.#pending.delete(input.serverNonce)
|
|
if (expiresAt === undefined || expiresAt < this.#now()) {
|
|
return false
|
|
}
|
|
const expected = Buffer.from(
|
|
calculateResponse(this.#secret, input),
|
|
'base64url'
|
|
)
|
|
let received: Buffer
|
|
try {
|
|
received = Buffer.from(input.response, 'base64url')
|
|
} catch {
|
|
return false
|
|
}
|
|
return (
|
|
expected.byteLength === received.byteLength &&
|
|
timingSafeEqual(expected, received)
|
|
)
|
|
}
|
|
|
|
#purgeExpired(): void {
|
|
const now = this.#now()
|
|
for (const [nonce, expiresAt] of this.#pending) {
|
|
if (expiresAt < now) {
|
|
this.#pending.delete(nonce)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function calculateResponse(
|
|
secret: Uint8Array,
|
|
input: {
|
|
serverNonce: string
|
|
clientNonce: string
|
|
controllerId: string
|
|
}
|
|
): string {
|
|
for (const value of [
|
|
input.serverNonce,
|
|
input.clientNonce,
|
|
input.controllerId
|
|
]) {
|
|
if (!/^[A-Za-z0-9._:-]{1,128}$/u.test(value)) {
|
|
throw new Error('Invalid installation challenge field')
|
|
}
|
|
}
|
|
return createHmac('sha256', secret)
|
|
.update(CHALLENGE_DOMAIN)
|
|
.update(input.serverNonce)
|
|
.update('\0')
|
|
.update(input.clientNonce)
|
|
.update('\0')
|
|
.update(input.controllerId)
|
|
.digest('base64url')
|
|
}
|