diff --git a/CMakeLists.txt b/CMakeLists.txt index 049581b6..d47e56c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,16 +120,22 @@ option(USE_TLS "Enable TLS support" FALSE) if (USE_TLS) option(USE_MBED_TLS "Use Mbed TLS" OFF) option(USE_OPEN_SSL "Use OpenSSL" OFF) + option(USE_SECURE_TRANSPORT "Use Secure Transport" OFF) # default to mbedtls on windows if nothing is configured if (WIN32 AND NOT USE_OPEN_SSL AND NOT USE_MBED_TLS) option(USE_MBED_TLS "Use Mbed TLS" ON) endif() + # default to securetranport on windows if nothing is configured + if (APPLE AND NOT USE_OPEN_SSL AND NOT USE_MBED_TLS) + option(USE_SECURE_TRANSPORT "Use Secure Transport" ON) + endif() + if (USE_MBED_TLS) list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketMbedTLS.h) list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketMbedTLS.cpp) - elseif (APPLE AND NOT USE_OPEN_SSL) + elseif (USE_SECURE_TRANSPORT) list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketAppleSSL.h) list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp) else() @@ -150,6 +156,8 @@ if (USE_TLS) target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_MBED_TLS) elseif (USE_OPEN_SSL) target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_OPEN_SSL) + elseif (USE_SECURE_TRANSPORT) + target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_SECURE_TRANSPORT) endif() endif() diff --git a/ixwebsocket/IXSelectInterruptEventFd.cpp b/ixwebsocket/IXSelectInterruptEventFd.cpp deleted file mode 100644 index 786dea7f..00000000 --- a/ixwebsocket/IXSelectInterruptEventFd.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * IXSelectInterruptEventFd.cpp - * Author: Benjamin Sergeant - * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. - */ - -// -// On Linux we use eventd to wake up select. -// - -// -// Linux/Android has a special type of virtual files. select(2) will react -// when reading/writing to those files, unlike closing sockets. -// -// https://linux.die.net/man/2/eventfd -// http://www.sourcexr.com/articles/2013/10/26/lightweight-inter-process-signaling-with-eventfd -// -// eventfd was added in Linux kernel 2.x, and our oldest Android (Kitkat 4.4) -// is on Kernel 3.x -// -// cf Android/Kernel table here -// https://android.stackexchange.com/questions/51651/which-android-runs-which-linux-kernel -// -// On macOS we use UNIX pipes to wake up select. -// - -#include "IXSelectInterruptEventFd.h" - -#include -#include -#include -#include -#include // for strerror -#include -#include // for write - -namespace ix -{ - SelectInterruptEventFd::SelectInterruptEventFd() - { - _eventfd = -1; - } - - SelectInterruptEventFd::~SelectInterruptEventFd() - { - ::close(_eventfd); - } - - bool SelectInterruptEventFd::init(std::string& errorMsg) - { - // calling init twice is a programming error - assert(_eventfd == -1); - - _eventfd = eventfd(0, 0); - if (_eventfd < 0) - { - std::stringstream ss; - ss << "SelectInterruptEventFd::init() failed in eventfd()" - << " : " << strerror(errno); - errorMsg = ss.str(); - - _eventfd = -1; - return false; - } - - if (fcntl(_eventfd, F_SETFL, O_NONBLOCK) == -1) - { - std::stringstream ss; - ss << "SelectInterruptEventFd::init() failed in fcntl() call" - << " : " << strerror(errno); - errorMsg = ss.str(); - - _eventfd = -1; - return false; - } - - return true; - } - - bool SelectInterruptEventFd::notify(uint64_t value) - { - int fd = _eventfd; - - if (fd == -1) return false; - - // we should write 8 bytes for an uint64_t - return write(fd, &value, sizeof(value)) == 8; - } - - // TODO: return max uint64_t for errors ? - uint64_t SelectInterruptEventFd::read() - { - int fd = _eventfd; - - uint64_t value = 0; - ::read(fd, &value, sizeof(value)); - return value; - } - - bool SelectInterruptEventFd::clear() - { - if (_eventfd == -1) return false; - - // 0 is a special value ; select will not wake up - uint64_t value = 0; - - // we should write 8 bytes for an uint64_t - return write(_eventfd, &value, sizeof(value)) == 8; - } - - int SelectInterruptEventFd::getFd() const - { - return _eventfd; - } -} // namespace ix diff --git a/ixwebsocket/IXSelectInterruptEventFd.h b/ixwebsocket/IXSelectInterruptEventFd.h deleted file mode 100644 index 6de6ba35..00000000 --- a/ixwebsocket/IXSelectInterruptEventFd.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * IXSelectInterruptEventFd.h - * Author: Benjamin Sergeant - * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. - */ - -#pragma once - -#include "IXSelectInterrupt.h" -#include -#include - -namespace ix -{ - class SelectInterruptEventFd final : public SelectInterrupt - { - public: - SelectInterruptEventFd(); - virtual ~SelectInterruptEventFd(); - - bool init(std::string& errorMsg) final; - - bool notify(uint64_t value) final; - bool clear() final; - uint64_t read() final; - int getFd() const final; - - private: - int _eventfd; - }; -} // namespace ix diff --git a/ixwebsocket/IXSocketAppleSSL.cpp b/ixwebsocket/IXSocketAppleSSL.cpp index 522d7819..f58e0c8d 100644 --- a/ixwebsocket/IXSocketAppleSSL.cpp +++ b/ixwebsocket/IXSocketAppleSSL.cpp @@ -1,10 +1,12 @@ /* * IXSocketAppleSSL.cpp * Author: Benjamin Sergeant - * Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. * * Adapted from Satori SDK Apple SSL code. */ +#ifdef IXWEBSOCKET_USE_SECURE_TRANSPORT + #include "IXSocketAppleSSL.h" #include "IXSocketConnect.h" @@ -307,3 +309,5 @@ namespace ix } } // namespace ix + +#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT diff --git a/ixwebsocket/IXSocketAppleSSL.h b/ixwebsocket/IXSocketAppleSSL.h index 988b6d0b..a693a187 100644 --- a/ixwebsocket/IXSocketAppleSSL.h +++ b/ixwebsocket/IXSocketAppleSSL.h @@ -1,8 +1,9 @@ /* * IXSocketAppleSSL.h * Author: Benjamin Sergeant - * Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. */ +#ifdef IXWEBSOCKET_USE_SECURE_TRANSPORT #pragma once @@ -47,3 +48,5 @@ namespace ix }; } // namespace ix + +#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT diff --git a/ixwebsocket/IXSocketMbedTLS.cpp b/ixwebsocket/IXSocketMbedTLS.cpp index a3e1bc9a..5842fc4c 100644 --- a/ixwebsocket/IXSocketMbedTLS.cpp +++ b/ixwebsocket/IXSocketMbedTLS.cpp @@ -1,12 +1,13 @@ /* * IXSocketMbedTLS.cpp * Author: Benjamin Sergeant - * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. * * Some code taken from * https://github.com/rottor12/WsClientLib/blob/master/lib/src/WsClientLib.cpp * and mini_client.c example from mbedtls */ +#ifdef IXWEBSOCKET_USE_MBED_TLS #include "IXSocketMbedTLS.h" @@ -280,3 +281,5 @@ namespace ix } } // namespace ix + +#endif // IXWEBSOCKET_USE_MBED_TLS diff --git a/ixwebsocket/IXSocketMbedTLS.h b/ixwebsocket/IXSocketMbedTLS.h index ec761f63..d804ddf0 100644 --- a/ixwebsocket/IXSocketMbedTLS.h +++ b/ixwebsocket/IXSocketMbedTLS.h @@ -1,8 +1,9 @@ /* * IXSocketMbedTLS.h * Author: Benjamin Sergeant - * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. */ +#ifdef IXWEBSOCKET_USE_MBED_TLS #pragma once @@ -54,3 +55,5 @@ namespace ix }; } // namespace ix + +#endif // IXWEBSOCKET_USE_MBED_TLS diff --git a/ixwebsocket/IXSocketOpenSSL.cpp b/ixwebsocket/IXSocketOpenSSL.cpp index cf8972fe..a9ca47e9 100644 --- a/ixwebsocket/IXSocketOpenSSL.cpp +++ b/ixwebsocket/IXSocketOpenSSL.cpp @@ -1,10 +1,11 @@ /* * IXSocketOpenSSL.cpp * Author: Benjamin Sergeant, Matt DeBoer - * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. * * Adapted from Satori SDK OpenSSL code. */ +#ifdef IXWEBSOCKET_USE_OPEN_SSL #include "IXSocketOpenSSL.h" @@ -731,3 +732,5 @@ namespace ix } } // namespace ix + +#endif // IXWEBSOCKET_USE_OPEN_SSL diff --git a/ixwebsocket/IXSocketOpenSSL.h b/ixwebsocket/IXSocketOpenSSL.h index a78e2fe6..908cc22a 100644 --- a/ixwebsocket/IXSocketOpenSSL.h +++ b/ixwebsocket/IXSocketOpenSSL.h @@ -1,8 +1,9 @@ /* * IXSocketOpenSSL.h * Author: Benjamin Sergeant, Matt DeBoer - * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. + * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. */ +#ifdef IXWEBSOCKET_USE_OPEN_SSL #pragma once @@ -59,3 +60,5 @@ namespace ix }; } // namespace ix + +#endif // IXWEBSOCKET_USE_OPEN_SSL diff --git a/ixwebsocket/IXWebSocketHandshake.cpp b/ixwebsocket/IXWebSocketHandshake.cpp index 727916a4..9554be4a 100644 --- a/ixwebsocket/IXWebSocketHandshake.cpp +++ b/ixwebsocket/IXWebSocketHandshake.cpp @@ -10,7 +10,7 @@ #include "IXSocketConnect.h" #include "IXUrlParser.h" #include "IXUserAgent.h" -#include "libwshandshake.hpp" +#include "IXWebSocketHandshakeKeyGen.h" #include #include #include diff --git a/ixwebsocket/libwshandshake.hpp b/ixwebsocket/IXWebSocketHandshakeKeyGen.h similarity index 100% rename from ixwebsocket/libwshandshake.hpp rename to ixwebsocket/IXWebSocketHandshakeKeyGen.h diff --git a/ws/ws.cpp b/ws/ws.cpp index e8613770..e3d714e2 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include #include