Commit 7463a34
Fix atomic device-key token clearing (#889)
* Fix non-atomic device-key write in ClearStoredTokens
ClearStoredTokens in DeviceIdentityStore used File.WriteAllBytes to
rewrite device-key-ed25519.json. A crash/power-loss mid-write could leave
a torn file, causing LoadExisting to silently regenerate a new keypair
and rotate the device identity.
Fix: Add DeviceIdentity.TryClearAllDeviceTokens that strips all token
fields using raw JSON filtering and writes atomically via temp-file +
File.Move (same pattern as AtomicWriteKeyFile). ClearStoredTokens now
delegates to it.
Also add AtomicWriteKeyFileRaw for the ConnectionPage rollback-restore
path that previously used File.WriteAllText directly.
Fixes #888
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Handle non-object identity JSON during token clear
Guard TryClearAllDeviceTokens before enumerating JSON object properties so valid-but-non-object JSON remains a best-effort no-op instead of throwing through ClearStoredTokens.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Preserve best-effort token clear behavior
Keep DeviceIdentityStore.ClearStoredTokens as a best-effort operation by logging unexpected failures from the shared atomic token-clear helper instead of allowing them to escape connection cleanup flows.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Christine Yan <christineyan@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 87dc3dc commit 7463a34
4 files changed
Lines changed: 98 additions & 22 deletions
File tree
- src
- OpenClaw.Connection
- OpenClaw.Tray.WinUI/Pages
- tests/OpenClaw.Connection.Tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
41 | | - | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 44 | + | |
62 | 45 | | |
63 | 46 | | |
64 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
97 | 168 | | |
98 | 169 | | |
99 | 170 | | |
| |||
523 | 594 | | |
524 | 595 | | |
525 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
526 | 607 | | |
527 | 608 | | |
528 | 609 | | |
529 | 610 | | |
530 | 611 | | |
531 | | - | |
| 612 | + | |
532 | 613 | | |
533 | 614 | | |
534 | 615 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2747 | 2747 | | |
2748 | 2748 | | |
2749 | 2749 | | |
2750 | | - | |
| 2750 | + | |
2751 | 2751 | | |
2752 | 2752 | | |
2753 | 2753 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| |||
0 commit comments