Skip to content

Commit

Permalink
use keybagd for container entitlement
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiChou committed Jan 3, 2024
1 parent a3ba884 commit e2d82bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
File renamed without changes.
21 changes: 12 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ export class BagBak extends EventEmitter {
await readFromPackage('agent', 'launchd.js'));
await launchdScript.load();

await this.#device.openChannel(`lockdown:com.apple.mobile.installation_proxy`);
const installerSession = await this.#device.attach('mobile_installation_proxy');
const installerScript = await installerSession.createScript(
await readFromPackage('agent', 'installer.js'));
await installerScript.load();
// for com.apple.private.security.container-manager entitlement
const keybagdPid = await launchdScript.exports.spawn('/usr/libexec/keybagd');
const keybagdSession = await this.#device.attach(keybagdPid);
const keybagdScript = await keybagdSession.createScript(
await readFromPackage('agent', 'keybagd.js'));
await keybagdScript.load();

// fist, copy directory to local
const remoteRoot = this.remote;
Expand Down Expand Up @@ -149,7 +150,7 @@ export class BagBak extends EventEmitter {
debug('main executable =>', mainExecutable);

if (mainExecutable.startsWith('/private/var/containers/Bundle/Application/')) {
installerScript.exports.chmod(mainExecutable);
keybagdScript.exports.chmod(mainExecutable);
}

/**
Expand Down Expand Up @@ -228,16 +229,18 @@ export class BagBak extends EventEmitter {
await this.#device.kill(pid);
}

await keybagdScript.unload();
await keybagdSession.detach();
await this.#device.kill(keybagdPid);
childPids.add(keybagdPid);

// cleanup
for (const pid of childPids) {
const zombieKilled = await launchdScript.exports.cleanup(pid);
debug('kill zombie pid', pid, '=>', zombieKilled ? 'OK' : 'failed');
}

await launchdScript.unload();
await launchdSession.detach();
await installerScript.unload();
await installerSession.detach();

return localRoot;
}
Expand Down

0 comments on commit e2d82bb

Please sign in to comment.