2 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 class Client: TrustedPeersHelperProtocol {
28 let endpoint: NSXPCListenerEndpoint?
29 let containerMap: ContainerMap
31 init(endpoint: NSXPCListenerEndpoint?, containerMap: ContainerMap) {
32 self.endpoint = endpoint
33 self.containerMap = containerMap
36 func ping(reply: @escaping (() -> Void)) {
40 func logComplete(function: String, container: ContainerName, error: Error?) {
41 if let error = error {
42 os_log("%@ errored for %@: %@", log: tplogDebug, type: .default, function, container.description, error as CVarArg)
44 os_log("%@ finished for %@", log: tplogDebug, type: .default, function, container.description)
48 internal func getContainer(withContainer container: String, context: String) throws -> Container {
49 let containerName = ContainerName(container: container, context: context)
50 return try self.containerMap.findOrCreate(name: containerName)
53 func dump(withContainer container: String, context: String, reply: @escaping ([AnyHashable: Any]?, Error?) -> Void) {
55 let containerName = ContainerName(container: container, context: context)
56 os_log("Dumping for %@", log: tplogDebug, type: .default, containerName.description)
57 let container = try self.containerMap.findOrCreate(name: containerName)
58 container.dump { result, error in
59 self.logComplete(function: "Dumping", container: container.name, error: error)
60 reply(result, CKXPCSuitableError(error))
63 os_log("Dumping failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
64 reply(nil, CKXPCSuitableError(error))
68 func dumpEgoPeer(withContainer container: String,
70 reply: @escaping (String?, TPPeerPermanentInfo?, TPPeerStableInfo?, TPPeerDynamicInfo?, Error?) -> Void) {
72 let containerName = ContainerName(container: container, context: context)
73 os_log("Dumping peer for %@", log: tplogDebug, type: .default, containerName.description)
74 let container = try self.containerMap.findOrCreate(name: containerName)
75 container.dumpEgoPeer { peerID, perm, stable, dyn, error in
76 self.logComplete(function: "Dumping peer", container: container.name, error: error)
77 reply(peerID, perm, stable, dyn, CKXPCSuitableError(error))
80 os_log("Dumping peer failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
81 reply(nil, nil, nil, nil, CKXPCSuitableError(error))
85 func trustStatus(withContainer container: String, context: String, reply: @escaping (TrustedPeersHelperEgoPeerStatus, Error?) -> Void) {
87 let containerName = ContainerName(container: container, context: context)
88 let container = try self.containerMap.findOrCreate(name: containerName)
89 container.trustStatus(reply: reply)
91 os_log("Trust status failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
92 reply(TrustedPeersHelperEgoPeerStatus(egoPeerID: nil,
93 status: TPPeerStatus.unknown,
94 viablePeerCountsByModelID: [:],
95 peerCountsByMachineID: [:],
98 CKXPCSuitableError(error))
102 func fetchTrustState(withContainer container: String, context: String, reply: @escaping (TrustedPeersHelperPeerState?, [TrustedPeersHelperPeer]?, Error?) -> Void) {
104 let containerName = ContainerName(container: container, context: context)
105 os_log("Fetch Trust State for %@", log: tplogDebug, type: .default, containerName.description)
106 let container = try self.containerMap.findOrCreate(name: containerName)
107 container.fetchTrustState(reply: reply)
109 os_log("Fetch Trust State failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
110 reply(nil, nil, CKXPCSuitableError(error))
114 func reset(withContainer container: String, context: String, resetReason: CuttlefishResetReason, reply: @escaping (Error?) -> Void) {
116 let containerName = ContainerName(container: container, context: context)
117 os_log("Resetting for %@", log: tplogDebug, type: .default, containerName.description)
118 let container = try self.containerMap.findOrCreate(name: containerName)
119 container.reset(resetReason: resetReason) { error in
120 self.logComplete(function: "Resetting", container: container.name, error: error)
121 reply(CKXPCSuitableError(error)) }
123 os_log("Resetting failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
124 reply(CKXPCSuitableError(error))
128 func localReset(withContainer container: String, context: String, reply: @escaping (Error?) -> Void) {
130 let containerName = ContainerName(container: container, context: context)
131 os_log("Performing local reset for %@", log: tplogDebug, type: .default, containerName.description)
132 let container = try self.containerMap.findOrCreate(name: containerName)
133 container.localReset { error in
134 self.logComplete(function: "Local reset", container: container.name, error: error)
135 reply(CKXPCSuitableError(error))
138 os_log("Local reset failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
139 reply(CKXPCSuitableError(error))
143 func setAllowedMachineIDsWithContainer(_ container: String,
145 allowedMachineIDs: Set<String>,
146 reply: @escaping (Bool, Error?) -> Void) {
148 let containerName = ContainerName(container: container, context: context)
149 os_log("Setting allowed machineIDs for %@ to %@", log: tplogDebug, type: .default, containerName.description, allowedMachineIDs)
150 let container = try self.containerMap.findOrCreate(name: containerName)
151 container.setAllowedMachineIDs(allowedMachineIDs) { differences, error in
152 self.logComplete(function: "Setting allowed machineIDs", container: container.name, error: error)
153 reply(differences, CKXPCSuitableError(error))
156 os_log("Setting allowed machineIDs failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
157 reply(false, CKXPCSuitableError(error))
161 func addAllowedMachineIDs(withContainer container: String,
163 machineIDs: [String],
164 reply: @escaping (Error?) -> Void) {
166 let containerName = ContainerName(container: container, context: context)
167 os_log("Adding allowed machineIDs for %@: %@", log: tplogDebug, type: .default, containerName.description, machineIDs)
168 let container = try self.containerMap.findOrCreate(name: containerName)
169 container.addAllow(machineIDs) { error in
170 self.logComplete(function: "Adding allowed machineIDs", container: container.name, error: error)
171 reply(CKXPCSuitableError(error))
174 os_log("Adding allowed machineID failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
175 reply(CKXPCSuitableError(error))
179 func removeAllowedMachineIDs(withContainer container: String,
181 machineIDs: [String],
182 reply: @escaping (Error?) -> Void) {
184 let containerName = ContainerName(container: container, context: context)
185 os_log("Removing allowed machineIDs for %@: %@", log: tplogDebug, type: .default, containerName.description, machineIDs)
186 let container = try self.containerMap.findOrCreate(name: containerName)
187 container.removeAllow(machineIDs) { error in
188 self.logComplete(function: "Removing allowed machineIDs", container: container.name, error: error)
189 reply(CKXPCSuitableError(error))
192 os_log("Removing allowed machineID failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
193 reply(CKXPCSuitableError(error))
197 func fetchAllowedMachineIDs(withContainer container: String, context: String, reply: @escaping (Set<String>?, Error?) -> Void) {
199 let containerName = ContainerName(container: container, context: context)
200 os_log("Fetching allowed machineIDs for %@", log: tplogDebug, type: .default, containerName.description)
201 let container = try self.containerMap.findOrCreate(name: containerName)
202 container.fetchAllowedMachineIDs() { mids, error in
203 self.logComplete(function: "Fetched allowed machineIDs", container: container.name, error: error)
204 reply(mids, CKXPCSuitableError(error))
207 os_log("Fetching allowed machineIDs failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
208 reply(nil, CKXPCSuitableError(error))
212 func fetchEgoEpoch(withContainer container: String, context: String, reply: @escaping (UInt64, Error?) -> Void) {
214 let containerName = ContainerName(container: container, context: context)
215 os_log("retrieving epoch for %@", log: tplogDebug, type: .default, containerName.description)
216 let container = try self.containerMap.findOrCreate(name: containerName)
217 container.getEgoEpoch { epoch, error in
218 reply(epoch, CKXPCSuitableError(error))
221 os_log("Epoch retrieval failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
222 reply(0, CKXPCSuitableError(error))
226 func prepare(withContainer container: String,
234 serialNumber: String,
236 policyVersion: NSNumber?,
237 policySecrets: [String: Data]?,
238 signingPrivKeyPersistentRef: Data?,
239 encPrivKeyPersistentRef: Data?,
240 reply: @escaping (String?, Data?, Data?, Data?, Data?, Error?) -> Void) {
242 let containerName = ContainerName(container: container, context: context)
243 os_log("Preparing new identity for %@", log: tplogDebug, type: .default, containerName.description)
244 let container = try self.containerMap.findOrCreate(name: containerName)
245 container.prepare(epoch: epoch,
246 machineID: machineID,
247 bottleSalt: bottleSalt,
250 deviceName: deviceName,
251 serialNumber: serialNumber,
252 osVersion: osVersion,
253 policyVersion: policyVersion?.uint64Value,
254 policySecrets: policySecrets,
255 signingPrivateKeyPersistentRef: signingPrivKeyPersistentRef,
256 encryptionPrivateKeyPersistentRef: encPrivKeyPersistentRef) { peerID, permanentInfo, permanentInfoSig, stableInfo, stableInfoSig, error in
257 self.logComplete(function: "Prepare", container: container.name, error: error)
258 reply(peerID, permanentInfo, permanentInfoSig, stableInfo, stableInfoSig, CKXPCSuitableError(error))
261 os_log("Prepare failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
262 reply(nil, nil, nil, nil, nil, CKXPCSuitableError(error))
266 func establish(withContainer container: String,
268 ckksKeys: [CKKSKeychainBackedKeySet],
269 tlkShares: [CKKSTLKShare],
270 preapprovedKeys: [Data]?,
271 reply: @escaping (String?, [CKRecord]?, Error?) -> Void) {
273 let containerName = ContainerName(container: container, context: context)
274 os_log("Establishing %@", log: tplogDebug, type: .default, containerName.description)
275 let container = try self.containerMap.findOrCreate(name: containerName)
276 container.establish(ckksKeys: ckksKeys,
277 tlkShares: tlkShares,
278 preapprovedKeys: preapprovedKeys) { peerID, keyHierarchyRecords, error in
279 self.logComplete(function: "Establishing", container: container.name, error: error)
280 reply(peerID, keyHierarchyRecords, CKXPCSuitableError(error)) }
282 os_log("Establishing failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
283 reply(nil, nil, CKXPCSuitableError(error))
287 func vouch(withContainer container: String,
291 permanentInfoSig: Data,
294 ckksKeys: [CKKSKeychainBackedKeySet],
295 reply: @escaping (Data?, Data?, Error?) -> Void) {
297 let containerName = ContainerName(container: container, context: context)
298 os_log("Vouching %@", log: tplogDebug, type: .default, containerName.description)
299 let container = try self.containerMap.findOrCreate(name: containerName)
300 container.vouch(peerID: peerID,
301 permanentInfo: permanentInfo,
302 permanentInfoSig: permanentInfoSig,
303 stableInfo: stableInfo,
304 stableInfoSig: stableInfoSig,
305 ckksKeys: ckksKeys) { voucher, voucherSig, error in
306 self.logComplete(function: "Vouching", container: container.name, error: error)
307 reply(voucher, voucherSig, CKXPCSuitableError(error)) }
309 os_log("Vouching failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
310 reply(nil, nil, CKXPCSuitableError(error))
314 func preflightVouchWithBottle(withContainer container: String,
317 reply: @escaping (String?, Error?) -> Void) {
319 let containerName = ContainerName(container: container, context: context)
320 os_log("Preflight Vouch With Bottle %@", log: tplogDebug, type: .default, containerName.description)
321 let container = try self.containerMap.findOrCreate(name: containerName)
322 container.preflightVouchWithBottle(bottleID: bottleID) { peerID, error in
323 self.logComplete(function: "Preflight Vouch With Bottle", container: container.name, error: error)
324 reply(peerID, CKXPCSuitableError(error)) }
326 os_log("Preflighting Vouch With Bottle failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
327 reply(nil, CKXPCSuitableError(error))
331 func vouchWithBottle(withContainer container: String,
336 tlkShares: [CKKSTLKShare],
337 reply: @escaping (Data?, Data?, Error?) -> Void) {
339 let containerName = ContainerName(container: container, context: context)
340 os_log("Vouching With Bottle %@", log: tplogDebug, type: .default, containerName.description)
341 let container = try self.containerMap.findOrCreate(name: containerName)
342 container.vouchWithBottle(bottleID: bottleID, entropy: entropy, bottleSalt: bottleSalt, tlkShares: tlkShares) { voucher, voucherSig, error in
343 self.logComplete(function: "Vouching With Bottle", container: container.name, error: error)
344 reply(voucher, voucherSig, CKXPCSuitableError(error)) }
346 os_log("Vouching with Bottle failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
347 reply(nil, nil, CKXPCSuitableError(error))
351 func vouchWithRecoveryKey(withContainer container: String,
355 tlkShares: [CKKSTLKShare],
356 reply: @escaping (Data?, Data?, Error?) -> Void) {
358 let containerName = ContainerName(container: container, context: context)
359 os_log("Vouching With Recovery Key %@", log: tplogDebug, type: .default, containerName.description)
360 let container = try self.containerMap.findOrCreate(name: containerName)
361 container.vouchWithRecoveryKey(recoveryKey: recoveryKey, salt: salt, tlkShares: tlkShares) { voucher, voucherSig, error in
362 self.logComplete(function: "Vouching With Recovery Key", container: container.name, error: error)
363 reply(voucher, voucherSig, CKXPCSuitableError(error)) }
365 os_log("Vouching with Recovery Key failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
366 reply(nil, nil, CKXPCSuitableError(error))
370 func join(withContainer container: String,
374 ckksKeys: [CKKSKeychainBackedKeySet],
375 tlkShares: [CKKSTLKShare],
376 preapprovedKeys: [Data],
377 reply: @escaping (String?, [CKRecord]?, Error?) -> Void) {
379 let containerName = ContainerName(container: container, context: context)
380 os_log("Joining %@", log: tplogDebug, type: .default, containerName.description)
381 let container = try self.containerMap.findOrCreate(name: containerName)
382 container.join(voucherData: voucherData,
383 voucherSig: voucherSig,
385 tlkShares: tlkShares,
386 preapprovedKeys: preapprovedKeys) { peerID, keyHierarchyRecords, error in reply(peerID, keyHierarchyRecords, CKXPCSuitableError(error)) }
388 reply(nil, nil, CKXPCSuitableError(error))
392 func preflightPreapprovedJoin(withContainer container: String,
394 reply: @escaping (Bool, Error?) -> Void) {
396 let containerName = ContainerName(container: container, context: context)
397 os_log("Attempting to preflight a preapproved join for %@", log: tplogDebug, type: .default, containerName.description)
398 let container = try self.containerMap.findOrCreate(name: containerName)
399 container.preflightPreapprovedJoin { success, error in reply(success, CKXPCSuitableError(error)) }
401 reply(false, CKXPCSuitableError(error))
405 func attemptPreapprovedJoin(withContainer container: String,
407 ckksKeys: [CKKSKeychainBackedKeySet],
408 tlkShares: [CKKSTLKShare],
409 preapprovedKeys: [Data],
410 reply: @escaping (String?, [CKRecord]?, Error?) -> Void) {
412 let containerName = ContainerName(container: container, context: context)
413 os_log("Attempting a preapproved join for %@", log: tplogDebug, type: .default, containerName.description)
414 let container = try self.containerMap.findOrCreate(name: containerName)
415 container.preapprovedJoin(ckksKeys: ckksKeys,
416 tlkShares: tlkShares,
417 preapprovedKeys: preapprovedKeys) { peerID, keyHierarchyRecords, error in reply(peerID, keyHierarchyRecords, CKXPCSuitableError(error)) }
419 reply(nil, nil, CKXPCSuitableError(error))
423 func update(withContainer container: String,
426 serialNumber: String?,
428 policyVersion: NSNumber?,
429 policySecrets: [String: Data]?,
430 reply: @escaping (TrustedPeersHelperPeerState?, Error?) -> Void) {
432 let containerName = ContainerName(container: container, context: context)
433 os_log("Updating %@", log: tplogDebug, type: .default, containerName.description)
434 let container = try self.containerMap.findOrCreate(name: containerName)
435 container.update(deviceName: deviceName,
436 serialNumber: serialNumber,
437 osVersion: osVersion,
438 policyVersion: policyVersion?.uint64Value,
439 policySecrets: policySecrets) { state, error in reply(state, CKXPCSuitableError(error)) }
441 reply(nil, CKXPCSuitableError(error))
445 func setPreapprovedKeysWithContainer(_ container: String,
447 preapprovedKeys: [Data],
448 reply: @escaping (Error?) -> Void) {
450 let containerName = ContainerName(container: container, context: context)
451 os_log("Updating %@", log: tplogDebug, type: .default, containerName.description)
452 let container = try self.containerMap.findOrCreate(name: containerName)
453 container.set(preapprovedKeys: preapprovedKeys) { error in reply(CKXPCSuitableError(error)) }
455 reply(CKXPCSuitableError(error))
459 func updateTLKs(withContainer container: String,
461 ckksKeys: [CKKSKeychainBackedKeySet],
462 tlkShares: [CKKSTLKShare],
463 reply: @escaping ([CKRecord]?, Error?) -> Void) {
465 let containerName = ContainerName(container: container, context: context)
466 os_log("Updating TLKs for %@", log: tplogDebug, type: .default, containerName.description)
467 let container = try self.containerMap.findOrCreate(name: containerName)
468 container.updateTLKs(ckksKeys: ckksKeys,
469 tlkShares: tlkShares,
472 reply(nil, CKXPCSuitableError(error))
476 func departByDistrustingSelf(withContainer container: String,
478 reply: @escaping (Error?) -> Void) {
480 let containerName = ContainerName(container: container, context: context)
481 os_log("Departing %@", log: tplogDebug, type: .default, containerName.description)
482 let container = try self.containerMap.findOrCreate(name: containerName)
483 container.departByDistrustingSelf { error in
484 reply(CKXPCSuitableError(error))
487 reply(CKXPCSuitableError(error))
491 func distrustPeerIDs(withContainer container: String,
493 peerIDs: Set<String>,
494 reply: @escaping (Error?) -> Void) {
496 let containerName = ContainerName(container: container, context: context)
497 os_log("Distrusting %@ in %@", log: tplogDebug, type: .default, peerIDs, containerName.description)
498 let container = try self.containerMap.findOrCreate(name: containerName)
499 container.distrust(peerIDs: peerIDs) { error in
500 reply(CKXPCSuitableError(error))
503 reply(CKXPCSuitableError(error))
507 func fetchViableBottles(withContainer container: String, context: String, reply: @escaping ([String]?, [String]?, Error?) -> Void) {
509 let containerName = ContainerName(container: container, context: context)
510 os_log("fetchViableBottles in %@", log: tplogDebug, type: .default, containerName.description)
511 let container = try self.containerMap.findOrCreate(name: containerName)
512 container.fetchViableBottles { sortedBottleIDs, partialBottleIDs, error in
513 reply(sortedBottleIDs, partialBottleIDs, CKXPCSuitableError(error))
516 reply(nil, nil, CKXPCSuitableError(error))
520 func fetchEscrowContents(withContainer container: String, context: String, reply: @escaping (Data?, String?, Data?, Error?) -> Void) {
522 let containerName = ContainerName(container: container, context: context)
523 os_log("fetchEscrowContents in %@", log: tplogDebug, type: .default, containerName.description)
524 let container = try self.containerMap.findOrCreate(name: containerName)
525 container.fetchEscrowContents { entropy, bottleID, signingPublicKey, error in
526 reply(entropy, bottleID, signingPublicKey, CKXPCSuitableError(error))
529 reply(nil, nil, nil, CKXPCSuitableError(error))
533 func fetchPolicy(withContainer container: String,
535 reply: @escaping (TPPolicy?, Error?) -> Void) {
537 let containerName = ContainerName(container: container, context: context)
538 os_log("Fetching policy for %@", log: tplogDebug, type: .default, containerName.description)
539 let container = try self.containerMap.findOrCreate(name: containerName)
540 container.fetchPolicy { policy, error in
541 reply(policy, CKXPCSuitableError(error))
544 reply(nil, CKXPCSuitableError(error))
548 func fetchPolicyDocuments(withContainer container: String,
550 keys: [NSNumber: String],
551 reply: @escaping ([NSNumber: [String]]?, Error?) -> Void) {
553 let containerName = ContainerName(container: container, context: context)
554 os_log("Fetching policy documents %@ with keys: %@", log: tplogDebug, type: .default, containerName.description, keys)
555 let container = try self.containerMap.findOrCreate(name: containerName)
556 container.fetchPolicyDocuments(keys: keys) { entries, error in
557 reply(entries, CKXPCSuitableError(error))
560 reply(nil, CKXPCSuitableError(error))
564 func validatePeers(withContainer container: String, context: String, reply: @escaping ([AnyHashable: Any]?, Error?) -> Void) {
566 let containerName = ContainerName(container: container, context: context)
567 os_log("ValidatePeers for %@", log: tplogDebug, type: .default, containerName.description)
568 let container = try self.containerMap.findOrCreate(name: containerName)
569 let request = ValidatePeersRequest()
570 container.validatePeers(request: request) { result, error in
571 self.logComplete(function: "validatePeers", container: container.name, error: error)
572 reply(result, CKXPCSuitableError(error))
575 os_log("ValidatePeers failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
576 reply(nil, CKXPCSuitableError(error))
580 func setRecoveryKeyWithContainer(_ container: String, context: String, recoveryKey: String, salt: String, ckksKeys: [CKKSKeychainBackedKeySet], reply: @escaping (Error?) -> Void) {
582 let containerName = ContainerName(container: container, context: context)
583 os_log("SetRecoveryKey for %@", log: tplogDebug, type: .default, containerName.description)
584 let container = try self.containerMap.findOrCreate(name: containerName)
585 container.setRecoveryKey(recoveryKey: recoveryKey, salt: salt, ckksKeys: ckksKeys) { error in
586 self.logComplete(function: "setRecoveryKey", container: container.name, error: error)
587 reply(CKXPCSuitableError(error))
590 os_log("SetRecoveryKey failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
591 reply(CKXPCSuitableError(error))
595 func reportHealth(withContainer container: String, context: String, stateMachineState: String, trustState: String, reply: @escaping (Error?) -> Void) {
597 let containerName = ContainerName(container: container, context: context)
598 os_log("ReportHealth for %@", log: tplogDebug, type: .default, containerName.description)
599 let container = try self.containerMap.findOrCreate(name: containerName)
600 let request = ReportHealthRequest.with {
601 $0.stateMachineState = stateMachineState
603 container.reportHealth(request: request) { error in
604 self.logComplete(function: "reportHealth", container: container.name, error: error)
605 reply(CKXPCSuitableError(error))
608 os_log("ReportHealth failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
609 reply(CKXPCSuitableError(error))
613 func pushHealthInquiry(withContainer container: String, context: String, reply: @escaping (Error?) -> Void) {
615 let containerName = ContainerName(container: container, context: context)
616 os_log("PushHealthInquiry for %@", log: tplogDebug, type: .default, containerName.description)
617 let container = try self.containerMap.findOrCreate(name: containerName)
618 container.pushHealthInquiry { error in
619 self.logComplete(function: "pushHealthInquiry", container: container.name, error: error)
620 reply(CKXPCSuitableError(error))
623 os_log("PushHealthInquiry failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
624 reply(CKXPCSuitableError(error))
628 func getViewsWithContainer(_ container: String, context: String, inViews: [String], reply: @escaping ([String]?, Error?) -> Void) {
630 let containerName = ContainerName(container: container, context: context)
631 os_log("GetViews (%@) for %@", log: tplogDebug, type: .default, inViews, containerName.description)
632 let container = try self.containerMap.findOrCreate(name: containerName)
633 container.getViews(inViews: inViews) { outViews, error in
634 reply(outViews, CKXPCSuitableError(error))
637 os_log("GetViews failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
638 reply(nil, CKXPCSuitableError(error))
642 func requestHealthCheck(withContainer container: String, context: String, requiresEscrowCheck: Bool, reply: @escaping (Bool, Bool, Bool, Error?) -> Void) {
644 let containerName = ContainerName(container: container, context: context)
645 os_log("Health Check! requiring escrow check? %d for %@", log: tplogDebug, type: .default, requiresEscrowCheck, containerName.description)
646 let container = try self.containerMap.findOrCreate(name: containerName)
647 container.requestHealthCheck(requiresEscrowCheck: requiresEscrowCheck) { postRepair, postEscrow, postReset, error in
648 reply(postRepair, postEscrow, postReset, CKXPCSuitableError(error))
651 os_log("Health Check! failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
652 reply(false, false, false, CKXPCSuitableError(error))
656 func getSupportAppInfo(withContainer container: String, context: String, reply: @escaping (Data?, Error?) -> Void) {
658 let containerName = ContainerName(container: container, context: context)
659 os_log("getSupportInfo %d for %@", log: tplogDebug, type: .default, containerName.description)
660 let container = try self.containerMap.findOrCreate(name: containerName)
661 container.getSupportAppInfo { info, error in
662 reply(info, CKXPCSuitableError(error))
665 os_log("getSupportInfo failed for (%@, %@): %@", log: tplogDebug, type: .default, container, context, error as CVarArg)
666 reply(nil, CKXPCSuitableError(error))