diff --git a/API.txt b/API.txt index 895094b..73d5e9e 100644 --- a/API.txt +++ b/API.txt @@ -133,4 +133,28 @@ Arguments: (optional) bool $ignore_implementation Forces aes_make_iv to create and store a new IV even if the phpseclib implementation is used. Returns: -nothing \ No newline at end of file +nothing + +--------------------------------------------------------------------------------- +Hook: +void hook_aes_config_change($decrypt_params, $encrypt_params) + +Description: +This hook provide ability for developers to reencrypt data when aes configuration changed. + +Arguments: +$decrypt_params An associative array with decrypt arguments containing the following keys: + - base64encode bool Whether this encrypted string is base64 encoded or not. + - custom_key string Use this as the key rather than the stored one for this operation. + - custom_cipher string Use this cipher rather than the default one. (only with Mcrypt - ignored with phpseclib) + - custom_iv Use string this initialization vector instead of the default one. + - custom_implementation string Can be "phpseclib" or "mcrypt". Warning: Does not check if the requested implementation actually exists. + +$encrypt_params An associative array with encrypt arguments containing the following keys: + - bool $base64encode bool Whether to return the string base64 encoded (recommended for database insertion). + - $custom_key string Use this as the key rather than the stored one for this operation. + - $custom_cipher string Use this cipher rather than the default one. (only with Mcrypt - ignored with phpseclib) + - $custom_iv string Use this initialization vector instead of the default one. + - $custom_implementation string Can be "phpseclib" or "mcrypt". Warning: Does not check if the requested implementation actually exists. + +See: aes_aes_config_change(); diff --git a/aes.module b/aes.module index 74ca64c..dca70ce 100644 --- a/aes.module +++ b/aes.module @@ -310,6 +310,7 @@ function aes_config_submit($form, &$form_state) { 'custom_implementation' => NULL, ); $do_reencypt = FALSE; + // If the cipher has changed... if ($form_state['values']['aes_cipher'] != variable_get("aes_cipher", "rijndael-128")) { variable_set("aes_cipher", $form_state['values']['aes_cipher']); @@ -356,6 +357,22 @@ function aes_config_submit($form, &$form_state) { } if ($do_reencypt) { + // Calling custom hook_aes_config_change from each module which implement this hook. + foreach (module_implements('aes_config_change') as $module) { + $function = $module . '_aes_config_change'; + $function($decrypt_params, $encrypt_params); + } + } + + variable_set("aes_viewing_method", $form_state['values']['view_method']); + +} + +/** + * Implements hook_aes_config_change(). + */ +function aes_aes_config_change($decrypt_params, $encrypt_params) { + // Re encrypt user paswords. $accounts = db_select('aes_passwords', 'p') ->fields('p', array('uid', 'pass')) ->condition('uid', 0, '!=') @@ -376,10 +393,6 @@ function aes_config_submit($form, &$form_state) { if (count($accounts)) { drupal_set_message(t("Updated the passwords of @updates_num users because of a change in encryption settings.", array('@updates_num' => count($accounts)))); } - } - - variable_set("aes_viewing_method", $form_state['values']['view_method']); - } /**