nx_websocket_handshake.nx
buildroot/runtime/nx_websocket_handshake.nx
about
websocket_handshake.nx -- compute Sec-WebSocket-Accept.
RFC 6455 ยง4.2.2: the server's response to a WebSocket upgrade
request includes a Sec-WebSocket-Accept header whose value is
base64( sha1( client_key || GUID ) )
where GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" is a
literal defined in the RFC (solely to make accidental
handshake-value forgery harder -- it doesn't add security).
client_key is the value of the Sec-WebSocket-Key request
header (a 16-byte random value, base64-encoded by the client,
so 24 ASCII chars including "=" padding).
Composes sha1.nx + base64.nx. The concatenation buffer is at
most 24 + 36 = 60 bytes.
Invariants:
WH1 Caller passes the raw client key bytes (typically 24
ASCII characters); we don't decode them -- the spec
says concatenate the client-sent base64 string AS IS
with the GUID string and hash that.
WH2 Output is 28 ASCII characters (base64 of 20 bytes).
dependencies 3 imports · 4 importers
imports: nx_syscalls.nxnx_sha1.nxnx_base64.nx
imported by: nx_websocket_client_upgrade.nxnx_websocket_client_upgrade_test.nxnx_websocket_handshake_test.nxnx_websocket_upgrade.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 40 | const WS_GUID_LEN: i64 = 36 |
| 41 | const WS_SHA1_BYTES: i64 = 20 |
| 42 | const WS_ACCEPT_LEN: i64 = 28 |
functions
| 36 | func ws_guid() -> *u8 called by 1: ws_accept |
| 47 | func ws_accept(key: *u8, key_len: i64, out: *u8) -> i64 called by 4: nx_ws_client_validate_responsemainmainnx_ws_upgrade_handshake calls 4: sys_mmapws_guidsha1b64_encode |
| 74 | func main() -> i64 |