diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 0c3ebff0c..f423588dc 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -15,17 +15,24 @@ jobs: strategy: matrix: pattern: - - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' - - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_USE_TLS=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=OFF' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=ON' + - '-DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=ON -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_OPENSSL' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/' + - '-DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/' steps: - name: Checkout uses: actions/checkout@v2 - name: Install Dependencies run: | - brew install boost openssl + brew install boost openssl gnutls + + mkdir -p /usr/local/include/boost-asio-gnutls + git clone https://github.com/paullouisageneau/boost-asio-gnutls.git + sudo cp -R boost-asio-gnutls/include/. /usr/local/include/boost-asio-gnutls/ + rm -rf boost-asio-gnutls - name: Configure env: OPENSSL_ROOT_DIR: /usr/local/opt/openssl @@ -47,7 +54,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - pattern: [0, 1, 2, 3, 4, 5, 6, 7] + pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] steps: - name: Checkout uses: actions/checkout@v2 @@ -56,23 +63,31 @@ jobs: sudo add-apt-repository ppa:mhier/libboost-latest sudo apt-get update sudo apt-get install boost1.67 + sudo apt-get install libgnutls28-dev + + git clone https://github.com/paullouisageneau/boost-asio-gnutls.git + sudo cp -R boost-asio-gnutls/include/. /usr/local/include/boost-asio-gnutls/ + rm -rf boost-asio-gnutls - name: Configure run: | - [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON" - [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_TLS=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF" - [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_TLS=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF" + [ ${{ matrix.pattern }} == 0 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 1 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=ON -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 2 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=ON -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 3 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 4 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=ON -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=ON -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 5 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=ON -DMQTT_TEST_4=ON -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=OFF" + [ ${{ matrix.pattern }} == 6 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=ON -DMQTT_TEST_6=ON -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=OFF -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 7 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=OFF -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=ON -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=ON" + [ ${{ matrix.pattern }} == 8 ] && FLAGS="-DCMAKE_CXX_COMPILER=clang++ -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" + [ ${{ matrix.pattern }} == 9 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=ON -DMQTT_USE_STR_CHECK=ON -DMQTT_USE_LOG=OFF -DMQTT_STD_ANY=ON -DMQTT_STD_OPTIONAL=ON -DMQTT_STD_VARIANT=ON -DMQTT_STD_STRING_VIEW=ON -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" + [ ${{ matrix.pattern }} == 10 ] && FLAGS="-DCMAKE_CXX_COMPILER=g++ -DMQTT_CODECOV=ON -DMQTT_TEST_1=ON -DMQTT_TEST_2=OFF -DMQTT_TEST_3=OFF -DMQTT_TEST_4=OFF -DMQTT_TEST_5=OFF -DMQTT_TEST_6=OFF -DMQTT_TEST_7=OFF -DMQTT_BUILD_EXAMPLES=ON -DMQTT_USE_WS=OFF -DMQTT_USE_STR_CHECK=OFF -DMQTT_USE_LOG=ON -DMQTT_STD_ANY=OFF -DMQTT_STD_OPTIONAL=OFF -DMQTT_STD_VARIANT=OFF -DMQTT_STD_STRING_VIEW=OFF -DMQTT_STD_SHARED_PTR_ARRAY=OFF -DMQTT_USE_TLS=MQTT_TLS_GNUTLS -DMQTT_BOOST_ASIO_GNUTLS_INCLUDE=/usr/local/include/boost-asio-gnutls/" cmake -S ${{ github.workspace }} -B ${{ runner.temp }} ${FLAGS} -DBOOSTROOT=/usr - name: Check Header Dependencies run: | cmake --build ${{ runner.temp }} --parallel $(nproc) --clean-first --target check_deps - name: Compile with Sanitizer - if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) + if: (matrix.pattern == 1) || (matrix.pattern == 2) || (matrix.pattern == 3) || (matrix.pattern == 8) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED -fsanitize=address @@ -81,7 +96,7 @@ jobs: CXXFLAGS="${CXXFLAGS} -pedantic -DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING" cmake --build ${{ runner.temp }} --clean-first - name: Compile without Sanitizer - if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) + if: (matrix.pattern == 0) || (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 9) || (matrix.pattern == 10) env: CFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED CXXFLAGS: -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -fno-omit-frame-pointer -DBOOST_ASIO_NO_DEPRECATED @@ -94,7 +109,7 @@ jobs: run: | ctest -VV - name: Code Coverage - if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) + if: (matrix.pattern == 4) || (matrix.pattern == 5) || (matrix.pattern == 6) || (matrix.pattern == 7) || (matrix.pattern == 9) || (matrix.pattern == 10) run: | sudo apt-get install lcov # Create lcov report diff --git a/.gitignore b/.gitignore index cf25ac6db..e9d3e9d63 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ CMakeLists.txt.user* + +# Build artifacts +build/ + +# VS code settings +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f2c1a3d..8fca91425 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,20 @@ IF (POLICY CMP0074) CMAKE_POLICY(SET CMP0074 NEW) ENDIF () +SET (MQTT_TLS_OPENSSL "MQTT_TLS_OPENSSL") +SET (MQTT_TLS_GNUTLS "MQTT_TLS_GNUTLS") + IF (MQTT_USE_TLS) MESSAGE (STATUS "TLS enabled") + IF (MQTT_USE_TLS STREQUAL ${MQTT_TLS_GNUTLS}) + MESSAGE (STATUS "Using GNUTLS") + IF (MQTT_BOOST_ASIO_GNUTLS_INCLUDE STREQUAL "") + MESSAGE (FATAL_ERROR "The MQTT_BOOST_ASIO_GNUTLS_INCLUDE variable needs to be set to the path of the boost-asio-gnutls headers") + ENDIF () + ELSE () + MESSAGE (STATUS "Using OpenSSL") + SET (MQTT_USE_TLS ${MQTT_TLS_OPENSSL}) + ENDIF() ELSE () MESSAGE (STATUS "TLS disabled") ENDIF () @@ -130,9 +142,13 @@ ELSE () ENDIF () IF (MQTT_USE_TLS) - FIND_PACKAGE (OpenSSL REQUIRED) - IF (MQTT_USE_STATIC_OPENSSL) - FIND_PACKAGE (ZLIB REQUIRED) + IF (MQTT_USE_TLS STREQUAL ${MQTT_TLS_GNUTLS}) + FIND_PACKAGE (GnuTLS REQUIRED) + ELSE () + FIND_PACKAGE (OpenSSL REQUIRED) + IF (MQTT_USE_STATIC_OPENSSL) + FIND_PACKAGE (ZLIB REQUIRED) + ENDIF () ENDIF () ENDIF () diff --git a/README.md b/README.md index 4bd2b42f1..2555e166a 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ g++ -std=c++14 -Ipath_to_mqtt_cpp/include your_program.cpp -pthread additional_o |what you want|required option| |---|---| -|TLS support|`-DMQTT_USE_TLS -pthread -lssl -lcrypto`| +|TLS support with OpenSSL|`-DMQTT_USE_TLS -pthread -lssl -lcrypto`| +|TLS support with GnuTLS|`-DMQTT_USE_TLS -DMQTT_USE_GNU_TLS -pthread -lssl -lcrypto`| |Logging support|`-DMQTT_USE_LOG -DBOOST_LOG_DYN_LINK -lboost_log -lboost_filesystem -lboost_thread`| |WebSocket support|`-DMQTT_USE_WS`| diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8769abc0a..5d778bae0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,6 +28,17 @@ strategy: MQTT_TEST_5: OFF MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: ON + ExamplesGnuTls: + MQTT_USE_TLS: MQTT_TLS_GNUTLS + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: ON ExamplesWs: MQTT_USE_TLS: OFF MQTT_USE_WS: ON @@ -95,7 +106,7 @@ strategy: MQTT_TEST_6: OFF MQTT_BUILD_EXAMPLES: OFF TestGroup6: - MQTT_USE_TLS: ON + MQTT_USE_TLS: MQTT_TLS_OPENSSL MQTT_USE_WS: OFF MQTT_USE_STR_CHECK: ON MQTT_TEST_1: OFF @@ -116,6 +127,39 @@ strategy: MQTT_TEST_5: OFF MQTT_TEST_6: ON MQTT_BUILD_EXAMPLES: OFF + TestGroup8: + MQTT_USE_TLS: MQTT_TLS_GNUTLS + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: OFF + MQTT_TEST_1: ON + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: OFF + TestGroup9: + MQTT_USE_TLS: MQTT_TLS_GNUTLS + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: ON + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: OFF + MQTT_BUILD_EXAMPLES: OFF + TestGroup10: + MQTT_USE_TLS: MQTT_TLS_GNUTLS + MQTT_USE_WS: OFF + MQTT_USE_STR_CHECK: ON + MQTT_TEST_1: OFF + MQTT_TEST_2: OFF + MQTT_TEST_3: OFF + MQTT_TEST_4: OFF + MQTT_TEST_5: OFF + MQTT_TEST_6: ON + MQTT_BUILD_EXAMPLES: OFF steps: - script: | diff --git a/example/tls_both.cpp b/example/tls_both.cpp index 3e6d6183e..f4185f65a 100644 --- a/example/tls_both.cpp +++ b/example/tls_both.cpp @@ -340,12 +340,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls<>( diff --git a/example/tls_server.cpp b/example/tls_server.cpp index 839a7cc53..b02284661 100644 --- a/example/tls_server.cpp +++ b/example/tls_server.cpp @@ -68,12 +68,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, boost::asio::ssl::context::pem); - ctx.use_private_key_file(key, boost::asio::ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(cert, tls::context::pem); + ctx.use_private_key_file(key, tls::context::pem); auto s = MQTT_NS::server_tls<>( boost::asio::ip::tcp::endpoint( diff --git a/example/tls_ws_both.cpp b/example/tls_ws_both.cpp index 23e532dc9..1d72d36b1 100644 --- a/example/tls_ws_both.cpp +++ b/example/tls_ws_both.cpp @@ -339,12 +339,12 @@ int main(int argc, char** argv) { std::uint16_t port = boost::lexical_cast(argv[1]); // server - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); boost::asio::io_context iocs; auto s = MQTT_NS::server_tls_ws<>( diff --git a/example/tls_ws_server.cpp b/example/tls_ws_server.cpp index 272ba4e5f..347bf7d27 100644 --- a/example/tls_ws_server.cpp +++ b/example/tls_ws_server.cpp @@ -68,12 +68,12 @@ int main(int argc, char** argv) { std::string cert = argv[2]; std::string key = argv[3]; - boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12); + tls::context ctx(tls::context::tlsv12); ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); - ctx.use_certificate_file(cert, boost::asio::ssl::context::pem); - ctx.use_private_key_file(key, boost::asio::ssl::context::pem); + tls::context::default_workarounds | + tls::context::single_dh_use); + ctx.use_certificate_file(cert, tls::context::pem); + ctx.use_private_key_file(key, tls::context::pem); auto s = MQTT_NS::server_tls_ws<>( boost::asio::ip::tcp::endpoint( diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 73f704b6a..4cddb9a14 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -16,16 +16,18 @@ IF(MQTT_USE_STATIC_OPENSSL) TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${CMAKE_DL_LIBS} ZLIB::ZLIB>) ENDIF() -TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:OpenSSL::SSL>) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} INTERFACE $<$:${GNUTLS_LIBRARIES}>) TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} INTERFACE $ $ $ + $<$:${GNUTLS_INCLUDE_DIRS} ${MQTT_BOOST_ASIO_GNUTLS_INCLUDE}> ) -TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS>) +TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_TLS=${MQTT_USE_TLS}>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_WS>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_STR_CHECK>) TARGET_COMPILE_DEFINITIONS(${PROJECT_NAME} INTERFACE $<$:MQTT_USE_LOG>) diff --git a/include/mqtt/async_client.hpp b/include/mqtt/async_client.hpp index 210e63a56..d9f46af81 100644 --- a/include/mqtt/async_client.hpp +++ b/include/mqtt/async_client.hpp @@ -82,7 +82,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class async_client : public client { * @param port port number * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class async_client : public client { * @return async_client object. * strand is controlled by ws_endpoint, not endpoint, so async_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class async_client : public client { * @param path path string * @return async_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -374,9 +374,9 @@ make_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -389,7 +389,7 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::string port, p ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client( ioc, @@ -399,9 +399,9 @@ make_tls_async_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -414,7 +414,7 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand( ioc, @@ -426,9 +426,9 @@ make_tls_async_client_no_strand(as::io_context& ioc, std::string host, std::uint #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>>; + using async_client_t = async_client, as::io_context::strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -439,7 +439,7 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws( ioc, @@ -450,9 +450,9 @@ make_tls_async_client_ws(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>>; + using async_client_t = async_client, null_strand>>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -463,7 +463,7 @@ make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_async_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws( ioc, @@ -585,9 +585,9 @@ make_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -600,7 +600,7 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::string port ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_32( ioc, @@ -610,9 +610,9 @@ make_tls_async_client_32(as::io_context& ioc, std::string host, std::uint16_t po ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -625,7 +625,7 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::s ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_32( ioc, @@ -637,9 +637,9 @@ make_tls_async_client_no_strand_32(as::io_context& ioc, std::string host, std::u #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, as::io_context::strand>, 4>; + using async_client_t = async_client, as::io_context::strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -650,7 +650,7 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::string p ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_ws_32( ioc, @@ -661,9 +661,9 @@ make_tls_async_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using async_client_t = async_client, null_strand>, 4>; + using async_client_t = async_client, null_strand>, 4>; return std::make_shared>( async_client_t::constructor_access(), ioc, @@ -674,7 +674,7 @@ make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_async_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_async_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/client.hpp b/include/mqtt/client.hpp index d783cb453..6b87ab72e 100644 --- a/include/mqtt/client.hpp +++ b/include/mqtt/client.hpp @@ -20,10 +20,7 @@ #include #include -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - +#include #include #if defined(MQTT_USE_WS) @@ -112,7 +109,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -122,7 +119,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -135,7 +132,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -146,7 +143,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -204,7 +201,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -214,7 +211,7 @@ class client : public endpoint { * @param port port number * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -227,7 +224,7 @@ class client : public endpoint { * @return client object. * strand is controlled by ws_endpoint, not endpoint, so client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -238,7 +235,7 @@ class client : public endpoint { * @param path path string * @return client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -335,7 +332,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -344,7 +341,7 @@ class client : public endpoint { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { static_assert(has_tls>::value, "Client is required to support TLS."); return ctx_; } @@ -1017,7 +1014,7 @@ class client : public endpoint { tim_session_expiry_(ioc_) { #if defined(MQTT_USE_TLS) - ctx_.set_verify_mode(as::ssl::verify_peer); + ctx_.set_verify_mode(tls::verify_peer); #endif // defined(MQTT_USE_TLS) } @@ -1038,14 +1035,14 @@ class client : public endpoint { #if defined(MQTT_USE_TLS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } #if defined(MQTT_USE_WS) template - void setup_socket(std::shared_ptr, Strand>>& socket) { + void setup_socket(std::shared_ptr, Strand>>& socket) { socket = std::make_shared(ioc_, ctx_); base::socket_optional().emplace(socket); } @@ -1132,20 +1129,20 @@ class client : public endpoint { template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.handshake(as::ssl::stream_base::client); + socket.handshake(tls::stream_base::client); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.handshake(as::ssl::stream_base::client, ec); + socket.handshake(tls::stream_base::client, ec); if (ec) return; start_session(force_move(props), force_move(session_life_keeper)); } @@ -1154,21 +1151,21 @@ class client : public endpoint { template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper) { - socket.next_layer().handshake(as::ssl::stream_base::client); + socket.next_layer().handshake(tls::stream_base::client); socket.handshake(host_, path_); start_session(force_move(props), force_move(session_life_keeper)); } template void handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, boost::system::error_code& ec) { - socket.next_layer().handshake(as::ssl::stream_base::client, ec); + socket.next_layer().handshake(tls::stream_base::client, ec); if (ec) return; socket.handshake(host_, path_, ec); if (ec) return; @@ -1219,12 +1216,12 @@ class client : public endpoint { template void async_handshake_socket( - tcp_endpoint, Strand>& socket, + tcp_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.async_handshake( - as::ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1244,12 +1241,12 @@ class client : public endpoint { #if defined(MQTT_USE_WS) template void async_handshake_socket( - ws_endpoint, Strand>& socket, + ws_endpoint, Strand>& socket, v5::properties props, any session_life_keeper, async_handler_t func) { socket.next_layer().async_handshake( - as::ssl::stream_base::client, + tls::stream_base::client, [ this, self = this->shared_from_this(), @@ -1494,12 +1491,12 @@ class client : public endpoint { }; template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #if defined(MQTT_USE_WS) template - struct has_tls, U>>> : std::true_type { + struct has_tls, U>>> : std::true_type { }; #endif // defined(MQTT_USE_WS) @@ -1519,7 +1516,7 @@ class client : public endpoint { optional password_; bool async_pingreq_ = false; #if defined(MQTT_USE_TLS) - as::ssl::context ctx_{as::ssl::context::tlsv12}; + tls::context ctx_{tls::context::tlsv12}; #endif // defined(MQTT_USE_TLS) #if defined(MQTT_USE_WS) std::string path_; @@ -1632,9 +1629,9 @@ make_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t po #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1647,7 +1644,7 @@ make_tls_client(as::io_context& ioc, std::string host, std::string port, protoco ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client( ioc, @@ -1657,9 +1654,9 @@ make_tls_client(as::io_context& ioc, std::string host, std::uint16_t port, proto ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1672,7 +1669,7 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::string por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand( ioc, @@ -1684,9 +1681,9 @@ make_tls_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t p #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>>; + using client_t = client, as::io_context::strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1697,7 +1694,7 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::string port, std: ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws( ioc, @@ -1708,9 +1705,9 @@ make_tls_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>>; + using client_t = client, null_strand>>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1721,7 +1718,7 @@ make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws( ioc, @@ -1843,9 +1840,9 @@ make_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1858,7 +1855,7 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::string port, prot ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_32( ioc, @@ -1868,9 +1865,9 @@ make_tls_client_32(as::io_context& ioc, std::string host, std::uint16_t port, pr ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1883,7 +1880,7 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::string ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_32( ioc, @@ -1895,9 +1892,9 @@ make_tls_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_ #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, as::io_context::strand>, 4>; + using client_t = client, as::io_context::strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1908,7 +1905,7 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::string port, s ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_ws_32( ioc, @@ -1919,9 +1916,9 @@ make_tls_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using client_t = client, null_strand>, 4>; + using client_t = client, null_strand>, 4>; return std::make_shared>( client_t::constructor_access(), ioc, @@ -1932,7 +1929,7 @@ make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::stri ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/endpoint.hpp b/include/mqtt/endpoint.hpp index 108185416..12e21a1be 100644 --- a/include/mqtt/endpoint.hpp +++ b/include/mqtt/endpoint.hpp @@ -4537,13 +4537,7 @@ class endpoint : public std::enable_shared_from_this #include - -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - +#include #include #if defined(MQTT_USE_WS) @@ -212,7 +208,7 @@ template < > class server_tls { public: - using socket_t = tcp_endpoint, Strand>; + using socket_t = tcp_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -230,7 +226,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -246,7 +242,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -254,7 +250,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -262,7 +258,7 @@ class server_tls { template server_tls( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -349,7 +345,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -357,7 +353,7 @@ class server_tls { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -393,7 +389,7 @@ class server_tls { ); auto ps = socket.get(); ps->async_handshake( - as::ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { *underlying_finished = true; @@ -419,7 +415,7 @@ class server_tls { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; @@ -701,7 +697,7 @@ template < > class server_tls_ws { public: - using socket_t = ws_endpoint, Strand>; + using socket_t = ws_endpoint, Strand>; using endpoint_t = callable_overlay>; /** @@ -719,7 +715,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con, AcceptorConfig&& config) @@ -735,7 +731,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc_accept, as::io_context& ioc_con) : server_tls_ws(std::forward(ep), force_move(ctx), ioc_accept, ioc_con, [](as::ip::tcp::acceptor&) {}) {} @@ -743,7 +739,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc, AcceptorConfig&& config) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, std::forward(config)) {} @@ -751,7 +747,7 @@ class server_tls_ws { template server_tls_ws( AsioEndpoint&& ep, - as::ssl::context&& ctx, + tls::context&& ctx, as::io_context& ioc) : server_tls_ws(std::forward(ep), force_move(ctx), ioc, ioc, [](as::ip::tcp::acceptor&) {}) {} @@ -838,7 +834,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context& get_ssl_context() { + tls::context& get_ssl_context() { return ctx_; } @@ -846,7 +842,7 @@ class server_tls_ws { * @brief Get boost asio ssl context. * @return ssl context */ - as::ssl::context const& get_ssl_context() const { + tls::context const& get_ssl_context() const { return ctx_; } @@ -883,7 +879,7 @@ class server_tls_ws { auto ps = socket.get(); ps->next_layer().async_handshake( - as::ssl::stream_base::server, + tls::stream_base::server, [this, socket = force_move(socket), tim, underlying_finished] (error_code ec) mutable { if (ec) { @@ -987,7 +983,7 @@ class server_tls_ws { bool close_request_{false}; accept_handler h_accept_; error_handler h_error_; - as::ssl::context ctx_; + tls::context ctx_; protocol_version version_ = protocol_version::undetermined; std::chrono::steady_clock::duration underlying_connect_timeout_ = std::chrono::seconds(10); }; diff --git a/include/mqtt/sync_client.hpp b/include/mqtt/sync_client.hpp index 79d71485e..2cc2c4305 100644 --- a/include/mqtt/sync_client.hpp +++ b/include/mqtt/sync_client.hpp @@ -82,7 +82,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -92,7 +92,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -105,7 +105,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>>>> + friend std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -116,7 +116,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>>>> + friend std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -174,7 +174,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); /** @@ -184,7 +184,7 @@ class sync_client : public client { * @param port port number * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version); #if defined(MQTT_USE_WS) @@ -197,7 +197,7 @@ class sync_client : public client { * @return sync_client object. * strand is controlled by ws_endpoint, not endpoint, so sync_client has null_strand template argument. */ - friend std::shared_ptr, as::io_context::strand>, 4>>> + friend std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); /** @@ -208,7 +208,7 @@ class sync_client : public client { * @param path path string * @return sync_client object */ - friend std::shared_ptr, null_strand>, 4>>> + friend std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path, protocol_version version); #endif // defined(MQTT_USE_WS) #endif // defined(MQTT_USE_TLS) @@ -372,9 +372,9 @@ make_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16 #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -387,7 +387,7 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::string port, pr ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client( ioc, @@ -397,9 +397,9 @@ make_tls_sync_client(as::io_context& ioc, std::string host, std::uint16_t port, ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -412,7 +412,7 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::strin ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand( ioc, @@ -424,9 +424,9 @@ make_tls_sync_client_no_strand(as::io_context& ioc, std::string host, std::uint1 #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>>; + using sync_client_t = sync_client, as::io_context::strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -437,7 +437,7 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>>>> +inline std::shared_ptr, as::io_context::strand>>>> make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws( ioc, @@ -448,9 +448,9 @@ make_tls_sync_client_ws(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>>; + using sync_client_t = sync_client, null_strand>>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -461,7 +461,7 @@ make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>>>> +inline std::shared_ptr, null_strand>>>> make_tls_sync_client_no_strand_ws(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws( ioc, @@ -583,9 +583,9 @@ make_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uin #if defined(MQTT_USE_TLS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -598,7 +598,7 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::string port, ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_32( ioc, @@ -608,9 +608,9 @@ make_tls_sync_client_32(as::io_context& ioc, std::string host, std::uint16_t por ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::string port, protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -623,7 +623,7 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::st ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::uint16_t port, protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_32( ioc, @@ -635,9 +635,9 @@ make_tls_sync_client_no_strand_32(as::io_context& ioc, std::string host, std::ui #if defined(MQTT_USE_WS) -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, as::io_context::strand>, 4>; + using sync_client_t = sync_client, as::io_context::strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -648,7 +648,7 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::string po ); } -inline std::shared_ptr, as::io_context::strand>, 4>>> +inline std::shared_ptr, as::io_context::strand>, 4>>> make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_ws_32( ioc, @@ -659,9 +659,9 @@ make_tls_sync_client_ws_32(as::io_context& ioc, std::string host, std::uint16_t ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::string port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { - using sync_client_t = sync_client, null_strand>, 4>; + using sync_client_t = sync_client, null_strand>, 4>; return std::make_shared>( sync_client_t::constructor_access(), ioc, @@ -672,7 +672,7 @@ make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std: ); } -inline std::shared_ptr, null_strand>, 4>>> +inline std::shared_ptr, null_strand>, 4>>> make_tls_sync_client_no_strand_ws_32(as::io_context& ioc, std::string host, std::uint16_t port, std::string path = "/", protocol_version version = protocol_version::v3_1_1) { return make_tls_sync_client_no_strand_ws_32( ioc, diff --git a/include/mqtt/tcp_endpoint.hpp b/include/mqtt/tcp_endpoint.hpp index 686d831df..4c813a750 100644 --- a/include/mqtt/tcp_endpoint.hpp +++ b/include/mqtt/tcp_endpoint.hpp @@ -10,10 +10,7 @@ #include #include -#if defined(MQTT_USE_TLS) -#include -#endif // defined(MQTT_USE_TLS) - +#include #include namespace MQTT_NS { diff --git a/include/mqtt/tls_implementation.hpp b/include/mqtt/tls_implementation.hpp new file mode 100644 index 000000000..8a1671dc2 --- /dev/null +++ b/include/mqtt/tls_implementation.hpp @@ -0,0 +1,51 @@ +// Copyright Takatoshi Kondo 2018 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#if !defined(MQTT_TLS_IMPLEMENTATION_HPP) +#define MQTT_TLS_IMPLEMENTATION_HPP + +#define MQTT_TLS_OPENSSL 1 +#define MQTT_TLS_GNUTLS 2 + +#if defined(MQTT_USE_TLS) +#if MQTT_USE_TLS == 0 +#define MQTT_USE_TLS MQTT_TLS_OPENSSL +#endif // MQTT_USE_TLS == 0 +#endif // defined(MQTT_USE_TLS) + +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL +#include +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS +#include +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL + +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL +namespace tls = boost::asio::ssl; +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS +namespace tls = boost::asio::gnutls; +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL + +namespace MQTT_NS { + +inline constexpr bool is_tls_short_read(int error_val) +{ + +#if MQTT_USE_TLS == MQTT_TLS_OPENSSL +#if defined(SSL_R_SHORT_READ) + return ERR_GET_REASON(error_val) == SSL_R_SHORT_READ; +#else // defined(SSL_R_SHORT_READ) + return ERR_GET_REASON(error_val) == tls::error::stream_truncated; +#endif // defined(SSL_R_SHORT_READ) +#elif MQTT_USE_TLS == MQTT_TLS_GNUTLS + return error_val == tls::error::stream_truncated; +#endif // MQTT_USE_TLS == MQTT_TLS_OPENSSL + + return false; +} + +} // namespace MQTT_NS + +#endif // MQTT_TLS_IMPLEMENTATION_HPP diff --git a/include/mqtt_client_cpp.hpp b/include/mqtt_client_cpp.hpp index 3bd280215..32143e0af 100644 --- a/include/mqtt_client_cpp.hpp +++ b/include/mqtt_client_cpp.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/mqtt_server_cpp.hpp b/include/mqtt_server_cpp.hpp index 4c6ee6418..197c02e93 100644 --- a/include/mqtt_server_cpp.hpp +++ b/include/mqtt_server_cpp.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f161b7ada..507fbcc82 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -89,6 +89,10 @@ ENDIF () FOREACH (source_file ${check_PROGRAMS}) GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE) + + # target_compile_options(${source_file_we} PUBLIC -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion) + set(BOOST_ASIO_NO_DEPRECATED) + ADD_EXECUTABLE (${source_file_we} ${source_file}) TARGET_COMPILE_DEFINITIONS (${source_file_we} PUBLIC $,,BOOST_TEST_DYN_LINK>) TARGET_LINK_LIBRARIES ( @@ -103,7 +107,7 @@ FOREACH (source_file ${check_PROGRAMS}) IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") IF (MQTT_CODECOV) SET_PROPERTY (TARGET ${source_file_we} - APPEND_STRING PROPERTY COMPILE_FLAGS " -O0 -g --coverage -fno-inline") + APPEND_STRING PROPERTY COMPILE_FLAGS " -O0 -g --coverage -fno-inline -fno-omit-frame-pointer -Werror -g -Wall -Wextra -Wno-ignored-qualifiers -Wconversion -DBOOST_ASIO_NO_DEPRECATED") SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY LINK_FLAGS " --coverage") ENDIF () diff --git a/test/combi_test.hpp b/test/combi_test.hpp index f4c63b154..7ad5b3473 100644 --- a/test/combi_test.hpp +++ b/test/combi_test.hpp @@ -109,6 +109,7 @@ inline void do_tls_test( std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); c->get_ssl_context().load_verify_file(base + "cacert.pem"); + test( ioc, c, diff --git a/test/test_ctx_init.hpp b/test/test_ctx_init.hpp index be4a3c6c4..547a8b846 100644 --- a/test/test_ctx_init.hpp +++ b/test/test_ctx_init.hpp @@ -10,22 +10,22 @@ #if defined(MQTT_USE_TLS) #include -#include #include "test_settings.hpp" +#include struct ctx_init { - ctx_init() : ctx(boost::asio::ssl::context::tlsv12) { + ctx_init() : ctx(tls::context::tlsv12) { ctx.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::single_dh_use); + tls::context::default_workarounds | + tls::context::single_dh_use); std::string path = boost::unit_test::framework::master_test_suite().argv[0]; std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - ctx.use_certificate_file(base + "server.crt.pem", boost::asio::ssl::context::pem); - ctx.use_private_key_file(base + "server.key.pem", boost::asio::ssl::context::pem); + ctx.use_certificate_file(base + "server.crt.pem", tls::context::pem); + ctx.use_private_key_file(base + "server.key.pem", tls::context::pem); } - boost::asio::ssl::context ctx; + tls::context ctx; }; #endif // defined(MQTT_USE_TLS) diff --git a/test/underlying_timeout.cpp b/test/underlying_timeout.cpp index a953c7061..0e8b0b393 100644 --- a/test/underlying_timeout.cpp +++ b/test/underlying_timeout.cpp @@ -112,10 +112,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -178,10 +178,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - boost::beast::websocket::stream> socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + boost::beast::websocket::stream> socket(ioc, ctx); char buf; @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE( connect_tls_ws_upg ) { BOOST_TEST(!ec); socket.next_layer().async_handshake( - as::ssl::stream_base::client, + tls::stream_base::client, [&] (MQTT_NS::error_code ec) { if (ec) { @@ -261,10 +261,10 @@ BOOST_AUTO_TEST_CASE( connect_tls_ashs ) { std::size_t pos = path.find_last_of("/\\"); std::string base = (pos == std::string::npos) ? "" : path.substr(0, pos + 1); - as::ssl::context ctx {as::ssl::context::tlsv12}; + tls::context ctx {tls::context::tlsv12}; ctx.load_verify_file(base + "cacert.pem"); - ctx.set_verify_mode(as::ssl::verify_peer); - as::ssl::stream socket(ioc, ctx); + ctx.set_verify_mode(tls::verify_peer); + tls::stream socket(ioc, ctx); char buf;