Differential D6980 Diff 23529 native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp
Changeset View
Changeset View
Standalone View
Standalone View
native/cpp/CommonCpp/Notifications/BackgroundDataStorage/NotificationsCryptoModule.cpp
#include "NotificationsCryptoModule.h" | #include "NotificationsCryptoModule.h" | ||||
#include "../../CryptoTools/Persist.h" | #include "../../CryptoTools/Persist.h" | ||||
#include "../../CryptoTools/Tools.h" | #include "../../CryptoTools/Tools.h" | ||||
#include "../../Tools/CommSecureStore.h" | #include "../../Tools/CommSecureStore.h" | ||||
#include "../../Tools/PlatformSpecificTools.h" | #include "../../Tools/PlatformSpecificTools.h" | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <folly/Optional.h> | |||||
#include <folly/String.h> | #include <folly/String.h> | ||||
#include <folly/dynamic.h> | #include <folly/dynamic.h> | ||||
#include <folly/json.h> | #include <folly/json.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <fstream> | #include <fstream> | ||||
#include <sstream> | #include <sstream> | ||||
namespace comm { | namespace comm { | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | crypto::CryptoModule cryptoModule{ | ||||
NotificationsCryptoModule::notificationsCryptoAccountID}; | NotificationsCryptoModule::notificationsCryptoAccountID}; | ||||
NotificationsCryptoModule::serializeAndFlushCryptoModule( | NotificationsCryptoModule::serializeAndFlushCryptoModule( | ||||
cryptoModule, | cryptoModule, | ||||
notificationsCryptoAccountPath, | notificationsCryptoAccountPath, | ||||
picklingKey, | picklingKey, | ||||
callingProcessName); | callingProcessName); | ||||
} | } | ||||
std::string NotificationsCryptoModule::getNotificationsIdentityKeys( | std::string NotificationsCryptoModule::getNotificationsIdentityKeys() { | ||||
const std::string &picklingKey) { | 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 = | const std::string path = | ||||
PlatformSpecificTools::getNotificationsCryptoAccountPath(); | PlatformSpecificTools::getNotificationsCryptoAccountPath(); | ||||
crypto::CryptoModule cryptoModule = | crypto::CryptoModule cryptoModule = | ||||
NotificationsCryptoModule::deserializeCryptoModule(path, picklingKey); | NotificationsCryptoModule::deserializeCryptoModule( | ||||
path, picklingKey.value()); | |||||
return cryptoModule.getIdentityKeys(); | return cryptoModule.getIdentityKeys(); | ||||
} | } | ||||
void NotificationsCryptoModule::clearSensitiveData() { | void NotificationsCryptoModule::clearSensitiveData() { | ||||
std::string notificationsCryptoAccountPath = | std::string notificationsCryptoAccountPath = | ||||
PlatformSpecificTools::getNotificationsCryptoAccountPath(); | PlatformSpecificTools::getNotificationsCryptoAccountPath(); | ||||
if (remove(notificationsCryptoAccountPath.c_str()) == -1 && errno != ENOENT) { | if (remove(notificationsCryptoAccountPath.c_str()) == -1 && errno != ENOENT) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"Unable to remove notifications crypto account. Security requirements " | "Unable to remove notifications crypto account. Security requirements " | ||||
"might be violated."); | "might be violated."); | ||||
} | } | ||||
} | } | ||||
} // namespace comm | } // namespace comm |