Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32605939
D7381.1767439609.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D7381.1767439609.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
@@ -39,6 +39,7 @@
std::string getIdentityKeys();
std::string getOneTimeKeys(size_t oneTimeKeysAmount = 50);
+ std::string generatePreKey();
void initializeInboundForReceivingSession(
const std::string &targetUserId,
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
@@ -115,6 +115,35 @@
this->keys.oneTimeKeys.begin(), this->keys.oneTimeKeys.end()};
}
+std::string CryptoModule::generatePreKey() {
+ size_t preKeySize =
+ ::olm_account_generate_prekey_random_length(this->account);
+
+ OlmBuffer random;
+ PlatformSpecificTools::generateSecureRandomBytes(random, preKeySize);
+
+ if (-1 ==
+ ::olm_account_generate_prekey(
+ this->account, random.data(), random.size())) {
+ throw std::runtime_error{
+ "error generatePreKey => " +
+ std::string{::olm_account_last_error(this->account)}};
+ }
+
+ ::olm_account_mark_prekey_as_published(this->account);
+
+ OlmBuffer preKey;
+ preKey.resize(::olm_account_prekey_length(this->account));
+
+ if (-1 == ::olm_account_prekey(this->account, preKey.data(), preKey.size())) {
+ throw std::runtime_error{
+ "error generatePreKey => " +
+ std::string{::olm_account_last_error(this->account)}};
+ }
+
+ return std::string{preKey.begin(), preKey.end()};
+}
+
void CryptoModule::initializeInboundForReceivingSession(
const std::string &targetUserId,
const OlmBuffer &encryptedMessage,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 3, 11:26 AM (14 h, 2 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5888258
Default Alt Text
D7381.1767439609.diff (1 KB)
Attached To
Mode
D7381: Implement prekey lifecycle in `CryptoModule`.
Attached
Detach File
Event Timeline
Log In to Comment