Skip to content

Commit 788f21b

Browse files
committed
No longer returning a db object if encryption can't be used
- Using FMDB's goodConnection method to check the state of the database (see https://github.com/ccgus/fmdb/blob/2.7.12/src/fmdb/FMDatabase.m#L512) - Removed fixFor530Bug which would automatically encrypt a non-encrypted database - with the use of goodConnection, app won't be able to get a non-encrypted database
1 parent ebe2dea commit 788f21b

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

libs/SmartStore/SmartStore/Classes/SFSmartStoreDatabaseManager.m

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,7 @@ - (FMDatabase *)openStoreDatabaseWithName:(NSString *)storeName key:(NSString *)
146146
return [[self class] openDatabaseWithPath:fullDbFilePath key:key salt:salt error:error];
147147
}
148148

149-
// If you created your database with an app based on Mobile SDK 5.3.0 using cocoapod
150-
// Then the key was never applied, and the database can be read directly
151-
// This method checks for that situation and encrypt the database if needed
152-
- (void)fixFor530Bug:(NSString *)storeName key:(NSString *)key salt:(NSString *)salt {
153-
NSString *fullDbFilePath = [self fullDbFilePathForStoreName:storeName];
154-
155-
__block BOOL needEncrypting = NO;
156-
[[FMDatabaseQueue databaseQueueWithPath:fullDbFilePath] inDatabase:^(FMDatabase* db) {
157-
// In the normal case, the db will not be readable - we don't want to be logging any errors
158-
BOOL logsErrors = db.logsErrors;
159-
db.logsErrors = NO;
160-
needEncrypting = [[self class] verifyDatabaseAccess:db error:nil];
161-
db.logsErrors = logsErrors;
162-
}];
163-
164-
if (needEncrypting) {
165-
[[self class] encryptDbWithStoreName:storeName storePath:fullDbFilePath key:key salt:salt error:nil];
166-
}
167-
}
168-
169149
- (FMDatabaseQueue *)openStoreQueueWithName:(NSString *)storeName key:(NSString *)key salt:(NSString *)salt error:(NSError * __autoreleasing *)error {
170-
[self fixFor530Bug:storeName key:key salt:salt];
171150

172151
__block BOOL result = YES;
173152
NSString *fullDbFilePath = [self fullDbFilePathForStoreName:storeName];
@@ -440,21 +419,16 @@ + (FMDatabase *)encryptOrUnencryptDb:(FMDatabase *)db
440419

441420
+ (BOOL)verifyDatabaseAccess:(FMDatabase *)db error:(NSError **)error
442421
{
443-
NSString *sqlCommand = @"SELECT name FROM sqlite_master LIMIT 1";
444-
FMResultSet *rs = [db executeQuery:sqlCommand];
445-
if (rs == nil) {
446-
// May not be results, but rs should never be nil coming back.
422+
if (![db goodConnection]) {
447423
if (error != nil) {
448424
NSString *errorDesc = [NSString stringWithFormat:kSFSmartStoreVerifyReadDbErrorDesc, [db databasePath], [db lastErrorMessage]];
449425
*error = [NSError errorWithDomain:kSFSmartStoreDbErrorDomain
450426
code:kSFSmartStoreVerifyReadDbErrorCode
451427
userInfo:@{NSLocalizedDescriptionKey: errorDesc}];
452428
}
453-
[rs close];
454429
return NO;
455430
}
456431

457-
[rs close];
458432
return YES;
459433
}
460434

0 commit comments

Comments
 (0)