diff --git a/ixwebsocket/IXWebSocketHandshake.cpp b/ixwebsocket/IXWebSocketHandshake.cpp index 01662939..e8e9ff25 100644 --- a/ixwebsocket/IXWebSocketHandshake.cpp +++ b/ixwebsocket/IXWebSocketHandshake.cpp @@ -242,7 +242,7 @@ namespace ix } char output[29] = {}; - WebSocketHandshakeKeyGen::generate(secWebSocketKey.c_str(), output); + WebSocketHandshakeKeyGen::generate(secWebSocketKey, output); if (std::string(output) != headers["sec-websocket-accept"]) { std::string errorMsg("Invalid Sec-WebSocket-Accept value"); @@ -348,7 +348,7 @@ namespace ix } char output[29] = {}; - WebSocketHandshakeKeyGen::generate(headers["sec-websocket-key"].c_str(), output); + WebSocketHandshakeKeyGen::generate(headers["sec-websocket-key"], output); std::stringstream ss; ss << "HTTP/1.1 101 Switching Protocols\r\n"; diff --git a/ixwebsocket/libwshandshake.hpp b/ixwebsocket/libwshandshake.hpp index 588e1b6e..fbe098b5 100644 --- a/ixwebsocket/libwshandshake.hpp +++ b/ixwebsocket/libwshandshake.hpp @@ -20,6 +20,7 @@ #include #include +#include class WebSocketHandshakeKeyGen { template @@ -100,7 +101,12 @@ class WebSocketHandshakeKeyGen { } public: - static inline void generate(const char input[24], char output[28]) { + static inline void generate(const std::string& inputStr, char output[28]) { + + char input[25] = {}; + strncpy(input, inputStr.c_str(), 25 - 1); + input[25 - 1] = '\0'; + uint32_t b_output[5] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };