Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

lncli: Use EOF as a terminator instead of the newline in lncli unlock --stdin command #8657

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions cmd/lncli/cmd_walletunlocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
Expand Down Expand Up @@ -469,7 +470,9 @@ var unlockCommand = cli.Command{
"a file that can be read by another user. " +
"This flag should only be used in " +
"combination with some sort of password " +
"manager or secrets vault.",
"manager or secrets vault. The password will " +
"be read from standard input until EOF " +
"(End of File) is encountered.",
},
statelessInitFlag,
},
Expand All @@ -491,11 +494,24 @@ func unlock(ctx *cli.Context) error {
// password manager. If the user types the password instead, it will be
// echoed in the console.
case ctx.IsSet("stdin"):
reader := bufio.NewReader(os.Stdin)
pw, err = reader.ReadBytes('\n')
// Copy the password from standard input to the buffer until
// EOF (End of File) is encountered.
var buf bytes.Buffer
if _, err := io.Copy(&buf, os.Stdin); err != nil {
return err
}
pw = buf.Bytes()

// Remove carriage return and newline characters.
pw = bytes.Trim(pw, "\r\n")
// Remove carriage return.
pw = bytes.Trim(pw, "\r")

// Check if the provided password has leading or trailing
// newline characters, then issue a warning since they will
// not be trimmed.
if !bytes.Equal(pw, bytes.Trim(pw, "\n")) {
fmt.Println("WARNING: Password contains leading or " +
"trailing newline characters.")
}

// Read the password from a terminal by default. This requires the
// terminal to be a real tty and will fail if a string is piped into
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ bitcoin peers' feefilter values into account](https://github.com/lightningnetwor
maintain a healthy connection to the network by checking the number of
outbound peers if they are below 6.

* [Use EOF as a terminator](https://github.com/lightningnetwork/lnd/pull/8657)
is added to `lncli unlock --stdin` command to use EOF as a terminator instead
of newline.

### Logging
* [Add the htlc amount](https://github.com/lightningnetwork/lnd/pull/8156) to
contract court logs in case of timed-out HTLCs in order to easily spot dust
Expand Down