WebSocket:客户端如何获取服务器 guid?
WebSocket: How does the client get the server guid?
在 RFC6455 第 7 和 8 页,您可以看到服务器如何处理客户端的 Sec-WebSocket-Key 值(连接个人 GUID,使用 SHA1 并返回 base64 编码的字符串)。
我想这是出于安全考虑。如果客户端知道服务器的 GUID,它可以进行相同的计算并将答案与其个人结果进行比较以识别服务器。
但是客户端如何知道服务器的 GUID?或者这个算法有一个完全不同的原因?
To prove that the handshake was received, the server has to take
two pieces of information and combine them to form a response. The
first piece of information comes from the |Sec-WebSocket-Key|
header field in the client handshake:
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Concretely, if as in the example above, the |Sec-WebSocket-Key|
header field had the value "dGhlIHNhbXBsZSBub25jZQ==", the server
would concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
C5AB0DC85B11". The server would then take the SHA-1 hash of this,
giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6
0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value is
then base64-encoded (see Section 4 of [RFC4648]), to give the value
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=". This value would then be echoed in
the |Sec-WebSocket-Accept| header field.
客户端不需要知道 GUID。这是一种防止代理重复使用 websocket 响应的机制。
在 RFC6455 第 7 和 8 页,您可以看到服务器如何处理客户端的 Sec-WebSocket-Key 值(连接个人 GUID,使用 SHA1 并返回 base64 编码的字符串)。
我想这是出于安全考虑。如果客户端知道服务器的 GUID,它可以进行相同的计算并将答案与其个人结果进行比较以识别服务器。
但是客户端如何知道服务器的 GUID?或者这个算法有一个完全不同的原因?
To prove that the handshake was received, the server has to take two pieces of information and combine them to form a response. The first piece of information comes from the |Sec-WebSocket-Key| header field in the client handshake:
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Concretely, if as in the example above, the |Sec-WebSocket-Key|
header field had the value "dGhlIHNhbXBsZSBub25jZQ==", the server
would concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
C5AB0DC85B11". The server would then take the SHA-1 hash of this,
giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6
0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value is
then base64-encoded (see Section 4 of [RFC4648]), to give the value
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=". This value would then be echoed in
the |Sec-WebSocket-Accept| header field.
客户端不需要知道 GUID。这是一种防止代理重复使用 websocket 响应的机制。