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 @@ -55,27 +55,27 @@ void forgetOldPrekey(); void initializeInboundForReceivingSession( - const std::string &targetUserId, + const std::string &targetDeviceId, const OlmBuffer &encryptedMessage, const OlmBuffer &idKeys, const bool overwrite = false); void initializeOutboundForSendingSession( - const std::string &targetUserId, + const std::string &targetDeviceId, const OlmBuffer &idKeys, const OlmBuffer &preKeys, const OlmBuffer &preKeySignature, const OlmBuffer &oneTimeKeys, size_t keyIndex = 0); - bool hasSessionFor(const std::string &targetUserId); - std::shared_ptr getSessionByUserId(const std::string &userId); + bool hasSessionFor(const std::string &targetDeviceId); + std::shared_ptr getSessionByDeviceId(const std::string &deviceId); Persist storeAsB64(const std::string &secretKey); void restoreFromB64(const std::string &secretKey, Persist persist); EncryptedData - encrypt(const std::string &targetUserId, const std::string &content); + encrypt(const std::string &targetDeviceId, const std::string &content); std::string - decrypt(const std::string &targetUserId, EncryptedData &encryptedData); + decrypt(const std::string &targetDeviceId, 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 @@ -223,13 +223,13 @@ } void CryptoModule::initializeInboundForReceivingSession( - const std::string &targetUserId, + const std::string &targetDeviceId, const OlmBuffer &encryptedMessage, const OlmBuffer &idKeys, const bool overwrite) { - if (this->hasSessionFor(targetUserId)) { + if (this->hasSessionFor(targetDeviceId)) { if (overwrite) { - this->sessions.erase(this->sessions.find(targetUserId)); + this->sessions.erase(this->sessions.find(targetDeviceId)); } else { throw std::runtime_error{ "error initializeInboundForReceivingSession => session already " @@ -241,20 +241,20 @@ this->keys.identityKeys.data(), encryptedMessage, idKeys); - this->sessions.insert(make_pair(targetUserId, std::move(newSession))); + this->sessions.insert(make_pair(targetDeviceId, std::move(newSession))); } void CryptoModule::initializeOutboundForSendingSession( - const std::string &targetUserId, + const std::string &targetDeviceId, const OlmBuffer &idKeys, const OlmBuffer &preKeys, const OlmBuffer &preKeySignature, const OlmBuffer &oneTimeKeys, size_t keyIndex) { - if (this->hasSessionFor(targetUserId)) { + if (this->hasSessionFor(targetDeviceId)) { Logger::log( - "olm session overwritten for the user with id: " + targetUserId); - this->sessions.erase(this->sessions.find(targetUserId)); + "olm session overwritten for the device with id: " + targetDeviceId); + this->sessions.erase(this->sessions.find(targetDeviceId)); } std::unique_ptr newSession = Session::createSessionAsInitializer( this->getOlmAccount(), @@ -264,16 +264,16 @@ preKeySignature, oneTimeKeys, keyIndex); - this->sessions.insert(make_pair(targetUserId, std::move(newSession))); + this->sessions.insert(make_pair(targetDeviceId, std::move(newSession))); } -bool CryptoModule::hasSessionFor(const std::string &targetUserId) { - return (this->sessions.find(targetUserId) != this->sessions.end()); +bool CryptoModule::hasSessionFor(const std::string &targetDeviceId) { + return (this->sessions.find(targetDeviceId) != this->sessions.end()); } std::shared_ptr -CryptoModule::getSessionByUserId(const std::string &userId) { - return this->sessions.at(userId); +CryptoModule::getSessionByDeviceId(const std::string &deviceId) { + return this->sessions.at(deviceId); } Persist CryptoModule::storeAsB64(const std::string &secretKey) { @@ -332,12 +332,12 @@ } EncryptedData CryptoModule::encrypt( - const std::string &targetUserId, + const std::string &targetDeviceId, const std::string &content) { - if (!this->hasSessionFor(targetUserId)) { + if (!this->hasSessionFor(targetDeviceId)) { throw std::runtime_error{"error encrypt => uninitialized session"}; } - OlmSession *session = this->sessions.at(targetUserId)->getOlmSession(); + OlmSession *session = this->sessions.at(targetDeviceId)->getOlmSession(); OlmBuffer encryptedMessage( ::olm_encrypt_message_length(session, content.size())); OlmBuffer messageRandom; @@ -360,12 +360,12 @@ } std::string CryptoModule::decrypt( - const std::string &targetUserId, + const std::string &targetDeviceId, EncryptedData &encryptedData) { - if (!this->hasSessionFor(targetUserId)) { + if (!this->hasSessionFor(targetDeviceId)) { throw std::runtime_error{"error decrypt => uninitialized session"}; } - OlmSession *session = this->sessions.at(targetUserId)->getOlmSession(); + OlmSession *session = this->sessions.at(targetDeviceId)->getOlmSession(); OlmBuffer utilityBuffer(::olm_utility_size()); OlmUtility *olmUtility = ::olm_utility(utilityBuffer.data());