From 708011ae76b626865d15c2fdc604827d11dc0196 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Fri, 29 Sep 2023 09:47:20 +0000 Subject: [PATCH] fix: should fix #714, closes out issue where length of websocket-sec-key was wrong --- src/dpp/wsclient.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dpp/wsclient.cpp b/src/dpp/wsclient.cpp index aa9c657240..de229f67e3 100644 --- a/src/dpp/wsclient.cpp +++ b/src/dpp/wsclient.cpp @@ -43,7 +43,17 @@ websocket_client::websocket_client(const std::string &hostname, const std::strin path(urlpath), data_opcode(opcode) { - key = std::to_string(time(nullptr)); + uint64_t k = (time(nullptr) * time(nullptr)); + /* A 64 bit value as hex with leading zeroes is always 16 chars. + * + * The request MUST include a header field with the name + * |Sec-WebSocket-Key|. The value of this header field MUST be a + * nonce consisting of a randomly selected 16-byte value that has + * been base64-encoded (see [Section 4 of + * [RFC4648]](https://datatracker.ietf.org/doc/html/rfc4648#section-4)). + * The nonce MUST be selected randomly for each connection. + */ + key = to_hex(k); key = base64_encode(reinterpret_cast(key.c_str()), key.length()); }