Skip to content

Commit eeef8e6

Browse files
committed
Release v1.0.5
2 parents 393009a + 6c96ca2 commit eeef8e6

File tree

14 files changed

+418
-26
lines changed

14 files changed

+418
-26
lines changed

.github/workflows/actions_build.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ on:
99

1010
env:
1111
COMMS_TAG: v5.3
12-
CC_MQTT5_TAG: v3.0.1
12+
CC_MQTT5_TAG: v3.0.2
1313
WIN_BOOST_VERSION: "1.87.0"
1414
WIN_BOOST_DIR: "C:/local/boost_1_87_0"
15+
WIN_OPENSSL_VERSION: "3.4.1"
1516

1617
jobs:
1718
build_gcc_ubuntu_22_04:
@@ -36,7 +37,7 @@ jobs:
3637
run: sudo apt-get update --fix-missing
3738

3839
- name: Install Packages
39-
run: sudo apt install libboost-all-dev mosquitto gcc-${{matrix.cc_ver}} g++-${{matrix.cc_ver}}
40+
run: sudo apt install libboost-all-dev libssl-dev mosquitto gcc-${{matrix.cc_ver}} g++-${{matrix.cc_ver}}
4041

4142
- name: Create Build Environment
4243
run: cmake -E make_directory ${{runner.workspace}}/build
@@ -103,7 +104,7 @@ jobs:
103104
run: sudo apt-get update --fix-missing
104105

105106
- name: Install Packages
106-
run: sudo apt install libboost-all-dev mosquitto gcc-${{matrix.cc_ver}} g++-${{matrix.cc_ver}}
107+
run: sudo apt install libboost-all-dev libssl-dev mosquitto gcc-${{matrix.cc_ver}} g++-${{matrix.cc_ver}}
107108

108109
- name: Create Build Environment
109110
run: cmake -E make_directory ${{runner.workspace}}/build
@@ -175,7 +176,7 @@ jobs:
175176
run: sudo apt-get update --fix-missing
176177

177178
- name: Install Packages
178-
run: sudo apt install libboost-all-dev mosquitto clang-${{matrix.cc_ver}}
179+
run: sudo apt install libboost-all-dev libssl-dev mosquitto clang-${{matrix.cc_ver}}
179180

180181
- name: Create Build Environment
181182
run: cmake -E make_directory ${{runner.workspace}}/build
@@ -243,7 +244,7 @@ jobs:
243244
run: sudo apt-get update --fix-missing
244245

245246
- name: Install Packages
246-
run: sudo apt install libboost-all-dev mosquitto clang-${{matrix.cc_ver}}
247+
run: sudo apt install libboost-all-dev libssl-dev mosquitto clang-${{matrix.cc_ver}}
247248

248249
- name: Create Build Environment
249250
run: cmake -E make_directory ${{runner.workspace}}/build
@@ -309,6 +310,12 @@ jobs:
309310
choco install boost-msvc-14.2 --version=${{env.WIN_BOOST_VERSION}}
310311
echo BOOST_DIR=${{env.WIN_BOOST_DIR}}/lib64-msvc-14.2/cmake >>%GITHUB_ENV%
311312
313+
- name: Install OpenSSL
314+
if: matrix.arch == 'x64'
315+
shell: cmd
316+
run: |
317+
choco install openssl --version=${{env.WIN_OPENSSL_VERSION}}
318+
312319
- name: Prepare externals
313320
shell: cmd
314321
run: |
@@ -369,6 +376,12 @@ jobs:
369376
choco install boost-msvc-14.3 --version=${{env.WIN_BOOST_VERSION}}
370377
echo BOOST_DIR=${{env.WIN_BOOST_DIR}}/lib64-msvc-14.3/cmake >>%GITHUB_ENV%
371378
379+
- name: Install OpenSSL
380+
if: matrix.arch == 'x64'
381+
shell: cmd
382+
run: |
383+
choco install openssl --version=${{env.WIN_OPENSSL_VERSION}}
384+
372385
- name: Prepare externals
373386
shell: cmd
374387
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project ("cc_mqtt5_libs")
55
option (CC_MQTT5_CLIENT_DEFAULT_LIB "Build and install default variant of MQTT5 client library" ON)
66
option (CC_MQTT5_CLIENT_LIB_FORCE_PIC "Force Position Independent Code (PIC) when compiling client library(ies)" OFF)
77
option (CC_MQTT5_CLIENT_APPS "Build and install client applications" ${CC_MQTT5_CLIENT_DEFAULT_LIB})
8+
option (CC_MQTT5_CLIENT_APPS_WITH_OPENSSL "Allow OpenSSL based functionality when building apps" ON)
89
option (CC_MQTT5_CLIENT_AFL_FUZZ "Build and install client AFL++ fuzzing application" OFF)
910
option (CC_MQTT5_WARN_AS_ERR "Treat warning as error" ON)
1011
option (CC_MQTT5_USE_CCACHE "Use ccache" OFF)

