Skip to content

Commit 8e84928

Browse files
Codextherealpaulgg
andauthored
Remove legacy keypair.pub after PQ migration (#96)
* Initial plan * fix: remove legacy keypair pub after migration --------- Co-authored-by: openai-code-agent[bot] <242516109+Codex@users.noreply.github.com> Co-authored-by: therealpaulgg <paul@paul.systems>
1 parent 9287025 commit 8e84928

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/actions/migrate.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func Migrate(c *cli.Context) error {
109109

110110
os.Remove(filepath.Join(sshSyncDir, "keypair.bak"))
111111
os.Remove(filepath.Join(sshSyncDir, "master_key.bak"))
112+
if err := removeLegacyPublicKey(sshSyncDir); err != nil {
113+
fmt.Fprintf(os.Stderr, "WARNING: could not remove legacy keypair.pub: %v\n", err)
114+
}
112115

113116
fmt.Println()
114117
fmt.Println("Migration complete! Your keys are now using post-quantum cryptography.")
@@ -196,3 +199,10 @@ func restoreBackup(backupPath, originalPath string) {
196199
fmt.Fprintf(os.Stderr, "WARNING: could not restore %s: %v\n", originalPath, err)
197200
}
198201
}
202+
203+
func removeLegacyPublicKey(sshSyncDir string) error {
204+
if err := os.Remove(filepath.Join(sshSyncDir, "keypair.pub")); err != nil && !errors.Is(err, os.ErrNotExist) {
205+
return err
206+
}
207+
return nil
208+
}

pkg/actions/migrate_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package actions
2+
3+
import (
4+
"errors"
5+
"os"
6+
"path/filepath"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestRemoveLegacyPublicKeyDeletesFile(t *testing.T) {
14+
dir := t.TempDir()
15+
pubPath := filepath.Join(dir, "keypair.pub")
16+
require.NoError(t, os.WriteFile(pubPath, []byte("legacy"), 0600))
17+
18+
require.NoError(t, removeLegacyPublicKey(dir))
19+
20+
_, err := os.Stat(pubPath)
21+
assert.True(t, errors.Is(err, os.ErrNotExist), "keypair.pub should be removed")
22+
}
23+
24+
func TestRemoveLegacyPublicKeyMissingOK(t *testing.T) {
25+
dir := t.TempDir()
26+
27+
assert.NoError(t, removeLegacyPublicKey(dir))
28+
}

0 commit comments

Comments
 (0)