From 6fc45951e42b0a7d4760e7b2eb09c647d1f75402 Mon Sep 17 00:00:00 2001 From: ishaan Date: Tue, 14 Jul 2026 22:05:23 +0530 Subject: read me --- cmd/eno/cobra.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'cmd/eno/cobra.go') 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)") -- cgit v1.3