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,43 +570,46 @@ 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;
|
||||||
return PearlMainQueueAwait( ^id {
|
NSString *exportedUser = [self exportSitesFor:[self activeUserInContext:context] revealPasswords:revealPasswords askExportPassword:
|
||||||
NSAlert *alert = [NSAlert new];
|
^NSString *(NSString *userName) {
|
||||||
[alert addButtonWithTitle:@"Import"];
|
return PearlMainQueueAwait( ^id {
|
||||||
[alert addButtonWithTitle:@"Cancel"];
|
NSAlert *alert = [NSAlert new];
|
||||||
alert.messageText = strf( @"Master Password For\n%@", userName );
|
[alert addButtonWithTitle:@"Export"];
|
||||||
alert.informativeText = @"Enter the current master password for this user.";
|
[alert addButtonWithTitle:@"Cancel"];
|
||||||
alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
|
alert.messageText = strf( @"Master Password For\n%@", userName );
|
||||||
[alert layout];
|
alert.informativeText = @"Enter the current master password for this user.";
|
||||||
if ([alert runModal] == NSAlertFirstButtonReturn)
|
alert.accessoryView = [[NSSecureTextField alloc] initWithFrame:NSMakeRect( 0, 0, 200, 22 )];
|
||||||
return ((NSTextField *)alert.accessoryView).stringValue;
|
[alert layout];
|
||||||
else
|
if ([alert runModal] == NSAlertFirstButtonReturn)
|
||||||
return nil;
|
return ((NSTextField *)alert.accessoryView).stringValue;
|
||||||
} );
|
else
|
||||||
} result:^(NSString *mpsites, NSError *error) {
|
return nil;
|
||||||
if (!mpsites || error) {
|
|
||||||
PearlMainQueue( ^{
|
|
||||||
[[NSAlert alertWithError:MPError( error, @"Failed to export mpsites." )] runModal];
|
|
||||||
} );
|
} );
|
||||||
return;
|
} error:&error];
|
||||||
}
|
|
||||||
|
|
||||||
NSError *coordinateError = nil;
|
if (error)
|
||||||
[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
|
PearlMainQueue( ^{
|
||||||
coordinateWritingItemAtURL:savePanel.URL options:0 error:&coordinateError byAccessor:^(NSURL *newURL) {
|
[[NSAlert alertWithError:MPError( error, @"Failed to export mpsites." )] runModal];
|
||||||
NSError *writeError = nil;
|
} );
|
||||||
if (![mpsites writeToURL:newURL atomically:NO encoding:NSUTF8StringEncoding error:&writeError])
|
if (!exportedUser)
|
||||||
PearlMainQueue( ^{
|
return;
|
||||||
[[NSAlert alertWithError:MPError( writeError, @"Could not write to the export file." )] runModal];
|
|
||||||
} );
|
NSError *coordinateError = nil;
|
||||||
}];
|
[[[NSFileCoordinator alloc] initWithFilePresenter:nil]
|
||||||
if (coordinateError)
|
coordinateWritingItemAtURL:savePanel.URL options:0 error:&coordinateError byAccessor:^(NSURL *newURL) {
|
||||||
PearlMainQueue( ^{
|
NSError *writeError = nil;
|
||||||
[[NSAlert alertWithError:MPError( coordinateError, @"Could not gain access to the export file." )] runModal];
|
if (![exportedUser writeToURL:newURL atomically:NO encoding:NSUTF8StringEncoding error:&writeError])
|
||||||
} );
|
PearlMainQueue( ^{
|
||||||
}];
|
[[NSAlert alertWithError:MPError( writeError, @"Could not write to the export file." )] runModal];
|
||||||
|
} );
|
||||||
|
}];
|
||||||
|
if (coordinateError)
|
||||||
|
PearlMainQueue( ^{
|
||||||
|
[[NSAlert alertWithError:MPError( coordinateError, @"Could not gain access to the export file." )] runModal];
|
||||||
|
} );
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateUsers {
|
- (void)updateUsers {
|
||||||
|
@ -626,25 +626,29 @@
|
|||||||
|
|
||||||
[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:
|
||||||
return PearlAwait( ^(void (^setResult)(id)) {
|
^NSString *(NSString *userName) {
|
||||||
PearlMainQueue( ^{
|
return PearlAwait( ^(void (^setResult)(id)) {
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:strf( @"Master Password For:\n%@", userName )
|
PearlMainQueue( ^{
|
||||||
message:@"Enter your master password to export the user."
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:strf(
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
@"Master Password For:\n%@", userName )
|
||||||
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
message:@"Enter your master password to export the user."
|
||||||
textField.secureTextEntry = YES;
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
}];
|
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
|
textField.secureTextEntry = YES;
|
||||||
setResult( alert.textFields.firstObject.text );
|
}];
|
||||||
}]];
|
[alert addAction:[UIAlertAction actionWithTitle:@"Export" style:UIAlertActionStyleDefault
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
setResult( nil );
|
setResult( alert.textFields.firstObject.text );
|
||||||
}]];
|
}]];
|
||||||
[self.navigationController presentViewController:alert animated:YES completion:nil];
|
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
|
||||||
} );
|
handler:^(UIAlertAction *action) {
|
||||||
} );
|
setResult( nil );
|
||||||
} error:&error];
|
}]];
|
||||||
|
[self.navigationController presentViewController:alert animated:YES completion:nil];
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
} error:&error];
|
||||||
|
|
||||||
PearlMainQueue( ^{
|
PearlMainQueue( ^{
|
||||||
if (error) {
|
if (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user