2

I'm having an issue to understand how can I "translate" the info_hash value to a real hash. Here's an example of what I'm getting from uTorrent when it's announcing to my tracker:

{
passkey: "77ec6a27adcc441648d66d0b873550e4",
info_hash: "YNvÿ@p",
peer_id: "-UT3430-89 ",
port: "54790",
uploaded: "0",
downloaded: "491520",
left: "24928863",
corrupt: "0",
key: "A2DD5E96",
numwant: "200",
compact: "1",
no_peer_id: "1"
}

What I'm trying to understand is how do I take this strange value: "YNvÿ@p" and get the info hash as sha1 (like: 594E98760099B1CFC3BFAA4070C0CC02F6C1AA90)? I'm using PHP on my server.

Now I've read already the following statements:

info_hash

The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. Note that this is a substring of the metainfo file. The info-hash must be the hash of the encoded form as found in the .torrent file, regardless of it being invalid. This value will almost certainly have to be escaped.

But it didn't help me much to understand what's going on.

Community
  • 1
  • 1
NeoTrix
  • 124
  • 8

2 Answers2

3

OK, I found the solution for that. For some reason, $_GET in PHP (we use CodeIgniter) won't get the full binary data, it looked like it was stripping it for some reason. And what's it left is only 'YNvÿ@p', but in matter of fact there were few more unknown binary symbols that got thrown on the way.

So... what I did is to get the full URL parameters is:

$parts = parse_url($_SERVER['REQUEST_URI']);

And then, I got this value in the 'info_hash' key:

D%3b%16%01%b2%af%d7%cbT%e1%a1%d0A%20%20%f7%ce%c2%d3%bf

Afterwards I just did this action:

$info_hash = bin2hex(urldecode($parts["info_hash"]));

And got a full hash!

@Sammitch, Thank you for pointing me to correct direction on this matter!

NeoTrix
  • 124
  • 8
1
# php -r 'echo(hex2bin("594E98760099B1CFC3BFAA4070C0CC02F6C1AA90"));' | hexdump -C
00000000  59 4e 98 76 00 99 b1 cf  c3 bf aa 40 70 c0 cc 02  |YN.v.......@p...|
00000010  f6 c1 aa 90                                       |....|

Notice a pattern?

Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • OK, nice, you are right. That's when you're doing hex2bin.... So if I understand right, in order to return to hex mode I need to use the 'bin2hex' function, right? Because I tried that now, and what it returns me is: 594e76c3bf4070. Which I can see that there are few similarities from the full hash: "594E98760099B1CFC3BFAA4070C0CC02F6C1AA90", but what I need is to find a way of getting the full hash like above. – NeoTrix Oct 02 '15 at 18:53
  • oh, BTW, sorry, the JSON array I posted is incorrect. The 'info_hash' value is: "YNvÿ@p", not a full hash like presented above. I edited the JSON output in the question. – NeoTrix Oct 02 '15 at 19:03
  • @NeoTrix no, it's not "YNvÿ@p", it's full of unprintable characters. Don't copy and paste mangled output, operate on the unmolested data within PHP. – Sammitch Oct 02 '15 at 20:24