From d8a9bf5a0d4a07a74e3b4b356f1768beddd36370 Mon Sep 17 00:00:00 2001 From: coso Date: Thu, 8 Jan 2026 18:43:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=87=E7=94=A8=E9=9D=99=E6=80=81=20U?= =?UTF-8?q?UID=20=E6=96=B9=E6=A1=88=E7=94=9F=E6=88=90=20Machine=20ID?= =?UTF-8?q?=EF=BC=88=E4=B8=8E=20AIClient-2-API=20=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除时间变化因子,Machine ID 保持静态 - 统一优先级:uuid > profileArn > clientId > 默认值 - 新增 generate_machine_id_from_credentials_with_uuid 函数 - 更新版本号至 v0.36.1 --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/providers/kiro.rs | 44 ++++++++++++++++----------------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index a0cbd1976..61e2069f4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "proxycast", "private": true, - "version": "0.36.0", + "version": "0.36.1", "type": "module", "repository": { "type": "git", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index be2256d79..ae5376f8b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3854,7 +3854,7 @@ dependencies = [ [[package]] name = "proxycast" -version = "0.36.0" +version = "0.36.1" dependencies = [ "anyhow", "arboard", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6ea617b72..f6b0430bf 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proxycast" -version = "0.36.0" +version = "0.36.1" description = "AI API Proxy Desktop App" authors = ["you"] edition = "2021" diff --git a/src-tauri/src/providers/kiro.rs b/src-tauri/src/providers/kiro.rs index fc498ffc6..886be36e2 100644 --- a/src-tauri/src/providers/kiro.rs +++ b/src-tauri/src/providers/kiro.rs @@ -14,42 +14,40 @@ use serde::{Deserialize, Serialize}; use std::error::Error; use std::path::PathBuf; -/// 根据凭证信息生成唯一的 Machine ID(参考 AIClient-2-API 实现) +/// 根据凭证信息生成唯一的 Machine ID(与 AIClient-2-API 保持一致) /// -/// 关键改进:每个凭证生成独立的 Machine ID,避免多账号共用同一指纹被检测 -/// 优先级:profileArn > clientId > 系统硬件 ID +/// 采用静态 UUID 方案:每个凭证生成固定的 Machine ID,不随时间变化 +/// 优先级:uuid > profileArn > clientId > 系统硬件 ID /// -/// 防指纹固化:添加基于小时的时间变化因子,在保持稳定性的同时避免指纹完全固化 -/// 这样每个 OAuth 凭证都有自己独立的指纹,模拟不同设备登录 +/// 这是目前最稳定的方案,与 AIClient-2-API 的实现完全一致 pub fn generate_machine_id_from_credentials( profile_arn: Option<&str>, client_id: Option<&str>, +) -> String { + generate_machine_id_from_credentials_with_uuid(None, profile_arn, client_id) +} + +/// 带 UUID 参数的 Machine ID 生成函数(与 AIClient-2-API 完全一致) +/// +/// 优先级:uuid > profileArn > clientId > 默认值 +/// 生成静态的 SHA256 哈希,不包含时间因子 +pub fn generate_machine_id_from_credentials_with_uuid( + uuid: Option<&str>, + profile_arn: Option<&str>, + client_id: Option<&str>, ) -> String { use sha2::{Digest, Sha256}; - // 优先使用凭证相关的唯一标识,确保每个账号有独立的 Machine ID - let unique_key = profile_arn + // 优先级:uuid > profileArn > clientId > 默认值(与 AIClient-2-API 一致) + let unique_key = uuid .filter(|s| !s.is_empty()) + .or(profile_arn.filter(|s| !s.is_empty())) .or(client_id.filter(|s| !s.is_empty())) - .map(|s| s.to_string()) - .unwrap_or_else(|| { - // 回退到系统硬件 ID - get_raw_machine_id().unwrap_or_else(|| "KIRO_DEFAULT_MACHINE".to_string()) - }); - - // 添加时间变化因子 - 按小时变化,避免指纹固化 - // 使用小时级别的时间戳,确保在同一小时内指纹稳定,但定期变化 - let now = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap_or_default() - .as_secs(); - - // 按小时分组,每小时指纹会轻微变化 - let hour_slot = now / 3600; + .unwrap_or("KIRO_DEFAULT_MACHINE"); + // 静态哈希,不添加时间因子(与 AIClient-2-API 保持一致) let mut hasher = Sha256::new(); hasher.update(unique_key.as_bytes()); - hasher.update(&hour_slot.to_le_bytes()); // 添加时间因子 let result = hasher.finalize(); format!("{:x}", result) }