More fixes of temporary moc accesses.
This commit is contained in:
parent
abe874cda3
commit
5bf8842031
@ -3,6 +3,7 @@
|
|||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<option name="myLocal" value="false" />
|
<option name="myLocal" value="false" />
|
||||||
<inspection_tool class="FunctionImplicitDeclarationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="FunctionImplicitDeclarationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="ImplicitIntegerAndEnumConversion" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="LossyEncoding" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="LossyEncoding" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="MethodIsLaterInTheScope" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="MethodIsLaterInTheScope" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="OCNotLocalizedStringInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="OCNotLocalizedStringInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
|
@ -92,60 +92,7 @@ static NSDictionary *keyQuery(MPUserEntity *user) {
|
|||||||
user.keyID = tryKey.keyID;
|
user.keyID = tryKey.keyID;
|
||||||
|
|
||||||
// Migrate existing elements.
|
// Migrate existing elements.
|
||||||
MPKey *recoverKey = nil;
|
[self migrateElementsForUser:user inContext:user.managedObjectContext toKey:tryKey];
|
||||||
#ifdef PEARL_UIKIT
|
|
||||||
PearlAlert *activityAlert = [PearlAlert showActivityWithTitle:PearlString(@"Migrating %d sites...", [user.elements count])];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (MPElementEntity *element in user.elements) {
|
|
||||||
if (element.type & MPElementTypeClassStored && ![element contentUsingKey:tryKey]) {
|
|
||||||
id content = nil;
|
|
||||||
if (recoverKey)
|
|
||||||
content = [element contentUsingKey:recoverKey];
|
|
||||||
|
|
||||||
while (!content) {
|
|
||||||
__block NSString *masterPassword = nil;
|
|
||||||
|
|
||||||
#ifdef PEARL_UIKIT
|
|
||||||
dispatch_group_t recoverPasswordGroup = dispatch_group_create();
|
|
||||||
dispatch_group_enter(recoverPasswordGroup);
|
|
||||||
[PearlAlert showAlertWithTitle:@"Enter Old Master Password"
|
|
||||||
message:PearlString(@"Your old master password is required to migrate the stored password for %@", element.name)
|
|
||||||
viewStyle:UIAlertViewStyleSecureTextInput
|
|
||||||
initAlert:nil
|
|
||||||
tappedButtonBlock:^(UIAlertView *alert_, NSInteger buttonIndex_) {
|
|
||||||
@try {
|
|
||||||
if (buttonIndex_ == [alert_ cancelButtonIndex])
|
|
||||||
// Don't Migrate
|
|
||||||
return;
|
|
||||||
|
|
||||||
masterPassword = [alert_ textFieldAtIndex:0].text;
|
|
||||||
}
|
|
||||||
@finally {
|
|
||||||
dispatch_group_leave(recoverPasswordGroup);
|
|
||||||
}
|
|
||||||
} cancelTitle:@"Don't Migrate" otherTitles:@"Migrate", nil];
|
|
||||||
dispatch_group_wait(recoverPasswordGroup, DISPATCH_TIME_FOREVER);
|
|
||||||
#endif
|
|
||||||
if (!masterPassword)
|
|
||||||
// Don't Migrate
|
|
||||||
break;
|
|
||||||
|
|
||||||
recoverKey = [element.algorithm keyForPassword:masterPassword ofUserNamed:user.name];
|
|
||||||
content = [element contentUsingKey:recoverKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!content)
|
|
||||||
// Don't Migrate
|
|
||||||
break;
|
|
||||||
|
|
||||||
[element setContent:content usingKey:tryKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[user saveContext];
|
|
||||||
#ifdef PEARL_UIKIT
|
|
||||||
[activityAlert cancelAlert];
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +163,7 @@ static NSDictionary *keyQuery(MPUserEntity *user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.lastUsed = [NSDate date];
|
user.lastUsed = [NSDate date];
|
||||||
[user saveContext];
|
[user.managedObjectContext saveToStore];
|
||||||
self.activeUser = user;
|
self.activeUser = user;
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:MPSignedInNotification object:self];
|
[[NSNotificationCenter defaultCenter] postNotificationName:MPSignedInNotification object:self];
|
||||||
@ -230,4 +177,66 @@ static NSDictionary *keyQuery(MPUserEntity *user) {
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)migrateElementsForUser:(MPUserEntity *)user inContext:(NSManagedObjectContext *)moc toKey:(MPKey *)newKey {
|
||||||
|
|
||||||
|
if (![user.elements count])
|
||||||
|
// Nothing to migrate.
|
||||||
|
return;
|
||||||
|
|
||||||
|
MPKey *recoverKey = newKey;
|
||||||
|
#ifdef PEARL_UIKIT
|
||||||
|
PearlAlert *activityAlert = [PearlAlert showActivityWithTitle:PearlString( @"Migrating %d sites...", [user.elements count] )];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (MPElementEntity *element in user.elements) {
|
||||||
|
if (element.type & MPElementTypeClassStored) {
|
||||||
|
id content = nil;
|
||||||
|
while (!(content = [element contentUsingKey:recoverKey])) {
|
||||||
|
// Failed to decrypt element with the current recoveryKey. Ask user for a new one to use.
|
||||||
|
__block NSString *masterPassword = nil;
|
||||||
|
|
||||||
|
#ifdef PEARL_UIKIT
|
||||||
|
dispatch_group_t recoverPasswordGroup = dispatch_group_create();
|
||||||
|
dispatch_group_enter( recoverPasswordGroup );
|
||||||
|
[PearlAlert showAlertWithTitle:@"Enter Old Master Password"
|
||||||
|
message:PearlString( @"Your old master password is required to migrate the stored password for %@",
|
||||||
|
element.name )
|
||||||
|
viewStyle:UIAlertViewStyleSecureTextInput
|
||||||
|
initAlert:nil tappedButtonBlock:^(UIAlertView *alert_, NSInteger buttonIndex_) {
|
||||||
|
@try {
|
||||||
|
if (buttonIndex_ == [alert_ cancelButtonIndex])
|
||||||
|
// Don't Migrate
|
||||||
|
return;
|
||||||
|
|
||||||
|
masterPassword = [alert_ textFieldAtIndex:0].text;
|
||||||
|
}
|
||||||
|
@finally {
|
||||||
|
dispatch_group_leave( recoverPasswordGroup );
|
||||||
|
}
|
||||||
|
} cancelTitle:@"Don't Migrate" otherTitles:@"Migrate", nil];
|
||||||
|
dispatch_group_wait( recoverPasswordGroup, DISPATCH_TIME_FOREVER );
|
||||||
|
#endif
|
||||||
|
if (!masterPassword)
|
||||||
|
// Don't Migrate
|
||||||
|
break;
|
||||||
|
|
||||||
|
recoverKey = [element.algorithm keyForPassword:masterPassword ofUserNamed:user.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!content)
|
||||||
|
// Don't Migrate
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (![recoverKey isEqualToKey:newKey])
|
||||||
|
[element setContent:content usingKey:newKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[moc saveToStore];
|
||||||
|
|
||||||
|
#ifdef PEARL_UIKIT
|
||||||
|
[activityAlert cancelAlert];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
NSError *error;
|
NSError *error;
|
||||||
if (![self save:&error]) {
|
if (![self save:&error]) {
|
||||||
err(@"While saving: %@", NSStringFromClass([self class]), error);
|
err(@"While saving: %@", error);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,13 +194,12 @@
|
|||||||
|
|
||||||
- (id)contentUsingKey:(MPKey *)key {
|
- (id)contentUsingKey:(MPKey *)key {
|
||||||
|
|
||||||
if (!(self.type & MPElementTypeClassGenerated)) {
|
assert(self.type & MPElementTypeClassGenerated);
|
||||||
err(@"Corrupt element: %@, type: %d is not in MPElementTypeClassGenerated", self.name, self.type);
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (![self.name length])
|
if (![self.name length])
|
||||||
return nil;
|
return nil;
|
||||||
|
if (!key)
|
||||||
|
return nil;
|
||||||
|
|
||||||
return [self.algorithm generateContentForElement:self usingKey:key];
|
return [self.algorithm generateContentForElement:self usingKey:key];
|
||||||
}
|
}
|
||||||
@ -222,6 +221,9 @@
|
|||||||
|
|
||||||
assert(self.type & MPElementTypeClassStored);
|
assert(self.type & MPElementTypeClassStored);
|
||||||
|
|
||||||
|
if (!key)
|
||||||
|
return nil;
|
||||||
|
|
||||||
NSData *encryptedContent;
|
NSData *encryptedContent;
|
||||||
if (self.type & MPElementFeatureDevicePrivate)
|
if (self.type & MPElementFeatureDevicePrivate)
|
||||||
encryptedContent = [PearlKeyChain dataOfItemForQuery:[MPElementStoredEntity queryForDevicePrivateElementNamed:self.name]];
|
encryptedContent = [PearlKeyChain dataOfItemForQuery:[MPElementStoredEntity queryForDevicePrivateElementNamed:self.name]];
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
element.type = type;
|
element.type = type;
|
||||||
element.lastUsed = [NSDate date];
|
element.lastUsed = [NSDate date];
|
||||||
element.version = MPAlgorithmDefaultVersion;
|
element.version = MPAlgorithmDefaultVersion;
|
||||||
[element saveContext];
|
[moc saveToStore];
|
||||||
|
|
||||||
NSManagedObjectID *elementOID = [element objectID];
|
NSManagedObjectID *elementOID = [element objectID];
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
@ -138,7 +138,7 @@
|
|||||||
self.outdatedAlertContainer.alpha = 1;
|
self.outdatedAlertContainer.alpha = 1;
|
||||||
self.suppressOutdatedAlert = YES;
|
self.suppressOutdatedAlert = YES;
|
||||||
}];
|
}];
|
||||||
[activeUser saveContext];
|
[activeUser.managedObjectContext saveToStore];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (![[MPiOSConfig get].actionsTipShown boolValue])
|
if (![[MPiOSConfig get].actionsTipShown boolValue])
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
if (selected) {
|
if (selected) {
|
||||||
MPUserEntity *activeUser = [MPAppDelegate get].activeUser;
|
MPUserEntity *activeUser = [MPAppDelegate get].activeUser;
|
||||||
activeUser.avatar = (unsigned)avatar.tag;
|
activeUser.avatar = (unsigned)avatar.tag;
|
||||||
[activeUser saveContext];
|
[activeUser.managedObjectContext saveToStore];
|
||||||
}
|
}
|
||||||
} options:0];
|
} options:0];
|
||||||
avatar.selected = (a == [MPAppDelegate get].activeUser.avatar);
|
avatar.selected = (a == [MPAppDelegate get].activeUser.avatar);
|
||||||
@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
MPUserEntity *activeUser = [MPAppDelegate get].activeUser;
|
MPUserEntity *activeUser = [MPAppDelegate get].activeUser;
|
||||||
activeUser.defaultType = type;
|
activeUser.defaultType = type;
|
||||||
[activeUser saveContext];
|
[activeUser.managedObjectContext saveToStore];
|
||||||
|
|
||||||
self.defaultTypeLabel.text = [[MPAppDelegate get].key.algorithm shortNameOfType:activeUser.defaultType];
|
self.defaultTypeLabel.text = [[MPAppDelegate get].key.algorithm shortNameOfType:activeUser.defaultType];
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@
|
|||||||
[[MPAppDelegate get] storeSavedKeyFor:activeUser];
|
[[MPAppDelegate get] storeSavedKeyFor:activeUser];
|
||||||
else
|
else
|
||||||
[[MPAppDelegate get] forgetSavedKeyFor:activeUser];
|
[[MPAppDelegate get] forgetSavedKeyFor:activeUser];
|
||||||
[activeUser saveContext];
|
[activeUser.managedObjectContext saveToStore];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)settings:(UIBarButtonItem *)sender {
|
- (IBAction)settings:(UIBarButtonItem *)sender {
|
||||||
|
@ -809,7 +809,7 @@
|
|||||||
|
|
||||||
if (buttonIndex == [sheet firstOtherButtonIndex])
|
if (buttonIndex == [sheet firstOtherButtonIndex])
|
||||||
[moc performBlock:^{
|
[moc performBlock:^{
|
||||||
[[MPAppDelegate get] changeMasterPasswordFor:targetedUser didResetBlock:^{
|
[[MPAppDelegate get] changeMasterPasswordFor:targetedUser inContext:moc didResetBlock:^{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[self avatarForUser:targetedUser] setSelected:YES];
|
[[self avatarForUser:targetedUser] setSelected:YES];
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user