Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16488] iOS: Property List lacks of Secure Class Protection - NSFileProtectionKey

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-06-03T03:01:07.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sRelease 4.1.0
ComponentsiOS
LabelssupportTeam
ReporterMarco Cota
AssigneeChee Kiat Ng
Created2014-02-20T23:05:26.000+0000
Updated2015-07-07T20:37:31.000+0000

Description

Issue

After a revision from customer Vulnerability assessment team they have raised a low priority issue in reference that the Property List lacks of Secure Class Protection - NSFileProtectionKey The list of files they are referring to is basically everything in the installed package on the device (Cache.db, Cookies.binarycookies, etc.)

Description

On iOS, every file is encrypted with an unique encryption key as illustrated in the image. The content of a file is encrypted with a per-file key, which is wrapped with a class key (data protection class key) and stored in a file metadata, which is in turn encrypted with the file system key (EMF key). The file system key is generated from the hardware UID. UID is unique per device and it is embedded in hardware and inaccessible to code running on CPU. A file which is encrypted only with the file system key, upon physical access to the device custom ramdisk techniques can be used to steal the file from passcode protected devices. To overcome this problem Data protection was introduced. Data protection protects the data at rest on iOS devices using encryption keys that are tied to the device passcode and UID. So if the file is protected with a data protection class and the user sets a passcode for the device, an attacker cannot access the file using custom ram disk technique until he knows the passcode. Data protection provides another layer of security to files by encrypting them with a passcode generated key. File protection is enabled by setting an accessibility constant to NSFileProtectionKey file attribute. Later the files are encrypted with a protection class key respective to the accessibility constant marked for that file. Ex: If a file is marked with NSProtectionComplete accessibility constant then the file is encrypted with Class 1 protection class key and it is available only when the user unlocks the device. If a file is created without specifying any accessibility constant then the file is marked as NSProtectionNone and it is accessible even the device is locked . List of accessibility constants available for files are shown in the below table.

iOS Reference

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

Comments

  1. Marco Cota 2014-03-18

    [~ingo] Do we have any updates on this?
  2. Sabil Rahim 2014-03-19

    [~ingo] From my initial looks. In our SDK whenever we create a Directory or a File we do not pass in any kind of FIleProtection attribute to it. By default as files are created with NSProtectionNone by OS. This would be a new feature to be added to the SDK.
  3. Ingo Muschenetz 2014-07-10

    Removing due date as this would appear in the next major release. Considering it for 3.4.0.
  4. Chee Kiat Ng 2015-05-27

    PR here: https://github.com/appcelerator/titanium_mobile/pull/6875 Added 2 new methods: *setProtectionKey()* *getProtectionKey()* To allow setting of NSFileProtectionKey to individual files for iOS. *Note* Setting of NSFileProtectionKey only works on iOS device, not simulator.

    Sample Code:

       
       var win = Ti.UI.createWindow({
         backgroundColor: 'white',
         layout: 'vertical'
       });
        
       var button1 = Ti.UI.createButton({
           title: 'create File',
           top: 100
       });
       var button2 = Ti.UI.createButton({
           title: 'set file attributes',
           top: 100
       });
       var button3 = Ti.UI.createButton({
           title: 'get file attributes',
           top: 100
       });
        
       button1.addEventListener('click', function(e) {
           //create file
           var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "textfile.txt");
           file.write('test');
       });
        
       button2.addEventListener('click', function(e) {
           //file attributes
           file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "textfile.txt");
           var result = file.setProtectionKey(Ti.Filesystem.IOS_FILE_PROTECTION_NONE);
       //  var result = file.setProtectionKey(Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE);
       //  var result = file.setProtectionKey(Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN);
       //  var result = file.setProtectionKey(Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION);
           if (result === true) {
               alert('success');
           }
           else {
               alert('failed');
           }
       });
        
       button3.addEventListener('click', function(e) {
           //file attributes
           file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "textfile.txt");
           var currentProtectionKey = file.getProtectionKey();
           if (currentProtectionKey == null) {
               alert('error getting protection key.');
           };
           if (currentProtectionKey == Ti.Filesystem.IOS_FILE_PROTECTION_NONE) {
               alert('None');
           };
           if (currentProtectionKey == Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE) {
               alert('Complete');
           };
           if (currentProtectionKey == Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN) {
               alert('Complete unless open');
           };
           if (currentProtectionKey == Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION) {
               alert('Complete until first user authentication');
           };
       
       });
        
       win.add(button1);
       win.add(button2);
       win.add(button3);
       win.open();
       

    Steps to test:

    1. Run sample code on device 2. *create file* 3. *set file attributes* 4. *get file attributes* 5. Repeat steps 3-4, using different protectionKey listed below: - Ti.Filesystem.IOS_FILE_PROTECTION_NONE - Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE - Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN - Ti.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION

    Expected Result:

    See alert dialog displaying the corresponding fileProtectionKey set
  5. Chee Kiat Ng 2015-06-03

    PR reviewed and merged by Pedro.
  6. Eric Wieber 2015-07-07

    Verified fixed, using: MacOS 10.11 Studio 4.1.0.201507061821 Ti SDK 4.2.0 Appc NPM 4.1.0-1 Appc CLI 4.1.0-5 Ti CLI 4.0.1 Alloy 1.6.2 Node v0.10.37 Java 1.7.0_45 preproduction Able to correctly get the file protection key of the created file.

JSON Source