Skip to content

Commit 98410d9

Browse files
authored
refactor(state): move device identity into canonical SQLite state (#110392)
* refactor: store device identities in SQLite * style: satisfy Swift identity lint limits * test: harden device identity migration fixtures * fix: harden SQLite device identity recovery * chore: remove stale identity helper * refactor: isolate device identity repair * chore: remove stale migration import * test: validate migrated identity key types * fix: harden device identity repair * style: format device identity assertion * fix: derive repaired identity key from PEM * style: remove redundant PEM conversions * fix: align native identity store with schema v4 * fix(state): satisfy SQLite identity CI gates * fix(state): coordinate native identity migration * test(doctor): include native identity claim path * fix(infra): preserve coordinator release error * fix(state): clear identity validation gates * refactor(apple): remove identity test-only APIs * refactor(apple): remove dead identity error type * test(apple): use canonical identity test seam * test(macos): isolate gateway readiness identity
1 parent d022b1f commit 98410d9

73 files changed

Lines changed: 5451 additions & 1227 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/.i18n/native-source.json‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22611,39 +22611,39 @@
2261122611
},
2261222612
{
2261322613
"kind": "ui-localized-call-multiline",
22614-
"line": 1281,
22614+
"line": 1283,
2261522615
"path": "apps/ios/Sources/Gateway/GatewayConnectionController.swift",
2261622616
"source": "Can't reach gateway at %1$@:%2$@. Verify Tailscale Serve is enabled and publishes this Gateway.",
2261722617
"surface": "apple",
2261822618
"id": "native.apple.1d1aa0192206041c"
2261922619
},
2262022620
{
2262122621
"kind": "ui-localized-call",
22622-
"line": 1290,
22622+
"line": 1292,
2262322623
"path": "apps/ios/Sources/Gateway/GatewayConnectionController.swift",
2262422624
"source": "Can't reach gateway at %1$@:%2$@. Check Tailscale or LAN.",
2262522625
"surface": "apple",
2262622626
"id": "native.apple.f8e351c2a7c24652"
2262722627
},
2262822628
{
2262922629
"kind": "ui-localized-call-multiline",
22630-
"line": 1296,
22630+
"line": 1298,
2263122631
"path": "apps/ios/Sources/Gateway/GatewayConnectionController.swift",
2263222632
"source": "TLS fingerprint verification timed out for %1$@:%2$@. Secure endpoint was reached, but TLS did not finish in time.",
2263322633
"surface": "apple",
2263422634
"id": "native.apple.5939318ffa667d0a"
2263522635
},
2263622636
{
2263722637
"kind": "ui-localized-call-multiline",
22638-
"line": 1304,
22638+
"line": 1306,
2263922639
"path": "apps/ios/Sources/Gateway/GatewayConnectionController.swift",
2264022640
"source": "No secure gateway endpoint was detected at %1$@:%2$@. Enable gateway TLS or Tailscale Serve, or use a trusted private LAN address with Unencrypted selected.",
2264122641
"surface": "apple",
2264222642
"id": "native.apple.9dd9783959c1a4ab"
2264322643
},
2264422644
{
2264522645
"kind": "ui-localized-call",
22646-
"line": 1314,
22646+
"line": 1316,
2264722647
"path": "apps/ios/Sources/Gateway/GatewayConnectionController.swift",
2264822648
"source": "Could not read the TLS certificate from %1$@:%2$@.",
2264922649
"surface": "apple",
@@ -23507,79 +23507,79 @@
2350723507
},
2350823508
{
2350923509
"kind": "conditional-branch",
23510-
"line": 4909,
23510+
"line": 4917,
2351123511
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2351223512
"source": "Connected",
2351323513
"surface": "apple",
2351423514
"id": "native.apple.c0a005f81d588867"
2351523515
},
2351623516
{
2351723517
"kind": "conditional-branch",
23518-
"line": 4909,
23518+
"line": 4917,
2351923519
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2352023520
"source": "Offline",
2352123521
"surface": "apple",
2352223522
"id": "native.apple.ae33908b61c6d70b"
2352323523
},
2352423524
{
2352523525
"kind": "conditional-branch",
23526-
"line": 6075,
23526+
"line": 6087,
2352723527
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2352823528
"source": "No chat messages yet",
2352923529
"surface": "apple",
2353023530
"id": "native.apple.4a98b3a346be2662"
2353123531
},
2353223532
{
2353323533
"kind": "conditional-branch",
23534-
"line": 6274,
23534+
"line": 6286,
2353523535
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2353623536
"source": "Connecting…",
2353723537
"surface": "apple",
2353823538
"id": "native.apple.b0d9c1ba8ef7ec19"
2353923539
},
2354023540
{
2354123541
"kind": "conditional-branch",
23542-
"line": 6274,
23542+
"line": 6286,
2354323543
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2354423544
"source": "Reconnecting…",
2354523545
"surface": "apple",
2354623546
"id": "native.apple.bd98e19b49309284"
2354723547
},
2354823548
{
2354923549
"kind": "conditional-branch",
23550-
"line": 8683,
23550+
"line": 8695,
2355123551
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2355223552
"source": "Approval",
2355323553
"surface": "apple",
2355423554
"id": "native.apple.0b1eff808df04e2b"
2355523555
},
2355623556
{
2355723557
"kind": "conditional-branch",
23558-
"line": 8683,
23558+
"line": 8695,
2355923559
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2356023560
"source": "This approval was already",
2356123561
"surface": "apple",
2356223562
"id": "native.apple.c74dccc1c5d71750"
2356323563
},
2356423564
{
2356523565
"kind": "conditional-branch",
23566-
"line": 8689,
23566+
"line": 8701,
2356723567
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2356823568
"source": "This approval was already set to Always Allow.",
2356923569
"surface": "apple",
2357023570
"id": "native.apple.4e3a9dc13016600b"
2357123571
},
2357223572
{
2357323573
"kind": "conditional-branch",
23574-
"line": 8690,
23574+
"line": 8702,
2357523575
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2357623576
"source": "Approval set to Always Allow.",
2357723577
"surface": "apple",
2357823578
"id": "native.apple.4864b3b8c6ed7158"
2357923579
},
2358023580
{
2358123581
"kind": "conditional-branch",
23582-
"line": 10028,
23582+
"line": 10040,
2358323583
"path": "apps/ios/Sources/Model/NodeAppModel.swift",
2358423584
"source": "\\(urlText.prefix(500))…",
2358523585
"surface": "apple",
@@ -31595,47 +31595,47 @@
3159531595
},
3159631596
{
3159731597
"kind": "conditional-branch",
31598-
"line": 385,
31598+
"line": 389,
3159931599
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3160031600
"source": "Main",
3160131601
"surface": "apple",
3160231602
"id": "native.apple.3cef985bef918988"
3160331603
},
3160431604
{
3160531605
"kind": "conditional-branch",
31606-
"line": 385,
31606+
"line": 389,
3160731607
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3160831608
"source": "Other",
3160931609
"surface": "apple",
3161031610
"id": "native.apple.5eca63e1a931e290"
3161131611
},
3161231612
{
3161331613
"kind": "ui-modifier",
31614-
"line": 459,
31614+
"line": 463,
3161531615
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3161631616
"source": "Show pairing requests",
3161731617
"surface": "apple",
3161831618
"id": "native.apple.72d7e38d56c76ff8"
3161931619
},
3162031620
{
3162131621
"kind": "ui-call",
31622-
"line": 484,
31622+
"line": 488,
3162331623
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3162431624
"source": "Refreshing microphones…",
3162531625
"surface": "apple",
3162631626
"id": "native.apple.469c920582755860"
3162731627
},
3162831628
{
3162931629
"kind": "ui-call",
31630-
"line": 491,
31630+
"line": 495,
3163131631
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3163231632
"source": "Microphone",
3163331633
"surface": "apple",
3163431634
"id": "native.apple.c0c6172187ca749a"
3163531635
},
3163631636
{
3163731637
"kind": "ui-call",
31638-
"line": 516,
31638+
"line": 520,
3163931639
"path": "apps/macos/Sources/OpenClaw/MenuContentView.swift",
3164031640
"source": "Disconnected (using System default)",
3164131641
"surface": "apple",
@@ -31779,15 +31779,15 @@
3177931779
},
3178031780
{
3178131781
"kind": "conditional-branch",
31782-
"line": 435,
31782+
"line": 436,
3178331783
"path": "apps/macos/Sources/OpenClaw/NodePairingApprovalPrompter.swift",
3178431784
"source": "Node pairing approved",
3178531785
"surface": "apple",
3178631786
"id": "native.apple.7eb0a88b8274ced8"
3178731787
},
3178831788
{
3178931789
"kind": "conditional-branch",
31790-
"line": 435,
31790+
"line": 436,
3179131791
"path": "apps/macos/Sources/OpenClaw/NodePairingApprovalPrompter.swift",
3179231792
"source": "Node pairing rejected",
3179331793
"surface": "apple",
@@ -36235,23 +36235,23 @@
3623536235
},
3623636236
{
3623736237
"kind": "conditional-branch",
36238-
"line": 455,
36238+
"line": 460,
3623936239
"path": "apps/macos/Sources/OpenClawMacCLI/WizardCommand.swift",
3624036240
"source": " [\\(initial)]",
3624136241
"surface": "apple",
3624236242
"id": "native.apple.2b7392aa9f8b47df"
3624336243
},
3624436244
{
3624536245
"kind": "conditional-branch",
36246-
"line": 502,
36246+
"line": 507,
3624736247
"path": "apps/macos/Sources/OpenClawMacCLI/WizardCommand.swift",
3624836248
"source": " — \\(option.hint!)",
3624936249
"surface": "apple",
3625036250
"id": "native.apple.9e54815f3eca97bf"
3625136251
},
3625236252
{
3625336253
"kind": "conditional-branch",
36254-
"line": 509,
36254+
"line": 514,
3625536255
"path": "apps/macos/Sources/OpenClawMacCLI/WizardCommand.swift",
3625636256
"source": " [\\(initialIndices.map(String.init).joined(separator: \",\"))]",
3625736257
"surface": "apple",

‎apps/ios/Sources/Gateway/GatewayConnectionController+ManualAuth.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import OpenClawKit
33

44
extension GatewayConnectionController {
55
static func migrateLegacyDeviceAuth() {
6+
guard
7+
let primaryIdentity = DeviceIdentityStore.loadOrCreatePersisted(),
8+
let shareIdentity = DeviceIdentityStore.loadOrCreatePersisted(profile: .shareExtension)
9+
else { return }
610
let migrationGatewayID = self.legacyDeviceAuthMigrationGatewayID()
711
let relay = ShareGatewayRelaySettings.loadConfig()
812
let instanceID = GatewaySettingsStore.currentInstanceID()
@@ -15,8 +19,6 @@ extension GatewayConnectionController {
1519
} else {
1620
GatewaySettingsStore.discardUnscopedGatewayCredentials(instanceId: instanceID)
1721
}
18-
let primaryIdentity = DeviceIdentityStore.loadOrCreate()
19-
let shareIdentity = DeviceIdentityStore.loadOrCreate(profile: .shareExtension)
2022
// The extension connects independently, so the host's last route cannot prove who
2123
// issued its legacy token. Require one extension re-pair instead of guessing an owner.
2224
DeviceAuthStore.discardUnscopedTokens(

‎apps/ios/Sources/Gateway/GatewayConnectionController.swift‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,20 +609,22 @@ final class GatewayConnectionController {
609609
}
610610

611611
private static func clearDeviceAuthTokens(gatewayID: String) {
612-
let primaryIdentity = DeviceIdentityStore.loadOrCreate()
613-
DeviceAuthStore.clearToken(deviceId: primaryIdentity.deviceId, role: "node", gatewayID: gatewayID)
614-
DeviceAuthStore.clearToken(deviceId: primaryIdentity.deviceId, role: "operator", gatewayID: gatewayID)
615-
let shareIdentity = DeviceIdentityStore.loadOrCreate(profile: .shareExtension)
616-
DeviceAuthStore.clearToken(
617-
deviceId: shareIdentity.deviceId,
618-
role: "node",
619-
gatewayID: gatewayID,
620-
profile: .shareExtension)
621-
DeviceAuthStore.clearToken(
622-
deviceId: shareIdentity.deviceId,
623-
role: "operator",
624-
gatewayID: gatewayID,
625-
profile: .shareExtension)
612+
if let primaryIdentity = DeviceIdentityStore.loadOrCreatePersisted() {
613+
DeviceAuthStore.clearToken(deviceId: primaryIdentity.deviceId, role: "node", gatewayID: gatewayID)
614+
DeviceAuthStore.clearToken(deviceId: primaryIdentity.deviceId, role: "operator", gatewayID: gatewayID)
615+
}
616+
if let shareIdentity = DeviceIdentityStore.loadOrCreatePersisted(profile: .shareExtension) {
617+
DeviceAuthStore.clearToken(
618+
deviceId: shareIdentity.deviceId,
619+
role: "node",
620+
gatewayID: gatewayID,
621+
profile: .shareExtension)
622+
DeviceAuthStore.clearToken(
623+
deviceId: shareIdentity.deviceId,
624+
role: "operator",
625+
gatewayID: gatewayID,
626+
profile: .shareExtension)
627+
}
626628
}
627629

628630
private func clearLegacyManualGatewayDefaults(matching stableID: String) {

‎apps/ios/Sources/Model/NodeAppModel.swift‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,7 +3918,7 @@ extension NodeAppModel {
39183918
}
39193919

39203920
private func hasStoredGatewayRoleToken(_ role: String, gatewayID: String) -> Bool {
3921-
let identity = DeviceIdentityStore.loadOrCreate()
3921+
guard let identity = DeviceIdentityStore.loadOrCreatePersisted() else { return false }
39223922
return DeviceAuthStore.loadToken(
39233923
deviceId: identity.deviceId,
39243924
role: role,
@@ -4788,9 +4788,13 @@ extension NodeAppModel {
47884788
password: String?,
47894789
forceTalkPermissionUpgradeRequest: Bool = false) -> Bool
47904790
{
4791-
let identity = DeviceIdentityStore.loadOrCreate()
4792-
let storedOperatorScopes = DeviceAuthStore
4793-
.loadToken(deviceId: identity.deviceId, role: "operator", gatewayID: gatewayID)?
4791+
let storedOperatorScopes = DeviceIdentityStore.loadOrCreatePersisted()
4792+
.flatMap { identity in
4793+
DeviceAuthStore.loadToken(
4794+
deviceId: identity.deviceId,
4795+
role: "operator",
4796+
gatewayID: gatewayID)
4797+
}?
47944798
.scopes ?? []
47954799
return Self.shouldRequestOperatorApprovalScope(
47964800
token: token,
@@ -4825,9 +4829,13 @@ extension NodeAppModel {
48254829
password: String?,
48264830
forceTalkPermissionUpgradeRequest: Bool = false) -> Bool
48274831
{
4828-
let identity = DeviceIdentityStore.loadOrCreate()
4829-
let storedOperatorScopes = DeviceAuthStore
4830-
.loadToken(deviceId: identity.deviceId, role: "operator", gatewayID: gatewayID)?
4832+
let storedOperatorScopes = DeviceIdentityStore.loadOrCreatePersisted()
4833+
.flatMap { identity in
4834+
DeviceAuthStore.loadToken(
4835+
deviceId: identity.deviceId,
4836+
role: "operator",
4837+
gatewayID: gatewayID)
4838+
}?
48314839
.scopes ?? []
48324840
return Self.shouldRequestOperatorAdminScope(
48334841
token: token,
@@ -4943,9 +4951,13 @@ extension NodeAppModel {
49434951
return
49444952
}
49454953
let gatewayID = config.nodeOptions.deviceAuthGatewayID ?? config.effectiveStableID
4946-
let identity = DeviceIdentityStore.loadOrCreate()
4947-
self.hasOperatorAdminScope = DeviceAuthStore
4948-
.loadToken(deviceId: identity.deviceId, role: "operator", gatewayID: gatewayID)?
4954+
self.hasOperatorAdminScope = DeviceIdentityStore.loadOrCreatePersisted()
4955+
.flatMap { identity in
4956+
DeviceAuthStore.loadToken(
4957+
deviceId: identity.deviceId,
4958+
role: "operator",
4959+
gatewayID: gatewayID)
4960+
}?
49494961
.scopes
49504962
.contains("operator.admin") == true
49514963
}

0 commit comments

Comments
 (0)