diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h --- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.h +++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.h @@ -73,10 +73,8 @@ EncryptedData encrypt(const std::string &targetUserId, const std::string &content); - std::string decrypt( - const std::string &targetUserId, - EncryptedData encryptedData, - const OlmBuffer &theirIdentityKey); + std::string + decrypt(const std::string &targetUserId, EncryptedData encryptedData); std::string signMessage(const std::string &message); static void verifySignature( diff --git a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp --- a/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp +++ b/native/cpp/CommonCpp/CryptoTools/CryptoModule.cpp @@ -341,8 +341,7 @@ std::string CryptoModule::decrypt( const std::string &targetUserId, - EncryptedData encryptedData, - const OlmBuffer &theirIdentityKey) { + EncryptedData encryptedData) { if (!this->hasSessionFor(targetUserId)) { throw std::runtime_error{"error decrypt => uninitialized session"}; } @@ -350,13 +349,6 @@ OlmBuffer tmpEncryptedMessage(encryptedData.message); - if (encryptedData.messageType == (size_t)olm::MessageType::PRE_KEY) { - if (!this->matchesInboundSession( - targetUserId, encryptedData, theirIdentityKey)) { - throw std::runtime_error{"error decrypt => matchesInboundSession"}; - } - } - size_t maxSize = ::olm_decrypt_max_plaintext_length( session, encryptedData.messageType, diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.h @@ -37,5 +37,9 @@ const std::string &callingProcessName); static bool isNotificationsSessionInitialized(const std::string &callingProcessName); + static std::string decrypt( + const std::string &data, + const size_t messageType, + const std::string &callingProcessName); }; } // namespace comm diff --git a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp --- a/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp +++ b/native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp @@ -233,4 +233,18 @@ "might be violated."); } } + +std::string NotificationsCryptoModule::decrypt( + const std::string &data, + const size_t messageType, + const std::string &callingProcessName) { + std::string decryptedData; + auto caller = [&](crypto::CryptoModule &cryptoModule) { + decryptedData = cryptoModule.decrypt( + NotificationsCryptoModule::keyserverHostedNotificationsID, + {std::vector(data.begin(), data.end()), messageType}); + }; + NotificationsCryptoModule::callCryptoModule(caller, callingProcessName); + return decryptedData; +} } // namespace comm