The Encrypted Files module allows Drupal 7 to encrypt files uploaded by users, and to decrypt these files for user download. Dynamic encryption of your uploaded files on-disk increases the security of their contents.

The module creates a custom read/write file stream wrapper, and provides a new download method that sits alongside Drupal's default public and private methods. You can make Encrypted Files the default download method for all files, apply it to specific file-type fields, and also password protect files individually.

Important note regarding file access:
Though Encrypted Files encrypts your files for storage, it does not provide any access checking for file downloads. Rather, it simply gives each encrypted file the same access as the node it is attached to. This allows you to leverage the Node Access System, permissions, and other access techniques available to Drupal to control access to encrypted files by restricting viewing access to their nodes.

Installation

Download and enable the AES Encryption module first. Then download and enable Encrypted Files like any other module. For more info on installing modules, see: http://drupal.org/documentation/install/modules-themes/modules-7

Requirements

To install and function correctly, Encrypted Files must:

  • Be able to write to a site's private files directory
  • Be able to create a directory within private files to store encrypted files

The module will report on install and on the site status report if it encounters problems with the above. If you encounter such issues, check:

  • That you have configured your private files directory at admin/config/media/file-system. The setting is "Private file system path"
  • That your private files directory is writable by your web server. The proper permission scheme for this directory depends on the configuration of your server and the user it's running under.

Note: By default, AES Encryption enables on install a feature that encodes new users' passwords with an algorithm that allows administrators to decrypt them. If you do not want this functionality, you can disable it by visiting admin/settings/aes and unchecking "Create AES passwords"

Usage

You can use Encrypted Files by selecting it as the default download method for all your site's files or as the upload destination for specific file fields. For convenience, the module provides two file field instances that you can add to your entities:

  • Encrypted File (encrypted_files_basic_file)
    Stores files using the site-wide encryption keys and the default file field widget and formatter
  • Password-protected File (encrypted_files_pass_protected)
    Stores each file with its own user-supplied encryption password and uses a custom widget and formatter for uploading and downloading files with passwords

Setting Encrypted Files as the default download method

Encrypting all files uploaded to your site is easy. Just set your site's default download method to "Private, encrypted files".

Using the supplied file field instances

The best way to use Encrypted Files is to add a file field that uses it as the upload destination to a content type. You may want to create a new content type specifically for encrypted files or attach the fields to an existing content type. The quickest way to do this is to use the file field instances that come with the module. Simply navigate to the manage fields section of your content type's configuration and scroll to the add existing field input. From the select an existing field select list, choose either File: encrypted_files_basic_file (Encrypted File) or File: encrypted_files_pass_protected (Password-protected File). Click save and customize any relevant file field settings on the next form, such as allowed file extensions and maximum upload size.

Creating new file fields

You can also create new file fields that use encryption. For a field that simply uses the site-wide encryption keys, just create a file type field with file as the widget and Encrypted Files as the upload destination. For a password-protected file field, create a file type field with password-protected file as the widget, Encrypted Files as the upload destination, and password-protected file as the format (on the manage display page).

Note: Currently, the module only supports password-protected file fields with single values. Multi-value password-protected fields will not work properly. Issue #1957112: Get password widget to work with multi-value fields documents this with the hopes of adding support in the near future.

Tips for optimal security

While Encrypted Files does a good job of securing files on your server, you can take steps to ensure other aspects of your environment contribute to optimal security. As the module stores one of its encryption keys and all encrypted file uploads with the private file system directory, you should make sure this directory and the files within it have the strictest file permission settings possible. While your site/server must be able to read from and write to these files, you should prevent any other users on your server from accessing them. Again, this depends on how your server is configured, such as what user your Drupal site is running under. For example, if Drupal is running as the same user that owns the private files directory and the files within it, you can set the directory and directories within it to have the Linux/Unix permission level 700 and all the files to have 600. This will deny access to all users except the owner. Following other security best practices, such as using a strong password for your server and logging into it using a secure mechanism like key-based SSH, will increase your security further.

In addition to protecting the private files on your server, you should also take steps to secure your Drupal database, as this is where the module stores its second encryption key. Steps you can take include using a strong password for the database user that your Drupal site uses, allowing only that user to access Drupal's database, and setting strict permissions on your settings.php file.

The above tips will help you protect the site-wide encryption keys that Encrypted Files uses for encryption. Keeping malicious users from accessing these keys is of prime importance to keeping your encrypted files safe. The module can, however, use per-file passwords instead of the site wide keys (see the Usage section above). Such files will be safe even if the site-wide encryption keys are compromised, but you should still advise your users to choose strong passwords when uploading password-protected files. You probably should also make it clear that these files cannot be recovered without their passwords, so special care should be taken to make sure the passwords aren't forgotten.

Comments

tryitonce’s picture

Encrypted Files also adds the option of storing all files as Private, encrypted files - under ..../admin/config/media/file-system.
If you activate this you may find, that images your upload will not be visible any more as they are encrypted. So, during uploading with IMCE and placing them with an editor on a page (and on the page after saving) they are not showing up.
I still need to experiment with this and for the time being returned my setting to "Private local files served by Drupal."
- see also Adding File Encryption to exisitng Drupal 7 site

koushikuk’s picture

I have used this module by created a file field in user profile and followed the encryption configuration rules. But the problem is that admin is unable to download the encrypted file which was uploaded by him though he has permission. After clicking on the uploaded file link a pop up window opens and it says that "You are not authorized to access this page." It seems that it is a permission issue, but not sure why it is happening. Please help..

gonchiponchi’s picture

I've the same problem described above, i don't know what's wrong, the files are encrypted but i can't access them by drupal.

vaseem’s picture

You need to implement this function to download encrypted files. This function returning an array of file headers.

/** 
 * Implements hook_file_download().
 */
function mymodule_file_download($uri) {
  $headers = array();
  if (isset($uri)) {
    module_load_include('inc', 'encrypted_files', 'includes/encrypted_files.file');
    $file = encrypted_files_load_file_by_uri($uri); // return file object depending on data stored in db
    if (isset($file)) {
      $headers = file_get_content_headers($file); 
    }
  }
  return $headers;
}