原始文献 / 论坛帖 / Re: JSON-RPC password

Re: JSON-RPC password

Bitcointalk · 2010-07-25 21:34:29 UTC

AuthorSatoshi Nakamoto
TitleRe: JSON-RPC password
Date2010-07-25 21:34:29 UTC
ForumBitcointalk · 原文

引用自:lachesis 于 July 25, 2010, 07:52:35 PM(https://bitcointalk.org/index.php?topic=461.msg5738#msg5738)
我发现了一个像是 bug 的东西:用户名和密码组合足够长时,bitcoind 里的 base64 编码器生成的 authorization 头长这样:
Code:
...
Authorization: Basic YWJiYWJiYWFiYmE6aGVsbG93b3JsZGhlbGxvd29ybGRoZWxsb3dvcmxkaGVsbG93
b3JsZGhlbGxvd29ybGRoZWxsb3dvcmxk

它每 64 个字符就插一个换行,这显然会破坏 Authorization 头,所以 "bitcoin getinfo" 这样的命令会失败。行为正常的客户端连服务器还是没问题的。

可以在 Base64Encode 函数末尾去掉 result 里的换行(还有 '\n')来解决:
Code:
result.erase(std::remove(result.begin(), result.end(), '\n'), result.end());
result.erase(std::remove(result.begin(), result.end(), '\n'), result.end());

密码设这么长还发现了这个 bug,给你 +1。

已上传到 SVN,rev 110。

英文原文

Quote from: lachesis on July 25, 2010, 07:52:35 PM(https://bitcointalk.org/index.php?topic=461.msg5738#msg5738)
I found what appears to be a bug: with a long enough username and password combination, the base64 encoder in bitcoind produces authorization headers that look like this:
Code:
...
Authorization: Basic YWJiYWJiYWFiYmE6aGVsbG93b3JsZGhlbGxvd29ybGRoZWxsb3dvcmxkaGVsbG93
b3JsZGhlbGxvd29ybGRoZWxsb3dvcmxk

It inserts a newline every 64 characters, which obviously breaks the Authorization header, so commands like "bitcoin getinfo" fail. The server still works fine with properly behaving clients.

This can be solved by removing the newlines (and maybe '
's) from result at the end of the Base64Encode function:
Code:
result.erase(std::remove(result.begin(), result.end(), '
'), result.end());
result.erase(std::remove(result.begin(), result.end(), '
'), result.end());

+1 to you for having such a long password that you found this bug.

Uploaded to SVN as rev 110.