提交记录修改docs/guide/guest-systems.md+1 −1看文件
新增internal/guestos/macos_password_darwin_test.go+37 −0看文件
修改internal/guestos/macos_settings_darwin_test.go+4 −1看文件
修改scripts/guest-os/macos-maintenance.swift+1 −25看文件
修改scripts/guest-os/macos-setup-password.swift+59 −9看文件
| @@ -93,7 +93,7 @@ Windows 在确认系统提权后自动创建磁盘、安装系统和建立客机 | ||
| 93 | 93 | |
| 94 | 94 | 如果系统没有自动展开面板,可手动进入「General(通用)→ Login Items & Extensions(登录项与扩展)→ By Category(按类别)→ File System Extensions(文件系统扩展)」。如果进入「macFUSE Extensions」后开关点击无反应,点击 Done 返回,改用上述入口。macOS 的 By Application(按应用)入口存在开关无法启用的问题,见 [macFUSE 维护者说明](https://github.com/macfuse/macfuse/issues/1194)。 |
| 95 | 95 | |
| 96 | 删除:这些权限都在虚拟 Mac 内确认,首次设置期间客机断网。Apple 询问管理员身份时,用户名填 `cagesetup`,密码与 Cage 账户相同;也可点选密码框后使用「填写授权密码」。设置画面的提示和操作按钮保留在客机画面之外,可以随时返回指引。启动、密码同步、读取权限或收尾失败时,引导显示具体原因与对应的重试入口。 | |
| 96 | 新增:这些权限都在虚拟 Mac 内确认,首次设置期间客机断网。Apple 询问管理员身份时,用户名填 `cagesetup`,密码与 Cage 账户相同;也可点选密码框后使用「填写授权密码」。已经允许辅助功能后,后续系统授权弹窗仍可使用该按钮;密码填入后,由你点击弹窗中的按钮确认授权。设置画面的提示和操作按钮保留在客机画面之外,可以随时返回指引。启动、密码同步、读取权限或收尾失败时,引导显示具体原因与对应的重试入口。 | |
| 97 | 97 | |
| 98 | 98 | 系统设置收尾时,Cage 会撤销临时管理员并关闭这台客机的首次设置入口。初始化页面随后提供「连接工作区并继续检查」;需要文件夹授权时,点击「打开工作区授权」,在 Cage 显示的授权窗口中核对目录并点击 Use Project(使用项目),验证通过后继续联网检查。操作详情显示失败原因及各项检查证据;只有全部关键检查通过,才能点击「进入工作台」。 |
| 99 | 99 | |
| @@ -0,0 +1,37 @@ | ||
| 1 | 新增:package guestos | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "os" | |
| 5 | 新增: "os/exec" | |
| 6 | 新增: "path/filepath" | |
| 7 | 新增: "testing" | |
| 8 | 新增:) | |
| 9 | 新增: | |
| 10 | 新增:// Exercise the shipping native password policy without granting host permissions. | |
| 11 | 新增:func TestMacPasswordAcceptsVerifiedSettingsExtensions(t *testing.T) { | |
| 12 | 新增: dir := t.TempDir() | |
| 13 | 新增: harness := `import AppKit | |
| 14 | 新增:struct Failure: Error { | |
| 15 | 新增: let code: Int | |
| 16 | 新增: let message: String | |
| 17 | 新增: init(_ code: Int, _ message: String) { self.code = code; self.message = message } | |
| 18 | 新增:} | |
| 19 | 新增:func requireGuest() throws { throw Failure(1,"unused") } | |
| 20 | 新增:func consoleUser() throws { throw Failure(1,"unused") } | |
| 21 | 新增:@main struct Check { | |
| 22 | 新增: @MainActor static func main() throws { try MacSetupPassword.selfTest() } | |
| 23 | 新增:} | |
| 24 | 新增:` | |
| 25 | 新增: input := filepath.Join(dir, "check.swift") | |
| 26 | 新增: if err := os.WriteFile(input, []byte(harness), 0600); err != nil { | |
| 27 | 新增: t.Fatal(err) | |
| 28 | 新增: } | |
| 29 | 新增: program := filepath.Join(dir, "password-check") | |
| 30 | 新增: source := filepath.Join("..", "..", "scripts", "guest-os", "macos-setup-password.swift") | |
| 31 | 新增: if output, err := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program).CombinedOutput(); err != nil { | |
| 32 | 新增: t.Fatalf("compile password policy: %v\n%s", err, output) | |
| 33 | 新增: } | |
| 34 | 新增: if output, err := exec.CommandContext(t.Context(), program).CombinedOutput(); err != nil { | |
| 35 | 新增: t.Fatalf("password policy: %v\n%s", err, output) | |
| 36 | 新增: } | |
| 37 | 新增:} | |
| @@ -16,7 +16,10 @@ func TestMacSettingsRoutesOpenSpecificPermissionPanes(t *testing.T) { | ||
| 16 | 16 | struct Failure: Error { init(_ code: Int, _ reason: String) {} } |
| 17 | 17 | func consoleUser() throws -> String { throw Failure(1,"unused") } |
| 18 | 18 | func requireGuest() throws { throw Failure(1,"unused") } |
| 19 | 删除:enum MacSetupPassword { static func runStream() -> Never { fatalError("unused") } } | |
| 19 | 新增:enum MacSetupPassword { | |
| 20 | 新增: static func runStream() -> Never { fatalError("unused") } | |
| 21 | 新增: static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { false } | |
| 22 | 新增:} | |
| 20 | 23 | @main struct Check { |
| 21 | 24 | @MainActor static func main() { |
| 22 | 25 | for purpose in ["projects", "screen", "input"] { |
| @@ -48,30 +48,6 @@ enum MacMaintenance { | ||
| 48 | 48 | code != nil && requirement != nil && SecCodeCheckValidity(code!, [], requirement!) == errSecSuccess |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 删除: private static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { | |
| 52 | 删除: guard let bundle = app.bundleIdentifier, applications.contains(bundle), AXIsProcessTrusted() else { return false } | |
| 53 | 删除: let application = AXUIElementCreateApplication(app.processIdentifier) | |
| 54 | 删除: AXUIElementSetMessagingTimeout(application, 0.5) | |
| 55 | 删除: func attribute(_ element: AXUIElement, _ name: String) -> CFTypeRef? { | |
| 56 | 删除: var value: CFTypeRef? | |
| 57 | 删除: return AXUIElementCopyAttributeValue(element, name as CFString, &value) == .success ? value : nil | |
| 58 | 删除: } | |
| 59 | 删除: guard let value = attribute(application, kAXFocusedUIElementAttribute), CFGetTypeID(value) == AXUIElementGetTypeID() else { return false } | |
| 60 | 删除: let field = value as! AXUIElement | |
| 61 | 删除: var pid: pid_t = 0 | |
| 62 | 删除: guard AXUIElementGetPid(field, &pid) == .success, pid == app.processIdentifier, | |
| 63 | 删除: attribute(field, kAXSubroleAttribute) as? String == kAXSecureTextFieldSubrole, | |
| 64 | 删除: attribute(field, kAXEnabledAttribute) as? Bool == true, | |
| 65 | 删除: let rawWindow = attribute(field, kAXWindowAttribute), CFGetTypeID(rawWindow) == AXUIElementGetTypeID() else { return false } | |
| 66 | 删除: let owner = rawWindow as! AXUIElement | |
| 67 | 删除: var origin = CGPoint.zero, size = CGSize.zero | |
| 68 | 删除: guard let position = attribute(owner, kAXPositionAttribute), let extent = attribute(owner, kAXSizeAttribute), | |
| 69 | 删除: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(), | |
| 70 | 删除: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size) else { return false } | |
| 71 | 删除: return abs(origin.x - window.minX) < 1 && abs(origin.y - window.minY) < 1 && | |
| 72 | 删除: abs(size.width - window.width) < 1 && abs(size.height - window.height) < 1 | |
| 73 | 删除: } | |
| 74 | 删除: | |
| 75 | 51 | static func run(_ operation: String, purpose: String) throws -> [String: Any] { |
| 76 | 52 | try requireGuest() |
| 77 | 53 | let session = try consoleSession() |
| @@ -119,7 +95,7 @@ enum MacMaintenance { | ||
| 119 | 95 | } |
| 120 | 96 | return ["version": 1, "session": session, "user": NSUserName(), "pid": front.processIdentifier, |
| 121 | 97 | "window": id, "bundle": front.bundleIdentifier!, |
| 122 | 删除: "password_focused": passwordFocused(front, window: bounds), | |
| 98 | 新增: "password_focused": MacSetupPassword.passwordFocused(front, window: bounds), | |
| 123 | 99 | "rect": [region.minX, region.minY, region.width, region.height], |
| 124 | 100 | "display": [display.minX, display.minY, display.width, display.height]] |
| 125 | 101 | } |
| @@ -105,26 +105,63 @@ enum MacSetupPassword { | ||
| 105 | 105 | return target |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 删除: private static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { | |
| 108 | 新增: static func allowsPasswordProcess(hostBundle: String, hostPID: pid_t, fieldPID: pid_t, | |
| 109 | 新增: fieldBundle: String, appleSigned: Bool) -> Bool { | |
| 110 | 新增: guard hostPID > 0, fieldPID > 0, | |
| 111 | 新增: ["com.apple.systempreferences", "com.apple.authorizationhost"].contains(hostBundle) else { return false } | |
| 112 | 新增: if fieldPID == hostPID { return true } | |
| 113 | 新增: return hostBundle == "com.apple.systempreferences" && appleSigned && | |
| 114 | 新增: ["com.apple.settings.PrivacySecurity.extension", "com.apple.extensionkit.AppExtensionManagement"].contains(fieldBundle) | |
| 115 | 新增: } | |
| 116 | 新增: | |
| 117 | 新增: static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { | |
| 118 | 新增: guard let bundle = app.bundleIdentifier, AXIsProcessTrusted(), | |
| 119 | 新增: ["com.apple.systempreferences", "com.apple.authorizationhost"].contains(bundle), signed(app, bundle: bundle) else { return false } | |
| 109 | 120 | let application = AXUIElementCreateApplication(app.processIdentifier) |
| 110 | 121 | AXUIElementSetMessagingTimeout(application, 0.25) |
| 111 | 122 | func attribute(_ element: AXUIElement, _ key: String) -> CFTypeRef? { |
| 112 | 123 | var value: CFTypeRef? |
| 113 | 124 | return AXUIElementCopyAttributeValue(element, key as CFString, &value) == .success ? value : nil |
| 114 | 125 | } |
| 126 | 新增: func bounds(_ element: AXUIElement) -> CGRect? { | |
| 127 | 新增: var origin = CGPoint.zero, size = CGSize.zero | |
| 128 | 新增: guard let position = attribute(element, kAXPositionAttribute), let extent = attribute(element, kAXSizeAttribute), | |
| 129 | 新增: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(), | |
| 130 | 新增: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size), | |
| 131 | 新增: [origin.x, origin.y, size.width, size.height].allSatisfy({ $0.isFinite }), size.width > 0, size.height > 0 else { return nil } | |
| 132 | 新增: return CGRect(origin: origin, size: size) | |
| 133 | 新增: } | |
| 134 | 新增: func ownsTarget(_ element: AXUIElement) -> Bool { | |
| 135 | 新增: var pid: pid_t = 0 | |
| 136 | 新增: guard AXUIElementGetPid(element, &pid) == .success, pid == app.processIdentifier, | |
| 137 | 新增: let role = attribute(element, kAXRoleAttribute) as? String, [kAXSheetRole, kAXWindowRole].contains(role), | |
| 138 | 新增: let rect = bounds(element) else { return false } | |
| 139 | 新增: return abs(rect.minX - window.minX) < 1 && abs(rect.minY - window.minY) < 1 && | |
| 140 | 新增: abs(rect.width - window.width) < 1 && abs(rect.height - window.height) < 1 | |
| 141 | 新增: } | |
| 115 | 142 | guard let value = attribute(application, kAXFocusedUIElementAttribute), CFGetTypeID(value) == AXUIElementGetTypeID() else { return false } |
| 116 | 143 | let field = value as! AXUIElement |
| 144 | 新增: AXUIElementSetMessagingTimeout(field, 0.25) | |
| 117 | 145 | var pid: pid_t = 0 |
| 118 | 删除: guard AXUIElementGetPid(field, &pid) == .success, pid == app.processIdentifier, | |
| 146 | 新增: guard AXUIElementGetPid(field, &pid) == .success, | |
| 119 | 147 | attribute(field, kAXSubroleAttribute) as? String == kAXSecureTextFieldSubrole, |
| 120 | 148 | attribute(field, kAXEnabledAttribute) as? Bool == true, |
| 121 | 删除: let owner = attribute(field, kAXWindowAttribute), CFGetTypeID(owner) == AXUIElementGetTypeID() else { return false } | |
| 122 | 删除: var origin = CGPoint.zero, size = CGSize.zero | |
| 123 | 删除: guard let position = attribute(owner as! AXUIElement, kAXPositionAttribute), let extent = attribute(owner as! AXUIElement, kAXSizeAttribute), | |
| 124 | 删除: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(), | |
| 125 | 删除: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size) else { return false } | |
| 126 | 删除: return abs(origin.x - window.minX) < 1 && abs(origin.y - window.minY) < 1 && | |
| 127 | 删除: abs(size.width - window.width) < 1 && abs(size.height - window.height) < 1 | |
| 149 | 新增: let fieldBounds = bounds(field), window.contains(fieldBounds) else { return false } | |
| 150 | 新增: let owner = pid == app.processIdentifier ? app : NSRunningApplication(processIdentifier: pid) | |
| 151 | 新增: let ownerBundle = owner?.bundleIdentifier ?? "" | |
| 152 | 新增: guard allowsPasswordProcess(hostBundle: bundle, hostPID: app.processIdentifier, fieldPID: pid, | |
| 153 | 新增: fieldBundle: ownerBundle, appleSigned: owner.map { signed($0, bundle: ownerBundle) } ?? false) else { return false } | |
| 154 | 新增: // System Settings embeds Apple settings extensions. Their secure field | |
| 155 | 新增: // can omit AXWindow; AXParent links it to the host's authorization sheet. | |
| 156 | 新增: if let raw = attribute(field, kAXWindowAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID(), ownsTarget(raw as! AXUIElement) { return true } | |
| 157 | 新增: var ancestor = field | |
| 158 | 新增: for _ in 0..<12 { | |
| 159 | 新增: guard let raw = attribute(ancestor, kAXParentAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID() else { return false } | |
| 160 | 新增: ancestor = raw as! AXUIElement | |
| 161 | 新增: AXUIElementSetMessagingTimeout(ancestor, 0.25) | |
| 162 | 新增: if ownsTarget(ancestor) { return true } | |
| 163 | 新增: } | |
| 164 | 新增: return false | |
| 128 | 165 | } |
| 129 | 166 | |
| 130 | 167 | static func probe() throws -> [String: Any] { |
| @@ -174,6 +211,19 @@ enum MacSetupPassword { | ||
| 174 | 211 | do { try validateRequest(Data(request.utf8)); throw Failure(1, "setup_password_test_request") } |
| 175 | 212 | catch let error as Failure where error.message == "setup_password_probe_request_invalid" { } |
| 176 | 213 | } |
| 214 | 新增: // System Settings may host a secure field in its signed Apple extension. | |
| 215 | 新增: for extensionBundle in ["com.apple.settings.PrivacySecurity.extension", "com.apple.extensionkit.AppExtensionManagement"] { | |
| 216 | 新增: guard allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731, | |
| 217 | 新增: fieldBundle: extensionBundle, appleSigned: true), | |
| 218 | 新增: !allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731, | |
| 219 | 新增: fieldBundle: extensionBundle, appleSigned: false) else { throw Failure(1, "setup_password_test_extension_signature") } | |
| 220 | 新增: } | |
| 221 | 新增: guard allowsPasswordProcess(hostBundle: "com.apple.authorizationhost", hostPID: 613, fieldPID: 613, | |
| 222 | 新增: fieldBundle: "com.apple.authorizationhost", appleSigned: true), | |
| 223 | 新增: !allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731, | |
| 224 | 新增: fieldBundle: "com.apple.finder", appleSigned: true), | |
| 225 | 新增: !allowsPasswordProcess(hostBundle: "com.apple.authorizationhost", hostPID: 613, fieldPID: 731, | |
| 226 | 新增: fieldBundle: "com.apple.settings.PrivacySecurity.extension", appleSigned: true) else { throw Failure(1, "setup_password_test_process_binding") } | |
| 177 | 227 | let display = CGRect(x: 0, y: 0, width: 1920, height: 1200) |
| 178 | 228 | let parent = Window(id: 38, pid: 2338, bounds: CGRect(x: 598, y: 258, width: 723, height: 625), layer: 0) |
| 179 | 229 | let panel = Window(id: 49, pid: 2338, bounds: CGRect(x: 830, y: 376, width: 260, height: 389), layer: 0) |

