WebSocket key1+key2+8_byte_data != 16 字节(128 位)?

发布于 2024-10-03 01:31:39 字数 341 浏览 1 评论 0原文

我正在尝试用 Java 构建一个 websocket 服务器,但我遇到了困难...... websocket 的规范说你必须连接 key1 和 key2 中的数字,然后将额外的 8 字节数据连接到 '...形成一个128位的字符串,其MD5和为 然后由服务器用来证明它读取了握手。

示例 key1 为 155712099 示例 key2 为 173347027 示例中的 8 字节额外数据是 Tm[K T2u

'155712099173347027Tm[K T2u' 是 26 字节,而不是想象中的 16 字节(128 位)!我在这里缺少什么?

我可以“获取”有关 websocket 的所有内容,但这里只有一小部分。

I'm trying to build a websocket server in Java, but I'm having difficulty... the specification of websockets say that you have to concatenate the numbers from key1 and key2 then concatenate the extra 8 bytes of data to '...form a 128 bit string whose MD5 sum is
then used by the server to prove that it read the handshake.'

The example key1 is 155712099
The example key2 is 173347027
The example 8 bytes of extra data is Tm[K T2u

'155712099173347027Tm[K T2u' is 26 bytes not 16 bytes (128 bits) like it's suppose to be! What am I missing here?

I can 'get' everything about websockets but this little part here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凌乱心跳 2024-10-10 01:31:39

您使用 key1 和 key2 作为数字字符串而不是 32 位数字。

例如,155712099 作为十六进制 32 位数字为:0x63、0xfa、0x47、0x09 (0x947fa63)。这就是你想要的。您需要将 key1 和 key2 字符串转换为无符号整数,然后将这 4 个字节打包到目标字节数组的位置 0(对于 key1)和位置 4(对于 key2)。

将 155712099 作为数字字符串将产生一个带有十六进制值的 9 字节字符串:0x31、0x35、0x35、0x37、0x31、0x32、0x30、0x39、0x39。另一方面,您确实希望将额外的字节直接打包到从位置 8 开始的目标字节数组中。这应该会给您一个 16 字节长的目标字节数组。

请注意,握手有意将不同的数据元素操纵为不同的数据类型,以尝试阻止针对 WebSockets 服务器的不同类型的攻击。

You are using key1 and key2 as a string of digits instead of 32-bit numbers.

For example, 155712099 as a hexidecimal 32-bit number is: 0x63, 0xfa, 0x47, 0x09 (0x947fa63). That's what you want. You need to convert the key1 and key2 strings into unsigned integers and then pack those 4 bytes into position 0 (for key1) and position 4 (for key2) of your target byte array.

Taking 155712099 as a string of digits will result in a 9 byte string with hex values: 0x31, 0x35, 0x35, 0x37, 0x31, 0x32, 0x30, 0x39, 0x39. On the other hand you do want to pack the extra bytes directly into your target byte array starting at position 8. That should give you a target byte array 16 bytes long.

Note that the handshake is intentionally manipulating the different data elements as different data-types to try and thwart different types of attacks against a WebSockets server.

烙印 2024-10-10 01:31:39

如果 key1 和 key2 是 32 位整数,您可能需要将每个的表示形式连接在一起,每个表示形式为 4 个字节,而不是它们的字符串表示形式。

If key1 and key2 are 32-bit integers, you probably need to concatenate together the representations of each of those as 4 bytes each, not their string representation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文