aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-21 20:36:04 +0530
committerishaan <contact@ishaan.cc>2026-07-21 20:36:04 +0530
commita92d0201b50c5c8e87638bd2ebb2e9e2b5b0983c (patch)
treebaa134e8baa73a5f6094ea56bb83d7e8603dfdef
parente48a02646f60b6fdff8db5c4105896756584ac63 (diff)
update gitignore so CI tests don't fail, update filenames
-rw-r--r--.gitignore2
-rw-r--r--cmd/eno/cobra.go2
-rw-r--r--cmd/eno/cobra_config.go71
-rw-r--r--cmd/eno/cobra_decrypt.go90
-rw-r--r--cmd/eno/cobra_edit.go63
-rw-r--r--cmd/eno/cobra_encrypt.go101
-rw-r--r--cmd/eno/cobra_rekey.go66
7 files changed, 393 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index aab35f8..c72cae0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-eno
+/eno
.tmp/
diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go
index 7283df1..a07ccf1 100644
--- a/cmd/eno/cobra.go
+++ b/cmd/eno/cobra.go
@@ -9,7 +9,7 @@ import (
var cobraCmd = &cobra.Command{
Use: "eno",
- Short: "file encryption tool",
+ Short: "encrypted notes and file encryption tool",
}
var initCmd = &cobra.Command{
diff --git a/cmd/eno/cobra_config.go b/cmd/eno/cobra_config.go
new file mode 100644
index 0000000..0872b28
--- /dev/null
+++ b/cmd/eno/cobra_config.go
@@ -0,0 +1,71 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "gitlab.com/whiteboardguy/eno/internal/config"
+)
+
+var configCmd = &cobra.Command{
+ Use: "config",
+ Short: "manage eno configuration",
+}
+
+var configSetCmd = &cobra.Command{
+ Use: "set <key> <value...>",
+ Short: "set a config value",
+ Args: cobra.MinimumNArgs(2),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if err := config.HandlerInit(); err != nil {
+ return err
+ }
+ key := strings.ToUpper(args[0])
+ if key == "PUBKEY_SERVICES" {
+ if len(args) < 3 {
+ return fmt.Errorf("pubkey_services requires name and url template")
+ }
+ return config.PubkeyServiceAdd(args[1], strings.Join(args[2:], " "))
+ }
+ return config.Set(key, strings.Join(args[1:], " "))
+ },
+}
+
+var configGetCmd = &cobra.Command{
+ Use: "get <key>",
+ Short: "get a config value",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ val, err := config.Get(args[0])
+ if err != nil {
+ return err
+ }
+ cmd.Println(val)
+ return nil
+ },
+}
+
+var configListCmd = &cobra.Command{
+ Use: "list",
+ Short: "list all config values",
+ Args: cobra.ExactArgs(0),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ for _, line := range config.List() {
+ cmd.Println(line)
+ }
+ return nil
+ },
+}
+
+var configRemoveCmd = &cobra.Command{
+ Use: "remove <key> [name]",
+ Short: "remove a config value or pubkey service",
+ Args: cobra.MinimumNArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ if strings.ToUpper(args[0]) == "PUBKEY_SERVICES" && len(args) >= 2 {
+ return config.PubkeyServiceRemove(args[1])
+ }
+ return config.Remove(args[0])
+ },
+}
diff --git a/cmd/eno/cobra_decrypt.go b/cmd/eno/cobra_decrypt.go
new file mode 100644
index 0000000..262816e
--- /dev/null
+++ b/cmd/eno/cobra_decrypt.go
@@ -0,0 +1,90 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "gitlab.com/whiteboardguy/eno/internal/config"
+ "gitlab.com/whiteboardguy/eno/internal/crypt"
+ "gitlab.com/whiteboardguy/eno/internal/utils"
+)
+
+var decryptCmd = &cobra.Command{
+ Use: "decrypt <file>",
+ Short: "decrypt a file",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ output, err := cmd.Flags().GetString("output")
+ if err != nil {
+ return fmt.Errorf("failed to get output flag: %v", err)
+ }
+
+ if output == "" {
+ output = strings.TrimSuffix(args[0], ".eno")
+ }
+
+ if _, err := os.Stat(output); err == nil {
+ ok, err := utils.AskUserYesNo("file '"+output+"' already exists. Overwrite?", false)
+ if err != nil {
+ return err
+ }
+ if !ok {
+ return fmt.Errorf("write aborted")
+ }
+ }
+
+ fileBytes, err := os.ReadFile(args[0])
+ if err != nil {
+ return fmt.Errorf("failed to read input file: %v", err)
+ }
+
+ authMode, err := utils.CheckFileAuthMode(args[0])
+ if err != nil {
+ return fmt.Errorf("failed to check auth mode: %v", err)
+ }
+
+ if authMode == crypt.SSH {
+ if config.Conf.DefaultSSHPrivPath == "" {
+ return fmt.Errorf("SSH not configured. Run 'eno ssh init' first")
+ }
+ plaintext, err := crypt.DecryptBytesSSH(fileBytes, config.Conf.DefaultSSHPrivPath)
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ crypt.TryMlock(plaintext)
+ defer clear(plaintext)
+
+ if err := os.WriteFile(output, plaintext, 0600); err != nil {
+ return fmt.Errorf("failed to write output file: %v", err)
+ }
+
+ return nil
+ }
+
+ fmt.Printf("Enter the passphrase: ")
+ password, err := utils.TakeSecureUserInput()
+ if err != nil {
+ return fmt.Errorf("failed to read passphrase: %v", err)
+ }
+ crypt.TryMlock(password)
+ defer clear(password)
+
+ plaintext, err := crypt.DecryptBytesPass(fileBytes, password)
+ if err != nil {
+ clear(password)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ crypt.TryMlock(plaintext)
+ defer clear(plaintext)
+
+ if err := os.WriteFile(output, plaintext, 0600); err != nil {
+ return fmt.Errorf("failed to write output file: %v", err)
+ }
+
+ return nil
+ },
+}
diff --git a/cmd/eno/cobra_edit.go b/cmd/eno/cobra_edit.go
new file mode 100644
index 0000000..aff69c2
--- /dev/null
+++ b/cmd/eno/cobra_edit.go
@@ -0,0 +1,63 @@
+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 editCmd = &cobra.Command{
+ Use: "edit <note>",
+ Short: "edit an existing encrypted note",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+
+ target := filepath.Clean(args[0])
+
+ ok, err := utils.AskUserYesNo("Edit "+target+" ?", true)
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ if !ok {
+ cmd.PrintErrln("Error: write 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:
+ err = crud.EditNoteSSH(target, config.Conf.DefaultSSHPrivPath, config.Conf.EditorString)
+ case crypt.Pass:
+ err = crud.EditNotePass(target, config.Conf.EditorString)
+ default:
+ cmd.PrintErrln("Error: unknown auth mode:", authMode)
+ os.Exit(1)
+ }
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ },
+}
diff --git a/cmd/eno/cobra_encrypt.go b/cmd/eno/cobra_encrypt.go
new file mode 100644
index 0000000..2cf6c01
--- /dev/null
+++ b/cmd/eno/cobra_encrypt.go
@@ -0,0 +1,101 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "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 encryptCmd = &cobra.Command{
+ Use: "encrypt <file>",
+ Short: "encrypt a file",
+ Args: cobra.ExactArgs(1),
+ RunE: func(cmd *cobra.Command, args []string) error {
+ output, err := cmd.Flags().GetString("output")
+ if err != nil {
+ return fmt.Errorf("failed to get output flag: %v", err)
+ }
+
+ if output == "" {
+ output = args[0] + ".eno"
+ }
+
+ if _, err := os.Stat(output); err == nil {
+ ok, err := utils.AskUserYesNo("file '"+output+"' already exists. Overwrite?", false)
+ if err != nil {
+ return err
+ }
+ if !ok {
+ return fmt.Errorf("write aborted")
+ }
+ }
+
+ fileBytes, err := os.ReadFile(args[0])
+ if err != nil {
+ return fmt.Errorf("failed to read input file: %v", err)
+ }
+ crypt.TryMlock(fileBytes)
+ defer clear(fileBytes)
+
+ sshFlag, err := cmd.Flags().GetBool("ssh")
+ if err != nil {
+ return fmt.Errorf("failed to get ssh flag: %v", err)
+ }
+
+ if sshFlag {
+ if config.Conf.DefaultSSHPubPath == "" {
+ return fmt.Errorf("SSH not configured. Run 'eno ssh init' first")
+ }
+ defaultPubKeyBytes, err := os.ReadFile(config.Conf.DefaultSSHPubPath)
+ if err != nil {
+ return fmt.Errorf("failed to read default SSH public key: %v", err)
+ }
+ pubKeys, _, err := crud.PromptRecipientKeys(defaultPubKeyBytes)
+ if err != nil {
+ return err
+ }
+ if len(pubKeys) == 0 {
+ return fmt.Errorf("at least one recipient public key is required")
+ }
+ encrypted, _, err := crypt.EncryptBytesSSH(fileBytes, pubKeys)
+ if err != nil {
+ clear(fileBytes)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+
+ if err := os.WriteFile(output, encrypted, 0600); err != nil {
+ return fmt.Errorf("failed to write output file: %v", err)
+ }
+
+ return nil
+ }
+
+ fmt.Printf("Enter a passphrase: ")
+ password, err := utils.TakeSecureUserInput()
+ if err != nil {
+ return fmt.Errorf("failed to read passphrase: %v", err)
+ }
+ crypt.TryMlock(password)
+ defer clear(password)
+
+ encrypted, err := crypt.EncryptBytesPass(fileBytes, password)
+ if err != nil {
+ clear(fileBytes)
+ clear(password)
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+
+ if err := os.WriteFile(output, encrypted, 0600); err != nil {
+ return fmt.Errorf("failed to write output file: %v", err)
+ }
+
+ return nil
+ },
+}
diff --git a/cmd/eno/cobra_rekey.go b/cmd/eno/cobra_rekey.go
new file mode 100644
index 0000000..2980c8d
--- /dev/null
+++ b/cmd/eno/cobra_rekey.go
@@ -0,0 +1,66 @@
+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:
+ err = crud.EditNoteSSH(target, config.Conf.DefaultSSHPrivPath, config.Conf.EditorString)
+
+ case crypt.Pass:
+ err = crud.EditNotePass(target, config.Conf.EditorString)
+
+ default:
+ cmd.PrintErrln("Error: unknown auth mode:", authMode)
+ os.Exit(1)
+ }
+
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ },
+}
+