Files
youle_app_ios_v2/ylgamehall/Source/Resource/AppSecrets.swift
T
joywayerandClaude Opus 4.7 83d9502dee ADR-009 凭证集中化:AppSecrets.plist + 七牛运行参数走 RemoteConfig.audio_*(契约影响)
【数据流改造(三分制)】
- 微信 AppID  唯一源 = Info.plist CFBundleURLTypes (URLName=weixin first scheme)
- 应用级凭证 唯一源 = AppSecrets.plist (wxAppSecret/qiniuAccessKey/qiniuSecretKey)
- 七牛运行参数 唯一源 = RemoteConfig 顶层 audio_domain / audio_bucket(远端动态注入)

【契约影响】
- ChannelConfig.plist:11 key → 10 key,移除 qiniudomain(ADR-007 守护规则同步)
- BundleConfig:删除 qiniuDomain 属性
- RemoteConfig:顶层新增可选字段 audioDomain / audioBucket(JSON snake_case 自动归一化)
- 启动期:WebContainerViewController parsed 分支校验 audio_domain/audio_bucket 非空,
  缺失抛 BootError.audioConfigMissing 弹 modal 永停(与 showmessage 同等致命)
- 上线前置:测试 / 生产远端 .txt 配置必须先补 audio_domain / audio_bucket 两个顶层 key
- WeChatSDK.appID / WeChatAuth.appSecret / QiniuConfig.* 调用方零签名变化

【新增】
- ylgamehall/Resources/AppSecrets.plist(3 key)
- ylgamehall/Source/Resource/AppSecrets.swift(单例加载,对齐 BundleConfig 模式)
- QiniuConfig 改 actor:cdnDomain/bucketName 进 actor 状态 + update(...) async;
  accessKey/secretKey 仍 nonisolated(直接读 AppSecrets)
- QiniuTokenSigner.uploadToken() 改 async(bucketName 来自 actor)
- QiniuUploader 预取 cdnDomain 闭包外,SDK 同步 callback 内直接拼 URL

【删除】
- WeChatSDK.swift  static let appID  硬编码 → Info.plist 启动期解析
- WeChatAuth.swift static let appSecret 硬编码 → AppSecrets.shared.wxAppSecret
- QiniuConfig 中 accessKey / secretKey / bucketName / cdnDomain 四处硬编码
- ChannelConfig.plist 的 qiniudomain 字段(plist 与代码双源僵尸字段)

【文档同步】
- Plan:新增 ADR-009 + ADR-007 守护规则改 10 key + §236 BundleConfig 描述
- Design §3.4 多处 "11 项" → "10 项";§7.0.3 plist 示例 + BundleConfig 代码骨架
  + Scripts/inject_channel.sh 同步
- SDK-Integration-Guide §0 凭证位置改三分制 + §尾"七牛域名读取"加新外壳路径
- Verification-Checklist L69 "(11 项)" → "(10 项)"

参考契约章节:docs/Development-Plan.md ADR-009、docs/H5-Native-Implementation-Design.md §7.0.3
BuildProject 通过,Xcode 即时诊断 0 警告。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-27 21:07:55 +08:00

50 lines
1.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AppSecrets.swift
// ylgamehall
//
// 应用级凭证(跨渠道相同):从 Bundle 内的 AppSecrets.plist 读 3 个 string 值。
//
// ⚠️ 客户端硬编码 = 父项目 CLAUDE.md「已识别但接受的安全风险」,
// 集中放进 plist 仅做"单一真相源"管理,不缓解安全面 —— msext IPA 已分发数年,
// 这些凭证等价泄露;沿用同一份不引入新攻击面,也无需后台中转。
//
// 与 ChannelConfig.plist 的语义边界:
// - ChannelConfig.plist:渠道差异化字段(每个渠道签名包不同值)
// - AppSecrets.plist:跨渠道相同凭证(一份硬编码,多渠道共用)
//
// 字段对应:
// - wxAppSecret : 微信 OAuth2 access_token 换取(msext SGDefineInfo.h:107
// - qiniuAccessKey : 七牛 putPolicy 签名 + 上传 token 前缀
// - qiniuSecretKey : 七牛 HMAC-SHA1 签名 putPolicy
//
// 注:微信 AppID 不在此 plist,唯一来源是 Info.plist 的 CFBundleURLTypes
// URLName=weixin 的 first scheme)。详见 WeChatSDK.swift。
//
import Foundation
nonisolated public final class AppSecrets: Sendable {
public static let shared = AppSecrets()
public let wxAppSecret: String
public let qiniuAccessKey: String
public let qiniuSecretKey: String
public init(bundle: Bundle = .main) {
let dict = Self.loadPlist(bundle: bundle)
wxAppSecret = dict["wxAppSecret"] ?? ""
qiniuAccessKey = dict["qiniuAccessKey"] ?? ""
qiniuSecretKey = dict["qiniuSecretKey"] ?? ""
}
private static func loadPlist(bundle: Bundle) -> [String: String] {
guard let url = bundle.url(forResource: "AppSecrets", withExtension: "plist"),
let data = try? Data(contentsOf: url),
let plist = try? PropertyListSerialization.propertyList(
from: data, format: nil) as? [String: String]
else { return [:] }
return plist
}
}