1

I'm using the following keys to calculate the correct handshake response string:
Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8
Key2: 1_ tx7X d < nw 334J702) 7]o}` 0
Key3: 54:6d:5b:4b:20:54:32:75

I've calculated Key1 and Key2's values:
Key1: 0947fa63 (hex)
Key2: 0a5510d3

However I'm not sure on what to do next, from what I can gather, you concatenate them and MD5 it, but that doesn't seem to work out i.e. MD5 hashing: 0947fa630a5510d3546d5b4b20543275

Help!

4

2 回答 2

3

这是用于创建响应哈希的 python 代码:

from hashlib import md5
import struct
....
hashed = md5(struct.pack('>II8s', num1, num2, key3)).digest()

在示例中,num1 和 num2 是 key1 和 key2 的数值。key3 是接收到的实际文本字符串(原始字节)。

struct.pack() 调用使用大端模式(用于数值)并将它们打包为每个数字的 4 个字节,然后是 8 个字节的 key3 字符串(字节)。

请参阅 python 结构模块的文档

C 版本看起来更像这样:

/* Pack it big-endian */
buf[0] = (num1 & 0xff000000) >> 24;
buf[1] = (num1 & 0xff0000) >> 16;
buf[2] = (num1 & 0xff00) >> 8;
buf[3] =  num1 & 0xff;

buf[4] = (num2 & 0xff000000) >> 24;
buf[5] = (num2 & 0xff0000) >> 16;
buf[6] = (num2 & 0xff00) >> 8;
buf[7] =  num2 & 0xff;

strncpy(buf+8, headers->key3, 8);
buf[16] = '\0';

md5_buffer(buf, 16, target);
target[16] = '\0';

md5_buffer 在glibc中。

如需进一步参考,您可以查看websockify的工作实现(上述代码来自哪里)(免责声明:我编写了 websockify)。

于 2011-01-19T20:40:42.550 回答
1

这是我的版本:

https://github.com/boothead/stargate/blob/master/stargate/handshake.py#L104

如果您使用星际之门,那么所有这些讨厌的东西都会为您完成:-)

于 2011-01-31T11:41:47.320 回答