You are here

README.txt in Real AES 8

Same filename and directory in other branches
  1. 8.2 README.txt
  2. 7.2 README.txt
  3. 7 README.txt
# Real AES

## Introduction

Real AES provides an encryption method plugin for the Encrypt module
(https://drupal.org/project/encrypt).

Defuse PHP-encryption provides authenticated encryption via an Encrypt-then-MAC
scheme. AES-128 CBC is the symmetric encryption algorithm, SHA-256 the hash
algorithm for the HMAC. IV's are automatically and randomly generated. You do
not need to manage the IV separately, as it is included in the ciphertext.

Ciphertext format is: HMAC || iv || ciphertext

The HMAC verifies both IV and Ciphertext.

## Authenticated encryption

Authenticated encryption ensures data integrity of the ciphertext. When
decrypting, integrity is checked first. Further decrypting operations will only
be executed when the integrity check passes.
This prevents certain ciphertext attacks on AES CBC.

## Differences to the AES module:

By default:

- Uses AES
- Only one encryption mode
- No IV reuse
- Authenticated encryption (prevents ciphertext tampering attacks eg the
  Padding Oracle "Vaudenay" attack)
- No silent key replacement
- No database keys
- No generation of weak keys
- Unambiguous padding, allowing correct decryption of binary data ending in 0x00
- Will not accept "keys" of incorrect length
- No support for AES encryption of user passwords
- Fails hard when there are problems with encryption or decryption

## Requirements

The Defuse PHP-Encryption library from https://github.com/defuse/php-encryption.
Install it via Composer, preferably by using the Composer Manager module:
Make sure you have the composer_manager module installed according to its
README.txt, so you will be able to run the "composer drupal-update" command.
This will download the Defuse PHP-Encryption library to your Drupal
installation.

## General configuration

If you need the defuse php-encryption library, or use the Encrypt plugin just
enable Real AES and install the library.

### Generate a key

To generate a 128 bits random key, use the following command on the Unix CLI:

dd if=/dev/urandom bs=16 count=1 > /path/to/aes.key

This file MUST be stored outside of the docroot. Copy this file to an
off-server, safe backup. If you lose the key, you will not be able to decrypt
encrypted information in the database.

If you do not have access to dd, generate the file using drush on a working
Drupal installation:

drush php-eval 'echo drupal_random_bytes(16);' > /path/to/aes.key

### Storing the key for using it with Real AES

Use the Key module (https://www.drupal.org/project/key) to store your
generated key. Used in combination with the Encrypt module, you'll be able to
select your key when configuring an encryption profile using the Real AES
encryption method.

It is important to ensure a proper key. We suggest to use the "File" key
provider, but generate the key yourself.

dd if=/dev/urandom bs=16 count=1 > /path/to/encrypt_key.key

or

drush php-eval 'echo drupal_random_bytes(16);' > /path/to/encrypt_key.key

Supply the key provider with the path to this file.

## Encrypt plugin configuration

Real AES adds the "Authenticated AES" encryption method as a selectable option
when creating a new encryption profile with the Encrypt module. Use it in
combination with the generated key, stored by the Key module (see above).

## Usage

Use the Authenticated AES encryption method with the Encrypt module
(https://drupal.org/project/encrypt).

## Further reading

* Encryption in PHP:
  https://defuse.ca/secure-php-encryption.htm
* Defuse php-encryption readme:
  https://github.com/defuse/php-encryption/blob/master/README.md
* Authenticated encryption:
  https://en.wikipedia.org/wiki/Authenticated_encryption
* CBC Block mode:
  https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29
* HMAC:
  https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
* SHA-256:
  https://en.wikipedia.org/wiki/SHA-2

## Key management

Key storage on the webserver is one of the weak points of this system. Consider
using Encrypt with a key management solution.

One example is https://www.drupal.org/project/townsec_key. We have not reviewed
this module or the system it connects with.

## Frequently given answers

Q Why not use AES-GCM?
A This is currently not supported by the php openssl library.

Q No AES-256?
A No.

Q But, why no AES-256??
A You won't need it unless your threat model includes adversaries having a
working and fast quantum computer implementing Grover's algorithm.

## Credits

This module was created by LimoenGroen - https://limoengroen.nl - after
carefully considering the various encryption modules and libraries.

The port to Drupal 8 was performed by Sven Decabooter, supported by Acquia.

The library doing the actual work, Defuse PHP encryption, is authored by
Taylor Hornby and Scott Arciszewski.

## Future plans:

Patch the module encrypted_files to use Defuse PHP-encryption and properly
derive a _key_ from a password.

File

README.txt
View source
  1. # Real AES
  2. ## Introduction
  3. Real AES provides an encryption method plugin for the Encrypt module
  4. (https://drupal.org/project/encrypt).
  5. Defuse PHP-encryption provides authenticated encryption via an Encrypt-then-MAC
  6. scheme. AES-128 CBC is the symmetric encryption algorithm, SHA-256 the hash
  7. algorithm for the HMAC. IV's are automatically and randomly generated. You do
  8. not need to manage the IV separately, as it is included in the ciphertext.
  9. Ciphertext format is: HMAC || iv || ciphertext
  10. The HMAC verifies both IV and Ciphertext.
  11. ## Authenticated encryption
  12. Authenticated encryption ensures data integrity of the ciphertext. When
  13. decrypting, integrity is checked first. Further decrypting operations will only
  14. be executed when the integrity check passes.
  15. This prevents certain ciphertext attacks on AES CBC.
  16. ## Differences to the AES module:
  17. By default:
  18. - Uses AES
  19. - Only one encryption mode
  20. - No IV reuse
  21. - Authenticated encryption (prevents ciphertext tampering attacks eg the
  22. Padding Oracle "Vaudenay" attack)
  23. - No silent key replacement
  24. - No database keys
  25. - No generation of weak keys
  26. - Unambiguous padding, allowing correct decryption of binary data ending in 0x00
  27. - Will not accept "keys" of incorrect length
  28. - No support for AES encryption of user passwords
  29. - Fails hard when there are problems with encryption or decryption
  30. ## Requirements
  31. The Defuse PHP-Encryption library from https://github.com/defuse/php-encryption.
  32. Install it via Composer, preferably by using the Composer Manager module:
  33. Make sure you have the composer_manager module installed according to its
  34. README.txt, so you will be able to run the "composer drupal-update" command.
  35. This will download the Defuse PHP-Encryption library to your Drupal
  36. installation.
  37. ## General configuration
  38. If you need the defuse php-encryption library, or use the Encrypt plugin just
  39. enable Real AES and install the library.
  40. ### Generate a key
  41. To generate a 128 bits random key, use the following command on the Unix CLI:
  42. dd if=/dev/urandom bs=16 count=1 > /path/to/aes.key
  43. This file MUST be stored outside of the docroot. Copy this file to an
  44. off-server, safe backup. If you lose the key, you will not be able to decrypt
  45. encrypted information in the database.
  46. If you do not have access to dd, generate the file using drush on a working
  47. Drupal installation:
  48. drush php-eval 'echo drupal_random_bytes(16);' > /path/to/aes.key
  49. ### Storing the key for using it with Real AES
  50. Use the Key module (https://www.drupal.org/project/key) to store your
  51. generated key. Used in combination with the Encrypt module, you'll be able to
  52. select your key when configuring an encryption profile using the Real AES
  53. encryption method.
  54. It is important to ensure a proper key. We suggest to use the "File" key
  55. provider, but generate the key yourself.
  56. dd if=/dev/urandom bs=16 count=1 > /path/to/encrypt_key.key
  57. or
  58. drush php-eval 'echo drupal_random_bytes(16);' > /path/to/encrypt_key.key
  59. Supply the key provider with the path to this file.
  60. ## Encrypt plugin configuration
  61. Real AES adds the "Authenticated AES" encryption method as a selectable option
  62. when creating a new encryption profile with the Encrypt module. Use it in
  63. combination with the generated key, stored by the Key module (see above).
  64. ## Usage
  65. Use the Authenticated AES encryption method with the Encrypt module
  66. (https://drupal.org/project/encrypt).
  67. ## Further reading
  68. * Encryption in PHP:
  69. https://defuse.ca/secure-php-encryption.htm
  70. * Defuse php-encryption readme:
  71. https://github.com/defuse/php-encryption/blob/master/README.md
  72. * Authenticated encryption:
  73. https://en.wikipedia.org/wiki/Authenticated_encryption
  74. * CBC Block mode:
  75. https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher_Block_Chaining_.28CBC.29
  76. * HMAC:
  77. https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
  78. * SHA-256:
  79. https://en.wikipedia.org/wiki/SHA-2
  80. ## Key management
  81. Key storage on the webserver is one of the weak points of this system. Consider
  82. using Encrypt with a key management solution.
  83. One example is https://www.drupal.org/project/townsec_key. We have not reviewed
  84. this module or the system it connects with.
  85. ## Frequently given answers
  86. Q Why not use AES-GCM?
  87. A This is currently not supported by the php openssl library.
  88. Q No AES-256?
  89. A No.
  90. Q But, why no AES-256??
  91. A You won't need it unless your threat model includes adversaries having a
  92. working and fast quantum computer implementing Grover's algorithm.
  93. ## Credits
  94. This module was created by LimoenGroen - https://limoengroen.nl - after
  95. carefully considering the various encryption modules and libraries.
  96. The port to Drupal 8 was performed by Sven Decabooter, supported by Acquia.
  97. The library doing the actual work, Defuse PHP encryption, is authored by
  98. Taylor Hornby and Scott Arciszewski.
  99. ## Future plans:
  100. Patch the module encrypted_files to use Defuse PHP-encryption and properly
  101. derive a _key_ from a password.