mirror of
https://github.com/Lakr233/vphone-cli.git
synced 2026-10-02 08:04:32 +08:00
42 lines
1.4 KiB
Swift
42 lines
1.4 KiB
Swift
import Darwin
|
|
import Foundation
|
|
import VPhoneSign
|
|
|
|
/// vphone prepares each executable's guest entitlements before IcliKit installs it.
|
|
/// Sign them with the same bundled signer used by the host CLI, without a
|
|
/// package-manager supplied ldid executable inside the VM.
|
|
@_cdecl("vp_guest_sign_binary")
|
|
func vpGuestSignBinary(
|
|
_ path: UnsafePointer<CChar>?,
|
|
_ entitlementsPath: UnsafePointer<CChar>?,
|
|
_ certificatePath: UnsafePointer<CChar>?,
|
|
) -> UnsafeMutablePointer<CChar>? {
|
|
guard let path else { return strdup("Missing executable path") }
|
|
|
|
do {
|
|
var options = VPhoneSignOptions()
|
|
if let entitlementsPath {
|
|
options.entitlements = try Data(
|
|
contentsOf: URL(fileURLWithPath: String(cString: entitlementsPath)),
|
|
options: .mappedIfSafe,
|
|
)
|
|
} else {
|
|
options.mergesExisting = true
|
|
}
|
|
if let certificatePath {
|
|
options.mergesExisting = true
|
|
options.identity = try VPhoneSignIdentity(
|
|
pkcs12: Data(
|
|
contentsOf: URL(fileURLWithPath: String(cString: certificatePath)),
|
|
options: .mappedIfSafe,
|
|
),
|
|
password: "",
|
|
)
|
|
}
|
|
try VPhoneSigner.sign(fileAt: URL(fileURLWithPath: String(cString: path)), options: options)
|
|
return nil
|
|
} catch {
|
|
return strdup(String(describing: error))
|
|
}
|
|
}
|