mirror of
https://github.com/insidegui/VirtualBuddy.git
synced 2026-12-01 23:49:43 +08:00
* Automatic provisioning of Mac apps launched via Xcode * Improve Xcode integration sheet UI * Security: harden local debugging socket and Xcode tool usage * Soften rule around Xcode MCP use and xcodebuild prohibition * Security: harden App Store Connect API key storage and access * Fix debugged app incorrectly detected as not provisioned due to wildcard matching in provisioning profile * Add previews for provisioning and debugging UI elements * Disambiguate virtual machine vs. host Mac in provisioning and signing team management UIs * Make Xcode debugging setup accessible from the Guest menu * Completely disable debugging socket when developer features disabled, fix socket dying on accept failure * Add versioning to scheme bindings, refer to VirtualBuddy components by a stable symlinked location, store scheme URLs so that app can potentially migrate schemes in the future * Delay showing provisioning sheet so that an app that's already provisioned for the VM doesn't trigger it
57 lines
2.6 KiB
Swift
57 lines
2.6 KiB
Swift
import Darwin
|
|
import Foundation
|
|
import Security
|
|
|
|
/// The code identity required of the process at the other end of a local socket.
|
|
/// The kernel records the peer's audit token when the connection is made, so the
|
|
/// check follows that exact process image and cannot be redirected by reusing its PID.
|
|
public struct DebugPeerRequirement: @unchecked Sendable {
|
|
private let requirement: SecRequirement
|
|
|
|
public init(_ text: String) throws {
|
|
var requirement: SecRequirement?
|
|
guard SecRequirementCreateWithString(text as CFString, [], &requirement) == errSecSuccess, let requirement else {
|
|
throw MacDebugError("Invalid code requirement for the debugger connection.")
|
|
}
|
|
self.requirement = requirement
|
|
}
|
|
|
|
/// The designated requirement of the running program. An app and the helper
|
|
/// executables signed as part of its bundle satisfy the same requirement.
|
|
public static func currentApplication() throws -> Self {
|
|
var current: SecCode?
|
|
var code: SecStaticCode?
|
|
var requirement: SecRequirement?
|
|
guard SecCodeCopySelf([], ¤t) == errSecSuccess, let current,
|
|
SecCodeCopyStaticCode(current, [], &code) == errSecSuccess, let code,
|
|
SecCodeCopyDesignatedRequirement(code, [], &requirement) == errSecSuccess, let requirement else {
|
|
throw MacDebugError("This app needs a code signature to accept debugger connections.")
|
|
}
|
|
return Self(requirement)
|
|
}
|
|
|
|
private init(_ requirement: SecRequirement) { self.requirement = requirement }
|
|
|
|
fileprivate func validate(_ token: audit_token_t) throws {
|
|
let attributes = [kSecGuestAttributeAudit: withUnsafeBytes(of: token) { Data($0) }] as CFDictionary
|
|
var peer: SecCode?
|
|
guard SecCodeCopyGuestWithAttributes(nil, attributes, [], &peer) == errSecSuccess, let peer,
|
|
SecCodeCheckValidity(peer, [], requirement) == errSecSuccess else {
|
|
throw POSIXError(.EACCES)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension DebugSocket {
|
|
/// Rejects a peer that runs as another user or does not satisfy the code requirement.
|
|
public func requirePeer(_ requirement: DebugPeerRequirement) throws {
|
|
var uid: uid_t = 0, gid: gid_t = 0
|
|
var token = audit_token_t()
|
|
var size = socklen_t(MemoryLayout<audit_token_t>.size)
|
|
guard getpeereid(descriptor, &uid, &gid) == 0, uid == getuid(),
|
|
getsockopt(descriptor, SOL_LOCAL, LOCAL_PEERTOKEN, &token, &size) == 0,
|
|
size == MemoryLayout<audit_token_t>.size else { throw POSIXError(.EACCES) }
|
|
try requirement.validate(token)
|
|
}
|
|
}
|