From 94fe99bb4d3db3a587e8c78891c1ec30bfdcb9e9 Mon Sep 17 00:00:00 2001 From: Denis Fateyev Date: Thu, 30 Jul 2026 00:49:25 +0500 Subject: [PATCH 1/4] Fix -Wconversion and -Wsign-compare warnings Cast std::string::size() to int for BIO_write, and use std::streamsize for the loop comparing against istream::gcount(). --- src/Base64.cpp | 4 ++-- src/Canonicalization.cpp | 2 +- src/SignatoryOptions.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Base64.cpp b/src/Base64.cpp index d36efe4..4134e8e 100644 --- a/src/Base64.cpp +++ b/src/Base64.cpp @@ -32,7 +32,7 @@ std::string DKIM::Conversion::Base64_Decode(const std::string& data) BIO_set_flags(i, BIO_FLAGS_BASE64_NO_NL); o = BIO_new(BIO_s_mem()); l = BIO_push(i, o); - BIO_write(o, data.c_str(), data.size()); + BIO_write(o, data.c_str(), (int)data.size()); (void) BIO_flush(o); char b[1024]; @@ -52,7 +52,7 @@ std::string DKIM::Conversion::Base64_Encode(const std::string& data) o = BIO_new(BIO_s_mem()); l = BIO_push(i, o); BIO_set_flags(l, BIO_FLAGS_BASE64_NO_NL); - BIO_write(l, data.c_str(), data.size()); + BIO_write(l, data.c_str(), (int)data.size()); (void) BIO_flush(l); std::string str; diff --git a/src/Canonicalization.cpp b/src/Canonicalization.cpp index ed75e13..2dfeaf0 100644 --- a/src/Canonicalization.cpp +++ b/src/Canonicalization.cpp @@ -141,7 +141,7 @@ bool DKIM::Conversion::CanonicalizationBody(std::istream& stream, DKIM::CanonMod stream.read(buffer, sizeof buffer); std::string buf; - for (size_t i = 0; i < stream.gcount(); ++i) + for (std::streamsize i = 0; i < stream.gcount(); ++i) { if (buffer[i] == '\r') continue; diff --git a/src/SignatoryOptions.cpp b/src/SignatoryOptions.cpp index a07ef08..0eff3bd 100644 --- a/src/SignatoryOptions.cpp +++ b/src/SignatoryOptions.cpp @@ -98,7 +98,7 @@ SignatoryOptions& SignatoryOptions::SetPrivateKey(const std::string& privatekey) BIO *o = BIO_new(BIO_s_mem()); if (!o) throw DKIM::PermanentError("BIO could not be created for RSA key"); - BIO_write(o, privatekey.c_str(), privatekey.size()); + BIO_write(o, privatekey.c_str(), (int)privatekey.size()); (void) BIO_flush(o); EVP_PKEY* privateKey = PEM_read_bio_PrivateKey(o, nullptr, nullptr, nullptr); BIO_free_all(o); @@ -328,7 +328,7 @@ AdditionalSignaturesOptions& AdditionalSignaturesOptions::SetPrivateKey(const st BIO *o = BIO_new(BIO_s_mem()); if (!o) throw DKIM::PermanentError("BIO could not be created for RSA key"); - BIO_write(o, privatekey.c_str(), privatekey.size()); + BIO_write(o, privatekey.c_str(), (int)privatekey.size()); (void) BIO_flush(o); EVP_PKEY* privateKey = PEM_read_bio_PrivateKey(o, nullptr, nullptr, nullptr); BIO_free_all(o); From 79ad755a2d083c32b94f6a298f9d6ba3e415e900 Mon Sep 17 00:00:00 2001 From: Denis Fateyev Date: Thu, 30 Jul 2026 00:51:16 +0500 Subject: [PATCH 2/4] Initialize md_nid to NID_undef - Fix -Wmaybe-uninitialized occurrences - Make RSA_sign/RSA_verify fail cleanly --- src/Signatory.cpp | 2 +- src/Validatory.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Signatory.cpp b/src/Signatory.cpp index 9e59350..8ab55d5 100644 --- a/src/Signatory.cpp +++ b/src/Signatory.cpp @@ -87,7 +87,7 @@ std::string Signatory::CreateSignature(const SignatoryOptions& options) // create signature for our header std::unique_ptr> evpmdhead(EVP_MD_CTX_create(), [] (EVP_MD_CTX* p) { EVP_MD_CTX_destroy(p); }); - int md_nid; + int md_nid = NID_undef; switch (options.GetDigestAlgorithm()) { case DKIM::DKIM_A_SHA1: diff --git a/src/Validatory.cpp b/src/Validatory.cpp index 5181e58..0f7025c 100644 --- a/src/Validatory.cpp +++ b/src/Validatory.cpp @@ -190,7 +190,7 @@ void Validatory::CheckSignature(const std::shared_ptr header, // create signature for our header std::unique_ptr> evpmdhead(EVP_MD_CTX_create(), [] (EVP_MD_CTX* p) { EVP_MD_CTX_destroy(p); }); - int md_nid; + int md_nid = NID_undef; switch (sig.GetDigestAlgorithm()) { case DKIM::DKIM_A_SHA1: From 70afb0ad621e63b6499b9954d629db156dfc5eb6 Mon Sep 17 00:00:00 2001 From: Denis Fateyev Date: Thu, 30 Jul 2026 01:07:22 +0500 Subject: [PATCH 3/4] Modernize CMake rules - Set the C++ standard via CMAKE_CXX_STANDARD - Drop hardcoded /usr/local paths in favor of pkg-config results - Install the library via INSTALL(TARGETS) instead of hand-written INSTALL(FILES) rules - Link OpenSSL through imported targets - Only set CMAKE_BUILD_TYPE when not provided - Replace deprecated SUBDIRS() with ADD_SUBDIRECTORY() --- CMakeLists.txt | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e22887..c453b27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,20 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5...4.0) -SET(CMAKE_BUILD_TYPE Release) -SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wconversion") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wconversion") -INCLUDE(FindPkgConfig) -PROJECT(libdkim++) +PROJECT(libdkim++ CXX) SET(TARGET_NAME "dkim++") INCLUDE(GNUInstallDirs) +INCLUDE(FindPkgConfig) + +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE Release) +ENDIF() +SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -Wconversion") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wconversion") + +SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) +SET(CMAKE_CXX_EXTENSIONS OFF) SET(TARGET_VERSION_MAJOR 2) SET(TARGET_VERSION_MINOR 4) @@ -16,10 +23,11 @@ SET(TARGET_VERSION_PATCH 1) SET(TARGET_VERSION ${TARGET_VERSION_MAJOR}.${TARGET_VERSION_MINOR}.${TARGET_VERSION_PATCH}) SET(DKIM_RELEASE "lib${TARGET_NAME}-${TARGET_VERSION}") -LINK_DIRECTORIES(/usr/local/lib) PKG_CHECK_MODULES(LIBSODIUM REQUIRED libsodium) FIND_PACKAGE(OpenSSL REQUIRED) +LINK_DIRECTORIES(${LIBSODIUM_LIBRARY_DIRS}) + FILE(GLOB_RECURSE SOURCE_FILES src/*.cpp) ADD_LIBRARY(${TARGET_NAME} SHARED @@ -28,38 +36,32 @@ ADD_LIBRARY(${TARGET_NAME} SHARED SET_PROPERTY(TARGET ${TARGET_NAME} PROPERTY VERSION ${TARGET_VERSION}) SET_PROPERTY(TARGET ${TARGET_NAME} PROPERTY SOVERSION ${TARGET_VERSION_MAJOR}) -IF("${CMAKE_SYSTEM}" MATCHES "Linux") +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(LIBRESOLV "resolv") -ENDIF("${CMAKE_SYSTEM}" MATCHES "Linux") +ENDIF() # Try with res_init ADD_DEFINITIONS(-DHAS_RES_NINIT) -ADD_DEFINITIONS("-std=c++11") TARGET_LINK_LIBRARIES(${TARGET_NAME} - ssl - crypto + OpenSSL::SSL + OpenSSL::Crypto ${LIBSODIUM_LIBRARIES} ${LIBRESOLV} ) INCLUDE_DIRECTORIES( - ${DIRECTORY} ${CMAKE_SOURCE_DIR} - /usr/local/include/ + ${LIBSODIUM_INCLUDE_DIRS} ) ENABLE_TESTING() -SUBDIRS( - tests - tools -) +ADD_SUBDIRECTORY(tests) +ADD_SUBDIRECTORY(tools) FILE(GLOB_RECURSE files src/*.hpp) INSTALL(FILES ${files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libdkim++) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdkim++.so DESTINATION ${CMAKE_INSTALL_LIBDIR}) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdkim++.so.${TARGET_VERSION} DESTINATION ${CMAKE_INSTALL_LIBDIR}) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdkim++.so.${TARGET_VERSION_MAJOR} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libdkim++.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libdkim++.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdkim++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) @@ -69,9 +71,9 @@ SET(CPACK_GENERATOR TBZ2) SET(CPACK_PACKAGE_FILE_NAME "${DKIM_RELEASE}") SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) INSTALL(CODE " - IF(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*) - FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/+DESC\" \"libdkim++ is a lightweight and portable DKIM (RFC6376) library for *NIX\n\") - FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/+COMMENT\" \"libdkim++ is a lightweight and portable DKIM (RFC6376)\n\") + IF(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*) + FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/+DESC\" \"libdkim++ is a lightweight and portable DKIM (RFC6376) library for *NIX\n\") + FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/+COMMENT\" \"libdkim++ is a lightweight and portable DKIM (RFC6376)\n\") FILE(WRITE \"\${CMAKE_INSTALL_PREFIX}/+CONTENTS\" \"@comment PKG_FORMAT_REVISION:1.1\n\") FILE(APPEND \"\${CMAKE_INSTALL_PREFIX}/+CONTENTS\" \"@name ${DKIM_RELEASE}\n\") FILE(APPEND \"\${CMAKE_INSTALL_PREFIX}/+CONTENTS\" \"@comment ORIGIN:/dev/null\n\") @@ -80,7 +82,7 @@ INSTALL(CODE " FILE(RELATIVE_PATH file \${CMAKE_INSTALL_PREFIX} \${file}) FILE(APPEND \"\${CMAKE_INSTALL_PREFIX}/+CONTENTS\" \"\${file}\n\") ENDFOREACH() - ENDIF(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*) + ENDIF(\${CMAKE_INSTALL_PREFIX} MATCHES .*/_CPack_Packages/.*) ") INCLUDE(CPack) ENDIF (CMAKE_SYSTEM_NAME MATCHES BSD) From 8fab7e1bc8c4f71f79c7990e568a617397d6d1db Mon Sep 17 00:00:00 2001 From: Denis Fateyev Date: Thu, 30 Jul 2026 01:19:36 +0500 Subject: [PATCH 4/4] Update pkg-config file - Reference RFC6376 (which obsoleted RFC4871) in the description - Declare libssl, libcrypto and libsodium in Requires.private so that static builders get the full dependency chain --- libdkim++.pc.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdkim++.pc.cmake b/libdkim++.pc.cmake index 1d6d3a3..e1669d1 100644 --- a/libdkim++.pc.cmake +++ b/libdkim++.pc.cmake @@ -4,7 +4,8 @@ libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: libdkim++ -Description: libdkim++ is a lightweight and portable DKIM (RFC4871) +Description: libdkim++ is a lightweight and portable DKIM (RFC6376) Version: @TARGET_VERSION@ +Requires.private: libssl libcrypto libsodium Libs: -L${libdir} -ldkim++ Cflags: -I${includedir}