client/afl_fuzz/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ int main(int argc, const char* argv[])
2020
return -1;
2121
}
2222

23-
// TODO: generate input
24-
2523
cc_mqtt5_client_afl_fuzz::Logger logger;
2624
if (!logger.open(opts)) {
2725
return -1;

client/app/common/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
if (CC_MQTT5_CLIENT_APPS_WITH_OPENSSL)
2+
find_package (OpenSSL REQUIRED)
3+
endif ()
4+
15
set (src
26
AppClient.cpp
37
ProgramOptions.cpp
48
Session.cpp
59
TcpSession.cpp
10+
TlsSession.cpp
611
)
712

813
add_library(${COMMON_APPS_LIB} STATIC ${src})
914
target_link_libraries(${COMMON_APPS_LIB} PUBLIC cc::cc_mqtt5_client Boost::system Boost::program_options ${EXTRA_BOOST_TARGETS} ${CMAKE_THREAD_LIBS_INIT})
15+
16+
if (TARGET OpenSSL::SSL)
17+
target_link_libraries (${COMMON_APPS_LIB} PRIVATE OpenSSL::SSL)
18+
target_compile_definitions(${COMMON_APPS_LIB} PUBLIC CC_MQTT5_CLIENT_APP_HAS_OPENSSL)
19+
endif ()
20+
1021
target_include_directories(
1122
${COMMON_APPS_LIB} BEFORE
1223
PUBLIC

client/app/common/ProgramOptions.cpp

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ void ProgramOptions::addNetwork(std::uint16_t port)
8181
m_desc.add(opts);
8282
}
8383

84+
void ProgramOptions::addTls()
85+
{
86+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
87+
po::options_description opts("TLS Options");
88+
opts.add_options()
89+
("tls", "Enable TLS encryption")
90+
("tls-ca", po::value<std::string>()->default_value(std::string()), "Path to the CA certificate(s) file (PEM)")
91+
("tls-key", po::value<std::string>()->default_value(std::string()), "Path to the private key file (PEM)")
92+
("tls-key-pass", po::value<std::string>()->default_value(std::string()), "Private key password")
93+
("tls-cert", po::value<std::string>()->default_value(std::string()), "Path to the certificate file (PEM)")
94+
;
95+
96+
m_desc.add(opts);
97+
#endif
98+
}
99+
84100
void ProgramOptions::addPublish()
85101
{
86102
po::options_description opts("Publish Options");
@@ -143,10 +159,70 @@ bool ProgramOptions::verbose() const
143159

144160
ProgramOptions::ConnectionType ProgramOptions::connectionType() const
145161
{
146-
// Hardcoded for now
162+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
163+
if (isTls()) {
164+
return ConnectionType_Tls;
165+
}
166+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
167+
147168
return ConnectionType_Tcp;
148169
}
149170

171+
std::string ProgramOptions::networkAddress() const
172+
{
173+
return m_vm["broker"].as<std::string>();
174+
}
175+
176+
std::uint16_t ProgramOptions::networkPort() const
177+
{
178+
return m_vm["port"].as<std::uint16_t>();
179+
}
180+
181+
bool ProgramOptions::isTls() const
182+
{
183+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
184+
return m_vm.count("tls") > 0U;
185+
#else
186+
return false;
187+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
188+
}
189+
190+
std::string ProgramOptions::tlsCa() const
191+
{
192+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
193+
return m_vm["tls-ca"].as<std::string>();
194+
#else // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
195+
return std::string();
196+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
197+
}
198+
199+
std::string ProgramOptions::tlsPrivateKey() const
200+
{
201+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
202+
return m_vm["tls-key"].as<std::string>();
203+
#else // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
204+
return std::string();
205+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
206+
}
207+
208+
std::string ProgramOptions::tlsPrivateKeyPass() const
209+
{
210+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
211+
return m_vm["tls-key-pass"].as<std::string>();
212+
#else // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
213+
return std::string();
214+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
215+
}
216+
217+
std::string ProgramOptions::tlsCert() const
218+
{
219+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
220+
return m_vm["tls-cert"].as<std::string>();
221+
#else // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
222+
return std::string();
223+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
224+
}
225+
150226
std::string ProgramOptions::clientId() const
151227
{
152228
return m_vm["client-id"].as<std::string>();
@@ -257,16 +333,6 @@ ProgramOptions::StringsList ProgramOptions::willUserProps() const
257333
return stringListOpts("will-user-prop");
258334
}
259335

260-
std::string ProgramOptions::networkAddress() const
261-
{
262-
return m_vm["broker"].as<std::string>();
263-
}
264-
265-
std::uint16_t ProgramOptions::networkPort() const
266-
{
267-
return m_vm["port"].as<std::uint16_t>();
268-
}
269-
270336
std::string ProgramOptions::pubTopic() const
271337
{
272338
return m_vm["pub-topic"].as<std::string>();

client/app/common/ProgramOptions.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ class ProgramOptions
2828
enum ConnectionType
2929
{
3030
ConnectionType_Tcp,
31+
ConnectionType_Tls,
3132
ConnectionType_ValuesLimit
3233
};
3334

3435
void addCommon();
3536
void addConnect();
3637
void addNetwork(std::uint16_t port = DefaultPort);
38+
void addTls();
3739
void addPublish();
3840
void addSubscribe();
3941

@@ -46,6 +48,17 @@ class ProgramOptions
4648
bool verbose() const;
4749
ConnectionType connectionType() const;
4850

51+
// Network Options
52+
std::string networkAddress() const;
53+
std::uint16_t networkPort() const;
54+
55+
// TLS Options
56+
bool isTls() const;
57+
std::string tlsCa() const;
58+
std::string tlsPrivateKey() const;
59+
std::string tlsPrivateKeyPass() const;
60+
std::string tlsCert() const;
61+
4962
// Connect Options
5063
std::string clientId() const;
5164
std::string username() const;
@@ -70,10 +83,6 @@ class ProgramOptions
7083
unsigned willMessageFormat() const;
7184
StringsList willUserProps() const;
7285

73-
// Network Options
74-
std::string networkAddress() const;
75-
std::uint16_t networkPort() const;
76-
7786
// Publish Options
7887
std::string pubTopic() const;
7988
std::string pubMessage() const;

client/app/common/Session.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Session.h"
99

1010
#include "TcpSession.h"
11+
#include "TlsSession.h"
1112

1213
#include <iostream>
1314
#include <type_traits>
@@ -19,7 +20,12 @@ Session::Ptr Session::create(boost::asio::io_context& io, const ProgramOptions&
1920
{
2021
using CreateFunc = Ptr (*)(boost::asio::io_context&, const ProgramOptions&);
2122
static const CreateFunc Map[] = {
22-
/* ConnectionType_Tcp */ &TcpSession::create
23+
/* ConnectionType_Tcp */ &TcpSession::create,
24+
#ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
25+
/* ConnectionType_Tls */ &TlsSession::create,
26+
#else // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
27+
/* ConnectionType_Tls */ nullptr,
28+
#endif // #ifdef CC_MQTT5_CLIENT_APP_HAS_OPENSSL
2329
};
2430
static constexpr std::size_t MapSize = std::extent<decltype(Map)>::value;
2531
static_assert(MapSize == ProgramOptions::ConnectionType_ValuesLimit);
@@ -30,6 +36,9 @@ Session::Ptr Session::create(boost::asio::io_context& io, const ProgramOptions&
3036
}
3137

3238
auto func = Map[idx];
39+
if (func == nullptr) {
40+
return Ptr();
41+
}
3342
return func(io, opts);
3443
}
3544

client/app/common/TcpSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void TcpSession::doRead()
7474
}
7575

7676
if (ec) {
77-
logError() << "Failed to read data: " << ec.message();
77+
logError() << "Failed to read data: " << ec.message() << std::endl;
7878
reportNetworkDisconnected();
7979
return;
8080
}

0 commit comments

Comments
 (0)