[ Index ] |
MailPress 7.2 |
[ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] [ Statistics ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of SwiftMailer. 5 * (c) 2004-2009 Chris Corbyn 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * Handles CRAM-MD5 authentication. 13 * 14 * @author Chris Corbyn 15 */ 16 class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport_Esmtp_Authenticator 17 { 18 /** 19 * Get the name of the AUTH mechanism this Authenticator handles. 20 * 21 * @return string 22 */ 23 public function getAuthKeyword() 24 { 25 return 'CRAM-MD5'; 26 } 27 28 /** 29 * {@inheritdoc} 30 */ 31 public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password) 32 { 33 try { 34 $challenge = $agent->executeCommand("AUTH CRAM-MD5\r\n", [334]); 35 $challenge = base64_decode(substr($challenge, 4)); 36 $message = base64_encode( 37 $username.' '.$this->getResponse($password, $challenge) 38 ); 39 $agent->executeCommand(sprintf("%s\r\n", $message), [235]); 40 41 return true; 42 } catch (Swift_TransportException $e) { 43 $agent->executeCommand("RSET\r\n", [250]); 44 45 throw $e; 46 } 47 } 48 49 /** 50 * Generate a CRAM-MD5 response from a server challenge. 51 * 52 * @param string $secret 53 * @param string $challenge 54 * 55 * @return string 56 */ 57 private function getResponse($secret, $challenge) 58 { 59 if (strlen($secret) > 64) { 60 $secret = pack('H32', md5($secret)); 61 } 62 63 if (strlen($secret) < 64) { 64 $secret = str_pad($secret, 64, chr(0)); 65 } 66 67 $k_ipad = substr($secret, 0, 64) ^ str_repeat(chr(0x36), 64); 68 $k_opad = substr($secret, 0, 64) ^ str_repeat(chr(0x5C), 64); 69 70 $inner = pack('H32', md5($k_ipad.$challenge)); 71 $digest = md5($k_opad.$inner); 72 73 return $digest; 74 } 75 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue May 19 15:55:14 2020 | Cross-referenced by PHPXref 0.7.1 |