From 49c73d1876352377f0c87e9e0db414a179006e9b Mon Sep 17 00:00:00 2001 From: Chris Punches Date: Thu, 27 Mar 2025 00:14:47 -0400 Subject: [PATCH] boilerplat to begin working on verify module -- to be developed in paralle to the install module which will load an external symbol if this module is available for simpler bootstrapping --- CMakeLists.txt | 5 +- modules/build/include/sealing.hpp | 1 - modules/verify/CMakeLists.txt | 51 ++++++ modules/verify/include/verify_commands.hpp | 84 +++++++++ modules/verify/src/verify_commands.cpp | 199 +++++++++++++++++++++ modules/verify/verify.cpp | 100 +++++++++++ 6 files changed, 438 insertions(+), 2 deletions(-) create mode 100644 modules/verify/CMakeLists.txt create mode 100644 modules/verify/include/verify_commands.hpp create mode 100644 modules/verify/src/verify_commands.cpp create mode 100644 modules/verify/verify.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ee177bf..d3208a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,8 +35,11 @@ add_subdirectory(modules/info ${CMAKE_BINARY_DIR}/build-modules/info) # add the build module by including that add_subdirectory(modules/build ${CMAKE_BINARY_DIR}/build-modules/build) +# add the verify module +add_subdirectory(modules/verify ${CMAKE_BINARY_DIR}/build-modules/verify) + # Create a custom target for building all modules -add_custom_target(modules DEPENDS info build) +add_custom_target(modules DEPENDS info build verify) # Installation rules install(TARGETS dpm DESTINATION bin) diff --git a/modules/build/include/sealing.hpp b/modules/build/include/sealing.hpp index 48975ad..0ce1a5e 100644 --- a/modules/build/include/sealing.hpp +++ b/modules/build/include/sealing.hpp @@ -65,7 +65,6 @@ int seal_final_package(const std::string &stage_dir, const std::string &output_d */ int unseal_package(const std::string& package_path, const std::string& output_dir, bool force); - /** * @brief Unseals component files in a stage directory * diff --git a/modules/verify/CMakeLists.txt b/modules/verify/CMakeLists.txt new file mode 100644 index 0000000..91a97c5 --- /dev/null +++ b/modules/verify/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.22) +project(verify_module) + +set(CMAKE_CXX_STANDARD 20) + +# Set DPM_ROOT_DIR based on whether this is a standalone build or part of the main build +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(DPM_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..") +else() + set(DPM_ROOT_DIR "${CMAKE_SOURCE_DIR}") +endif() + +# Create shared library +add_library(verify MODULE + verify.cpp + src/verify_commands.cpp +) + +# Set output properties +set_target_properties( + verify PROPERTIES + PREFIX "" + SUFFIX ".so" +) + +# Include directories +target_include_directories(verify PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${DPM_ROOT_DIR} +) + +# Standalone version - used for debugging +add_executable(verify_standalone + verify.cpp + src/verify_commands.cpp +) + +# Define the BUILD_STANDALONE macro for the standalone build +target_compile_definitions(verify_standalone PRIVATE BUILD_STANDALONE) + +# Include directories for standalone +target_include_directories(verify_standalone PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${DPM_ROOT_DIR} +) + +# Set the output name for the standalone executable +set_target_properties( + verify_standalone PROPERTIES + OUTPUT_NAME "verify_debug" +) \ No newline at end of file diff --git a/modules/verify/include/verify_commands.hpp b/modules/verify/include/verify_commands.hpp new file mode 100644 index 0000000..371bb64 --- /dev/null +++ b/modules/verify/include/verify_commands.hpp @@ -0,0 +1,84 @@ +/** + * @file verify_commands.hpp + * @brief Header file for the verify module command handlers + * + * Defines functions and enumerations for the verify module which verifies + * the integrity and signatures of installed packages. + * + * @copyright Copyright (c) 2025 SILO GROUP LLC + * @author Chris Punches + * + * Part of the Dark Horse Linux Package Manager (DPM) + */ +#pragma once + +#include +#include +#include + +/** + * @enum Command + * @brief Enumeration of supported commands for the verify module + */ +enum Command { + CMD_UNKNOWN, /**< Unknown or unsupported command */ + CMD_HELP, /**< Display help information */ + CMD_CHECKSUM, /**< Verify package checksums */ + CMD_SIGNATURE /**< Verify package signatures */ +}; + +/** + * @brief Handler for the checksum command + * + * Verifies the checksums of installed packages. + * + * @param argc Number of arguments + * @param argv Array of arguments + * @return 0 on success, non-zero on failure + */ +int cmd_checksum(int argc, char** argv); + +/** + * @brief Handler for the signature command + * + * Verifies the signatures of installed packages. + * + * @param argc Number of arguments + * @param argv Array of arguments + * @return 0 on success, non-zero on failure + */ +int cmd_signature(int argc, char** argv); + +/** + * @brief Handler for the help command + * + * Displays information about available commands in the verify module. + * + * @param argc Number of arguments + * @param argv Array of arguments + * @return 0 on success, non-zero on failure + */ +int cmd_help(int argc, char** argv); + +/** + * @brief Handler for unknown commands + * + * Displays an error message for unrecognized commands. + * + * @param command The unrecognized command string + * @param argc Number of arguments + * @param argv Array of arguments + * @return 1 to indicate failure + */ +int cmd_unknown(const char* command, int argc, char** argv); + +/** + * @brief Parses a command string into a Command enum value + * + * Converts a command string to the appropriate Command enum value + * for internal routing. + * + * @param cmd_str The command string to parse + * @return The corresponding Command enum value + */ +Command parse_command(const char* cmd_str); \ No newline at end of file diff --git a/modules/verify/src/verify_commands.cpp b/modules/verify/src/verify_commands.cpp new file mode 100644 index 0000000..a9c8282 --- /dev/null +++ b/modules/verify/src/verify_commands.cpp @@ -0,0 +1,199 @@ +/** + * @file verify_commands.cpp + * @brief Implementation of command handlers for the verify module + * + * Implements the command handlers for verifying package checksums and signatures. + * + * @copyright Copyright (c) 2025 SILO GROUP LLC + * @author Chris Punches + * + * Part of the Dark Horse Linux Package Manager (DPM) + */ + +#include "verify_commands.hpp" + +int cmd_checksum(int argc, char** argv) { + // Parse command line arguments + bool all_packages = false; + std::string package_name = ""; + bool verbose = false; + bool show_help = false; + + // Process command-line arguments + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + + if (arg == "-a" || arg == "--all") { + all_packages = true; + } else if (arg == "-p" || arg == "--package") { + if (i + 1 < argc) { + package_name = argv[i + 1]; + i++; // Skip the next argument + } + } else if (arg == "-v" || arg == "--verbose") { + verbose = true; + } else if (arg == "-h" || arg == "--help" || arg == "help") { + show_help = true; + } + } + + // If help was requested, show it and return + if (show_help) { + dpm_con(LOG_INFO, "Usage: dpm verify checksum [options]"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Verifies the checksums of installed packages."); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Options:"); + dpm_con(LOG_INFO, " -a, --all Verify all installed packages"); + dpm_con(LOG_INFO, " -p, --package NAME Verify a specific package"); + dpm_con(LOG_INFO, " -v, --verbose Enable verbose output"); + dpm_con(LOG_INFO, " -h, --help Display this help message"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Examples:"); + dpm_con(LOG_INFO, " dpm verify checksum --all"); + dpm_con(LOG_INFO, " dpm verify checksum --package=mypackage"); + return 0; + } + + // Set verbose logging if requested + if (verbose) { + dpm_set_logging_level(LOG_DEBUG); + } + + // Validate that either all packages or a specific package is specified + if (!all_packages && package_name.empty()) { + dpm_con(LOG_ERROR, "Either --all or --package must be specified"); + return 1; + } + + // Validate that both all packages and a specific package are not specified + if (all_packages && !package_name.empty()) { + dpm_con(LOG_ERROR, "Cannot specify both --all and --package"); + return 1; + } + + // Placeholder implementation + if (all_packages) { + dpm_con(LOG_INFO, "Verifying checksums for all installed packages..."); + dpm_con(LOG_INFO, "Not yet implemented."); + } else { + dpm_con(LOG_INFO, ("Verifying checksums for package: " + package_name).c_str()); + dpm_con(LOG_INFO, "Not yet implemented."); + } + + return 0; +} + +int cmd_signature(int argc, char** argv) { + // Parse command line arguments + bool all_packages = false; + std::string package_name = ""; + bool verbose = false; + bool show_help = false; + + // Process command-line arguments + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + + if (arg == "-a" || arg == "--all") { + all_packages = true; + } else if (arg == "-p" || arg == "--package") { + if (i + 1 < argc) { + package_name = argv[i + 1]; + i++; // Skip the next argument + } + } else if (arg == "-v" || arg == "--verbose") { + verbose = true; + } else if (arg == "-h" || arg == "--help" || arg == "help") { + show_help = true; + } + } + + // If help was requested, show it and return + if (show_help) { + dpm_con(LOG_INFO, "Usage: dpm verify signature [options]"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Verifies the signatures of installed packages."); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Options:"); + dpm_con(LOG_INFO, " -a, --all Verify all installed packages"); + dpm_con(LOG_INFO, " -p, --package NAME Verify a specific package"); + dpm_con(LOG_INFO, " -v, --verbose Enable verbose output"); + dpm_con(LOG_INFO, " -h, --help Display this help message"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Examples:"); + dpm_con(LOG_INFO, " dpm verify signature --all"); + dpm_con(LOG_INFO, " dpm verify signature --package=mypackage"); + return 0; + } + + // Set verbose logging if requested + if (verbose) { + dpm_set_logging_level(LOG_DEBUG); + } + + // Validate that either all packages or a specific package is specified + if (!all_packages && package_name.empty()) { + dpm_con(LOG_ERROR, "Either --all or --package must be specified"); + return 1; + } + + // Validate that both all packages and a specific package are not specified + if (all_packages && !package_name.empty()) { + dpm_con(LOG_ERROR, "Cannot specify both --all and --package"); + return 1; + } + + // Placeholder implementation + if (all_packages) { + dpm_con(LOG_INFO, "Verifying signatures for all installed packages..."); + dpm_con(LOG_INFO, "Not yet implemented."); + } else { + dpm_con(LOG_INFO, ("Verifying signatures for package: " + package_name).c_str()); + dpm_con(LOG_INFO, "Not yet implemented."); + } + + return 0; +} + +int cmd_help(int argc, char** argv) { + dpm_con(LOG_INFO, "DPM Verify Module - Verifies the integrity and signatures of installed packages."); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Available commands:"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, " checksum - Verify checksums of installed packages"); + dpm_con(LOG_INFO, " signature - Verify signatures of installed packages"); + dpm_con(LOG_INFO, " help - Display this help message"); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "Usage: dpm verify "); + dpm_con(LOG_INFO, ""); + dpm_con(LOG_INFO, "For command-specific help, use: dpm verify --help"); + + return 0; +} + +int cmd_unknown(const char* command, int argc, char** argv) { + std::string msg = "Unknown command: "; + msg += (command ? command : ""); + dpm_con(LOG_WARN, msg.c_str()); + dpm_con(LOG_WARN, "Run 'dpm verify help' for a list of available commands"); + return 1; +} + +Command parse_command(const char* cmd_str) { + if (cmd_str == nullptr || strlen(cmd_str) == 0) { + return CMD_HELP; + } + + if (strcmp(cmd_str, "help") == 0) { + return CMD_HELP; + } + else if (strcmp(cmd_str, "checksum") == 0) { + return CMD_CHECKSUM; + } + else if (strcmp(cmd_str, "signature") == 0) { + return CMD_SIGNATURE; + } + + return CMD_UNKNOWN; +} \ No newline at end of file diff --git a/modules/verify/verify.cpp b/modules/verify/verify.cpp new file mode 100644 index 0000000..e95b5f4 --- /dev/null +++ b/modules/verify/verify.cpp @@ -0,0 +1,100 @@ +/** + * @file verify.cpp + * @brief DPM verify module implementation + * + * Implements a DPM module that verifies the integrity and signatures + * of installed packages. + * + * @copyright Copyright (c) 2025 SILO GROUP LLC + * @author Chris Punches + * + * Part of the Dark Horse Linux Package Manager (DPM) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * For bug reports or contributions, please contact the dhlp-contributors + * mailing list at: https://lists.darkhorselinux.org/mailman/listinfo/dhlp-contributors + */ + +#include "include/verify_commands.hpp" + +/** + * @def MODULE_VERSION + * @brief Version information for the verify module + * + * Defines the version string that will be returned by dpm_module_get_version() + */ +#define MODULE_VERSION "0.1.0" + +/** + * @brief Returns the module version string + * + * Required implementation of the DPM module interface that provides + * version information for the verify module. + * + * @return Const char pointer to the module version string + */ +extern "C" const char* dpm_module_get_version(void) { + return MODULE_VERSION; +} + +/** + * @brief Returns the module description string + * + * Required implementation of the DPM module interface that provides + * a human-readable description of the verify module and its functionality. + * + * @return Const char pointer to the module description string + */ +extern "C" const char* dpm_get_description(void) { + return "Verifies the integrity and signatures of installed packages."; +} + +/** + * @brief Main entry point for the verify module + * + * Required implementation of the DPM module interface that serves as the + * primary execution point for the module. Parses the command and routes + * execution to the appropriate handler function. + * + * @param command The command string to execute + * @param argc Number of arguments + * @param argv Array of argument strings + * @return 0 on success, non-zero on failure + */ +extern "C" int dpm_module_execute(const char* command, int argc, char** argv) { + // Parse the command + Command cmd = parse_command(command); + + // Route to the appropriate command handler + switch (cmd) { + case CMD_CHECKSUM: + return cmd_checksum(argc, argv); + + case CMD_SIGNATURE: + return cmd_signature(argc, argv); + + case CMD_HELP: + return cmd_help(argc, argv); + + case CMD_UNKNOWN: + default: + return cmd_unknown(command, argc, argv); + } +} + +// If we're building in standalone mode, include the main function +#ifdef BUILD_STANDALONE +DPM_MODULE_STANDALONE_MAIN() +#endif // BUILD_STANDALONE \ No newline at end of file