Skip to content

Commit

Permalink
readpassword: show where stdin is connected
Browse files Browse the repository at this point in the history
Should make debugging situations like

	#852
	Empty stdin in mkinitcpio hook

easier.

Examples:

$ echo -n "" | ./gocryptfs -init a
Choose a password for protecting your files.
Reading Password from stdin (connected to "pipe:[749878]")
Got empty Password from stdin

$ ./gocryptfs -init a < /dev/null
Choose a password for protecting your files.
Reading Password from stdin (connected to "/dev/null")
Got empty Password from stdin

$ ./gocryptfs -init a < /dev/zero
Choose a password for protecting your files.
Reading Password from stdin (connected to "/dev/zero")
fatal: maximum password length of 2048 bytes exceeded

$ ./gocryptfs -init a < /dev/full
Choose a password for protecting your files.
Reading Password from stdin (connected to "/dev/full")
fatal: maximum password length of 2048 bytes exceeded

$ jakob@brikett:~/go/src/github.com/rfjakob/gocryptfs$ ./gocryptfs -init a < /dev/urandom
Choose a password for protecting your files.
Reading Password from stdin (connected to "/dev/urandom")

Your master key is:

    4e45a317-595d8a2d-46493a30-97de86ef-
    540c7364-f0acc297-dd6f2592-7d9a5c97

If the gocryptfs.conf file becomes corrupted or you ever forget your password,
there is only one hope for recovery: The master key. Print it to a piece of
paper and store it in a drawer. This message is only printed once.
The gocryptfs filesystem has been created successfully.
You can now mount it using: gocryptfs a MOUNTPOINT
  • Loading branch information
rfjakob committed Aug 23, 2024
1 parent 533c9eb commit b78e6a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/readpassword/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ func readPasswordTerminal(prompt string) ([]byte, error) {
// readPasswordStdin reads a line from stdin.
// It exits with a fatal error on read error or empty result.
func readPasswordStdin(prompt string) ([]byte, error) {
tlog.Info.Printf("Reading %s from stdin", prompt)
// This should make debugging situations like
// https://github.com/rfjakob/gocryptfs/issues/852
// easier. Only works on Linux, otherwise shows "?".
target, err := os.Readlink("/proc/self/fd/0")
if err != nil {
target = "?"
}
tlog.Info.Printf("Reading %s from stdin (connected to %q)", prompt, target)
p, err := readLineUnbuffered(os.Stdin)
if err != nil {
return nil, err
Expand Down

0 comments on commit b78e6a1

Please sign in to comment.