Page MenuHomePhabricator

D6980.id23526.diff
No OneTemporary

D6980.id23526.diff

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
@@ -1,7 +1,6 @@
#include "CommCoreModule.h"
#include "../CryptoTools/DeviceID.h"
#include "../Notifications/BackgroundDataStorage/NotificationsCryptoModule.h"
-#include "../Tools/CommSecureStore.h"
#include "DatabaseManager.h"
#include "DraftStoreOperations.h"
#include "InternalModules/GlobalDBSingleton.h"
@@ -10,7 +9,6 @@
#include "ThreadStoreOperations.h"
#include <ReactCommon/TurboModuleUtils.h>
-#include <folly/Optional.h>
#include <folly/dynamic.h>
#include <folly/json.h>
#include <future>
@@ -822,17 +820,24 @@
}
jsi::Value CommCoreModule::getUserPublicKey(jsi::Runtime &rt) {
- CommSecureStore secureStore{};
- folly::Optional<std::string> picklingKey = secureStore.get(
- NotificationsCryptoModule::secureStoreNotificationsAccountDataKey);
return createPromiseAsJSIValue(
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [=, &innerRt]() {
std::string error;
- if (!picklingKey.hasValue()) {
- error =
- "Attempt to retrieve notifications crypto account before it "
- "was correctly initialized.";
+ std::string primaryKeysResult;
+ std::string notificationsKeysResult;
+ if (this->cryptoModule == nullptr) {
+ error = "user has not been initialized";
+ } else {
+ primaryKeysResult = this->cryptoModule->getIdentityKeys();
+ }
+ try {
+ if (!error.size()) {
+ notificationsKeysResult =
+ NotificationsCryptoModule::getNotificationsIdentityKeys();
+ }
+ } catch (const std::exception &e) {
+ error = e.what();
}
std::string notificationsCurve25519Cpp, notificationsEd25519Cpp,
@@ -840,64 +845,40 @@
primaryEd25519Cpp;
if (!error.size()) {
- std::string primaryKeysResult;
- std::string notificationsKeysResult;
-
- if (this->cryptoModule == nullptr) {
- error = "user has not been initialized";
- } else {
- primaryKeysResult = this->cryptoModule->getIdentityKeys();
- }
+ folly::dynamic parsedPrimary;
try {
- std::string unwrappedPicklingKey = picklingKey.value();
- if (!error.size()) {
- notificationsKeysResult =
- NotificationsCryptoModule::getNotificationsIdentityKeys(
- unwrappedPicklingKey);
- }
- } catch (const std::exception &e) {
- error = e.what();
+ parsedPrimary = folly::parseJson(primaryKeysResult);
+ } catch (const folly::json::parse_error &e) {
+ error =
+ "parsing identity keys failed with: " + std::string(e.what());
}
-
if (!error.size()) {
- folly::dynamic parsedPrimary;
+ primaryCurve25519Cpp = parsedPrimary["curve25519"].asString();
+ primaryEd25519Cpp = parsedPrimary["ed25519"].asString();
+
+ folly::dynamic parsedNotifications;
try {
- parsedPrimary = folly::parseJson(primaryKeysResult);
+ parsedNotifications = folly::parseJson(notificationsKeysResult);
} catch (const folly::json::parse_error &e) {
- error = "parsing identity keys failed with: " +
+ error = "parsing notifications keys failed with: " +
std::string(e.what());
}
if (!error.size()) {
- primaryCurve25519Cpp = parsedPrimary["curve25519"].asString();
- primaryEd25519Cpp = parsedPrimary["ed25519"].asString();
-
- folly::dynamic parsedNotifications;
- try {
- parsedNotifications =
- folly::parseJson(notificationsKeysResult);
- } catch (const folly::json::parse_error &e) {
- error = "parsing notifications keys failed with: " +
- std::string(e.what());
- }
- if (!error.size()) {
- notificationsCurve25519Cpp =
- parsedNotifications["curve25519"].asString();
- notificationsEd25519Cpp =
- parsedNotifications["ed25519"].asString();
-
- folly::dynamic blobPayloadJSON = folly::dynamic::object(
- "primaryIdentityPublicKeys",
- folly::dynamic::object("ed25519", primaryEd25519Cpp)(
- "curve25519", primaryCurve25519Cpp))(
- "notificationIdentityPublicKeys",
- folly::dynamic::object(
- "ed25519", notificationsEd25519Cpp)(
- "curve25519", notificationsCurve25519Cpp));
-
- blobPayloadCpp = folly::toJson(blobPayloadJSON);
- signatureCpp =
- this->cryptoModule->signMessage(blobPayloadCpp);
- }
+ notificationsCurve25519Cpp =
+ parsedNotifications["curve25519"].asString();
+ notificationsEd25519Cpp =
+ parsedNotifications["ed25519"].asString();
+
+ folly::dynamic blobPayloadJSON = folly::dynamic::object(
+ "primaryIdentityPublicKeys",
+ folly::dynamic::object("ed25519", primaryEd25519Cpp)(
+ "curve25519", primaryCurve25519Cpp))(
+ "notificationIdentityPublicKeys",
+ folly::dynamic::object("ed25519", notificationsEd25519Cpp)(
+ "curve25519", notificationsCurve25519Cpp));
+
+ blobPayloadCpp = folly::toJson(blobPayloadJSON);
+ signatureCpp = this->cryptoModule->signMessage(blobPayloadCpp);
}
}
}
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
@@ -6,6 +6,7 @@
namespace comm {
class NotificationsCryptoModule {
+ const static std::string secureStoreNotificationsAccountDataKey;
const static std::string notificationsCryptoAccountID;
static void serializeAndFlushCryptoModule(
@@ -18,12 +19,9 @@
const std::string &picklingKey);
public:
- const static std::string secureStoreNotificationsAccountDataKey;
-
static void
initializeNotificationsCryptoAccount(const std::string &callingProcessName);
static void clearSensitiveData();
- static std::string
- getNotificationsIdentityKeys(const std::string &picklingKey);
+ static std::string getNotificationsIdentityKeys();
};
} // 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
@@ -5,7 +5,6 @@
#include "../../Tools/PlatformSpecificTools.h"
#include <fcntl.h>
-#include <folly/Optional.h>
#include <folly/String.h>
#include <folly/dynamic.h>
#include <folly/json.h>
@@ -156,12 +155,21 @@
callingProcessName);
}
-std::string NotificationsCryptoModule::getNotificationsIdentityKeys(
- const std::string &picklingKey) {
+std::string NotificationsCryptoModule::getNotificationsIdentityKeys() {
+ CommSecureStore secureStore{};
+ folly::Optional<std::string> picklingKey = secureStore.get(
+ NotificationsCryptoModule::secureStoreNotificationsAccountDataKey);
+ if (!picklingKey.hasValue()) {
+ throw std::runtime_error(
+ "Attempt to retrieve notifications crypto account before it was "
+ "correctly initialized.");
+ }
+
const std::string path =
PlatformSpecificTools::getNotificationsCryptoAccountPath();
crypto::CryptoModule cryptoModule =
- NotificationsCryptoModule::deserializeCryptoModule(path, picklingKey);
+ NotificationsCryptoModule::deserializeCryptoModule(
+ path, picklingKey.value());
return cryptoModule.getIdentityKeys();
}

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 2:15 AM (21 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679149
Default Alt Text
D6980.id23526.diff (8 KB)

Event Timeline