Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CramMd5Authenticator.php

class CramMd5Authenticator

Handles CRAM-MD5 authentication.

@author Chris Corbyn

Hierarchy

  • class \Symfony\Component\Mailer\Transport\Smtp\Auth\CramMd5Authenticator implements \Symfony\Component\Mailer\Transport\Smtp\Auth\AuthenticatorInterface

Expanded class hierarchy of CramMd5Authenticator

File

vendor/symfony/mailer/Transport/Smtp/Auth/CramMd5Authenticator.php, line 22

Namespace

Symfony\Component\Mailer\Transport\Smtp\Auth
View source
class CramMd5Authenticator implements AuthenticatorInterface {
    public function getAuthKeyword() : string {
        return 'CRAM-MD5';
    }
    
    /**
     * @see https://www.ietf.org/rfc/rfc4954.txt
     */
    public function authenticate(EsmtpTransport $client) : void {
        $challenge = $client->executeCommand("AUTH CRAM-MD5\r\n", [
            334,
        ]);
        $challenge = base64_decode(substr($challenge, 4));
        $message = base64_encode($client->getUsername() . ' ' . $this->getResponse($client->getPassword(), $challenge));
        $client->executeCommand(\sprintf("%s\r\n", $message), [
            235,
        ]);
    }
    
    /**
     * Generates a CRAM-MD5 response from a server challenge.
     */
    private function getResponse(string $secret, string $challenge) : string {
        if (!$secret) {
            throw new InvalidArgumentException('A non-empty secret is required.');
        }
        if (\strlen($secret) > 64) {
            $secret = pack('H32', md5($secret));
        }
        if (\strlen($secret) < 64) {
            $secret = str_pad($secret, 64, \chr(0));
        }
        $kipad = substr($secret, 0, 64) ^ str_repeat(\chr(0x36), 64);
        $kopad = substr($secret, 0, 64) ^ str_repeat(\chr(0x5c), 64);
        $inner = pack('H32', md5($kipad . $challenge));
        return md5($kopad . $inner);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CramMd5Authenticator::authenticate public function Overrides AuthenticatorInterface::authenticate
CramMd5Authenticator::getAuthKeyword public function Gets the name of the AUTH mechanism this Authenticator handles. Overrides AuthenticatorInterface::getAuthKeyword
CramMd5Authenticator::getResponse private function Generates a CRAM-MD5 response from a server challenge.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal