project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

Doesn't encrypt the .sqlite file and extra "ecd" tables doesn't have any records. #330

Open arviejhay opened 4 years ago

arviejhay commented 4 years ago

I am using Xcode 10.3 for an iOS 9.0 project. I'm trying to use Encrypted Core Data to encrypted both the Core Data and the .sqlite file but the problem is that it doesn't encrypt the .sqlite file.

I verified this when i hexdump the .sqlite file, it still shows the SQL Format and other plain text instead of encrypted text like it shown in the library's github repo.

Initially, the .sqlite file contains 172 tables but the number of tables increases to 342 when using the library. I checked it on the SQLiteStudio and the database is full of tables with "ecd" appended to the table names (example: ecdStocks), i assumed that ecd is the acronym of the library, not to mentioned that it still includes the old tables with "Z" appended on it (example: ZSTOCKS).
Is this normal for the library to do this?
Another problem is that the "ecd" tables doesn't contain any records while the old tables before it was converted to "ecd" contain full of records.

Here's the code that i use with the library.

- (NSManagedObjectContext *)masterManagedObjectContext {
if (_masterManagedObjectContext != nil) {
    return _masterManagedObjectContext;
}

NSURL *storeURL = [[self getApplicationDocumentsDirectory] URLByAppendingPathComponent:SQLITE_FILENAME];
// This is the result of the URL /Users/user1/Library/Developer/CoreSimulator/Devices/BE0082D4-2D71-42A2-959D-F1AC2BD947D9/data/Containers/Data/Application/CC4BA3B8-9143-47F3-BF2D-5DABB6EDB137/Documents/dbTest.sqlite
NSString *path = [storeURL path]; //get the URL string

NSDictionary *options = @{ EncryptedStorePassphraseKey: @"",
                           EncryptedStoreDatabaseLocation: path,
                           NSMigratePersistentStoresAutomaticallyOption : @YES,
                           NSInferMappingModelAutomaticallyOption : @YES,
                           @"journal_mode" : @"DELETE"
                           };
NSError *error = nil;

NSManagedObjectModel *objectModel = [self managedObjectModel];

NSPersistentStoreCoordinator *coordinator = [EncryptedStore makeStoreWithOptions:options managedObjectModel:objectModel error:&error];
//NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];

NSLog(@"%@", error.localizedDescription); //result is nil

if (coordinator != nil) {
    _masterManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    [_masterManagedObjectContext performBlockAndWait:^{
        [_masterManagedObjectContext setPersistentStoreCoordinator:coordinator];
    }];
}

return _masterManagedObjectContext;

}

I tried to validate the path by using this condition

if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
    NSLog(@"%@", @"Exist");
}

It outputs the "Exist" on the console which means that the library has access to the .sqlite file. I also validate this by using an incorrect passcode which the library outputs an error since my .sqlite file doesn't have a password.

Deleting and rebuilding the app still doesn't work.
The library doesn't include any error messages which means it doesn't have a problem accessing it.