1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package main
import (
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"gitlab.com/whiteboardguy/eno/internal/config"
"gitlab.com/whiteboardguy/eno/internal/crud"
"gitlab.com/whiteboardguy/eno/internal/crypt"
"gitlab.com/whiteboardguy/eno/internal/utils"
)
var rekeyCmd = &cobra.Command{
Use: "rekey <note>",
Short: "change the password or ssh recipients of a note",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
target := filepath.Clean(args[0])
ok, err := utils.AskUserYesNo("Re-Key "+target+" ?", true)
if err != nil {
cmd.PrintErrln("Error:", err)
os.Exit(1)
}
if !ok {
cmd.PrintErrln("Error: re-key aborted")
os.Exit(1)
}
target = strings.TrimSuffix(target, ".eno")
target += ".eno"
if _, err := os.Stat(target); os.IsNotExist(err) {
alt := filepath.Join(config.Conf.DataDir, target)
if _, err2 := os.Stat(alt); err2 == nil {
target = alt
}
}
authMode, err := utils.CheckFileAuthMode(target)
if err != nil {
cmd.PrintErrln("Error:", err)
os.Exit(1)
}
switch authMode {
case crypt.SSH:
if config.Conf.DefaultSSHPrivPath == "" || config.Conf.DefaultSSHPubPath == "" {
cmd.PrintErrln("Error: SSH not configured. Run 'eno ssh init' first")
os.Exit(1)
}
pubKeyBytes, readErr := os.ReadFile(config.Conf.DefaultSSHPubPath)
if readErr != nil {
cmd.PrintErrln("Error:", readErr)
os.Exit(1)
}
err = crud.RekeyNoteSSH(target, config.Conf.DefaultSSHPrivPath, pubKeyBytes)
case crypt.Pass:
err = crud.RekeyNotePass(target)
default:
cmd.PrintErrln("Error: unknown auth mode:", authMode)
os.Exit(1)
}
if err != nil {
cmd.PrintErrln("Error:", err)
os.Exit(1)
}
},
}
|