websocket_handshake.nx
buildroot/runtime/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 · 0 importers
imports: syscalls.nxnx_sha1.nxbase64.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 34 | const WS_GUID_LEN: i64 = 36 |
| 35 | const WS_SHA1_BYTES: i64 = 20 |
| 36 | const WS_ACCEPT_LEN: i64 = 28 |
functions
| 30 | func ws_guid() -> *u8 {
called by 1: ws_accept |
| 41 | func ws_accept(key: *u8, key_len: i64, out: *u8) -> i64 { |
| 68 | func main() -> i64 {
calls 1: ws_accept |