Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3388485
D14044.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D14044.diff
View Options
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
@@ -29,6 +29,7 @@
// returns number of published keys
size_t publishOneTimeKeys();
bool prekeyExistsAndOlderThan(uint64_t threshold);
+ OlmBuffer pickleAccount(const std::string &secretKey);
public:
const std::string id;
@@ -72,6 +73,7 @@
Persist storeAsB64(const std::string &secretKey);
void restoreFromB64(const std::string &secretKey, Persist persist);
+ std::string pickleAccountToString(const std::string &secretKey);
EncryptedData
encrypt(const std::string &targetDeviceId, const std::string &content);
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
@@ -328,23 +328,29 @@
this->sessions.erase(deviceId);
}
-Persist CryptoModule::storeAsB64(const std::string &secretKey) {
- Persist persist;
- size_t accountPickleLength =
- ::olm_pickle_account_length(this->getOlmAccount());
+OlmBuffer CryptoModule::pickleAccount(const std::string &secretKey) {
+ OlmAccount *olmAccount = this->getOlmAccount();
+ size_t accountPickleLength = ::olm_pickle_account_length(olmAccount);
OlmBuffer accountPickleBuffer(accountPickleLength);
- if (accountPickleLength !=
- ::olm_pickle_account(
- this->getOlmAccount(),
- secretKey.data(),
- secretKey.size(),
- accountPickleBuffer.data(),
- accountPickleLength)) {
- throw std::runtime_error{
- "error storeAsB64 => " +
- std::string{::olm_account_last_error(this->getOlmAccount())}};
+
+ size_t result = ::olm_pickle_account(
+ olmAccount,
+ secretKey.data(),
+ secretKey.size(),
+ accountPickleBuffer.data(),
+ accountPickleLength);
+
+ if (accountPickleLength != result) {
+ throw std::runtime_error(
+ "Error in pickleAccount => " +
+ std::string(::olm_account_last_error(olmAccount)));
}
- persist.account = accountPickleBuffer;
+ return accountPickleBuffer;
+}
+
+Persist CryptoModule::storeAsB64(const std::string &secretKey) {
+ Persist persist;
+ persist.account = this->pickleAccount(secretKey);
std::unordered_map<std::string, std::shared_ptr<Session>>::iterator it;
for (it = this->sessions.begin(); it != this->sessions.end(); ++it) {
@@ -356,6 +362,11 @@
return persist;
}
+std::string CryptoModule::pickleAccountToString(const std::string &secretKey) {
+ OlmBuffer pickledAccount = this->pickleAccount(secretKey);
+ return std::string(pickledAccount.begin(), pickledAccount.end());
+}
+
void CryptoModule::restoreFromB64(
const std::string &secretKey,
Persist persist) {
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -2559,10 +2559,8 @@
if (!error.size()) {
try {
pickleKey = crypto::Tools::generateRandomString(64);
- crypto::Persist persist =
- this->contentCryptoModule->storeAsB64(pickleKey);
pickledAccount =
- std::string(persist.account.begin(), persist.account.end());
+ this->contentCryptoModule->pickleAccountToString(pickleKey);
} catch (const std::exception &e) {
error = "Failed to pickle crypto account";
}
@@ -2615,10 +2613,8 @@
if (!error.size()) {
try {
pickleKey = crypto::Tools::generateRandomString(64);
- crypto::Persist persist =
- this->contentCryptoModule->storeAsB64(pickleKey);
pickledAccount =
- std::string(persist.account.begin(), persist.account.end());
+ this->contentCryptoModule->pickleAccountToString(pickleKey);
} catch (const std::exception &e) {
error = "Failed to pickle crypto account";
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 2:33 PM (18 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601299
Default Alt Text
D14044.diff (4 KB)
Attached To
Mode
D14044: [CryptoModule] store only pickled Olm Account in User Keys Backup
Attached
Detach File
Event Timeline
Log In to Comment