function _acquia_search_derived_key in Acquia Connector 7
Same name and namespace in other branches
- 7.3 acquia_search/acquia_search.module \_acquia_search_derived_key()
- 7.2 acquia_search/acquia_search.module \_acquia_search_derived_key()
Derive a key for the solr hmac using the information shared with acquia.com.
3 calls to _acquia_search_derived_key()
- AcquiaSearchTest::testHMAC in acquia_search/
tests/ acquia_search.test - acquia_search_authenticator in acquia_search/
acquia_search.module - Creates an authenticator based on a data string and HMAC-SHA1.
- acquia_search_valid_response in acquia_search/
acquia_search.module - Validate the authenticity of returned data using a nonce and HMAC-SHA1.
File
- acquia_search/
acquia_search.module, line 255 - Integration between Acquia Drupal and Acquia's hosted solr search service.
Code
function _acquia_search_derived_key($env_id = NULL) {
static $derived_key = array();
if (empty($env_id)) {
$env_id = 0;
}
if (!isset($derived_key[$env_id])) {
// If we set an explicit environment, check if this needs to overridden
// Use the default
$identifier = acquia_agent_settings('acquia_identifier');
$key = acquia_agent_settings('acquia_key');
// See if we need to overwrite these values
if ($env_id) {
// Load the explicit environment and a manually set search key.
if ($search_key = apachesolr_environment_variable_get($env_id, 'acquia_search_key')) {
$derived_key[$env_id] = $search_key;
}
}
// In any case, this is equal for all subscriptions. Also
// even if the search sub is different, the main subscription should be
// active
$subscription = acquia_agent_settings('acquia_subscription_data');
// We use a salt from acquia.com in key derivation since this is a shared
// value that we could change on the AN side if needed to force any
// or all clients to use a new derived key. We also use a string
// ('solr') specific to the service, since we want each service using a
// derived key to have a separate one.
if (empty($subscription['active']) || empty($key) || empty($identifier)) {
// Expired or invalid subscription - don't continue.
$derived_key[$env_id] = '';
}
elseif (!isset($derived_key[$env_id])) {
$salt = isset($subscription['derived_key_salt']) ? $subscription['derived_key_salt'] : '';
$derivation_string = $identifier . 'solr' . $salt;
$derived_key[$env_id] = hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $key);
}
}
return $derived_key[$env_id];
}