webscoket 中的 mask 细节

掩码用于给客户端到服务端的帧数据加密(异或的方式,非常简单),对此RFC6455中给了一些细节如下:

The masking key is contained completely within the frame, as defined in Section 5.2 as frame-masking-key. It is used to mask the "Payload data" defined in the same section as frame-payload-data, which includes "Extension data" and "Application data".

我们看到,这个写的很清楚,掩码是给 payload  进行加密用的,这个位置会产生一个误解,就是,如果我没有 payload 的时候,是不是可以不需要掩码?比如一个 ping 帧,不带任何数据是否不需要mask?

答案是否定的!

协议中有这么一段话:

In the WebSocket Protocol, data is transmitted using a sequence of frames. To avoid confusing network intermediaries (such as intercepting proxies) and for security reasons that are further discussed in Section 10.3, a client MUST mask all frames that it sends to the server (see Section 5.3 for further details). (Note that masking is done whether or not the WebSocket Protocol is running over TLS.) The server MUST close the connection upon receiving a frame that is not masked. In this case, a server MAY send a Close frame with a status code of 1002 (protocol error) as defined in Section 7.4.1. A server MUST NOT mask any frames that it sends to the client. A client MUST close a connection if it detects a masked frame. In this case, it MAY use the status code 1002 (protocol error) as defined in Section 7.4.1. (These rules might be relaxed in a future specification.)

这段明确说了,客户端发送到服务器的所有帧都必须有掩码,而服务器发送到客户端的所有帧都必须没有掩码。如果违背了这个规则,就必须以1002错误关闭连接。

因此,你可以看到客户端发送到服务器的ping,实际上是带了掩码的,哪怕这个ping没有任何payload 数据。

相关推荐

  1. webscoket mask 细节

    2024-04-03 08:04:02       13 阅读
  2. nlptransformermask

    2024-04-03 08:04:02       42 阅读
  3. .net 实现 Webscoket 对象一些细节和疑问

    2024-04-03 08:04:02       15 阅读
  4. Djangoajax细节

    2024-04-03 08:04:02       16 阅读
  5. 自注意力机制gen_nopeek_mask()函数

    2024-04-03 08:04:02       27 阅读
  6. 细节之PyTorch torch.ones([])

    2024-04-03 08:04:02       17 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 08:04:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 08:04:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 08:04:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 08:04:02       18 阅读

热门阅读

  1. 安装transforers时报错:error: can‘t find Rust compiler

    2024-04-03 08:04:02       14 阅读
  2. HTML如何设置字体样式?

    2024-04-03 08:04:02       11 阅读
  3. 进程和线程之间的区别和联系

    2024-04-03 08:04:02       12 阅读
  4. 串口屏接口之RS232/485的理解

    2024-04-03 08:04:02       12 阅读
  5. 国外服务器租用需要考虑哪些重要信息

    2024-04-03 08:04:02       14 阅读
  6. OCRmyPDF:全能PDF光学字符识别工具及其Python集成

    2024-04-03 08:04:02       9 阅读
  7. Docker in Docker原理与实战

    2024-04-03 08:04:02       9 阅读
  8. 第四章:Minikube生命周期管理命令

    2024-04-03 08:04:02       11 阅读
  9. springboot + mybatis支持多数据库

    2024-04-03 08:04:02       12 阅读
  10. 【Python进阶(五)】——模块搜索及工作目录

    2024-04-03 08:04:02       10 阅读
  11. Quill文档(四):使用Parchment克隆Medium

    2024-04-03 08:04:02       11 阅读