@@ -26,56 +26,6 @@ func DefaultCredentialsPath() string {
2626 return filepath .Join (dir , "doubletake" , "credentials.json" )
2727}
2828
29- // SaveCredentials writes pairing credentials to disk (legacy single-device format).
30- func SaveCredentials (path string , pairingID string , pub ed25519.PublicKey , priv ed25519.PrivateKey ) error {
31- creds := SavedCredentials {
32- PairingID : pairingID ,
33- Ed25519Public : []byte (pub ),
34- Ed25519Seed : priv .Seed (),
35- }
36- data , err := json .MarshalIndent (creds , "" , " " )
37- if err != nil {
38- return fmt .Errorf ("marshal credentials: %w" , err )
39- }
40- if err := os .WriteFile (path , data , 0600 ); err != nil {
41- return fmt .Errorf ("write credentials: %w" , err )
42- }
43- return nil
44- }
45-
46- // LoadCredentials reads pairing credentials from disk.
47- // Supports both the legacy single-device format and the multi-device map format
48- // written by CredentialStore. Returns nil, nil if the file doesn't exist.
49- func LoadCredentials (path string ) (* SavedCredentials , error ) {
50- data , err := os .ReadFile (path )
51- if err != nil {
52- if os .IsNotExist (err ) {
53- return nil , nil
54- }
55- return nil , fmt .Errorf ("read credentials: %w" , err )
56- }
57-
58- // Try multi-device format first (map[string]*SavedCredentials)
59- var multi map [string ]* SavedCredentials
60- if err := json .Unmarshal (data , & multi ); err == nil && len (multi ) > 0 {
61- for _ , creds := range multi {
62- if creds != nil && creds .PairingID != "" {
63- return creds , nil
64- }
65- }
66- }
67-
68- // Fall back to legacy single-device format
69- var creds SavedCredentials
70- if err := json .Unmarshal (data , & creds ); err != nil {
71- return nil , fmt .Errorf ("unmarshal credentials: %w" , err )
72- }
73- if creds .PairingID == "" {
74- return nil , nil
75- }
76- return & creds , nil
77- }
78-
7929// Ed25519Keys reconstructs the key pair from saved credentials.
8030func (c * SavedCredentials ) Ed25519Keys () (ed25519.PublicKey , ed25519.PrivateKey ) {
8131 if len (c .Ed25519Seed ) != ed25519 .SeedSize {
@@ -105,17 +55,8 @@ func NewCredentialStore(path string) (*CredentialStore, error) {
10555 }
10656 return nil , fmt .Errorf ("read credential store: %w" , err )
10757 }
108- // Try multi-device format first
10958 if err := json .Unmarshal (data , & cs .devices ); err != nil {
110- // Fall back to legacy single-device format
111- var single SavedCredentials
112- if err2 := json .Unmarshal (data , & single ); err2 != nil {
113- return nil , fmt .Errorf ("unmarshal credential store: %w" , err )
114- }
115- // Store under empty key — will be re-keyed on first successful connect
116- if single .PairingID != "" {
117- cs .devices ["" ] = & single
118- }
59+ return nil , fmt .Errorf ("unmarshal credential store: %w" , err )
11960 }
12061 return cs , nil
12162}
@@ -124,11 +65,7 @@ func NewCredentialStore(path string) (*CredentialStore, error) {
12465func (cs * CredentialStore ) Lookup (deviceID string ) * SavedCredentials {
12566 cs .mu .Lock ()
12667 defer cs .mu .Unlock ()
127- if creds := cs .devices [deviceID ]; creds != nil {
128- return creds
129- }
130- // Check legacy empty-key entry
131- return cs .devices ["" ]
68+ return cs .devices [deviceID ]
13269}
13370
13471// Len returns the number of stored credential entries.
@@ -138,13 +75,6 @@ func (cs *CredentialStore) Len() int {
13875 return len (cs .devices )
13976}
14077
141- // Import adds a credential entry without persisting (used for legacy migration at startup).
142- func (cs * CredentialStore ) Import (deviceID string , creds * SavedCredentials ) {
143- cs .mu .Lock ()
144- defer cs .mu .Unlock ()
145- cs .devices [deviceID ] = creds
146- }
147-
14878// Save stores credentials for a device and persists to disk.
14979func (cs * CredentialStore ) Save (deviceID string , pairingID string , pub ed25519.PublicKey , priv ed25519.PrivateKey ) error {
15080 cs .mu .Lock ()
@@ -155,10 +85,6 @@ func (cs *CredentialStore) Save(deviceID string, pairingID string, pub ed25519.P
15585 Ed25519Public : []byte (pub ),
15686 Ed25519Seed : priv .Seed (),
15787 }
158- // Remove legacy empty-key entry if we now have a proper key
159- if deviceID != "" {
160- delete (cs .devices , "" )
161- }
16288 return cs .persist ()
16389}
16490
0 commit comments