Inherits NSFileManager, and <NSStreamDelegate>.
This class is a subclass of the native NSFileManager class, for access to the BlackBerry Dynamics secure file system.
Secure File System
The secure file system is part of the BlackBerry Dynamics Secure Storage feature.
For applications, the BlackBerry Dynamics secure file system behaves like the default file system, with the following differences.
- All data within the secure file system is stored on the device in an encrypted form.
- Directory and file names are also encrypted.
- The secure file system cannot be accessed until BlackBerry Dynamics authorization processing is complete, see under authorize (GDiOS) .
Every operating system has a maximum supported length for the names of files and directories. For example, iOS 11 supports a maximum length of 255 bytes, given by the NAME_MAX constant. The encrypted form of the name of a directory or file will typically be longer than the plaintext, and it is the encrypted form that must be within the limits supported by the operating system. This means that names in the secure file system have a shorter effective maximum supported length. It isn't possible to give a simple maximum but the following should be expected.
- Names that are 16 bytes or longer will be increased by a factor of 4:3 approximately.
- Shorter names will be increased to a length of 20 bytes approximately.
Encryption and decryption is transparent to the application code:
- The application passes its data to a file writing interface. The BlackBerry Dynamics runtime encrypts the data and stores it on the device.
- When a file-reading interface is utilized, the runtime decrypts and returns the data.
- Path access interfaces accept plaintext parameters for directory and file names. The runtime encrypts the parameter values in order to create paths in the secure store.
- Directory and file names provided as return values are plaintext. The runtime decrypts paths in the secure store in order to generate the return values.
The encryption method used by the BlackBerry Dynamics runtime generally requires that the user has entered a security password, from which an encryption key is derived.
Usage
This class is a subclass of the native NSFileManager class. It should be easy to replace references to NSFileManager with references to GDFileManager, in order to convert application code that utilizes the native file system into code that utilizes the secure file system.
The differences between this class and NSFileManager are:
- Write access is limited to the secure store.
- There is no access to "Ubiquitous" files and directories, i.e. no access to items in "cloud" storage.
- There is no access to native application group containers, which aren't secured by BlackBerry Dynamics. The - containerURLForSecurityApplicationGroupIdentifier: (GDFileManager) function returns the same value as the base class would for an invalid group identifier.
- The secure file system doesn't have a designated temporary directory. The temporaryDirectory property mustn't be used to create paths.
- File Provider extensions aren't supported. The - getFileProviderServicesForItemAtURL:completionHandler: (GDFileManager) interface always fails.
- Returned NSURL values for locations within the secure file system can only be utilized by BlackBerry Dynamics programming interfaces, see below.
- Returned NSString values for paths within the secure file system can only be utilized by BlackBerry Dynamics programming interfaces, see below.
- Error codes could be in the specific GDFileManager error domain, or could be general NS error codes.
The NSURL values returned by functions in this class can only be used to access files and directories by BlackBerry Dynamics programming interfaces. They cannot be used by native interfaces, such as NSInputStream nor stringWithContentsOfURL: for example.
The NSString values for paths returned by functions in this class can only be used to access files and directories by BlackBerry Dynamics programming interfaces. They cannot be used by native interfaces, such as stringByResolvingSymlinksInPath, nor dataWithContentsOfFile: for example.
To read and write files in the secure store, use functions in this class or in one of the other BlackBerry Dynamics programming interfaces. For example:
Don't use file-reading and -writing functions in the native NS classes to access files in the secure store.
Best practice for building paths for use with this class is as follows. First use an NSSearchPathDirectory value to generate a path prefix, for example by calling the NSSearchPathForDirectoriesInDomains: function. Then append to the prefix, for example by calling the NSString stringByAppendingPath: function or the NSURL URLByAppendingPathComponent function.
The functions in this API utilize NSError in a conventional way. Function calls accept as a parameter the location of a pointer to NSError, i.e. a pointer to a pointer, with type NSError**. The location may be nil. If the location isn't nil, and an error occurs, the BlackBerry Dynamics runtime overwrites the pointer at the specified location with the address of an object that describes the error that occurred.
The documentation of this class includes descriptions for functions and other elements of the programming interface that:
- Have different semantics to the corresponding elements in the base class.
- Are not present in the base class.
Elements of the base class that are overriden, but have the same semantics, are listed in the documentation of this class, but not described further. Elements of the base class that aren't overriden are not listed. See the documentation of the base class, NSFileManager, for full descriptions.
- See also
- NSFileManager class reference on the apple.com developer website.
-
Error Handling Programming Guide on the apple.com developer website.
-
NSSearchPathForDirectoriesInDomains reference documentation on the apple.com developer website.
-
GDFileManager Error Domain
-
Secure SQL Database API
-
GDPersistentStoreCoordinator
-
GDFileHandle
-
C Language Programming Interface List
Code Snippets
The following code snippets illustrate some common tasks.
Simple conversion to secure file system
The following code snippets illustrate simple conversion of a function that uses the native file system to use the secure files system instead.
The second function in the snippet is the original; the third is the converted version. The changed line is flagged with a comment. The first function in the snippet is a utility that is used by both the original and the converted function, with no changes.
- (NSString *)documentsFolderPathForFileNamed:(NSString *)fileName
{
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:fileName];
}
- (BOOL)writeMyFile
{
NSString *text = @"Text that is not protected.";
NSData *fileData = [text dataUsingEncoding:NSUTF8StringEncoding];
BOOL fileCreated =
createFileAtPath:[self
documentsFolderPathForFileNamed:@"MyFile.txt"]
contents:fileData
attributes:nil];
return fileCreated;
}
- (BOOL)writeMyFileGD
{
NSString *text = @"Text to be protected by BlackBerry Dynamics.";
NSData *fileData = [text dataUsingEncoding:NSUTF8StringEncoding];
BOOL fileCreated =
createFileAtPath:[self
documentsFolderPathForFileNamed:@"MyFile.txt"]
contents:fileData
attributes:nil];
return fileCreated;
}
GDFileManager * defaultManager()