Skip to content

Commit

Permalink
Fix bug related to data protection mode "complete until first auth" w…
Browse files Browse the repository at this point in the history
…here FIC would incorrectly think that data was inaccessible while locked, even though the device had previously been unlocked.
  • Loading branch information
Mallory Paine committed Mar 29, 2014
1 parent 1275a08 commit 1c457cb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions FastImageCache/FICImageTable.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ @interface FICImageTable () {
NSCountedSet *_inUseEntries;
NSDictionary *_imageFormatDictionary;

BOOL _isFileDataProtected;
NSString *_fileDataProtectionMode;
BOOL _canAccessData;
}
@property(nonatomic, weak) FICImageCache *imageCache;
@end
Expand Down Expand Up @@ -172,10 +173,7 @@ - (instancetype)initWithFormat:(FICImageFormat *)imageFormat imageCache:(FICImag
}

NSDictionary *attributes = [fileManager attributesOfItemAtPath:_filePath error:NULL];
NSString *protectionMode = [attributes objectForKey:NSFileProtectionKey];
if (protectionMode) {
_isFileDataProtected = [protectionMode isEqualToString:NSFileProtectionNone] == NO;
}
_fileDataProtectionMode = [attributes objectForKey:NSFileProtectionKey];

_fileDescriptor = open([_filePath fileSystemRepresentation], O_RDWR | O_CREAT, 0666);

Expand Down Expand Up @@ -496,8 +494,20 @@ - (void)_setEntryCount:(NSInteger)entryCount {
// by using NSFileProtectionNone
- (BOOL)canAccessEntryData {
BOOL result = YES;
if (_isFileDataProtected) {
if ([_fileDataProtectionMode isEqualToString:NSFileProtectionComplete]) {
result = [[UIApplication sharedApplication] isProtectedDataAvailable];
} else if ([_fileDataProtectionMode isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication]) {
// For "complete until first auth", if we were previously able to access data, then we'll still be able to
// access it. If we haven't yet been able to access data, we'll need to try until we are successful.
if (_canAccessData == NO) {
if ([[UIApplication sharedApplication] isProtectedDataAvailable]) {
// we are unlocked, so we're good to go.
_canAccessData = YES;
} else {
// we are locked, so try to access data.
_canAccessData = [NSData dataWithContentsOfMappedFile:_filePath] != nil;
}
}
}
return result;
}
Expand Down

0 comments on commit 1c457cb

Please sign in to comment.