Initial commit

This commit is contained in:
Milan Stute
2021-03-03 14:19:09 +01:00
commit 52dde375e3
93 changed files with 8048 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
// OpenHaystack Tracking personal Bluetooth devices via Apple's Find My network
//
// Copyright © 2021 Secure Mobile Networking Lab (SEEMOO)
// Copyright © 2021 The Open Wireless Link Project
//
// SPDX-License-Identifier: AGPL-3.0-only
import Foundation
class AccessoryController: ObservableObject {
static let shared = AccessoryController()
@Published var accessories: [Accessory]
init() {
self.accessories = KeychainController.loadAccessoriesFromKeychain()
}
init(accessories: [Accessory]) {
self.accessories = accessories
}
func save() throws {
try KeychainController.storeInKeychain(accessories: self.accessories)
}
func load() {
self.accessories = KeychainController.loadAccessoriesFromKeychain()
}
func updateWithDecryptedReports(devices: [FindMyDevice]) {
// Assign last locations
for device in FindMyController.shared.devices {
if let idx = self.accessories.firstIndex(where: {$0.id == Int(device.deviceId)}) {
self.objectWillChange.send()
let accessory = self.accessories[idx]
let report = device.decryptedReports?
.sorted(by: {$0.timestamp ?? Date.distantPast > $1.timestamp ?? Date.distantPast })
.first
accessory.lastLocation = report?.location
accessory.locationTimestamp = report?.timestamp
self.accessories[idx] = accessory
}
}
}
}