update Android to use shared mosis-core library

- Remove duplicate sandbox sources from Android (now in core/)
- Update Android CMakeLists to link mosis-core
- Add OpenSSL crypto support for Android
- Update all includes to use core library headers
- Remove duplicate logger from Android (use core logger)
- Add openssl to Android vcpkg dependencies

This removes ~5,500 lines of duplicate code by sharing
the sandbox implementation between desktop and Android.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 12:14:24 +01:00
parent 33841516f1
commit 486c194f08
41 changed files with 160 additions and 5467 deletions

View File

@@ -9,6 +9,9 @@
#include <windows.h>
#include <bcrypt.h>
#pragma comment(lib, "bcrypt.lib")
#elif defined(MOSIS_HAS_OPENSSL)
#include <openssl/evp.h>
#include <openssl/hmac.h>
#endif
namespace mosis {
@@ -162,9 +165,68 @@ std::string ComputeHMAC(HashAlgorithm algo, const std::string& key, const std::s
return result;
}
#elif defined(MOSIS_HAS_OPENSSL)
//=============================================================================
// HASHING (OpenSSL)
//=============================================================================
static std::string BytesToHex(const unsigned char* data, size_t len) {
std::ostringstream oss;
oss << std::hex << std::setfill('0');
for (size_t i = 0; i < len; i++) {
oss << std::setw(2) << static_cast<int>(data[i]);
}
return oss.str();
}
static const EVP_MD* GetOpenSSLAlgorithm(HashAlgorithm algo) {
switch (algo) {
case HashAlgorithm::SHA256: return EVP_sha256();
case HashAlgorithm::SHA512: return EVP_sha512();
case HashAlgorithm::SHA1: return EVP_sha1();
case HashAlgorithm::MD5: return EVP_md5();
default: return EVP_sha256();
}
}
std::string ComputeHash(HashAlgorithm algo, const std::string& data) {
const EVP_MD* md = GetOpenSSLAlgorithm(algo);
unsigned char hash[EVP_MAX_MD_SIZE];
unsigned int hash_len = 0;
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
if (!ctx) return "";
if (EVP_DigestInit_ex(ctx, md, nullptr) != 1 ||
EVP_DigestUpdate(ctx, data.data(), data.size()) != 1 ||
EVP_DigestFinal_ex(ctx, hash, &hash_len) != 1) {
EVP_MD_CTX_free(ctx);
return "";
}
EVP_MD_CTX_free(ctx);
return BytesToHex(hash, hash_len);
}
std::string ComputeHMAC(HashAlgorithm algo, const std::string& key, const std::string& data) {
const EVP_MD* md = GetOpenSSLAlgorithm(algo);
unsigned char hmac_result[EVP_MAX_MD_SIZE];
unsigned int hmac_len = 0;
unsigned char* result = HMAC(md,
key.data(), static_cast<int>(key.size()),
reinterpret_cast<const unsigned char*>(data.data()),
data.size(),
hmac_result, &hmac_len);
if (!result) return "";
return BytesToHex(hmac_result, hmac_len);
}
#else
// Stub implementations for non-Windows (would need OpenSSL or similar)
// Stub implementations when no crypto library is available
std::string ComputeHash(HashAlgorithm algo, const std::string& data) {
(void)algo;
(void)data;