Page MenuHomePhabricator

D5332.diff
No OneTemporary

D5332.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.h
@@ -16,12 +16,13 @@
static std::once_flag initialized;
static int sqlcipherEncryptionKeySize;
- static std::string secureStoreEncryptionKeyID;
public:
static std::string sqliteFilePath;
static std::string encryptionKey;
+ static std::string secureStoreEncryptionKeyID;
+
SQLiteQueryExecutor();
static void initialize(std::string &databasePath);
std::unique_ptr<Thread> getThread(std::string threadID) const override;
diff --git a/native/ios/Comm/AppDelegate.mm b/native/ios/Comm/AppDelegate.mm
--- a/native/ios/Comm/AppDelegate.mm
+++ b/native/ios/Comm/AppDelegate.mm
@@ -15,6 +15,7 @@
#import <reacthermes/HermesExecutorFactory.h>
#import "CommCoreModule.h"
+#import "CommSecureStoreIOSWrapper.h"
#import "GlobalDBSingleton.h"
#import "GlobalNetworkSingleton.h"
#import "Logger.h"
@@ -69,6 +70,12 @@
- (BOOL)application:(UIApplication *)application
willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ NSString *secureStoreEncryptionKeyID = [NSString
+ stringWithUTF8String:
+ (comm::SQLiteQueryExecutor::secureStoreEncryptionKeyID.c_str())];
+ [[CommSecureStoreIOSWrapper sharedInstance]
+ migrateOptionsForKey:secureStoreEncryptionKeyID
+ withVersion:@"0"];
[self attemptDatabaseInitialization];
return YES;
}
diff --git a/native/ios/Comm/CommSecureStoreIOSWrapper.h b/native/ios/Comm/CommSecureStoreIOSWrapper.h
--- a/native/ios/Comm/CommSecureStoreIOSWrapper.h
+++ b/native/ios/Comm/CommSecureStoreIOSWrapper.h
@@ -9,4 +9,5 @@
- (void)set:(NSString *)key value:(NSString *)value;
- (NSString *)get:(NSString *)key;
+- (void)migrateOptionsForKey:(NSString *)key withVersion:(NSString *)version;
@end
diff --git a/native/ios/Comm/CommSecureStoreIOSWrapper.mm b/native/ios/Comm/CommSecureStoreIOSWrapper.mm
--- a/native/ios/Comm/CommSecureStoreIOSWrapper.mm
+++ b/native/ios/Comm/CommSecureStoreIOSWrapper.mm
@@ -16,6 +16,7 @@
- (NSString *)_getValueWithKey:(NSString *)key
withOptions:(NSDictionary *)options
error:(NSError **)error;
+- (void)_deleteValueWithKey:(NSString *)key withOptions:(NSDictionary *)options;
@end
@implementation CommSecureStoreIOSWrapper
@@ -33,6 +34,8 @@
(EXSecureStore *)[[moduleRegistryProvider moduleRegistry]
getExportedModuleOfClass:EXSecureStore.class];
shared.secureStore = secureStore;
+ shared.options =
+ @{@"keychainAccessible" : @(EXSecureStoreAccessibleAfterFirstUnlock)};
});
return shared;
}
@@ -64,4 +67,33 @@
error:&error];
}
+- (void)migrateOptionsForKey:(NSString *)key withVersion:(NSString *)version {
+ NSString *secureStoreKeyVersionID = [key stringByAppendingString:@".version"];
+ NSString *failureProtectionCopyKey = [key stringByAppendingString:@".copy"];
+
+ NSString *secureStoreKeyVersion = [self get:secureStoreKeyVersionID];
+ if (secureStoreKeyVersion &&
+ [secureStoreKeyVersion isEqualToString:version]) {
+ return;
+ }
+
+ NSString *value = [self get:key];
+ NSString *valueCopy = [self get:failureProtectionCopyKey];
+
+ if (value) {
+ [self set:failureProtectionCopyKey value:value];
+ [[self secureStore] _deleteValueWithKey:key withOptions:[self options]];
+ } else if (valueCopy) {
+ value = valueCopy;
+ } else {
+ [self set:secureStoreKeyVersionID value:version];
+ return;
+ }
+
+ [self set:key value:value];
+ [self set:secureStoreKeyVersionID value:version];
+ [[self secureStore] _deleteValueWithKey:failureProtectionCopyKey
+ withOptions:[self options]];
+}
+
@end

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 1:48 PM (19 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694810
Default Alt Text
D5332.diff (3 KB)

Event Timeline