forked from fritob/Camper-Monitor
CamperMonitor (Haupt-Repo) und VanAligneiOS (aus dem gemergten solar-integration-Branch) liefen unter zwei verschiedenen internen Namen, obwohl die App nach aussen längst einheitlich "VanControl Pro" heisst. Jetzt durchgängig VanControl: - Ordner: CamperMonitor/, CamperMonitorWatch/, CamperMonitorComplication/, VanAligneiOSWidget/ → VanControl/, VanControlWatch/, VanControlComplication/, VanControlWidget/ - Xcode-Projekt: CamperMonitor.xcodeproj → VanControl.xcodeproj, alle Targets/Schemes/Produktnamen entsprechend umbenannt - Bundle-Identifier auf Wunsch mitgeändert: de.s0.fototeddy.VanControl* (App noch nicht veröffentlicht); dabei auch die WKCompanionAppBundleIdentifier-Werte korrigiert, die noch das alte de.fritob-Präfix statt des tatsächlichen de.s0.fototeddy-Präfixes trugen - Swift-Dateien/Typen: CamperMonitorApp → VanControlApp, VanAligneiOSWidget* → VanControlWidget* - Config/*-Info.plist umbenannt, README.md/Tools/README.md/run-tests.sh auf die neuen Pfade angepasst Bewusst unverändert: firmware/vanalign und alle Bezüge auf "VanAlign" als Namen der Neigungsmesser-Hardware (eigenständiges Produkt, kein App-Name) sowie der komplette Android/-Ordner. Build (App, Watch, Debug) und Protokoll-Testlauf grün. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
60 lines
2.2 KiB
Swift
60 lines
2.2 KiB
Swift
import Foundation
|
|
import Security
|
|
|
|
/// Ablage für die Victron-Verschlüsselungsschlüssel. Die gehören nicht in die
|
|
/// UserDefaults, deshalb Keychain.
|
|
enum KeychainStore {
|
|
|
|
private static let service = "de.fritob.VanControl.victronKeys"
|
|
|
|
static func setKey(_ hex: String?, for deviceID: UUID) {
|
|
let account = deviceID.uuidString
|
|
var query: [String: Any] = [
|
|
kSecClass as String: kSecClassGenericPassword,
|
|
kSecAttrService as String: service,
|
|
kSecAttrAccount as String: account,
|
|
]
|
|
SecItemDelete(query as CFDictionary)
|
|
|
|
guard let hex, let data = hex.data(using: .utf8) else { return }
|
|
query[kSecValueData as String] = data
|
|
query[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlock
|
|
SecItemAdd(query as CFDictionary, nil)
|
|
}
|
|
|
|
static func key(for deviceID: UUID) -> String? {
|
|
let query: [String: Any] = [
|
|
kSecClass as String: kSecClassGenericPassword,
|
|
kSecAttrService as String: service,
|
|
kSecAttrAccount as String: deviceID.uuidString,
|
|
kSecReturnData as String: true,
|
|
kSecMatchLimit as String: kSecMatchLimitOne,
|
|
]
|
|
var result: AnyObject?
|
|
guard SecItemCopyMatching(query as CFDictionary, &result) == errSecSuccess,
|
|
let data = result as? Data else { return nil }
|
|
return String(data: data, encoding: .utf8)
|
|
}
|
|
}
|
|
|
|
extension String {
|
|
/// Wandelt einen Hex-String in Bytes. Leerzeichen, Doppelpunkte und ein
|
|
/// führendes "0x" werden ignoriert, damit sich der Schlüssel aus
|
|
/// VictronConnect einfach einfügen lässt.
|
|
var hexBytes: [UInt8]? {
|
|
var cleaned = self.lowercased()
|
|
.replacingOccurrences(of: "0x", with: "")
|
|
.filter { $0.isHexDigit }
|
|
guard !cleaned.isEmpty, cleaned.count % 2 == 0 else { return nil }
|
|
var bytes: [UInt8] = []
|
|
bytes.reserveCapacity(cleaned.count / 2)
|
|
while !cleaned.isEmpty {
|
|
let pair = String(cleaned.prefix(2))
|
|
cleaned.removeFirst(2)
|
|
guard let byte = UInt8(pair, radix: 16) else { return nil }
|
|
bytes.append(byte)
|
|
}
|
|
return bytes
|
|
}
|
|
}
|