From 04254887692f6920589b5419fdcd17a0d2c561d1 Mon Sep 17 00:00:00 2001 From: malloc Date: Tue, 3 Apr 2018 17:03:45 -0500 Subject: [PATCH] 4 files wounded 0 dead --- server/src/main.cpp | 2 -- server/src/sock/scapesock.cpp | 10 +++++++++- server/src/sock/scapesock.hpp | 2 ++ server/src/sock/tcpsock_win.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/server/src/main.cpp b/server/src/main.cpp index d333778..941a5ca 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -34,8 +34,6 @@ int main(int argc, char **argv) { client.Handshake(); else break; - //client.Receive(&buffer, SOSC_TCP_BLOCK); - //std::cout << buffer; } server.Close(); diff --git a/server/src/sock/scapesock.cpp b/server/src/sock/scapesock.cpp index dab30f0..7efc9d7 100644 --- a/server/src/sock/scapesock.cpp +++ b/server/src/sock/scapesock.cpp @@ -53,16 +53,24 @@ int sosc::ScapeConnection::Handshake() { return SOSC_SHAKE_ERR; } + websocket_key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + websocket_key = cgc::base64_encode(cgc::sha1(websocket_key, true)); + std::stringstream stream; stream << "HTTP/1.1 101 Switching Protocols\r\n" << "Upgrade: websocket\r\n" << "Connection: Upgrade\r\n" - << "Sec-WebSock"; + << "Sec-WebSocket-Accept: " << websocket_key << "\r\n\r\n"; + this->client.Send(stream.str()); this->handshaked = true; return SOSC_SHAKE_DONE; } +sosc::ScapeConnection::~ScapeConnection() { + this->Close(); +} + /******************************/ /* END SCAPECONNECTION CODE */ /******************************/ diff --git a/server/src/sock/scapesock.hpp b/server/src/sock/scapesock.hpp index 9e6321a..7b04764 100644 --- a/server/src/sock/scapesock.hpp +++ b/server/src/sock/scapesock.hpp @@ -1,6 +1,8 @@ #ifndef SOSC_SCAPESOCK_H #define SOSC_SCAPESOCK_H +#include "../crypto/sha1.hpp" +#include "../crypto/base64.hpp" #include "packet.hpp" #include "tcpsock.hpp" diff --git a/server/src/sock/tcpsock_win.cpp b/server/src/sock/tcpsock_win.cpp index 89e41fe..dd30c99 100644 --- a/server/src/sock/tcpsock_win.cpp +++ b/server/src/sock/tcpsock_win.cpp @@ -223,9 +223,9 @@ bool sosc::TcpServer::Listen(uint16_t port) { return true; } -int sosc::TcpServer::Accept(TcpClient* client) { +bool sosc::TcpServer::Accept(TcpClient* client) { if(!this->sock_open) - return -1; + return false; SOSC_SOCK_T sock; SOSC_ADDR_T addr; @@ -234,12 +234,12 @@ int sosc::TcpServer::Accept(TcpClient* client) { sock = accept(this->sock, (struct sockaddr*)&addr, &addr_len); if(sock == INVALID_SOCKET) { this->Close(); - return -1; + return false; } client->Close(); client->Open(sock, addr, addr_len); - return 0; + return true; } void sosc::TcpServer::Close() {