From e791b40309232a275724dc283acdc40b1b2d1f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Sun, 20 Oct 2024 20:54:40 +0200 Subject: [PATCH] Add support for the password flag to the decrypt command --- cli/cmd/authenticator.go | 7 ++++++- cli/pkg/authenticator/decrypt.go | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/cmd/authenticator.go b/cli/cmd/authenticator.go index 7f72adf29d..7e6ca100c3 100644 --- a/cli/cmd/authenticator.go +++ b/cli/cmd/authenticator.go @@ -19,11 +19,16 @@ var decryptExportCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { inputPath := args[0] outputPath := args[1] - return authenticator.DecryptExport(inputPath, outputPath) + + password, _ := cmd.Flags().GetString("password") + + return authenticator.DecryptExport(inputPath, outputPath, password) }, } func init() { + decryptExportCmd.Flags().StringP("password", "p", "", "Password for decryption") + rootCmd.AddCommand(authenticatorCmd) authenticatorCmd.AddCommand(decryptExportCmd) } diff --git a/cli/pkg/authenticator/decrypt.go b/cli/pkg/authenticator/decrypt.go index f841de2717..c19e1dbbc7 100644 --- a/cli/pkg/authenticator/decrypt.go +++ b/cli/pkg/authenticator/decrypt.go @@ -21,7 +21,7 @@ type _KDF struct { Salt string `json:"salt"` } -func DecryptExport(inputPath string, outputPath string) error { +func DecryptExport(inputPath string, outputPath string, password string) error { exportFile, err := internal.ResolvePath(inputPath) if err != nil { return fmt.Errorf("error resolving exportFile path (in): %v", err) @@ -45,10 +45,13 @@ func DecryptExport(inputPath string, outputPath string) error { return fmt.Errorf("unsupported export version: %d", export.Version) } - password, err := internal.GetSensitiveField("Enter password to decrypt export") - if err != nil { - return err + if password == "" { + password, err = internal.GetSensitiveField("Enter password to decrypt export") + if err != nil { + return err + } } + fmt.Printf("\n....") key, err := eCrypto.DeriveArgonKey(password, export.KDFParams.Salt, export.KDFParams.MemLimit, export.KDFParams.OpsLimit) if err != nil {