Skip to content

Commit b7b3449

Browse files
mrodgers-witekiokartben
authored andcommitted
net: websocket: don't mask data sent from server via zvfs write
RFC6455 section 5.1 specifies that "A server MUST NOT mask any frames that it sends to the client". Implement this for websocket write calls via ZVFS, by storing in the websocket_context whether a socket is acting in the client or server role, and using this to determine if sent data should be masked. Signed-off-by: Matt Rodgers <[email protected]>
1 parent ad1657f commit b7b3449

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

subsys/net/lib/websocket/websocket.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ int websocket_connect(int sock, struct websocket_request *wreq,
276276
ctx->recv_buf.size = wreq->tmp_buf_len;
277277
ctx->sec_accept_key = sec_accept_key;
278278
ctx->http_cb = wreq->http_cb;
279+
ctx->is_client = 1;
279280

280281
mbedtls_sha1((const unsigned char *)&rnd_value, sizeof(rnd_value),
281282
sec_accept_key);
@@ -1070,9 +1071,8 @@ static int websocket_send(struct websocket_context *ctx, const uint8_t *buf,
10701071

10711072
NET_DBG("[%p] Sending %zd bytes", ctx, buf_len);
10721073

1073-
ret = websocket_send_msg(ctx->sock, buf, buf_len,
1074-
WEBSOCKET_OPCODE_DATA_TEXT,
1075-
true, true, timeout);
1074+
ret = websocket_send_msg(ctx->sock, buf, buf_len, WEBSOCKET_OPCODE_DATA_TEXT,
1075+
ctx->is_client, true, timeout);
10761076
if (ret < 0) {
10771077
errno = -ret;
10781078
return -1;
@@ -1184,6 +1184,7 @@ int websocket_register(int sock, uint8_t *recv_buf, size_t recv_buf_len)
11841184
ctx->real_sock = sock;
11851185
ctx->recv_buf.buf = recv_buf;
11861186
ctx->recv_buf.size = recv_buf_len;
1187+
ctx->is_client = 0;
11871188

11881189
fd = zvfs_reserve_fd();
11891190
if (fd < 0) {

subsys/net/lib/websocket/websocket_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ __net_socket struct websocket_context {
119119

120120
/** Did we receive all from peer during HTTP handshake */
121121
uint8_t all_received : 1;
122+
123+
/** 1 if this websocket is a client, 0 if a server */
124+
uint8_t is_client : 1;
122125
};
123126

124127
#if defined(CONFIG_NET_TEST)

0 commit comments

Comments
 (0)