You are here

public function SearchApiAcquiaSearchConnection::getDerivedKey in Acquia Search for Search API 7.2

Derive a key for the solr hmac using the information shared with acquia.com.

See also

_acquia_search_derived_key()

2 calls to SearchApiAcquiaSearchConnection::getDerivedKey()
SearchApiAcquiaSearchConnection::authenticator in includes/v2/SearchApiAcquiaSearchConnection.php
Creates an authenticator based on a data string and HMAC-SHA1.
SearchApiAcquiaSearchConnection::validResponse in includes/v2/SearchApiAcquiaSearchConnection.php
Validate the authenticity of returned data using a nonce and HMAC-SHA1.

File

includes/v2/SearchApiAcquiaSearchConnection.php, line 53

Class

SearchApiAcquiaSearchConnection
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

public function getDerivedKey() {
  if (!isset($this->derivedKey)) {
    $key = acquia_agent_settings('acquia_key');
    $subscription = acquia_agent_settings('acquia_subscription_data');
    $identifier = acquia_agent_settings('acquia_identifier');

    // 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.
      $this->derivedKey = '';
    }
    else {
      $salt = isset($subscription['derived_key_salt']) ? $subscription['derived_key_salt'] : '';
      $derivation_string = $identifier . 'solr' . $salt;
      $this->derivedKey = hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $key);
    }
  }
  return $this->derivedKey;
}