You are here

function _acquia_agent_hmac in Acquia Connector 7.3

Same name and namespace in other branches
  1. 6.2 acquia_agent/acquia_agent_streams.inc \_acquia_agent_hmac()
  2. 6 acquia_agent/acquia_agent_streams.inc \_acquia_agent_hmac()
  3. 7 acquia_agent/acquia_agent.module \_acquia_agent_hmac()
  4. 7.2 acquia_agent/acquia_agent.module \_acquia_agent_hmac()

Calculate HMAC.

Calculates a HMAC-SHA1 according to RFC2104 (http://www.ietf.org/rfc/rfc2104.txt). With addition of xmlrpc params.

Parameters

string $key: Key.

int $time: Time.

string $nonce: Nonce.

mixed $params: Params.

Return value

string Response.

7 calls to _acquia_agent_hmac()
acquia_agent_valid_response in acquia_agent/acquia_agent.module
Determine if a response from Acquia is valid.
acquia_connector_test_credentials in acquia_agent/tests/acquia_connector_test.module
Test credentials.
acquia_connector_test_nspi_update in acquia_agent/tests/acquia_connector_test.module
Test update.
acquia_connector_test_subscription in acquia_agent/tests/acquia_connector_test.module
Test subscription.
acquia_connector_test_validate_authenticator in acquia_agent/tests/acquia_connector_test.module
Needs comment.

... See full list

File

acquia_agent/acquia_agent.module, line 905
Acquia Agent securely sends information to Acquia Insight.

Code

function _acquia_agent_hmac($key, $time, $nonce, $params) {
  if (empty($params['rpc_version']) || $params['rpc_version'] < 2) {
    $encoded_params = serialize($params);
    $string = $time . ':' . $nonce . ':' . $key . ':' . $encoded_params;
    return base64_encode(pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $string)))));
  }
  elseif ($params['rpc_version'] == 2) {
    $encoded_params = json_encode($params);
    $string = $time . ':' . $nonce . ':' . $encoded_params;
    return sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $string)));
  }
  else {
    $string = $time . ':' . $nonce;
    return sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $string)));
  }
}