Skip to content
Closed
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
50 changes: 46 additions & 4 deletions src/crypto/key_validator/key_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,57 @@ namespace libp2p::crypto::validator {

outcome::result<void> KeyValidatorImpl::validateEcdsa(
const PrivateKey &key) const {
// TODO(xDimon): Check if it possible to validate ECDSA key by some way.
// issue: https://github.com/libp2p/cpp-libp2p/issues/103
// Basic ECDSA private key validation
// ECDSA private keys are typically 32 bytes for P-256, 48 bytes for P-384, 66 bytes for P-521
if (key.data.empty()) {
return KeyValidatorError::INVALID_PRIVATE_KEY;
}

// Check for reasonable key sizes (32-66 bytes covers most common curves)
if (key.data.size() < 32 || key.data.size() > 66) {
return KeyValidatorError::WRONG_PRIVATE_KEY_SIZE;
}

// Check that the key is not all zeros (invalid private key)
bool all_zeros = true;
for (const auto& byte : key.data) {
if (byte != 0) {
all_zeros = false;
break;
}
}
if (all_zeros) {
return KeyValidatorError::INVALID_PRIVATE_KEY;
}

return outcome::success();
}

outcome::result<void> KeyValidatorImpl::validateEcdsa(
const PublicKey &key) const {
// TODO(xDimon): Check if it possible to validate ECDSA key by some way.
// issue: https://github.com/libp2p/cpp-libp2p/issues/103
// Basic ECDSA public key validation
if (key.data.empty()) {
return KeyValidatorError::INVALID_PUBLIC_KEY;
}

// ECDSA public keys are typically 64 bytes (uncompressed) or 33/49/67 bytes (compressed)
// for P-256/P-384/P-521 respectively
if (key.data.size() < 33 || key.data.size() > 133) {
return KeyValidatorError::WRONG_PUBLIC_KEY_SIZE;
}

// Check that the key is not all zeros (invalid public key)
bool all_zeros = true;
for (const auto& byte : key.data) {
if (byte != 0) {
all_zeros = false;
break;
}
}
if (all_zeros) {
return KeyValidatorError::INVALID_PUBLIC_KEY;
}

return outcome::success();
}

Expand Down
6 changes: 3 additions & 3 deletions src/storage/sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ namespace libp2p::storage {
}
}

int SQLite::getErrorCode() {
int SQLite::getErrorCode() const {
return sqlite3_extended_errcode(db_.connection().get());
}

std::string SQLite::getErrorMessage() {
int ec{getErrorCode()};
std::string SQLite::getErrorMessage() const {
const int ec{getErrorCode()};
return (0 == ec) ? std::string()
: std::string(sqlite3_errstr(ec)) + ": "
+ sqlite3_errmsg(db_.connection().get());
Expand Down
Loading