-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c1bd70
commit e212840
Showing
17 changed files
with
605 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_cipher_list.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Diagnostic Client library | ||
* Copyright (C) 2024 Avijit Dey | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
#ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CIPHER_LIST_H_ | ||
#define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CIPHER_LIST_H_ | ||
|
||
#include <cstdint> | ||
|
||
namespace boost_support { | ||
namespace client { | ||
namespace tls { | ||
|
||
/** | ||
* @brief The TLS 1.2 cipher suites supported | ||
*/ | ||
enum class Tls12CipherSuites : std::uint16_t { | ||
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA25 = 49195, | ||
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 49196, | ||
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 52393, | ||
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 49187, | ||
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 49188 | ||
}; | ||
|
||
/** | ||
* @brief The TLS 1.3 cipher suites supported | ||
*/ | ||
enum class Tls13CipherSuites : std::uint16_t { | ||
TLS_AES_128_GCM_SHA256 = 4865, | ||
TLS_AES_256_GCM_SHA384 = 4866, | ||
TLS_CHACHA20_POLY1305_SHA256 = 4867, | ||
TLS_AES_128_CCM_SHA256 = 4868, | ||
TLS_AES_128_CCM_8_SHA256 = 4869 | ||
}; | ||
|
||
} // namespace tls | ||
} // namespace client | ||
} // namespace boost_support | ||
#endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CIPHER_LIST_H_ |
157 changes: 157 additions & 0 deletions
157
diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_client.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* Diagnostic Client library | ||
* Copyright (C) 2024 Avijit Dey | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
#ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CLIENT_H_ | ||
#define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CLIENT_H_ | ||
|
||
#include <functional> | ||
#include <string_view> | ||
|
||
#include "boost-support/client/tls/tls_version.h" | ||
#include "boost-support/message/tcp/tcp_message.h" | ||
#include "core/include/result.h" | ||
|
||
namespace boost_support { | ||
namespace client { | ||
namespace tls { | ||
|
||
// Forward declaration | ||
template<typename TlsVersion> | ||
class TlsClient; | ||
|
||
/** | ||
* @brief Client that manages secured tcp connection using Tls version 1.2 | ||
*/ | ||
using TlsClient12 = TlsClient<TlsVersion12>; | ||
|
||
/** | ||
* @brief Client that manages secured tcp connection using Tls version 1.3 | ||
*/ | ||
using TlsClient13 = TlsClient<TlsVersion13>; | ||
|
||
/** | ||
* @brief Client that manages secured tcp connection | ||
* @tparam TlsVersion | ||
* The tls version to be used by client for communication | ||
*/ | ||
template<typename TlsVersion> | ||
class TlsClient final { | ||
public: | ||
/** | ||
* @brief Type alias for Tcp message | ||
*/ | ||
using Message = boost_support::message::tcp::TcpMessage; | ||
|
||
/** | ||
* @brief Type alias for Tcp message pointer | ||
*/ | ||
using MessagePtr = boost_support::message::tcp::TcpMessagePtr; | ||
|
||
/** | ||
* @brief Type alias for Tcp message const pointer | ||
*/ | ||
using MessageConstPtr = boost_support::message::tcp::TcpMessageConstPtr; | ||
|
||
/** | ||
* @brief Tcp function template used for reception | ||
*/ | ||
using HandlerRead = std::function<void(MessagePtr)>; | ||
|
||
public: | ||
/** | ||
* @brief Constructs an instance of TlsClient | ||
* @param[in] local_ip_address | ||
* The local ip address | ||
* @param[in] local_port_num | ||
* The local port number | ||
* @param[in] ca_certification_path | ||
* The path to root ca certificate | ||
*/ | ||
TlsClient(std::string_view local_ip_address, std::uint16_t local_port_num, std::string_view ca_certification_path, | ||
TlsVersion tls_version) noexcept; | ||
|
||
/** | ||
* @brief Deleted copy assignment and copy constructor | ||
*/ | ||
TlsClient(const TlsClient &other) noexcept = delete; | ||
TlsClient &operator=(const TlsClient &other) noexcept = delete; | ||
|
||
/** | ||
* @brief Move assignment and move constructor | ||
*/ | ||
TlsClient(TlsClient &&other) noexcept; | ||
TlsClient &operator=(TlsClient &&other) noexcept; | ||
|
||
/** | ||
* @brief Destruct an instance of TlsClient | ||
*/ | ||
~TlsClient() noexcept; | ||
|
||
/** | ||
* @brief Initialize the client | ||
*/ | ||
void Initialize() noexcept; | ||
|
||
/** | ||
* @brief De-initialize the client | ||
*/ | ||
void DeInitialize() noexcept; | ||
|
||
/** | ||
* @brief Function to set the read handler that is invoked when message is received | ||
* @details The ownership of provided read handler is moved | ||
* @param[in] read_handler | ||
* The handler to be set | ||
*/ | ||
void SetReadHandler(HandlerRead read_handler) noexcept; | ||
|
||
/** | ||
* @brief Function to connect to remote ip address and port number | ||
* @param[in] host_ip_address | ||
* The host ip address | ||
* @param[in] host_port_num | ||
* The host port number | ||
* @return Empty void on success, otherwise error is returned | ||
*/ | ||
core_type::Result<void> ConnectToHost(std::string_view host_ip_address, std::uint16_t host_port_num); | ||
|
||
/** | ||
* @brief Function to disconnect from remote host if already connected | ||
* @return Empty void on success, otherwise error is returned | ||
*/ | ||
core_type::Result<void> DisconnectFromHost(); | ||
|
||
/** | ||
* @brief Function to get the connection status | ||
* @return True if connected, False otherwise | ||
*/ | ||
auto IsConnectedToHost() const noexcept -> bool; | ||
|
||
/** | ||
* @brief Function to transmit the provided tcp message | ||
* @param[in] tcp_message | ||
* The tcp message | ||
* @return Empty void on success, otherwise error is returned | ||
*/ | ||
core_type::Result<void> Transmit(MessageConstPtr tcp_message); | ||
|
||
private: | ||
/** | ||
* @brief Forward declaration of tls client implementation | ||
*/ | ||
class TlsClientImpl; | ||
|
||
/** | ||
* @brief Unique pointer to tls client implementation | ||
*/ | ||
std::unique_ptr<TlsClientImpl> tls_client_impl_; | ||
}; | ||
|
||
} // namespace tls | ||
} // namespace client | ||
} // namespace boost_support | ||
#endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_CLIENT_H_ |
38 changes: 38 additions & 0 deletions
38
diag-client-lib/lib/boost-support/include/boost-support/client/tls/tls_version.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Diagnostic Client library | ||
* Copyright (C) 2024 Avijit Dey | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
#ifndef DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_VERSION_H_ | ||
#define DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_VERSION_H_ | ||
|
||
#include <cstdint> | ||
#include <initializer_list> | ||
|
||
#include "boost-support/client/tls/tls_cipher_list.h" | ||
|
||
namespace boost_support { | ||
namespace client { | ||
namespace tls { | ||
|
||
template<typename CipherSuite> | ||
struct TlsVersion { | ||
std::initializer_list<CipherSuite> cipher_suites{}; | ||
}; | ||
|
||
/** | ||
* @brief Strong type for TLS version 1.2 | ||
*/ | ||
using TlsVersion12 = TlsVersion<Tls12CipherSuites>; | ||
|
||
/** | ||
* @brief Strong type for TLS version 1.3 | ||
*/ | ||
using TlsVersion13 = TlsVersion<Tls13CipherSuites>; | ||
|
||
} // namespace tls | ||
} // namespace client | ||
} // namespace boost_support | ||
#endif // DIAG_CLIENT_LIB_LIB_BOOST_SUPPORT_INCLUDE_BOOST_SUPPORT_CLIENT_TLS_TLS_VERSION_H_ |
Oops, something went wrong.