include all ssl backends inside special per backend macro
This commit is contained in:
parent
4b2b133c10
commit
c70f1d09a8
@ -120,16 +120,22 @@ option(USE_TLS "Enable TLS support" FALSE)
|
|||||||
if (USE_TLS)
|
if (USE_TLS)
|
||||||
option(USE_MBED_TLS "Use Mbed TLS" OFF)
|
option(USE_MBED_TLS "Use Mbed TLS" OFF)
|
||||||
option(USE_OPEN_SSL "Use OpenSSL" 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
|
# default to mbedtls on windows if nothing is configured
|
||||||
if (WIN32 AND NOT USE_OPEN_SSL AND NOT USE_MBED_TLS)
|
if (WIN32 AND NOT USE_OPEN_SSL AND NOT USE_MBED_TLS)
|
||||||
option(USE_MBED_TLS "Use Mbed TLS" ON)
|
option(USE_MBED_TLS "Use Mbed TLS" ON)
|
||||||
endif()
|
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)
|
if (USE_MBED_TLS)
|
||||||
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketMbedTLS.h)
|
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketMbedTLS.h)
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketMbedTLS.cpp)
|
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_HEADERS ixwebsocket/IXSocketAppleSSL.h)
|
||||||
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp)
|
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp)
|
||||||
else()
|
else()
|
||||||
@ -150,6 +156,8 @@ if (USE_TLS)
|
|||||||
target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_MBED_TLS)
|
target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_MBED_TLS)
|
||||||
elseif (USE_OPEN_SSL)
|
elseif (USE_OPEN_SSL)
|
||||||
target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_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()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -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 <assert.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string.h> // for strerror
|
|
||||||
#include <sys/eventfd.h>
|
|
||||||
#include <unistd.h> // 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
|
|
@ -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 <stdint.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
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
|
|
@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketAppleSSL.cpp
|
* IXSocketAppleSSL.cpp
|
||||||
* Author: Benjamin Sergeant
|
* 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.
|
* Adapted from Satori SDK Apple SSL code.
|
||||||
*/
|
*/
|
||||||
|
#ifdef IXWEBSOCKET_USE_SECURE_TRANSPORT
|
||||||
|
|
||||||
#include "IXSocketAppleSSL.h"
|
#include "IXSocketAppleSSL.h"
|
||||||
|
|
||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
@ -307,3 +309,5 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketAppleSSL.h
|
* IXSocketAppleSSL.h
|
||||||
* Author: Benjamin Sergeant
|
* 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
|
#pragma once
|
||||||
|
|
||||||
@ -47,3 +48,5 @@ namespace ix
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_SECURE_TRANSPORT
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketMbedTLS.cpp
|
* IXSocketMbedTLS.cpp
|
||||||
* Author: Benjamin Sergeant
|
* 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
|
* Some code taken from
|
||||||
* https://github.com/rottor12/WsClientLib/blob/master/lib/src/WsClientLib.cpp
|
* https://github.com/rottor12/WsClientLib/blob/master/lib/src/WsClientLib.cpp
|
||||||
* and mini_client.c example from mbedtls
|
* and mini_client.c example from mbedtls
|
||||||
*/
|
*/
|
||||||
|
#ifdef IXWEBSOCKET_USE_MBED_TLS
|
||||||
|
|
||||||
#include "IXSocketMbedTLS.h"
|
#include "IXSocketMbedTLS.h"
|
||||||
|
|
||||||
@ -280,3 +281,5 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_MBED_TLS
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketMbedTLS.h
|
* IXSocketMbedTLS.h
|
||||||
* Author: Benjamin Sergeant
|
* 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
|
#pragma once
|
||||||
|
|
||||||
@ -54,3 +55,5 @@ namespace ix
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_MBED_TLS
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketOpenSSL.cpp
|
* IXSocketOpenSSL.cpp
|
||||||
* Author: Benjamin Sergeant, Matt DeBoer
|
* 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.
|
* Adapted from Satori SDK OpenSSL code.
|
||||||
*/
|
*/
|
||||||
|
#ifdef IXWEBSOCKET_USE_OPEN_SSL
|
||||||
|
|
||||||
#include "IXSocketOpenSSL.h"
|
#include "IXSocketOpenSSL.h"
|
||||||
|
|
||||||
@ -731,3 +732,5 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_OPEN_SSL
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* IXSocketOpenSSL.h
|
* IXSocketOpenSSL.h
|
||||||
* Author: Benjamin Sergeant, Matt DeBoer
|
* 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
|
#pragma once
|
||||||
|
|
||||||
@ -59,3 +60,5 @@ namespace ix
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ix
|
} // namespace ix
|
||||||
|
|
||||||
|
#endif // IXWEBSOCKET_USE_OPEN_SSL
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "IXSocketConnect.h"
|
#include "IXSocketConnect.h"
|
||||||
#include "IXUrlParser.h"
|
#include "IXUrlParser.h"
|
||||||
#include "IXUserAgent.h"
|
#include "IXUserAgent.h"
|
||||||
#include "libwshandshake.hpp"
|
#include "IXWebSocketHandshakeKeyGen.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#include <ixwebsocket/IXNetSystem.h>
|
#include <ixwebsocket/IXNetSystem.h>
|
||||||
#include <ixwebsocket/IXSocket.h>
|
#include <ixwebsocket/IXSocket.h>
|
||||||
#include <ixwebsocket/IXUserAgent.h>
|
#include <ixwebsocket/IXUserAgent.h>
|
||||||
#include <spdlog/sinks/basic_file_sink.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user