aboutsummaryrefslogtreecommitdiff
path: root/cmd/eno/cobra.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-14 22:05:23 +0530
committerishaan <contact@ishaan.cc>2026-07-14 22:05:23 +0530
commit6fc45951e42b0a7d4760e7b2eb09c647d1f75402 (patch)
treed37a12add7bb092f200eea7c7f4a27d225cbc8d1 /cmd/eno/cobra.go
parent6b33b7a8abf03d15a8164ff207547f45475e737e (diff)
read me
Diffstat (limited to 'cmd/eno/cobra.go')
-rw-r--r--cmd/eno/cobra.go65
1 files changed, 65 insertions, 0 deletions
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)")