Resolve export state generation.
This commit is contained in:
parent
60f60d087e
commit
d9e5f77bee
@ -621,7 +621,7 @@ static NSOperationQueue *_mpwQueue = nil;
|
|||||||
|
|
||||||
- (NSString *)exportLoginForSite:(MPSiteEntity *)site usingKey:(MPKey *)key {
|
- (NSString *)exportLoginForSite:(MPSiteEntity *)site usingKey:(MPKey *)key {
|
||||||
|
|
||||||
if (!(site.type & MPSiteFeatureExportContent) || site.loginGenerated || ![site.loginName length])
|
if (site.loginGenerated || ![site.loginName length])
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
__block NSData *state = nil;
|
__block NSData *state = nil;
|
||||||
|
@ -719,6 +719,7 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MPKey *key = [[MPKey alloc] initForFullName:user.name withMasterPassword:masterPassword];
|
||||||
exportUser = mpw_marshal_user( user.name.UTF8String,
|
exportUser = mpw_marshal_user( user.name.UTF8String,
|
||||||
mpw_masterKeyProvider_str( masterPassword.UTF8String ), user.algorithm.version );
|
mpw_masterKeyProvider_str( masterPassword.UTF8String ), user.algorithm.version );
|
||||||
exportUser->redacted = !revealPasswords;
|
exportUser->redacted = !revealPasswords;
|
||||||
@ -731,11 +732,10 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
|
|||||||
MPCounterValue counter = MPCounterValueInitial;
|
MPCounterValue counter = MPCounterValueInitial;
|
||||||
if ([site isKindOfClass:[MPGeneratedSiteEntity class]])
|
if ([site isKindOfClass:[MPGeneratedSiteEntity class]])
|
||||||
counter = ((MPGeneratedSiteEntity *)site).counter;
|
counter = ((MPGeneratedSiteEntity *)site).counter;
|
||||||
MPMarshalledSite *exportSite = mpw_marshal_site( exportUser,
|
MPMarshalledSite *exportSite = mpw_marshal_site( exportUser, site.name.UTF8String, site.type, counter, site.algorithm.version );
|
||||||
site.name.UTF8String, site.type, counter, site.algorithm.version );
|
exportSite->resultState = mpw_strdup( [site.algorithm exportPasswordForSite:site usingKey:key].UTF8String );
|
||||||
exportSite->resultState = mpw_strdup( [site.algorithm exportPasswordForSite:site usingKey:self.key].UTF8String );
|
exportSite->loginState = mpw_strdup( [site.algorithm exportLoginForSite:site usingKey:key].UTF8String );
|
||||||
exportSite->loginState = mpw_strdup( [site.algorithm exportLoginForSite:site usingKey:self.key].UTF8String );
|
exportSite->loginType = site.loginGenerated || !exportSite->loginState? MPResultTypeTemplateName: MPResultTypeStatefulPersonal;
|
||||||
exportSite->loginType = site.loginGenerated? MPResultTypeTemplateName: MPResultTypeStatefulPersonal;
|
|
||||||
exportSite->url = mpw_strdup( site.url.UTF8String );
|
exportSite->url = mpw_strdup( site.url.UTF8String );
|
||||||
exportSite->uses = (unsigned int)site.uses;
|
exportSite->uses = (unsigned int)site.uses;
|
||||||
exportSite->lastUsed = (time_t)site.lastUsed.timeIntervalSince1970;
|
exportSite->lastUsed = (time_t)site.lastUsed.timeIntervalSince1970;
|
||||||
|
@ -546,15 +546,6 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.key) {
|
|
||||||
NSAlert *alert = [NSAlert new];
|
|
||||||
alert.messageText = @"User Locked";
|
|
||||||
alert.informativeText = @"To export your sites, first unlock your user by opening Master Password.";
|
|
||||||
[alert runModal];
|
|
||||||
[self showPopup:nil];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NSDateFormatter *exportDateFormatter = [NSDateFormatter new];
|
NSDateFormatter *exportDateFormatter = [NSDateFormatter new];
|
||||||
[exportDateFormatter setDateFormat:@"yyyy'-'MM'-'dd"];
|
[exportDateFormatter setDateFormat:@"yyyy'-'MM'-'dd"];
|
||||||
|
|
||||||
@ -579,11 +570,13 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
if ([savePanel runModal] == NSFileHandlingPanelCancelButton)
|
if ([savePanel runModal] == NSFileHandlingPanelCancelButton)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[self exportSitesRevealPasswords:revealPasswords
|
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
||||||
askExportPassword:^NSString *(NSString *userName) {
|
NSError *error = nil;
|
||||||
|
NSString *exportedUser = [self exportSitesFor:[self activeUserInContext:context] revealPasswords:revealPasswords askExportPassword:
|
||||||
|
^NSString *(NSString *userName) {
|
||||||
return PearlMainQueueAwait( ^id {
|
return PearlMainQueueAwait( ^id {
|
||||||
NSAlert *alert = [NSAlert new];
|
NSAlert *alert = [NSAlert new];
|
||||||
[alert addButtonWithTitle:@"Import"];
|
[alert addButtonWithTitle:@"Export"];
|
||||||
[alert addButtonWithTitle:@"Cancel"];
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
alert.messageText = strf( @"Master Password For\n%@", userName );
|
alert.messageText = strf( @"Master Password For\n%@", userName );
|
||||||
alert.informativeText = @"Enter the current master password for this user.";
|
alert.informativeText = @"Enter the current master password for this user.";
|
||||||
@ -594,19 +587,20 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven
|
|||||||
else
|
else
|
||||||
return nil;
|
return nil;
|
||||||
} );
|
} );
|
||||||
} result:^(NSString *mpsites, NSError *error) {
|
} error:&error];
|
||||||
if (!mpsites || error) {
|
|
||||||
|
if (error)
|
||||||
PearlMainQueue( ^{
|
PearlMainQueue( ^{
|
||||||
[[NSAlert alertWithError:MPError( error, @"Failed to export mpsites." )] runModal];
|
[[NSAlert alertWithError:MPError( error, @"Failed to export mpsites." )] runModal];
|
||||||
} );
|
} );
|
||||||
|
if (!exportedUser)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
NSError *coordinateError = nil;
|
NSError *coordinateError = nil;
|
||||||
[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
|
[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
|
||||||
coordinateWritingItemAtURL:savePanel.URL options:0 error:&coordinateError byAccessor:^(NSURL *newURL) {
|
coordinateWritingItemAtURL:savePanel.URL options:0 error:&coordinateError byAccessor:^(NSURL *newURL) {
|
||||||
NSError *writeError = nil;
|
NSError *writeError = nil;
|
||||||
if (![mpsites writeToURL:newURL atomically:NO encoding:NSUTF8StringEncoding error:&writeError])
|
if (![exportedUser writeToURL:newURL atomically:NO encoding:NSUTF8StringEncoding error:&writeError])
|
||||||
PearlMainQueue( ^{
|
PearlMainQueue( ^{
|
||||||
[[NSAlert alertWithError:MPError( writeError, @"Could not write to the export file." )] runModal];
|
[[NSAlert alertWithError:MPError( writeError, @"Could not write to the export file." )] runModal];
|
||||||
} );
|
} );
|
||||||
|
@ -626,19 +626,23 @@
|
|||||||
|
|
||||||
[MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
[MPiOSAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
|
||||||
NSError *error = nil;
|
NSError *error = nil;
|
||||||
NSString *exportedUser = [self exportSitesFor:[self activeUserInContext:context] revealPasswords:revealPasswords askExportPassword:^NSString *(NSString *userName) {
|
NSString *exportedUser = [self exportSitesFor:[self activeUserInContext:context] revealPasswords:revealPasswords askExportPassword:
|
||||||
|
^NSString *(NSString *userName) {
|
||||||
return PearlAwait( ^(void (^setResult)(id)) {
|
return PearlAwait( ^(void (^setResult)(id)) {
|
||||||
PearlMainQueue( ^{
|
PearlMainQueue( ^{
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:strf( @"Master Password For:\n%@", userName )
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:strf(
|
||||||
|
@"Master Password For:\n%@", userName )
|
||||||
message:@"Enter your master password to export the user."
|
message:@"Enter your master password to export the user."
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
||||||
textField.secureTextEntry = YES;
|
textField.secureTextEntry = YES;
|
||||||
}];
|
}];
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
[alert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault
|
||||||
|
handler:^(UIAlertAction *action) {
|
||||||
setResult( alert.textFields.firstObject.text );
|
setResult( alert.textFields.firstObject.text );
|
||||||
}]];
|
}]];
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
|
||||||
|
handler:^(UIAlertAction *action) {
|
||||||
setResult( nil );
|
setResult( nil );
|
||||||
}]];
|
}]];
|
||||||
[self.navigationController presentViewController:alert animated:YES completion:nil];
|
[self.navigationController presentViewController:alert animated:YES completion:nil];
|
||||||
|
Loading…
Reference in New Issue
Block a user