2
0

Show internal reason for why import fails.

This commit is contained in:
Maarten Billemont 2020-04-20 17:09:38 -04:00
parent 694b5ea227
commit d4de3afb72

View File

@ -563,50 +563,46 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
// Read metadata for the import file. // Read metadata for the import file.
MPMarshalledFile *file = mpw_marshal_read( NULL, importData.UTF8String ); MPMarshalledFile *file = mpw_marshal_read( NULL, importData.UTF8String );
if (!file) MPMarshalledUser *importUser = nil;
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ @try {
@"type" : @(MPMarshalErrorInternal), if (!file)
NSLocalizedDescriptionKey: @"Could not process Master Password import data.", return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
}]), @"While importing sites." ); @"type" : @(MPMarshalErrorInternal),
if (file->error.type != MPMarshalSuccess) { NSLocalizedDescriptionKey: @"Could not process Master Password import data.",
MPMarshalErrorType type = file->error.type; }]), @"While importing sites." );
mpw_marshal_file_free( &file ); if (file->error.type != MPMarshalSuccess) {
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(type), @"type" : @(file->error.type),
NSLocalizedDescriptionKey: @"Could not parse Master Password import data.", NSLocalizedDescriptionKey: strf( @"Could not parse Master Password import data:\n%@", @(file->error.message) ),
}]), @"While importing sites." ); }]), @"While importing sites." );
} }
if (file->info->format == MPMarshalFormatNone) { if (file->info->format == MPMarshalFormatNone) {
mpw_marshal_file_free( &file ); return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ @"type" : @(MPMarshalErrorFormat),
@"type" : @(MPMarshalErrorFormat), NSLocalizedDescriptionKey: @"This is not a Master Password import file.",
NSLocalizedDescriptionKey: @"This is not a Master Password import file.", }]), @"While importing sites." );
}]), @"While importing sites." );
}
// Get master password for import file.
MPKey *importKey;
NSString *importMasterPassword;
do {
importMasterPassword = askImportPassword( @(file->info->fullName) );
if (!importMasterPassword) {
inf( @"Import cancelled." );
mpw_marshal_file_free( &file );
return MPError( ([NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]), @"" );
} }
importKey = [[MPKey alloc] initForFullName:@(file->info->fullName) withMasterPassword:importMasterPassword]; // Get master password for import file.
} while ([[[importKey keyIDForAlgorithm:MPAlgorithmForVersion( file->info->algorithm )] encodeHex] MPKey *importKey;
caseInsensitiveCompare:@(file->info->keyID)] != NSOrderedSame); NSString *importMasterPassword;
do {
importMasterPassword = askImportPassword( @(file->info->fullName) );
if (!importMasterPassword) {
inf( @"Import cancelled." );
return MPError( ([NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]), @"" );
}
// Parse import data. importKey = [[MPKey alloc] initForFullName:@(file->info->fullName) withMasterPassword:importMasterPassword];
MPMarshalledUser *importUser = mpw_marshal_auth( file, mpw_masterKeyProvider_str( importMasterPassword.UTF8String ) ); } while ([[[importKey keyIDForAlgorithm:MPAlgorithmForVersion( file->info->algorithm )] encodeHex]
caseInsensitiveCompare:@(file->info->keyID)] != NSOrderedSame);
@try { // Parse import data.
importUser = mpw_marshal_auth( file, mpw_masterKeyProvider_str( importMasterPassword.UTF8String ) );
if (!importUser || file->error.type != MPMarshalSuccess) if (!importUser || file->error.type != MPMarshalSuccess)
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(file->error.type), @"type" : @(file->error.type),
NSLocalizedDescriptionKey: @(file->error.message), NSLocalizedDescriptionKey: strf( @"Could not authenticate Master Password import:\n%@", @(file->error.message) ),
}]), @"While importing sites." ); }]), @"While importing sites." );
// Find an existing user to update. // Find an existing user to update.