@mcesystems/apple-kit 1.0.95 → 1.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +258 -258
  2. package/dist/index.js +97 -67
  3. package/dist/index.js.map +2 -2
  4. package/dist/index.mjs +97 -67
  5. package/dist/index.mjs.map +3 -3
  6. package/dist/resources/plist/certificate-trust.xml +43 -43
  7. package/dist/resources/plist/wifi-enterprise.xml +59 -59
  8. package/dist/resources/plist/wifi-standard.xml +50 -50
  9. package/dist/types/index.d.ts +13 -34
  10. package/package.json +3 -3
  11. package/resources/ios.exe +0 -0
  12. package/resources/wintun-LICENSE.txt +84 -0
  13. package/resources/wintun.dll +0 -0
  14. package/scripts/README.md +209 -209
  15. package/scripts/build-windows.sh.template +222 -222
  16. package/dist/resources/bin/darwin/idevice_id +0 -0
  17. package/dist/resources/bin/darwin/idevicedebug +0 -0
  18. package/dist/resources/bin/darwin/idevicediagnostics +0 -0
  19. package/dist/resources/bin/darwin/ideviceinfo +0 -0
  20. package/dist/resources/bin/darwin/ideviceinstaller +0 -0
  21. package/dist/resources/bin/darwin/idevicename +0 -0
  22. package/dist/resources/bin/darwin/idevicepair +0 -0
  23. package/dist/resources/bin/darwin/idevicescreenshot +0 -0
  24. package/dist/resources/bin/darwin/idevicesyslog +0 -0
  25. package/dist/resources/bin/darwin/iproxy +0 -0
  26. package/dist/resources/bin/darwin/libcrypto.3.dylib +0 -0
  27. package/dist/resources/bin/darwin/libimobiledevice-1.0.6.dylib +0 -0
  28. package/dist/resources/bin/darwin/libimobiledevice-glue-1.0.0.dylib +0 -0
  29. package/dist/resources/bin/darwin/liblzma.5.dylib +0 -0
  30. package/dist/resources/bin/darwin/libplist-2.0.4.dylib +0 -0
  31. package/dist/resources/bin/darwin/libssl.3.dylib +0 -0
  32. package/dist/resources/bin/darwin/libusbmuxd-2.0.7.dylib +0 -0
  33. package/dist/resources/bin/darwin/libzip.5.dylib +0 -0
  34. package/dist/resources/bin/darwin/libzstd.1.dylib +0 -0
  35. package/dist/resources/licenses/LGPL-2.1.txt +0 -33
  36. package/dist/types/index.d.ts.map +0 -1
  37. package/dist/types/logic/actions/activation.d.ts +0 -12
  38. package/dist/types/logic/actions/activation.d.ts.map +0 -1
  39. package/dist/types/logic/actions/device.d.ts +0 -15
  40. package/dist/types/logic/actions/device.d.ts.map +0 -1
  41. package/dist/types/logic/actions/install.d.ts +0 -10
  42. package/dist/types/logic/actions/install.d.ts.map +0 -1
  43. package/dist/types/logic/actions/pair.d.ts +0 -6
  44. package/dist/types/logic/actions/pair.d.ts.map +0 -1
  45. package/dist/types/logic/actions/proxy.d.ts +0 -23
  46. package/dist/types/logic/actions/proxy.d.ts.map +0 -1
  47. package/dist/types/logic/actions/restore.d.ts +0 -36
  48. package/dist/types/logic/actions/restore.d.ts.map +0 -1
  49. package/dist/types/logic/actions/tool.d.ts +0 -8
  50. package/dist/types/logic/actions/tool.d.ts.map +0 -1
  51. package/dist/types/logic/activationFlow.d.ts +0 -15
  52. package/dist/types/logic/activationFlow.d.ts.map +0 -1
  53. package/dist/types/logic/appleDeviceKit.d.ts +0 -164
  54. package/dist/types/logic/appleDeviceKit.d.ts.map +0 -1
  55. package/dist/types/logic/dataParser.d.ts +0 -23
  56. package/dist/types/logic/dataParser.d.ts.map +0 -1
  57. package/dist/types/logic/iosCli.d.ts +0 -6
  58. package/dist/types/logic/iosCli.d.ts.map +0 -1
  59. package/dist/types/logic/utils/resolvePath.d.ts +0 -13
  60. package/dist/types/logic/utils/resolvePath.d.ts.map +0 -1
  61. package/dist/types/types/activation.d.ts +0 -28
  62. package/dist/types/types/activation.d.ts.map +0 -1
  63. package/dist/types/types/ios.d.ts +0 -152
  64. package/dist/types/types/ios.d.ts.map +0 -1
  65. package/dist/types/types/trust.d.ts +0 -10
  66. package/dist/types/types/trust.d.ts.map +0 -1
  67. package/dist/types/types/types.d.ts +0 -47
  68. package/dist/types/types/types.d.ts.map +0 -1
  69. package/dist/types/types/wifi.d.ts +0 -19
  70. package/dist/types/types/wifi.d.ts.map +0 -1
  71. package/dist/types/types.d.ts +0 -140
  72. package/dist/types/types.d.ts.map +0 -1
  73. package/dist/types/utils/debug.d.ts +0 -17
  74. package/dist/types/utils/debug.d.ts.map +0 -1
  75. package/dist/types/utils/templateLoader.d.ts +0 -8
  76. package/dist/types/utils/templateLoader.d.ts.map +0 -1
  77. package/dist/types/utils/wifiProfile.d.ts +0 -14
  78. package/dist/types/utils/wifiProfile.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -376,8 +376,7 @@ var require_retry_promise = __commonJS({
376
376
 
377
377
  // src/logic/appleDeviceKit.ts
378
378
  import { readFileSync, unlinkSync } from "node:fs";
379
- import { mkdir, stat } from "node:fs/promises";
380
- import { writeFile as writeFile2 } from "node:fs/promises";
379
+ import { mkdir, stat, writeFile as writeFile2 } from "node:fs/promises";
381
380
  import { join as join5 } from "node:path";
382
381
 
383
382
  // ../tool-debug/dist/index.mjs
@@ -1686,6 +1685,9 @@ ${out.stderr}`;
1686
1685
  rmSync(lockdownFile, { force: true });
1687
1686
  return true;
1688
1687
  }
1688
+ getLockdownPath() {
1689
+ return getLockdownPath();
1690
+ }
1689
1691
  };
1690
1692
 
1691
1693
  // ../mdm-client/dist/index.mjs
@@ -38604,31 +38606,34 @@ function escapeXml(str) {
38604
38606
  var { logInfo: logInfo5 } = createLoggers("apple-kit:wifi-profile");
38605
38607
  async function generateWifiProfile(config, options) {
38606
38608
  const {
38607
- ssid,
38608
38609
  encryptionType,
38609
38610
  password,
38610
38611
  autoJoin = true,
38611
38612
  organizationName = "MCE Systems",
38612
- displayName = `WiFi - ${ssid}`,
38613
38613
  enterprise = false,
38614
38614
  username,
38615
38615
  acceptAnyCertificate = true
38616
38616
  } = config;
38617
+ const resolvedSsid = config.ssid ?? process.env.WIFI_SSID ?? "";
38618
+ if (!resolvedSsid) {
38619
+ throw new Error("WiFi SSID is required. Set config.ssid or WIFI_SSID environment variable.");
38620
+ }
38617
38621
  const profileUuid = randomUUID().toUpperCase();
38618
38622
  const payloadUuid = randomUUID().toUpperCase();
38619
- const profileId = `com.mce.wifi.${ssid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
38623
+ const profileId = `com.mce.wifi.${resolvedSsid.replace(/[^a-zA-Z0-9]/g, "")}.${Date.now()}`;
38620
38624
  const payloadId = `${profileId}.payload`;
38621
- logInfo5(`Generating WiFi profile for SSID: ${ssid}, encryption: ${encryptionType}`);
38625
+ const displayNameToUse = config.displayName ?? `WiFi - ${resolvedSsid}`;
38626
+ logInfo5(`Generating WiFi profile for SSID: ${resolvedSsid}, encryption: ${encryptionType}`);
38622
38627
  const templateName = enterprise ? "wifi-enterprise.xml" : "wifi-standard.xml";
38623
38628
  const template = await loadTemplate(templateName, options?.plistDir);
38624
38629
  const variables = {
38625
- ssid: config.ssid ?? process.env.WIFI_SSID,
38630
+ ssid: resolvedSsid,
38626
38631
  password: config.password ?? process.env.WIFI_PASSWORD,
38627
38632
  encryptionType: parseWifiEncryptionType(config.encryptionType ?? process.env.WIFI_ENCRYPTION),
38628
38633
  autoJoin: autoJoin ? "true" : "false",
38629
38634
  hiddenNetwork: config.hiddenNetwork ?? process.env.WIFI_HIDDEN === "true",
38630
38635
  organizationName,
38631
- displayName,
38636
+ displayName: displayNameToUse,
38632
38637
  profileId,
38633
38638
  profileUuid,
38634
38639
  payloadId,
@@ -38723,10 +38728,9 @@ function isAbortError(error) {
38723
38728
  return error instanceof DOMException && error.name === "AbortError";
38724
38729
  }
38725
38730
  var ActivationFlow = class {
38726
- constructor(udid, iosClient, deviceActions) {
38731
+ constructor(udid, iosClient) {
38727
38732
  this.udid = udid;
38728
38733
  this.iosClient = iosClient;
38729
- this.deviceActions = deviceActions;
38730
38734
  setNamespace4(`${udid}`);
38731
38735
  }
38732
38736
  mdmClient;
@@ -38762,14 +38766,6 @@ var ActivationFlow = class {
38762
38766
  signal
38763
38767
  );
38764
38768
  throwIfAborted2(signal);
38765
- const expectedSsid = config.wifiProfileConfig?.ssid;
38766
- if (expectedSsid) {
38767
- if (await this.deviceActions.isWifiConnected(15e3) !== expectedSsid) {
38768
- throw new Error(
38769
- `WiFi profile not installed correctly, expected ${expectedSsid} but got ${await this.deviceActions.isWifiConnected(15e3)}`
38770
- );
38771
- }
38772
- }
38773
38769
  await this.installMdmProfile(events, signal);
38774
38770
  throwIfAborted2(signal);
38775
38771
  }
@@ -39172,46 +39168,60 @@ var IosClient = class {
39172
39168
  async devMode() {
39173
39169
  return this.runIosCommand(["devmode", "enable", "--udid", this.udid]);
39174
39170
  }
39175
- async tunnelStart(userspace = false) {
39176
- const args = ["tunnel", "start", "--udid", this.udid, ...userspace ? ["--userspace"] : []];
39177
- logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
39178
- const child = spawn(this.iosPath, args, {
39179
- windowsHide: true,
39180
- env: {
39181
- ...process.env,
39182
- USBMUXD_SOCKET_ADDRESS: this.usbmuxdAddress
39183
- },
39184
- stdio: ["ignore", "pipe", "pipe"]
39171
+ async tunnelStart(userspace = false, pairRecordPath) {
39172
+ return new Promise((resolve2, reject) => {
39173
+ const args = [
39174
+ "tunnel",
39175
+ "start",
39176
+ `--pair-record-path=${pairRecordPath ?? "default"}`,
39177
+ "--udid",
39178
+ this.udid,
39179
+ ...userspace ? ["--userspace"] : []
39180
+ ];
39181
+ logDetail(`Spawning tunnel: ${this.iosPath} ${args.join(" ")}`);
39182
+ const child = spawn(this.iosPath, args, {
39183
+ windowsHide: true,
39184
+ env: {
39185
+ ...process.env,
39186
+ USBMUXD_SOCKET_ADDRESS: this.usbmuxdAddress
39187
+ },
39188
+ stdio: ["ignore", "pipe", "pipe"]
39189
+ });
39190
+ let settled = false;
39191
+ const cleanup = () => {
39192
+ child.off("error", onError);
39193
+ child.off("exit", onExit);
39194
+ child.stdout?.off("data", onReadyCheck);
39195
+ child.stderr?.off("data", onReadyCheck);
39196
+ clearTimeout(readyTimeout);
39197
+ };
39198
+ const finish = (result) => {
39199
+ if (settled) {
39200
+ return;
39201
+ }
39202
+ settled = true;
39203
+ cleanup();
39204
+ if (result.reject) {
39205
+ reject(result.reject);
39206
+ return;
39207
+ }
39208
+ if (result.resolve !== void 0) {
39209
+ resolve2(result.resolve);
39210
+ }
39211
+ };
39212
+ const onError = (err) => finish({ reject: err });
39213
+ const onExit = (code) => finish({ reject: new Error(`Tunnel exited early (code=${code})`) });
39214
+ const onReadyCheck = (data) => {
39215
+ const line = data.toString();
39216
+ const isReady = line.includes("Tunnel server started") || line.includes("tunnel") && (line.includes("listening") || line.includes("connected"));
39217
+ if (isReady) finish({ resolve: child });
39218
+ };
39219
+ const readyTimeout = setTimeout(() => finish({ resolve: child }), 1e4);
39220
+ child.once("error", onError);
39221
+ child.once("exit", onExit);
39222
+ child.stdout?.on("data", onReadyCheck);
39223
+ child.stderr?.on("data", onReadyCheck);
39185
39224
  });
39186
- let settled = false;
39187
- const cleanup = () => {
39188
- child.off("error", onError);
39189
- child.off("exit", onExit);
39190
- child.stdout?.off("data", onReadyCheck);
39191
- child.stderr?.off("data", onReadyCheck);
39192
- clearTimeout(readyTimeout);
39193
- };
39194
- const finish = (result) => {
39195
- if (settled) return;
39196
- settled = true;
39197
- cleanup();
39198
- if (result.reject) throw result.reject;
39199
- if (result.resolve !== void 0) return result.resolve;
39200
- throw new Error("Tunnel process not found");
39201
- };
39202
- const onError = (err) => finish({ reject: err });
39203
- const onExit = (code) => finish({ reject: new Error(`Tunnel exited early (code=${code})`) });
39204
- const onReadyCheck = (data) => {
39205
- const line = data.toString();
39206
- const isReady = line.includes("Tunnel server started") || line.includes("tunnel") && (line.includes("listening") || line.includes("connected"));
39207
- if (isReady) finish({ resolve: child });
39208
- };
39209
- const readyTimeout = setTimeout(() => finish({ resolve: child }), 1e4);
39210
- child.once("error", onError);
39211
- child.once("exit", onExit);
39212
- child.stdout?.on("data", onReadyCheck);
39213
- child.stderr?.on("data", onReadyCheck);
39214
- return child;
39215
39225
  }
39216
39226
  async fsyncPull({
39217
39227
  app,
@@ -39333,9 +39343,9 @@ var AppleDeviceKit = class _AppleDeviceKit {
39333
39343
  this.iosClient = new IosClient(iosBinaryPath, udid, usbmuxdAddress);
39334
39344
  this.deviceActions = new DeviceActions(this.deviceId, this.iosClient);
39335
39345
  this.installActions = new InstallActions(this.deviceId, this.iosClient);
39336
- this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient, this.deviceActions);
39346
+ this.activationFlow = new ActivationFlow(this.deviceId, this.iosClient);
39337
39347
  this.proxyActions = new ProxyActions(this.deviceId, this.iosClient);
39338
- this.ensureTunnel();
39348
+ this.getTunnelReady();
39339
39349
  }
39340
39350
  deviceId;
39341
39351
  proxyProcess = null;
@@ -39347,7 +39357,18 @@ var AppleDeviceKit = class _AppleDeviceKit {
39347
39357
  activationFlow;
39348
39358
  proxyActions;
39349
39359
  tunnelProcess = null;
39360
+ tunnelReadyPromise = null;
39350
39361
  static IOS_17_VERSION = 17;
39362
+ /**
39363
+ * Returns a promise that resolves when the tunnel is ready (or immediately if not needed).
39364
+ * Reuses the same in-flight promise so constructor and methods don't race.
39365
+ */
39366
+ getTunnelReady() {
39367
+ if (!this.tunnelReadyPromise) {
39368
+ this.tunnelReadyPromise = this.runEnsureTunnel();
39369
+ }
39370
+ return this.tunnelReadyPromise;
39371
+ }
39351
39372
  /**
39352
39373
  * Check if iOS version requires tunneling (iOS 17+)
39353
39374
  */
@@ -39365,9 +39386,15 @@ var AppleDeviceKit = class _AppleDeviceKit {
39365
39386
  }
39366
39387
  }
39367
39388
  /**
39368
- * Ensure tunnel is started for iOS 17+ devices
39389
+ * Ensure tunnel is started for iOS 17+ devices. Safe to call multiple times; reuses in-flight setup.
39369
39390
  */
39370
39391
  async ensureTunnel() {
39392
+ await this.getTunnelReady();
39393
+ }
39394
+ /**
39395
+ * Internal tunnel startup. Called once per tunnel lifecycle; getTunnelReady() caches this promise.
39396
+ */
39397
+ async runEnsureTunnel() {
39371
39398
  const requiresTunnel = await this.requiresTunneling();
39372
39399
  if (!requiresTunnel) {
39373
39400
  logDetail2(`Device ${this.deviceId} does not require tunneling (iOS < 17)`);
@@ -39380,19 +39407,28 @@ var AppleDeviceKit = class _AppleDeviceKit {
39380
39407
  }
39381
39408
  logInfo7(`Starting tunnel for device ${this.deviceId} (iOS 17+)`);
39382
39409
  try {
39383
- const tunnelProcess = await this.iosClient.tunnelStart(true);
39410
+ const pairRecordPath = join5(
39411
+ this.deviceActions.getLockdownPath() ?? "",
39412
+ "RemotePairing",
39413
+ `${this.deviceId}`
39414
+ );
39415
+ await mkdir(pairRecordPath, { recursive: true });
39416
+ const tunnelProcess = await this.iosClient.tunnelStart(true, pairRecordPath);
39384
39417
  this.tunnelProcess = tunnelProcess;
39385
39418
  tunnelProcess.on("exit", (code) => {
39386
39419
  logError3(`Tunnel process for device ${this.deviceId} exited with code ${code}`);
39387
39420
  this.tunnelProcess = null;
39421
+ this.tunnelReadyPromise = null;
39388
39422
  });
39389
39423
  tunnelProcess.on("error", (error) => {
39390
39424
  logError3(`Tunnel process error for device ${this.deviceId}: ${error.message}`);
39391
39425
  this.tunnelProcess = null;
39426
+ this.tunnelReadyPromise = null;
39392
39427
  });
39393
39428
  await new Promise((resolve2) => setTimeout(resolve2, 1e3));
39394
39429
  logInfo7(`Tunnel started successfully for device ${this.deviceId}`);
39395
39430
  } catch (error) {
39431
+ this.tunnelReadyPromise = null;
39396
39432
  logError3(
39397
39433
  `Failed to start tunnel for device ${this.deviceId}: ${error instanceof Error ? error.message : String(error)}`
39398
39434
  );
@@ -39630,9 +39666,6 @@ var AppleDeviceKit = class _AppleDeviceKit {
39630
39666
  }
39631
39667
  logInfo7(`File ${fileName} pushed to device ${this.deviceId}`);
39632
39668
  } finally {
39633
- if (requiresTunnel) {
39634
- this.stopTunnel();
39635
- }
39636
39669
  try {
39637
39670
  unlinkSync(tmpFilePath);
39638
39671
  } catch (_error) {
@@ -39669,9 +39702,6 @@ var AppleDeviceKit = class _AppleDeviceKit {
39669
39702
  logInfo7(`File ${fileName} pulled from device ${this.deviceId}`);
39670
39703
  return fileData;
39671
39704
  } finally {
39672
- if (requiresTunnel) {
39673
- this.stopTunnel();
39674
- }
39675
39705
  try {
39676
39706
  unlinkSync(tmpFilePath);
39677
39707
  } catch (_error) {