From 8ebc072fb0ceae229196e8d3d8ff15bbbc049fdd Mon Sep 17 00:00:00 2001 From: ishaan Date: Wed, 15 Jul 2026 07:23:47 +0530 Subject: better encrypted/decrypted file perms --- cmd/eno/cobra.go | 8 ++++---- cmd/eno/config.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'cmd/eno') diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go index 1a58681..4a7443e 100644 --- a/cmd/eno/cobra.go +++ b/cmd/eno/cobra.go @@ -74,7 +74,7 @@ var encryptCmd = &cobra.Command{ os.Exit(1) } - if err := os.WriteFile(output, encrypted, 0644); err != nil { + if err := os.WriteFile(output, encrypted, 0600); err != nil { return fmt.Errorf("failed to write output file: %v", err) } @@ -95,7 +95,7 @@ var encryptCmd = &cobra.Command{ os.Exit(1) } - if err := os.WriteFile(output, encrypted, 0644); err != nil { + if err := os.WriteFile(output, encrypted, 0600); err != nil { return fmt.Errorf("failed to write output file: %v", err) } @@ -149,7 +149,7 @@ var decryptCmd = &cobra.Command{ crypt.TryMlock(plaintext) defer clear(plaintext) - if err := os.WriteFile(output, plaintext, 0644); err != nil { + if err := os.WriteFile(output, plaintext, 0600); err != nil { return fmt.Errorf("failed to write output file: %v", err) } @@ -172,7 +172,7 @@ var decryptCmd = &cobra.Command{ crypt.TryMlock(plaintext) defer clear(plaintext) - if err := os.WriteFile(output, plaintext, 0644); err != nil { + if err := os.WriteFile(output, plaintext, 0600); err != nil { return fmt.Errorf("failed to write output file: %v", err) } diff --git a/cmd/eno/config.go b/cmd/eno/config.go index 6725e84..90bdf1b 100644 --- a/cmd/eno/config.go +++ b/cmd/eno/config.go @@ -109,7 +109,7 @@ func handlerInit() error { if err := os.MkdirAll(filepath.Dir(Conf.ConfPath), 0755); err != nil { return fmt.Errorf("creating config dir: %w", err) } - f, err := os.Create(Conf.ConfPath) + f, err := os.OpenFile(Conf.ConfPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return fmt.Errorf("creating config file: %w", err) } @@ -187,7 +187,7 @@ func updateConfig(key string, val any) error { lines = append(lines, newLine) } - err = os.WriteFile(Conf.ConfPath, []byte(strings.Join(lines, "\n")), 0644) + err = os.WriteFile(Conf.ConfPath, []byte(strings.Join(lines, "\n")), 0600) if err != nil { return err } -- cgit v1.3