A Windows user on Discord: the Agents list keeps saying Claude Desktop's
inferenceGatewayApiKey (00000000-0000-4000-8000-6d6167706965.json) was
changed. Reconnect and a Desktop restart help only until the next start.
Cause: Claude Desktop 4.4212.0 (2026-10-29, Windows and macOS) seals
configLibrary secrets at rest. Its custom-3p:keys sweep runs at every start
and rewrites each clear-text secret field, inferenceGatewayApiKey among
them, in place as
"__sealed__:v1:" + base64(protect("anthropic.claude.crossProfileSecret.v1:"
+ {"configLibrary":{"key":k,"value":v}}))
Desktop opens the value again when it reads the profile, so it still sends
magpie's key and the gateway takes it. Only magpie's file check saw another
string. In 4.29.0 the writer was gated on !app.isPackaged; in 4.4212 the
gate is gone. Read from the 4.4212 nupkg and macOS zip's app.asar.
protect is the claude-native addon's userDpapiProtect on Windows (user
DPAPI, entropy "anthropic.claude.crossProfileSecret.v1") and Electron
safeStorage (Keychain) on macOS.
Fix: desktopOpen opens a sealed value before Check and Sync judge it. On
Windows it is opened with CryptUnprotectData and that entropy, the prefix
and the configLibrary key are checked, and the clear key is then compared
as before, so a sealed key that isn't magpie's is still "was changed". A
seal magpie can't open (macOS Keychain, another user, a bad blob) is
unknown, not changed: no notice, and Sync doesn't write over it. The
gateway's auth is unchanged; it still takes only the key magpie wrote,
which is what Desktop sends after opening the seal.
Run (mote, at this head on 99c2567cf): gofmt -l clean, go vet
./internal/agent, GOOS=windows and GOOS=linux go vet ./internal/agent,
go test -count=1 -timeout 45m ./internal/agent ok. Windows (xiaomi-gpu,
win-run): go test -count=1 -timeout 45m ./internal/agent: 14 reds, none
in Claude Desktop's key path. 13 fail the same at base 99c2567cf run
there; TestHermesProfilesFollowMagpieModel passed at the base and passes
6 of 6 alone at this head. All 14 are filed: #4115 (Hermes, Desktop
language, DesktopExec, WorkBuddy, Copilot/Qoder folders ...), #2808
(Codex keychain), #1827. The new Windows seal tests pass there.
Real blob: on xiaomi-gpu, Desktop's own claude-native-binding.node
(userDpapiProtect) sealed the clear text exactly as Desktop 4.4212 builds
it; desktopOpen opened it from Go to the original key (a throwaway test,
deleted after, since the blob opens only for that user).
Broken by hand: with the old claudedesktop.go, TestClaudeDesktopSealedKey
IsNotChanged fails with the reported message ("... inferenceGatewayApiKey
... was changed ...") and TestClaudeDesktopImportedSealedKeyStays fails on
its check and on Sync rewriting the sealed key. Without the entropy, the
real-blob open failed ("The data is invalid").
Not tried: a real Claude Desktop 4.4212 running against magpie on Windows
or macOS (not started; the live config on this Mac untouched). On macOS a
sealed key is left unknown rather than opened, so a key changed there by
hand after sealing is not reported until Desktop's file is clear again.
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
)
|
|
|
|
// desktopSealHere seals v at key k as Claude Desktop does on Windows: the
|
|
// user's DPAPI, with its entropy, over its prefix and
|
|
// {"configLibrary":{key,value}}.
|
|
func desktopSealHere(t *testing.T, k, v string) string {
|
|
t.Helper()
|
|
j, _ := json.Marshal(map[string]any{"configLibrary": map[string]string{"key": k, "value": v}})
|
|
b := []byte(desktopSealedWith + string(j))
|
|
in := windows.DataBlob{Size: uint32(len(b)), Data: &b[0]}
|
|
e := []byte(desktopEntropy)
|
|
entropy := windows.DataBlob{Size: uint32(len(e)), Data: &e[0]}
|
|
var out windows.DataBlob
|
|
if err := windows.CryptProtectData(&in, nil, &entropy, 0, nil, windows.CRYPTPROTECT_UI_FORBIDDEN, &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer windows.LocalFree(windows.Handle(unsafe.Pointer(out.Data)))
|
|
return desktopSealed + base64.StdEncoding.EncodeToString(unsafe.Slice(out.Data, out.Size))
|
|
}
|
|
|
|
func TestDesktopOpensWhatDesktopSealed(t *testing.T) {
|
|
k := "inferenceGatewayApiKey"
|
|
if got, known := desktopOpen(k, desktopSealHere(t, k, "magpie-x-claude-desktop")); !known || got != "magpie-x-claude-desktop" {
|
|
t.Errorf("opened %q %v", got, known)
|
|
}
|
|
// sealed for another key: Desktop wouldn't open it there either
|
|
if got, known := desktopOpen(k, desktopSealHere(t, "anthropicApiKey", "sk")); known {
|
|
t.Errorf("another key's seal opened to %q", got)
|
|
}
|
|
}
|
|
|
|
// On Windows magpie opens the key Desktop sealed: magpie's own is on
|
|
// magpie, another one sealed is a change.
|
|
func TestClaudeDesktopSealedKeyOpened(t *testing.T) {
|
|
home, p := desktopSandbox(t)
|
|
os.MkdirAll(p.dir, 0o755)
|
|
a := claudeDesktop(home)
|
|
if err := a.Field("provider").Set("magpie"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
k := "inferenceGatewayApiKey"
|
|
edit.SetJSON(p.prof, edit.KV{Path: k, Value: desktopSealHere(t, k, agentKey("claude-desktop"))})
|
|
if c := a.Check(); c != "" {
|
|
t.Errorf("check with magpie's key sealed: %s", c)
|
|
}
|
|
edit.SetJSON(p.prof, edit.KV{Path: k, Value: desktopSealHere(t, k, "sk-someone-elses")})
|
|
if c := a.Check(); !strings.Contains(c, "was changed") {
|
|
t.Errorf("check with another key sealed: %q", c)
|
|
}
|
|
}
|