verdnatura-chat/patches/react-native-mmkv-storage+0...

158 lines
6.8 KiB
Diff
Raw Permalink Normal View History

[NEW] Encrypt user credentials and preferences (#2247) * install react-native-mmkv-storage * wip ios migration * change all js rn-user-defaults -> react-native-mmkv-storage * remove all rn-user-defaults native references (iOS) * android migration from rn-user-defaults to react-native-mmkv-storage * ios app group accessible mmkv * handle get errors * remove access of credentials from legacy native apps * remove data of user defaults * remove no longer necessary import * js mmkv encryption * run migration only once * reply from notification android * fix app group key access at native level ios * encrypt user credentials using a specific key * ios encrypt with random key * use a random key at the first encryption * encrypt migrated data on js land * remove unused function * reply notifications ios should be working * use fix instanceID * android ejson retrieve encrypted data * remove encryption migrated data for a while * encryption working between app and share extension * fix patch react-native-notifications * ssl pinning working using mmkv encrypted data * improve react-native-notifications * run encrypt migration data only once * fix build * fix patches magic string * fix mmkv id * mmkv -> userPreferences * fix instance id on android migration * cast our oldest sharedPreferences string into an object * revert log remove * create currentServer Rocket.Chat key * wrap mmkv api class * change the get logic * move userPreferences to lib * move encrypt migrated data to userPreferences class * check if the new object is new before insert * invalidate ci yarn cache * fix sort migration from android shared preferences * fix splashscreen forever * invalidate yarn cache * invalidate yarn cache * fix patch * Minor change * fix android notifications looking for wrong mmkv instance * Fix some issues on iOS mmkv native access * Remove unnecessary code * Fix notification reply and ssl pinning * WIP NotificationService use MMKV credentials * Add KeychainGroup * Notification idOnly get credentials from mmkv * Some fixes * Invalidate yarn cache * Pods * Use MMKVAppExtension on NotificationService Co-authored-by: Diego Mello <diegolmello@gmail.com>
2020-08-19 17:14:22 +00:00
diff --git a/node_modules/react-native-mmkv-storage/android/src/main/java/com/ammarahmed/mmkv/StorageGetters.java b/node_modules/react-native-mmkv-storage/android/src/main/java/com/ammarahmed/mmkv/StorageGetters.java
index 568e369..229b911 100644
--- a/node_modules/react-native-mmkv-storage/android/src/main/java/com/ammarahmed/mmkv/StorageGetters.java
+++ b/node_modules/react-native-mmkv-storage/android/src/main/java/com/ammarahmed/mmkv/StorageGetters.java
@@ -52,8 +52,12 @@ public class StorageGetters {
case Constants.DATA_TYPE_MAP:
case Constants.DATA_TYPE_ARRAY:
Bundle bundle = kv.decodeParcelable(key, Bundle.class);
- WritableMap map = Arguments.fromBundle(bundle);
- callback.invoke(null, map);
+ if (bundle == null) {
+ callback.invoke(null, null);
+ } else {
+ WritableMap map = Arguments.fromBundle(bundle);
+ callback.invoke(null, map);
+ }
break;
}
diff --git a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m b/node_modules/react-native-mmkv-storage/ios/SecureStorage.m
index 70f3a01..30d7251 100644
--- a/node_modules/react-native-mmkv-storage/ios/SecureStorage.m
+++ b/node_modules/react-native-mmkv-storage/ios/SecureStorage.m
@@ -46,7 +46,6 @@ - (void) setSecureKey: (NSString *)key value:(NSString *)value
- (NSString *) getSecureKey:(NSString *)key
callback:(RCTResponseSenderBlock)callback
{
-
@try {
[self handleAppUninstallation];
NSString *value = [self searchKeychainCopyMatching:key];
@@ -130,7 +129,8 @@ - (void) removeSecureKey:(NSString *)key
- (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
NSMutableDictionary *searchDictionary = [[NSMutableDictionary alloc] init];
- serviceName = [[NSBundle mainBundle] bundleIdentifier];
+ // this value is shared by main app and extensions, so, is the best to be used here
+ serviceName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroup"];
[searchDictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
@@ -139,6 +139,9 @@ - (NSMutableDictionary *)newSearchDictionary:(NSString *)identifier {
[searchDictionary setObject:encodedIdentifier forKey:(id)kSecAttrAccount];
[searchDictionary setObject:serviceName forKey:(id)kSecAttrService];
+ NSString *keychainGroup = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"KeychainGroup"];
+ [searchDictionary setObject:keychainGroup forKey:(id)kSecAttrAccessGroup];
+
return searchDictionary;
}
@@ -240,10 +243,13 @@ - (void)clearSecureKeyStore
- (void)handleAppUninstallation
{
- if (![[NSUserDefaults standardUserDefaults] boolForKey:@"RnSksIsAppInstalled"]) {
+ // use app group user defaults to prevent clear when it's share extension
+ NSString *suiteName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroup"];
+ NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:suiteName];
+ if (![userDefaults boolForKey:@"RnSksIsAppInstalled"]) {
[self clearSecureKeyStore];
- [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"RnSksIsAppInstalled"];
- [[NSUserDefaults standardUserDefaults] synchronize];
+ [userDefaults setBool:YES forKey:@"RnSksIsAppInstalled"];
+ [userDefaults synchronize];
}
}
diff --git a/node_modules/react-native-mmkv-storage/ios/StorageGetters.m b/node_modules/react-native-mmkv-storage/ios/StorageGetters.m
index 909d056..d62814a 100644
--- a/node_modules/react-native-mmkv-storage/ios/StorageGetters.m
+++ b/node_modules/react-native-mmkv-storage/ios/StorageGetters.m
@@ -38,8 +38,13 @@ +(void) getItem:(NSString *)ID
if ([kv containsKey:key]) {
switch (type.integerValue) {
case 1:
-
- callback(@[[NSNull null], [kv getObjectOfClass:NSString.class forKey:key]]);
+ {
+ NSString* string = [kv getObjectOfClass:NSString.class forKey:key];
+ if (!string) {
+ string = (NSString *)[NSNull null];
+ }
+ callback(@[[NSNull null], string]);
+ }
break;
case 2:
diff --git a/node_modules/react-native-mmkv-storage/ios/StorageIndexer.m b/node_modules/react-native-mmkv-storage/ios/StorageIndexer.m
index e7c914b..891cf93 100644
--- a/node_modules/react-native-mmkv-storage/ios/StorageIndexer.m
+++ b/node_modules/react-native-mmkv-storage/ios/StorageIndexer.m
@@ -58,7 +58,11 @@ + (void) removeKeyFromIndexer:(MMKV *)kv
if (index != NULL && [index containsObject:key]) {
[index removeObject:key];
- [kv setObject:index forKey:stringsIndexKey];
+ if (!index || [index count] == 0) {
+ [kv removeValueForKey:stringsIndexKey];
+ } else {
+ [kv setObject:index forKey:stringsIndexKey];
+ }
return;
}
@@ -67,7 +71,11 @@ + (void) removeKeyFromIndexer:(MMKV *)kv
if (index != NULL && [index containsObject:key]) {
[index removeObject:key];
- [kv setObject:index forKey:intIndexKey];
+ if (!index || [index count] == 0) {
+ [kv removeValueForKey:intIndexKey];
+ } else {
+ [kv setObject:index forKey:intIndexKey];
+ }
return;
}
@@ -76,7 +84,11 @@ + (void) removeKeyFromIndexer:(MMKV *)kv
if (index != NULL && [index containsObject:key]) {
[index removeObject:key];
- [kv setObject:index forKey:boolIndexKey];
+ if (!index || [index count] == 0) {
+ [kv removeValueForKey:boolIndexKey];
+ } else {
+ [kv setObject:index forKey:boolIndexKey];
+ }
return;
}
@@ -85,7 +97,11 @@ + (void) removeKeyFromIndexer:(MMKV *)kv
if (index != NULL && [index containsObject:key]) {
[index removeObject:key];
- [kv setObject:index forKey:mapIndexKey];
+ if (!index || [index count] == 0) {
+ [kv removeValueForKey:mapIndexKey];
+ } else {
+ [kv setObject:index forKey:mapIndexKey];
+ }
return;
}
@@ -94,7 +110,11 @@ + (void) removeKeyFromIndexer:(MMKV *)kv
if (index != NULL && [index containsObject:key]) {
[index removeObject:key];
- [kv setObject:index forKey:arrayIndexKey];
+ if (!index || [index count] == 0) {
+ [kv removeValueForKey:arrayIndexKey];
+ } else {
+ [kv setObject:index forKey:arrayIndexKey];
+ }
return;
}