diff --git a/native/android/app/src/cpp/PlatformSpecificTools.cpp b/native/android/app/src/cpp/PlatformSpecificTools.cpp index ced2f2498..c9303d3f6 100644 --- a/native/android/app/src/cpp/PlatformSpecificTools.cpp +++ b/native/android/app/src/cpp/PlatformSpecificTools.cpp @@ -1,43 +1,58 @@ #include "jniHelpers.h" #include #include #include using namespace facebook::jni; class PlatformSpecificToolsJavaClass : public JavaClass { public: static auto constexpr kJavaDescriptor = "Lapp/comm/android/fbjni/PlatformSpecificTools;"; static comm::crypto::OlmBuffer generateSecureRandomBytes(size_t size) { static const auto cls = javaClassStatic(); static auto method = cls->getStaticMethod("generateSecureRandomBytes"); auto methodResult = method(cls, (int)size); comm::crypto::OlmBuffer result(size); std::vector bytes(size); methodResult->getRegion(0, size, bytes.data()); for (size_t i = 0; i < size; ++i) { result[i] = bytes[i]; } return result; } + + static std::string getNotificationsCryptoAccountPath() { + static const auto cls = javaClassStatic(); + static auto method = + cls->getStaticMethod("getNotificationsCryptoAccountPath"); + return method(cls)->toStdString(); + } }; namespace comm { void PlatformSpecificTools::generateSecureRandomBytes( crypto::OlmBuffer &buffer, size_t size) { NativeAndroidAccessProvider::runTask([&buffer, size]() { buffer = PlatformSpecificToolsJavaClass::generateSecureRandomBytes(size); }); } std::string PlatformSpecificTools::getDeviceOS() { return std::string{"android"}; } +std::string PlatformSpecificTools::getNotificationsCryptoAccountPath() { + std::string path; + NativeAndroidAccessProvider::runTask([&path]() { + path = PlatformSpecificToolsJavaClass::getNotificationsCryptoAccountPath(); + }); + return path; +} + } // namespace comm diff --git a/native/cpp/CommonCpp/Tools/PlatformSpecificTools.h b/native/cpp/CommonCpp/Tools/PlatformSpecificTools.h index 83d3b8567..1627e0120 100644 --- a/native/cpp/CommonCpp/Tools/PlatformSpecificTools.h +++ b/native/cpp/CommonCpp/Tools/PlatformSpecificTools.h @@ -1,13 +1,14 @@ #pragma once #include "../CryptoTools/Tools.h" namespace comm { class PlatformSpecificTools { public: static void generateSecureRandomBytes(crypto::OlmBuffer &buffer, size_t size); static std::string getDeviceOS(); + static std::string getNotificationsCryptoAccountPath(); }; } // namespace comm diff --git a/native/ios/Comm/PlatformSpecificTools.mm b/native/ios/Comm/PlatformSpecificTools.mm index a77f02b72..7a46bcfb2 100644 --- a/native/ios/Comm/PlatformSpecificTools.mm +++ b/native/ios/Comm/PlatformSpecificTools.mm @@ -1,26 +1,40 @@ #import "PlatformSpecificTools.h" #import #import namespace comm { void PlatformSpecificTools::generateSecureRandomBytes( crypto::OlmBuffer &buffer, size_t size) { uint8_t randomBytes[size]; const int status = SecRandomCopyBytes(kSecRandomDefault, size, randomBytes); if (status == errSecSuccess) { buffer = crypto::OlmBuffer(randomBytes, randomBytes + size); } else { throw std::runtime_error( "SecRandomCopyBytes failed for some reason, error code: " + std::to_string(status)); } } std::string PlatformSpecificTools::getDeviceOS() { return std::string{"ios"}; } +std::string PlatformSpecificTools::getNotificationsCryptoAccountPath() { + NSURL *groupUrl = [NSFileManager.defaultManager + containerURLForSecurityApplicationGroupIdentifier:@"group.app.comm"]; + if (groupUrl == nil) { + throw std::runtime_error( + "Failed to resolve notifications crypto account path - could not find " + "groupUrl"); + } + return std::string( + [[groupUrl + URLByAppendingPathComponent:@"comm_notifications_crypto_account"] + .path UTF8String]); +} + }; // namespace comm