JSON-RPC 密码
原始发布页
打开来源页面查看 1 个交叉存档
我已经把为 JSON-RPC 添加密码的改动上传到了 SVN。如果你配置好了构建环境,请测试一下。
-server 开关被替换为 -rpcpw=<password>,bitcoind 也使用这个开关。 bitcoin -rpcpw=<password> -- 运行并开放 JSON-RPC 端口 bitcoind -rpcpw=<password> -- 带密码的守护进程
如果你对开关名称有更好的想法,请告诉我,但要记住,将来还会有一个用于加密数据库的密码。我不确定,不过我认为这两者可能需要使用不同的密码。
如果没有设置密码,它会发出警告。
现在所有命令都要求把密码作为第一个参数。如果你运行“bitcoind help”,它会告诉你这一点。
核心代码: // Check password if (params.size() < 1 || params[0].type() != str_type) throw runtime_error("First parameter must be the password."); if (params[0].get_str() != strRPCPassword) { if (strRPCPassword.size() < 15) Sleep(50); begin = strRequest.end(); printf("ThreadRPCServer incorrect password attempt "); throw runtime_error("Incorrect password."); }
对这些决定有什么意见吗?
if (strRPCPassword.size() < 15) Sleep(50); -- 这意味着,如果密码较短,每次尝试后都会等待 50ms。这可能被用于 DoS 攻击,但我认为,如果密码较短,更重要的是防范暴力扫描密码。这可能会让外部人员知道密码是否少于 15 个字符,但少于 15 个字符并没有多值得注意,大多数密码都不到 15 个字符。如果你想排除 DoS 的可能性,只需使用 15 个或更多字符的密码。
begin = strRequest.end(); -- 如果这是一个包含多次调用的单一请求,只要有一次密码错误,我就丢弃剩余部分。这样你就无法在一个数据包里塞入数百万次密码尝试。你怎么看,这样处理对吗?(反正多次调用可能几乎从来没人使用)
我还修正了帮助中重复列出的两个命令: getaddressesbylabel <pw> <label> getbalance <pw> getblockcount <pw> getblocknumber <pw> getconnectioncount <pw> getdifficulty <pw> getgenerate <pw> getinfo <pw> getlabel <pw> <bitcoinaddress> getnewaddress <pw> [label] getreceivedbyaddress <pw> <bitcoinaddress> [minconf=1] getreceivedbylabel <pw> <label> [minconf=1] help <pw> listreceivedbyaddress <pw> [minconf=1] [includeempty=false] listreceivedbylabel <pw> [minconf=1] [includeempty=false] sendtoaddress <pw> <bitcoinaddress> <amount> [comment] [comment-to] setgenerate <pw> <generate> [genproclimit] setlabel <pw> <bitcoinaddress> <label> stop <pw>
英文原文
展开英文原文
I uploaded to SVN my changes to add a password to JSON-RPC. If you're set up to build, please test it.
The -server switch is replaced with -rpcpw=<password>, which is also used with bitcoind. bitcoin -rpcpw=<password> -- runs with JSON-RPC port open bitcoind -rpcpw=<password> -- daemon with password
If you have a better idea for the switch name, let me know, but keep in mind there will eventually be a password for encrypting the database too. I'm not sure but I think they may want to use different passwords for the two.
It gives a warning if you don't set a password.
All commands now require the password as the first parameter. It'll tell you that if you run "bitcoind help".
The central code:
// Check password if (params.size() < 1 || params[0].type() != str_type) throw runtime_error("First parameter must be the password."); if (params[0].get_str() != strRPCPassword) { if (strRPCPassword.size() < 15) Sleep(50); begin = strRequest.end(); printf("ThreadRPCServer incorrect password attempt "); throw runtime_error("Incorrect password."); }
Any comments on these decisions?
if (strRPCPassword.size() < 15) Sleep(50); -- this means if it's a short password, it'll wait 50ms after each attempt. This might be used as a DoS attack, but I figured if it's a short password, it's more important to protect against brute force password scan. This may tell outsiders whether the password is less than 15 characters, but less than 15 isn't all that noteworthy, most passwords are less than 15. If you want to close the DoS possibility, just use a password 15 characters or longer.
begin = strRequest.end(); -- if it's a single request with multiple invocations, I throw away the rest if one has a bad password. This is so you can't stuff it with millions of password attempts in one packet. What do you think, is this the right thing to do? (multiple invocation is probably almost never used anyway)
I also fixed the two duplicated commands listed in the help:
getaddressesbylabel <pw> <label> getbalance <pw> getblockcount <pw> getblocknumber <pw> getconnectioncount <pw> getdifficulty <pw> getgenerate <pw> getinfo <pw> getlabel <pw> <bitcoinaddress> getnewaddress <pw> [label] getreceivedbyaddress <pw> <bitcoinaddress> [minconf=1] getreceivedbylabel <pw> <label> [minconf=1] help <pw> listreceivedbyaddress <pw> [minconf=1] [includeempty=false] listreceivedbylabel <pw> [minconf=1] [includeempty=false] sendtoaddress <pw> <bitcoinaddress> <amount> [comment] [comment-to] setgenerate <pw> <generate> [genproclimit] setlabel <pw> <bitcoinaddress> <label> stop <pw>