diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 104 | ||||
| -rw-r--r-- | cmd/eno/cobra.go | 65 | ||||
| -rw-r--r-- | cmd/eno/cobra_new.go | 8 | ||||
| -rw-r--r-- | internal/crud/cli_new.go | 84 | ||||
| -rw-r--r-- | internal/crypt/sshKey.go | 2 |
6 files changed, 150 insertions, 114 deletions
@@ -1,2 +1,3 @@ eno .tmp/ +internal/crypt/crypt_test.go @@ -2,104 +2,118 @@ **Encrypted Notes, Oui.** -A CLI tool for creating, editing, and managing encrypted notes with passphrase or SSH key authentication. +[View Better Docs](https://stigr.org/eno.html) -## Install +Eno is a Linux CLI tool for encrypted notes authenticated by your SSH key — no +cloud, no daemon, no extra passwords. -```bash -go install gitlab.com/whiteboardguy/eno/cmd/eno@latest -``` +## Motivation + +I wanted encrypted notes designed for linux. Not the gnupg all-in-one mess, nor +something as "javascripty" as Notesnook (*amazing tho*). Something for the +terminal. Something quite simple. Something that could be synced and backed up +using just git (TBD). -Or download a binary from the [releases page](https://gitlab.com/whiteboardguy/eno/-/releases). +<!-- TODO: add terminal recording or GIF showing eno in action --> -## Quickstart +## Quick Start ```bash -# initialize config eno init - -# create a passphrase-protected note eno new my-note - -# create and open in editor immediately eno new my-note -e - -# create an SSH-authenticated note eno new my-note --ssh - -# decrypt and edit an existing note eno edit my-note ``` +## Install + +Install Go if you don't have it: + +```bash +# Arch Linux +sudo pacman -S go +# Fedora +sudo dnf install golang +# Debian / Ubuntu +sudo apt install golang +``` + +Then install eno: +```bash +go install gitlab.com/whiteboardguy/eno/cmd/eno@latest +``` + ## Usage ### `eno init` -Create default config at `~/.config/eno/eno.conf` (or `$XDG_CONFIG_HOME/eno/eno.conf`). +Creates default config in `~/.config/eno/eno.conf` (`$XDG_CONFIG_HOME/eno/eno.conf`). ### `eno new <note>` -Create encrypted note. Note name defaults to `~/.EnoNotes/<note>.eno`. Use `-o` to specify custom output path. +Creates encrypted note. Defaults to `~/.EnoNotes/<note>.eno`. Use `-o` for custom path. -Flags: -- `-o, --output` — output file path -- `-e, --edit` — open editor after creating -- `--ssh` — use SSH key for authentication instead of passphrase +| Flag | Description | +|---|---| +| `-o, --output` | Output file path | +| `-e, --edit` | Open editor after creating | +| `--ssh` | Use SSH key instead of passphrase | ### `eno edit <note>` -Decrypt note to temp file, open editor, re-encrypt on save. Temp file is securely wiped on exit. +Decrypts, opens in editor, re-encrypts on save. Temp file securely wiped on exit. ### `eno encrypt <file>` -Encrypt any file with a passphrase. Output defaults to `<file>.eno`. +Encrypts any file with passphrase. Output defaults to `<file>.eno`. -Flags: -- `-o, --output` — output file path +| Flag | Description | +|---|---| +| `-o, --output` | Output file path | ### `eno decrypt <file>` -Decrypt a `.eno` file. Output defaults to `<file>` (with `.eno` stripped). +Decrypts `.eno` file. Output defaults to `<file>` (`.eno` stripped). -Flags: -- `-o, --output` — output file path +| Flag | Description | +|---|---| +| `-o, --output` | Output file path | ### `eno ssh init` -Register an SSH key for note authentication. Writes key paths into config. Supports Ed25519 keys only with passphrase-protected private keys. +Registers SSH key for note auth. Writes key paths to config. Ed25519 only, +passphrase-protected private keys required. ## Configuration -File: `~/.config/eno/eno.conf` (or `$XDG_CONFIG_HOME/eno/eno.conf`) +`~/.config/eno/eno.conf` (`$XDG_CONFIG_HOME/eno/eno.conf`) | Key | Default | Description | |---|---|---| -| `EDITOR_STRING` | `$EDITOR %s` or `nvim %s` | Editor command template. `%s` is replaced with temp file path | -| `DATA_DIR` | `~/.EnoNotes` | Directory for encrypted notes | -| `SSH_INIT` | `false` | Whether SSH has been initialized | -| `DEFAULT_SSH_PRIV` | — | Path to default SSH private key | -| `DEFAULT_SSH_PUB` | — | Path to default SSH public key | +| `EDITOR_STRING` | `$EDITOR %s` or `nvim %s` | Editor command template. `%s` replaced with temp file path | +| `DATA_DIR` | `~/.EnoNotes` | Encrypted notes directory | +| `SSH_INIT` | `false` | SSH initialized flag | +| `DEFAULT_SSH_PRIV` | — | Default SSH private key path | +| `DEFAULT_SSH_PUB` | — | Default SSH public key path | -## File Format - -Encrypted `.eno` files use a custom format: +## How It Works ``` <header-length>:<gob-encoded headers><ChaCha20-Poly1305 ciphertext> ``` -- Header length is ASCII decimal, terminated by `:` -- Headers contain salt, nonce, auth type (passphrase or SSH), and per-recipient wrapped keys -- Ciphertext is encrypted with ChaCha20-Poly1305 - -## Cryptography +- `header-length` — ASCII decimal, `:`-terminated +- Headers — salt, nonce, auth type (passphrase or SSH), per-recipient wrapped keys +- Ciphertext — ChaCha20-Poly1305 encrypted | Mode | Key Derivation | Cipher | |---|---|---| | Passphrase | Argon2id (1 pass, 2MB memory, 2 parallelism) | ChaCha20-Poly1305 | | SSH | X25519 ECDH ephemeral key exchange per recipient | ChaCha20-Poly1305 | -SSH mode converts Ed25519 keys to X25519 for ECDH. A random 32-byte note key is encrypted per recipient. +Ed25519 keys converted to X25519 for ECDH. 32-byte random note key encrypted +per recipient. ## Build from source diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go index ced2bc2..1a58681 100644 --- a/cmd/eno/cobra.go +++ b/cmd/eno/cobra.go @@ -48,6 +48,39 @@ var encryptCmd = &cobra.Command{ 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 Conf.DefaultSSHPubPath == "" { + return fmt.Errorf("SSH not configured. Run 'eno ssh init' first") + } + defaultPubKeyBytes, err := os.ReadFile(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 { + cmd.PrintErrln("Error:", err) + os.Exit(1) + } + + if err := os.WriteFile(output, encrypted, 0644); 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 { @@ -99,6 +132,30 @@ var decryptCmd = &cobra.Command{ 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 Conf.DefaultSSHPrivPath == "" { + return fmt.Errorf("SSH not configured. Run 'eno ssh init' first") + } + plaintext, err := crypt.DecryptBytesSSH(fileBytes, Conf.DefaultSSHPrivPath) + if err != nil { + cmd.PrintErrln("Error:", err) + os.Exit(1) + } + crypt.TryMlock(plaintext) + defer clear(plaintext) + + if err := os.WriteFile(output, plaintext, 0644); 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 { @@ -159,6 +216,13 @@ var editCmd = &cobra.Command{ target = strings.TrimSuffix(target, ".eno") target += ".eno" + if _, err := os.Stat(target); os.IsNotExist(err) { + alt := filepath.Join(Conf.DataDir, target) + if _, err2 := os.Stat(alt); err2 == nil { + target = alt + } + } + authMode, err := utils.CheckFileAuthMode(target) if err != nil { cmd.PrintErrln("Error:", err) @@ -183,6 +247,7 @@ var editCmd = &cobra.Command{ func init() { encryptCmd.Flags().StringP("output", "o", "", "output file (required)") + encryptCmd.Flags().Bool("ssh", false, "encrypt using SSH public keys (interactive)") // encryptCmd.MarkFlagRequired("output") decryptCmd.Flags().StringP("output", "o", "", "output file (required)") diff --git a/cmd/eno/cobra_new.go b/cmd/eno/cobra_new.go index d424fea..19436fb 100644 --- a/cmd/eno/cobra_new.go +++ b/cmd/eno/cobra_new.go @@ -43,6 +43,14 @@ var newCmd = &cobra.Command{ } } + if _, err := os.Stat(Conf.DataDir); os.IsNotExist(err) { + if err := os.MkdirAll(Conf.DataDir, 0700); err != nil { + cmd.PrintErrln("Error:", err) + os.Exit(1) + } + cmd.Println("Created data directory:", Conf.DataDir) + } + if _, err := os.Stat(output); err == nil { ok, err := utils.AskUserYesNo("file '"+output+"' already exists. Overwrite?", false) if err != nil { diff --git a/internal/crud/cli_new.go b/internal/crud/cli_new.go index cd06455..664d655 100644 --- a/internal/crud/cli_new.go +++ b/internal/crud/cli_new.go @@ -159,10 +159,10 @@ func NewNotePassEdit(output, editorString string) error { return err } -func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { +func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { useDefault, err := utils.AskUserYesNo("Do you want to encrypt the note with your own default Public Key?", true) if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) + return nil, false, fmt.Errorf("failed to read confirmation: %v", err) } if !useDefault { fmt.Println("Warning: you will not be able to open or edit this note again.") @@ -171,7 +171,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { addMore, err := utils.AskUserYesNo("Do you want to add more public keys?", false) if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) + return nil, false, fmt.Errorf("failed to read confirmation: %v", err) } pubKeys := [][]byte{} @@ -186,7 +186,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() if err := scanner.Err(); err != nil { - return fmt.Errorf("failed to read public key: %v", err) + return nil, false, fmt.Errorf("failed to read public key: %v", err) } input := strings.TrimSpace(scanner.Text()) @@ -207,7 +207,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { var err error keyBytes, err = os.ReadFile(part) if err != nil { - return fmt.Errorf("failed to read public key file %s: %v", part, err) + return nil, false, fmt.Errorf("failed to read public key file %s: %v", part, err) } } @@ -216,7 +216,7 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { more, err := utils.AskUserYesNo("Add more public keys?", false) if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) + return nil, false, fmt.Errorf("failed to read confirmation: %v", err) } if !more { break @@ -224,6 +224,14 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { } } + return pubKeys, useDefault, nil +} + +func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { + pubKeys, _, err := PromptRecipientKeys(defaultPubKeyBytes) + if err != nil { + return err + } if len(pubKeys) == 0 { return fmt.Errorf("at least one recipient public key is required") } @@ -255,70 +263,10 @@ func NewNoteSSH(output string, defaultPubKeyBytes []byte) error { } func NewNoteSSHEdit(output string, defaultPubKeyBytes []byte, defaultPrivKeyPath string, editorString string) error { - useDefault, err := utils.AskUserYesNo("Do you want to encrypt the note with your own default Public Key?", true) + pubKeys, useDefault, err := PromptRecipientKeys(defaultPubKeyBytes) if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) - } - if !useDefault { - fmt.Println("Warning: you will not be able to open or edit this note again.") - fmt.Println(" make sure you've used the '--edit' flag.") - } - - addMore, err := utils.AskUserYesNo("Do you want to add more public keys?", false) - if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) - } - - pubKeys := [][]byte{} - - if useDefault { - pubKeys = append(pubKeys, defaultPubKeyBytes) - } - - if addMore { - for { - fmt.Print("Enter a public key, or path to a public key file (comma-separated for multiple): ") - scanner := bufio.NewScanner(os.Stdin) - scanner.Scan() - if err := scanner.Err(); err != nil { - return fmt.Errorf("failed to read public key: %v", err) - } - - input := strings.TrimSpace(scanner.Text()) - if input == "" { - continue - } - - for part := range strings.SplitSeq(input, ",") { - part = strings.TrimSpace(part) - if part == "" { - continue - } - - var keyBytes []byte - if strings.HasPrefix(part, "ssh-") { - keyBytes = []byte(part) - } else { - var err error - keyBytes, err = os.ReadFile(part) - if err != nil { - return fmt.Errorf("failed to read public key file %s: %v", part, err) - } - } - - pubKeys = append(pubKeys, bytes.TrimSpace(keyBytes)) - } - - more, err := utils.AskUserYesNo("Add more public keys?", false) - if err != nil { - return fmt.Errorf("failed to read confirmation: %v", err) - } - if !more { - break - } - } + return err } - if len(pubKeys) == 0 { return fmt.Errorf("at least one recipient public key is required") } diff --git a/internal/crypt/sshKey.go b/internal/crypt/sshKey.go index 3b0b344..e36d6fd 100644 --- a/internal/crypt/sshKey.go +++ b/internal/crypt/sshKey.go @@ -178,7 +178,7 @@ func FindAndUnwrapNoteKey(recipients []WrappedKey, privKeyPath string) ([]byte, return nil, fmt.Errorf("read SSH key: %w", err) } TryMlock(pemBytes) - clear(pemBytes) + defer clear(pemBytes) parsed, err := ssh.ParseRawPrivateKey(pemBytes) if err != nil { |