Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
cmake_minimum_required(VERSION 3.12)

# Set CMake policies to handle compatibility with older dependencies
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
cmake_policy(SET CMP0144 NEW)
endif()

# Set policy to handle older CMake requirements in dependencies
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.5")
cmake_policy(SET CMP0000 NEW)
endif()

if (PACKAGE_MANAGER)
if(NOT PACKAGE_MANAGER MATCHES "^(hunter|vcpkg)$")
message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set")
Expand All @@ -16,10 +26,6 @@ else ()
endif ()
message(STATUS "Selected package manager: ${PACKAGE_MANAGER}")

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27")
cmake_policy(SET CMP0144 NEW)
endif()

find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
Expand Down
38 changes: 38 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@
# CMAKE_ARGS "CMAKE_VARIABLE=value"
# )

# Fix for Protobuf CMake compatibility issue with modern CMake versions
hunter_config(
Protobuf
VERSION 3.19.4-p0
CMAKE_ARGS
CMAKE_POLICY_VERSION_MINIMUM=3.5
protobuf_BUILD_TESTS=OFF
protobuf_BUILD_SHARED_LIBS=OFF
KEEP_PACKAGE_SOURCES
)

# Fix for c-ares CMake compatibility issue with modern CMake versions
hunter_config(
c-ares
VERSION 1.14.0-p0
CMAKE_ARGS
CMAKE_POLICY_VERSION_MINIMUM=3.5
KEEP_PACKAGE_SOURCES
)

# Fix for yaml-cpp CMake compatibility issue with modern CMake versions
hunter_config(
yaml-cpp
VERSION 0.6.2-0f9a586-p1
CMAKE_ARGS
CMAKE_POLICY_VERSION_MINIMUM=3.5
KEEP_PACKAGE_SOURCES
)

# Fix for Boost.DI CMake compatibility issue with modern CMake versions
hunter_config(
Boost.DI
VERSION 1.1.0-p1
CMAKE_ARGS
CMAKE_POLICY_VERSION_MINIMUM=3.5
KEEP_PACKAGE_SOURCES
)

hunter_config(
soralog
VERSION 0.2.5
Expand Down
22 changes: 11 additions & 11 deletions src/security/tls/tls_details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ namespace libp2p::security::tls_details {
constexpr size_t prefix_size = sign_prefix.size();
size_t msg_len = prefix_size + cert_pub_key.size();

uint8_t buf[msg_len]; // NOLINT
memcpy(buf, sign_prefix.data(), sign_prefix.size());
memcpy(buf + sign_prefix.size(), // NOLINT
std::vector<uint8_t> buf(msg_len);
memcpy(buf.data(), sign_prefix.data(), sign_prefix.size());
memcpy(buf.data() + sign_prefix.size(), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
cert_pub_key.data(),
cert_pub_key.size());

Expand All @@ -179,7 +179,7 @@ namespace libp2p::security::tls_details {

return crypto::ed25519::Ed25519ProviderImpl{}
// NOLINTNEXTLINE(cppcoreguidelines-narrowing-conversions)
.sign(BytesIn(buf, msg_len), pk_data)
.sign(BytesIn(buf.data(), msg_len), pk_data)
.value();
}

Expand All @@ -203,8 +203,8 @@ namespace libp2p::security::tls_details {
void assignSerial(X509 *cert) {
BIGNUM *bn = BN_new();
CLEANUP_PTR(bn, BN_free);
if (BN_pseudo_rand(bn, 64, 0, 0) == 0) {
throw std::runtime_error("BN_pseudo_rand failed");
if (BN_rand(bn, 64, 0, 0) == 0) {
throw std::runtime_error("BN_rand failed");
}

ASN1_INTEGER *rand_int = ASN1_INTEGER_new();
Expand Down Expand Up @@ -402,13 +402,13 @@ namespace libp2p::security::tls_details {
constexpr size_t prefix_size = sign_prefix.size();

size_t msg_len = prefix_size + len;
uint8_t buf[msg_len]; // NOLINT
memcpy(buf, sign_prefix.data(), prefix_size);
uint8_t *b = buf + prefix_size; // NOLINT
i2d_PUBKEY(cert_pubkey, &b);
std::vector<uint8_t> buf(msg_len);
memcpy(buf.data(), sign_prefix.data(), prefix_size);
uint8_t *buf_ptr = buf.data() + prefix_size; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
i2d_PUBKEY(cert_pubkey, &buf_ptr);

auto verify_res = crypto::ed25519::Ed25519ProviderImpl{}.verify(
BytesIn(buf, buf + msg_len), // NOLINT
BytesIn(buf.data(), buf.data() + msg_len), // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
signature,
ed25519pkey);

Expand Down
11 changes: 7 additions & 4 deletions src/transport/tcp/tcp_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ namespace libp2p::transport {
auto &[info, layers] = r.value();
auto conn = std::make_shared<TcpConnection>(*context_, layers);
auto connect =
[=,
self{shared_from_this()},
[self{shared_from_this()},
handler{std::move(handler)},
layers = std::move(layers)](
layers = std::move(layers),
conn,
address,
remoteId,
mux_config_ = mux_config_](
outcome::result<boost::asio::ip::tcp::resolver::results_type>
r) mutable {
if (not r) {
return handler(r.error());
}
conn->connect(
r.value(),
[=, handler{std::move(handler)}, layers = std::move(layers)](
[=, handler{std::move(handler)}, layers = std::move(layers), &conn, &address, &remoteId](
auto ec, auto &e) mutable {
if (ec) {
std::ignore = conn->close();
Expand Down
Loading