You are here

class CryptConnector in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/CryptConnector.php \Drupal\acquia_connector\CryptConnector
  2. 3.x src/CryptConnector.php \Drupal\acquia_connector\CryptConnector

Class CryptConnector.

Extends secure password hashing functions based on the Portable PHP password hashing framework.

@package Drupal\acquia_connector

Hierarchy

Expanded class hierarchy of CryptConnector

3 files declare their use of CryptConnector
AcquiaSearchTest.php in acquia_search/tests/src/Unit/AcquiaSearchTest.php
NspiController.php in tests/modules/src/Controller/NspiController.php
SearchSubscriber.php in acquia_search/src/EventSubscriber/SearchSubscriber.php

File

src/CryptConnector.php, line 15

Namespace

Drupal\acquia_connector
View source
class CryptConnector extends PhpassHashedPassword {

  /**
   * The string name of a hashing algorithm usable by hash(), like 'sha256'.
   *
   * @var string
   */
  private $algo;

  /**
   * Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to hash.
   *
   * @var string
   */
  private $password;

  /**
   * An existing hash or the output of $this->generateSalt().
   *
   * @var string
   */
  private $setting;

  /**
   * CryptConnector constructor.
   *
   * @param string $algo
   *   The string name of a hashing algorithm usable by hash(), like 'sha256'.
   * @param string $password
   *   Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to
   *   hash.
   * @param string $setting
   *   An existing hash or the output of $this->generateSalt(). Must be at least
   *   12 characters (the settings and salt).
   * @param mixed $extra_md5
   *   (Deprecated) If not empty password needs to be hashed with MD5 first.
   */
  public function __construct($algo, $password, $setting, $extra_md5) {
    $this->algo = $algo;
    $this->password = $password;
    $this->setting = $setting;
  }

  /**
   * Crypt pass.
   *
   * @return string
   *   Crypt password.
   */
  public function cryptPass() {
    $crypt_pass = $this
      ->crypt($this->algo, $this->password, $this->setting);
    return $crypt_pass;
  }

  /**
   * Helper function. Calculate sha1 hash.
   *
   * @param string $key
   *   Acquia Subscription Key.
   * @param string $string
   *   String to calculate hash.
   *
   * @return string
   *   Sha1 string.
   */
  public static function acquiaHash($key, $string) {
    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)));
  }

  /**
   * Derive a key for the solr hmac using a salt, id and key.
   *
   * @param string $salt
   *   Salt.
   * @param string $id
   *   Acquia Subscription ID.
   * @param string $key
   *   Acquia Subscription Key.
   *
   * @return string
   *   Derived Key.
   */
  public static function createDerivedKey($salt, $id, $key) {
    $derivation_string = $id . 'solr' . $salt;
    return hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $key);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CryptConnector::$algo private property The string name of a hashing algorithm usable by hash(), like 'sha256'.
CryptConnector::$password private property Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to hash.
CryptConnector::$setting private property An existing hash or the output of $this->generateSalt().
CryptConnector::acquiaHash public static function Helper function. Calculate sha1 hash.
CryptConnector::createDerivedKey public static function Derive a key for the solr hmac using a salt, id and key.
CryptConnector::cryptPass public function Crypt pass.
CryptConnector::__construct public function CryptConnector constructor. Overrides PhpassHashedPassword::__construct
PasswordInterface::PASSWORD_MAX_LENGTH constant Maximum password length.
PhpassHashedPassword::$countLog2 protected property Specifies the number of times the hashing function will be applied when generating new password hashes. The number of times is calculated by raising 2 to the power of the given value.
PhpassHashedPassword::$ITOA64 public static property Returns a string for mapping an int to the corresponding base 64 character.
PhpassHashedPassword::base64Encode protected function Encodes bytes into printable base 64 using the *nix standard from crypt().
PhpassHashedPassword::check public function Check whether a plain text password matches a hashed password. Overrides PasswordInterface::check
PhpassHashedPassword::crypt protected function Hash a password using a secure stretched hash.
PhpassHashedPassword::enforceLog2Boundaries protected function Ensures that $count_log2 is within set bounds. 1
PhpassHashedPassword::generateSalt protected function Generates a random base 64-encoded salt prefixed with hash settings.
PhpassHashedPassword::getCountLog2 public function Parses the log2 iteration count from a stored hash or setting string.
PhpassHashedPassword::hash public function Hash a password using a secure hash. Overrides PasswordInterface::hash
PhpassHashedPassword::HASH_LENGTH constant The expected (and maximum) number of characters in a hashed password.
PhpassHashedPassword::MAX_HASH_COUNT constant The maximum allowed log2 number of iterations for password stretching.
PhpassHashedPassword::MIN_HASH_COUNT constant The minimum allowed log2 number of iterations for password stretching.
PhpassHashedPassword::needsRehash public function Check whether a hashed password needs to be replaced with a new hash. Overrides PasswordInterface::needsRehash