rough impl of checksum verification
parent
d41c9a65e3
commit
7ebc3ebad3
|
@ -65,4 +65,4 @@ extern "C" std::string generate_file_checksum(const std::filesystem::path& file_
|
||||||
* @param input_string The string to be hashed
|
* @param input_string The string to be hashed
|
||||||
* @return String containing the hexadecimal representation of the checksum, or empty string on error
|
* @return String containing the hexadecimal representation of the checksum, or empty string on error
|
||||||
*/
|
*/
|
||||||
extern "C" std::string generate_string_checksum(const std::string& input_string);
|
extern "C" std::string generate_string_checksum(const std::string& input_string);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "verification.hpp"
|
#include "verification.hpp"
|
||||||
|
|
||||||
|
|
||||||
int verify_checksums_package(const std::string& package_path) {
|
int verify_checksums_package(const std::string& package_path) {
|
||||||
// Check if the package file exists
|
// Check if the package file exists
|
||||||
if (!std::filesystem::exists(package_path)) {
|
if (!std::filesystem::exists(package_path)) {
|
||||||
|
@ -20,11 +21,97 @@ int verify_checksums_package(const std::string& package_path) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Placeholder implementation
|
|
||||||
dpm_log(LOG_INFO, ("Verifying checksums for package: " + package_path).c_str());
|
dpm_log(LOG_INFO, ("Verifying checksums for package: " + package_path).c_str());
|
||||||
dpm_log(LOG_INFO, "Package checksum verification not yet implemented");
|
|
||||||
|
|
||||||
return 0;
|
// Load the build module to access functions
|
||||||
|
void* build_module = nullptr;
|
||||||
|
int result = check_and_load_build_module(build_module);
|
||||||
|
if (result != 0 || build_module == nullptr) {
|
||||||
|
dpm_log(LOG_ERROR, "Failed to load build module");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary directory for extraction
|
||||||
|
std::filesystem::path temp_dir = std::filesystem::temp_directory_path() / "dpm_verify_tmp";
|
||||||
|
|
||||||
|
// Remove temp directory if it already exists
|
||||||
|
if (std::filesystem::exists(temp_dir)) {
|
||||||
|
try {
|
||||||
|
std::filesystem::remove_all(temp_dir);
|
||||||
|
} catch (const std::filesystem::filesystem_error& e) {
|
||||||
|
dpm_log(LOG_ERROR, ("Failed to clean up existing temp directory: " + std::string(e.what())).c_str());
|
||||||
|
dpm_unload_module(build_module);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the temp directory
|
||||||
|
try {
|
||||||
|
std::filesystem::create_directory(temp_dir);
|
||||||
|
} catch (const std::filesystem::filesystem_error& e) {
|
||||||
|
dpm_log(LOG_ERROR, ("Failed to create temp directory: " + std::string(e.what())).c_str());
|
||||||
|
dpm_unload_module(build_module);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unseal the package to the temp directory using dpm_execute_symbol
|
||||||
|
dpm_log(LOG_INFO, "Unsealing package to temporary directory for verification...");
|
||||||
|
std::string output_dir = temp_dir.string();
|
||||||
|
bool force = true; // Force overwrite if directory exists
|
||||||
|
|
||||||
|
result = dpm_execute_symbol(build_module, "unseal_package", package_path, output_dir, force);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
dpm_log(LOG_ERROR, "Failed to unseal package for verification");
|
||||||
|
dpm_unload_module(build_module);
|
||||||
|
|
||||||
|
// Clean up temp directory
|
||||||
|
try {
|
||||||
|
std::filesystem::remove_all(temp_dir);
|
||||||
|
} catch (const std::filesystem::filesystem_error&) {
|
||||||
|
// Ignore cleanup errors
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the extracted stage directory name (package name without .dpm)
|
||||||
|
std::string package_filename = std::filesystem::path(package_path).filename().string();
|
||||||
|
std::string stage_name = package_filename;
|
||||||
|
|
||||||
|
// Remove .dpm extension if present
|
||||||
|
const std::string dpm_extension = ".dpm";
|
||||||
|
if (stage_name.ends_with(dpm_extension)) {
|
||||||
|
stage_name = stage_name.substr(0, stage_name.length() - dpm_extension.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path stage_dir = temp_dir / stage_name;
|
||||||
|
|
||||||
|
// Verify checksums in the extracted stage directory
|
||||||
|
dpm_log(LOG_INFO, ("Verifying checksums in extracted stage: " + stage_dir.string()).c_str());
|
||||||
|
|
||||||
|
// Now verify the stage directory checksums
|
||||||
|
result = verify_checksums_stage(stage_dir.string());
|
||||||
|
|
||||||
|
// Clean up temp directory
|
||||||
|
dpm_log(LOG_INFO, "Cleaning up temporary extraction directory...");
|
||||||
|
try {
|
||||||
|
std::filesystem::remove_all(temp_dir);
|
||||||
|
} catch (const std::filesystem::filesystem_error& e) {
|
||||||
|
dpm_log(LOG_WARN, ("Failed to clean up temp directory: " + std::string(e.what())).c_str());
|
||||||
|
// Continue execution - this is just a cleanup warning
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up module handle
|
||||||
|
dpm_unload_module(build_module);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
dpm_log(LOG_INFO, "Package checksum verification completed successfully");
|
||||||
|
} else {
|
||||||
|
dpm_log(LOG_ERROR, "Package checksum verification failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int verify_checksums_stage(const std::string& stage_dir) {
|
int verify_checksums_stage(const std::string& stage_dir) {
|
||||||
|
@ -53,22 +140,13 @@ int verify_checksums_stage(const std::string& stage_dir) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the unseal_stage_components function
|
// Use dpm_execute_symbol to call the unseal_stage_components function
|
||||||
typedef int (*UnsealComponentsFunc)(const std::filesystem::path&);
|
std::filesystem::path stage_path(stage_dir);
|
||||||
dlerror(); // Clear any previous error
|
result = dpm_execute_symbol(build_module, "unseal_stage_components", stage_path);
|
||||||
UnsealComponentsFunc unseal_components = (UnsealComponentsFunc)dlsym(build_module, "unseal_stage_components");
|
|
||||||
const char* dlsym_error = dlerror();
|
|
||||||
if (dlsym_error) {
|
|
||||||
dpm_log(LOG_ERROR, ("Failed to find unseal_stage_components function: " + std::string(dlsym_error)).c_str());
|
|
||||||
dlclose(build_module);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the function to unseal the components
|
|
||||||
result = unseal_components(std::filesystem::path(stage_dir));
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
dpm_log(LOG_ERROR, "Failed to unseal stage components");
|
dpm_log(LOG_ERROR, "Failed to unseal stage components");
|
||||||
dlclose(build_module);
|
dpm_unload_module(build_module);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,26 +154,26 @@ int verify_checksums_stage(const std::string& stage_dir) {
|
||||||
result = checksum_verify_package_digest(stage_dir, build_module);
|
result = checksum_verify_package_digest(stage_dir, build_module);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
dpm_log(LOG_ERROR, "Package digest verification failed");
|
dpm_log(LOG_ERROR, "Package digest verification failed");
|
||||||
dlclose(build_module);
|
dpm_unload_module(build_module);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = checksum_verify_contents_digest(stage_dir, build_module);
|
result = checksum_verify_contents_digest(stage_dir, build_module);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
dpm_log(LOG_ERROR, "Contents manifest verification failed");
|
dpm_log(LOG_ERROR, "Contents manifest verification failed");
|
||||||
dlclose(build_module);
|
dpm_unload_module(build_module);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = checksum_verify_hooks_digest(stage_dir, build_module);
|
result = checksum_verify_hooks_digest(stage_dir, build_module);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
dpm_log(LOG_ERROR, "Hooks digest verification failed");
|
dpm_log(LOG_ERROR, "Hooks digest verification failed");
|
||||||
dlclose(build_module);
|
dpm_unload_module(build_module);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
dlclose(build_module);
|
dpm_unload_module(build_module);
|
||||||
|
|
||||||
dpm_log(LOG_INFO, "All checksums verified successfully");
|
dpm_log(LOG_INFO, "All checksums verified successfully");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -115,6 +193,7 @@ int verify_signature_package(const std::string& package_path) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int verify_signature_stage(const std::string& stage_dir) {
|
int verify_signature_stage(const std::string& stage_dir) {
|
||||||
// Check if the stage directory exists
|
// Check if the stage directory exists
|
||||||
if (!std::filesystem::exists(stage_dir)) {
|
if (!std::filesystem::exists(stage_dir)) {
|
||||||
|
|
Loading…
Reference in New Issue