Skip to content

Commit 8b958ab

Browse files
committed
Merge #7550: rpc: Input-from-stdin mode for bitcoin-cli
f22f14c doc: mention bitcoin-cli -stdin in release notes (Wladimir J. van der Laan) 92bcca3 rpc: Input-from-stdin mode for bitcoin-cli (Wladimir J. van der Laan)
2 parents a08c41d + f22f14c commit 8b958ab

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

doc/release-notes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ Example item
88
----------------
99

1010

11+
bitcoin-cli: arguments privacy
12+
--------------------------------
13+
14+
The RPC command line client gained a new argument, `-stdin`
15+
to read extra arguments from standard input, one per line until EOF/Ctrl-D.
16+
For example:
17+
18+
$ echo -e "mysecretcode\n120" | src/bitcoin-cli -stdin walletpassphrase
19+
20+
It is recommended to use this for sensitive information such as wallet
21+
passphrases, as command-line arguments can usually be read from the process
22+
table by any user on the system.
23+
1124
0.13.0 Change log
1225
=================
1326

src/bitcoin-cli.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ std::string HelpMessageCli()
4343
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
4444
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
4545
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout during HTTP requests (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
46+
strUsage += HelpMessageOpt("-stdin", _("Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases)"));
4647

4748
return strUsage;
4849
}
@@ -232,15 +233,17 @@ int CommandLineRPC(int argc, char *argv[])
232233
argc--;
233234
argv++;
234235
}
235-
236-
// Method
237-
if (argc < 2)
238-
throw runtime_error("too few parameters");
239-
string strMethod = argv[1];
240-
241-
// Parameters default to strings
242-
std::vector<std::string> strParams(&argv[2], &argv[argc]);
243-
UniValue params = RPCConvertValues(strMethod, strParams);
236+
std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
237+
if (GetBoolArg("-stdin", false)) {
238+
// Read one arg per line from stdin and append
239+
std::string line;
240+
while (std::getline(std::cin,line))
241+
args.push_back(line);
242+
}
243+
if (args.size() < 1)
244+
throw runtime_error("too few parameters (need at least command)");
245+
std::string strMethod = args[0];
246+
UniValue params = RPCConvertValues(strMethod, std::vector<std::string>(args.begin()+1, args.end()));
244247

245248
// Execute and handle connection failures with -rpcwait
246249
const bool fWait = GetBoolArg("-rpcwait", false);

0 commit comments

Comments
 (0)