Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit cfab084

Browse files
committed
use fallback for older versions of boost for TLS 1.2 support
1 parent 6192c13 commit cfab084

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ set(BOOST_COMPONENTS system thread filesystem date_time)
1111
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
1212
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
1313
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex)
14-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_REGEX")
14+
message("legacy GCC detected: boost regex")
15+
add_definitions(-DUSE_BOOST_REGEX)
1516
endif()
1617
endif()
1718
find_package(Boost 1.53.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
19+
if(Boost_MINOR_VERSION LESS 58)
20+
message("legacy boost detected: using TLS 1.2 workaround")
21+
add_definitions(-DBOOST_TLS12_FALLBACK)
22+
endif()
1823
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
1924

2025
if(APPLE)

client_https.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ namespace SimpleWeb {
1313
Client(const std::string& server_port_path, bool verify_certificate=true,
1414
const std::string& cert_file=std::string(), const std::string& private_key_file=std::string(),
1515
const std::string& verify_file=std::string()) :
16-
ClientBase<HTTPS>::ClientBase(server_port_path, 443), context(boost::asio::ssl::context::tlsv12) {
16+
#ifdef BOOST_TLS12_FALLBACK
17+
ClientBase<HTTPS>::ClientBase(server_port_path, 443), context(boost::asio::ssl::context::sslv23) {
18+
long disallow_ssl_flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1;
19+
context.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | disallow_ssl_flags);
20+
#else
21+
ClientBase<HTTPS>::ClientBase(server_port_path, 443), context(boost::asio::ssl::context::tlsv12) {
22+
#endif
1723
if(cert_file.size()>0 && private_key_file.size()>0) {
1824
context.use_certificate_chain_file(cert_file);
1925
context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);

server_https.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ namespace SimpleWeb {
2525
}
2626

2727
Server(const std::string& cert_file, const std::string& private_key_file, const std::string& verify_file=std::string()):
28-
ServerBase<HTTPS>::ServerBase(443), context(boost::asio::ssl::context::tlsv12) {
28+
#ifdef BOOST_TLS12_FALLBACK
29+
ServerBase<HTTPS>::ServerBase(443), context(boost::asio::ssl::context::sslv23) {
30+
long disallow_ssl_flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1;
31+
context.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2 | disallow_ssl_flags);
32+
#else
33+
ServerBase<HTTPS>::ServerBase(443), context(boost::asio::ssl::context::tlsv12) {
34+
#endif
2935
context.use_certificate_chain_file(cert_file);
3036
context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem);
3137

0 commit comments

Comments
 (0)