Files
glook9001andglook9001 ffe3fba8af refactor(crypto): remove standalone sha256 and migrate all callers to OpenSSL EVP (#122)
* refactor(crypto): deprecate custom sha256 in favor of OpenSSL libcrypto

- Remove standalone src/foundation/sha256.cc, include/mocktail/sha256.h, and tests/sha256_test.cc
- Remove mocktail_crypto_foundation library and sha256_test targets from CMake
- Export clean FileDigest and HashText helpers via include/update/payload_integrity.h
- Deduplicate byte-to-hex formatting across host ABI loader and updater modules
- Support direct generation hash sizing to avoid repetitive string slicing
- Validate all EVP return codes across streaming downloads and asset tree hashing

* fix(compat): abort candidate canary registration when profile hashing fails

- Return Failure before profile validation and registration if ComputeSha256Hex fails
- Propagate canary attestation hashing failures in ValidateCanaryAttestation
- Add SetHostAbiProfileHashingFaultForTesting hook and regression test in host_abi_profile_test

---------

Co-authored-by: glook9001 <310372091+glook9001@users.noreply.github.com>
2026-09-10 18:11:02 +03:00

73 lines
2.1 KiB
C++

#ifndef MOCKTAIL_UPDATE_PAYLOAD_INTEGRITY_H_
#define MOCKTAIL_UPDATE_PAYLOAD_INTEGRITY_H_
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
struct evp_md_ctx_st;
namespace mocktail::update {
class FileDigest final {
public:
FileDigest();
~FileDigest();
FileDigest(const FileDigest&) = delete;
FileDigest& operator=(const FileDigest&) = delete;
bool valid() const noexcept { return context_ != nullptr; }
bool Update(const void* data, std::size_t size);
bool Update(std::string_view bytes);
std::string FinalHex(std::size_t max_chars = 0);
private:
struct evp_md_ctx_st* context_ = nullptr;
};
std::string HashText(std::string_view text, std::string* error = nullptr);
std::string HashText(std::string_view text, std::size_t max_hex_chars,
std::string* error = nullptr);
struct PayloadMetadata {
std::string package_name;
std::string version_name;
std::uint64_t version_code = 0;
std::string build_id;
std::string library_sha256;
std::string base_apk_sha256;
std::string split_apk_sha256;
std::size_t asset_file_count = 0;
std::string asset_tree_sha256;
};
struct PayloadIntegrityResult {
PayloadMetadata metadata;
std::string payload_id;
std::string error;
explicit operator bool() const { return error.empty(); }
};
std::string HashRegularFile(const std::filesystem::path& path,
std::string* error = nullptr);
std::string HashAssetTree(const std::filesystem::path& root,
std::size_t* file_count,
std::string* error = nullptr);
PayloadIntegrityResult VerifyPreparedPayload(
const std::filesystem::path& directory);
// Reads and validates the immutable payload layout and metadata without
// rehashing the archived APKs and complete asset tree. Callers that stage or
// promote new bytes must use VerifyPreparedPayload instead.
PayloadIntegrityResult InspectPreparedPayload(
const std::filesystem::path& directory);
} // namespace mocktail::update
#endif // MOCKTAIL_UPDATE_PAYLOAD_INTEGRITY_H_