Page MenuHomePhabricator

D7796.diff
No OneTemporary

D7796.diff

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
@@ -63,20 +63,14 @@
size_t keyIndex = 0);
bool hasSessionFor(const std::string &targetUserId);
std::shared_ptr<Session> getSessionByUserId(const std::string &userId);
- bool matchesInboundSession(
- const std::string &targetUserId,
- EncryptedData encryptedData,
- const OlmBuffer &theirIdentityKey) const;
Persist storeAsB64(const std::string &secretKey);
void restoreFromB64(const std::string &secretKey, Persist persist);
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
@@ -238,31 +238,6 @@
return this->sessions.at(userId);
}
-bool CryptoModule::matchesInboundSession(
- const std::string &targetUserId,
- EncryptedData encryptedData,
- const OlmBuffer &theirIdentityKey) const {
- OlmSession *session = this->sessions.at(targetUserId)->getOlmSession();
- // Check that the inbound session matches the message it was created from.
- OlmBuffer tmpEncryptedMessage(encryptedData.message);
- if (1 !=
- ::olm_matches_inbound_session(
- session, tmpEncryptedMessage.data(), tmpEncryptedMessage.size())) {
- return false;
- }
-
- // Check that the inbound session matches the key this message is supposed
- // to be from.
- tmpEncryptedMessage = OlmBuffer(encryptedData.message);
- return 1 ==
- ::olm_matches_inbound_session_from(
- session,
- theirIdentityKey.data() + ID_KEYS_PREFIX_OFFSET,
- KEYSIZE,
- tmpEncryptedMessage.data(),
- tmpEncryptedMessage.size());
-}
-
Persist CryptoModule::storeAsB64(const std::string &secretKey) {
Persist persist;
size_t accountPickleLength = ::olm_pickle_account_length(this->account);
@@ -339,8 +314,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"};
}
@@ -348,13 +322,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<uint8_t>(data.begin(), data.end()), messageType});
+ };
+ NotificationsCryptoModule::callCryptoModule(caller, callingProcessName);
+ return decryptedData;
+}
} // namespace comm

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 5:21 PM (21 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601758
Default Alt Text
D7796.diff (4 KB)

Event Timeline