2022-08-28 11:21:57 +00:00
|
|
|
// Package obscure provides the obscure command.
|
2017-01-08 16:24:03 +00:00
|
|
|
package obscure
|
|
|
|
|
|
|
|
import (
|
2021-01-27 16:24:10 +00:00
|
|
|
"bufio"
|
2017-01-08 16:24:03 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-07-31 02:32:28 +00:00
|
|
|
"os"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs/config/obscure"
|
2017-01-08 16:24:03 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 15:58:11 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2017-01-08 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 15:58:11 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2017-01-08 16:24:03 +00:00
|
|
|
Use: "obscure password",
|
2020-09-03 12:12:54 +00:00
|
|
|
Short: `Obscure password for use in the rclone config file.`,
|
2021-11-04 11:50:43 +00:00
|
|
|
Long: `In the rclone config file, human-readable passwords are
|
2020-06-05 11:48:28 +00:00
|
|
|
obscured. Obscuring them is done by encrypting them and writing them
|
|
|
|
out in base64. This is **not** a secure way of encrypting these
|
|
|
|
passwords as rclone can decrypt them - it is to prevent "eyedropping"
|
|
|
|
- namely someone seeing a password in the rclone config file by
|
|
|
|
accident.
|
|
|
|
|
|
|
|
Many equally important things (like access tokens) are not obscured in
|
|
|
|
the config file. However it is very hard to shoulder surf a 64
|
|
|
|
character hex token.
|
|
|
|
|
2020-07-31 02:32:28 +00:00
|
|
|
This command can also accept a password through STDIN instead of an
|
2021-01-27 16:24:10 +00:00
|
|
|
argument by passing a hyphen as an argument. This will use the first
|
|
|
|
line of STDIN as the password not including the trailing newline.
|
2020-07-31 02:32:28 +00:00
|
|
|
|
2022-06-19 17:55:37 +00:00
|
|
|
echo "secretpassword" | rclone obscure -
|
2020-07-31 02:32:28 +00:00
|
|
|
|
|
|
|
If there is no data on STDIN to read, rclone obscure will default to
|
|
|
|
obfuscating the hyphen itself.
|
|
|
|
|
2020-06-05 11:48:28 +00:00
|
|
|
If you want to encrypt the config file then please use config file
|
|
|
|
encryption - see [rclone config](/commands/rclone_config/) for more
|
|
|
|
info.`,
|
2022-11-26 22:40:49 +00:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"versionIntroduced": "v1.36",
|
|
|
|
},
|
2021-01-27 16:24:10 +00:00
|
|
|
RunE: func(command *cobra.Command, args []string) error {
|
2017-01-08 16:24:03 +00:00
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2020-07-31 02:32:28 +00:00
|
|
|
var password string
|
|
|
|
fi, _ := os.Stdin.Stat()
|
|
|
|
if args[0] == "-" && (fi.Mode()&os.ModeCharDevice) == 0 {
|
2021-01-27 16:24:10 +00:00
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
if scanner.Scan() {
|
|
|
|
password = scanner.Text()
|
|
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-31 02:32:28 +00:00
|
|
|
} else {
|
|
|
|
password = args[0]
|
|
|
|
}
|
2017-01-08 16:24:03 +00:00
|
|
|
cmd.Run(false, false, command, func() error {
|
2020-07-31 02:32:28 +00:00
|
|
|
obscured := obscure.MustObscure(password)
|
2018-01-18 20:19:55 +00:00
|
|
|
fmt.Println(obscured)
|
2017-01-08 16:24:03 +00:00
|
|
|
return nil
|
|
|
|
})
|
2021-01-27 16:24:10 +00:00
|
|
|
return nil
|
2017-01-08 16:24:03 +00:00
|
|
|
},
|
|
|
|
}
|