cvs: pear /Net_SMTP SMTP.php package.xml
| From: | Jon Parise | Date: | Sun, 12 Jan 2003 23:21:01 +0000 |
| Subject: | cvs: pear /Net_SMTP SMTP.php package.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8207@lists.php.net to get a copy of this message | ||
jon Sun Jan 12 18:21:01 2003 EDT
Modified files:
/pear/Net_SMTP SMTP.php package.xml
Log:
Adding preliminary CRAM-MD5 authentication support.
Submitted by: Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>
Index: pear/Net_SMTP/SMTP.php
diff -u pear/Net_SMTP/SMTP.php:1.19 pear/Net_SMTP/SMTP.php:1.20
--- pear/Net_SMTP/SMTP.php:1.19 Fri Jan 10 16:17:05 2003
+++ pear/Net_SMTP/SMTP.php Sun Jan 12 18:21:00 2003
@@ -82,7 +82,7 @@
* The list of supported authentication methods, ordered by preference.
* @var string
*/
- var $_auth_methods = array('LOGIN', 'PLAIN');
+ var $_auth_methods = array('CRAM-MD5', 'LOGIN', 'PLAIN');
/**
* Constructor
@@ -346,6 +346,9 @@
}
switch ($method) {
+ case 'CRAM-MD5':
+ $result = $this->_authCRAM_MD5($uid, $pwd);
+ break;
case 'LOGIN':
$result = $this->_authLogin($uid, $pwd);
break;
@@ -363,6 +366,70 @@
}
return true;
+ }
+
+ /**
+ * Generate an HMAC MD5 digest string for the given key and data.
+ *
+ * This code was stolen from the Auth_SASL class.
+ *
+ * @author Richard Heyes <richard@php.net>
+ *
+ * @param string $key The secret key
+ * @param string $data The data to protect
+ * @return string The HMAC MD5 digest
+ */
+ function _HMAC_MD5($key, $data)
+ {
+ if (strlen($key) > 64) {
+ $key = pack('H32', md5($pass));
+ }
+ if (strlen($key) < 64) {
+ $key = str_pad($key, 64, chr(0));
+ }
+
+ $k_ipad = '';
+ $k_opad = '';
+
+ for ($i = 0; $i < 64; $i++) {
+ $byte = ord($key{$i});
+ $k_ipad .= chr($byte ^ 0x36);
+ $k_opad .= chr($byte ^ 0x5C);
+ }
+
+ $inner = pack('H32', md5($k_ipad . $data));
+ $digest = md5($k_opad . $inner);
+
+ return $digest;
+ }
+
+ /* Authenticates the user using the CRAM-MD5 method.
+ *
+ * @param string The userid to authenticate as.
+ * @param string The password to authenticate with.
+ *
+ * @return mixed Returns a PEAR_Error with an error message on any
+ * kind of failure, or true on success.
+ * @access private
+ */
+ function _authCRAM_MD5($uid, $pwd)
+ {
+ if (PEAR::isError($error = $this->_put('AUTH', 'CRAM-MD5'))) {
+ return $error;
+ }
+ if (PEAR::isError($error = $this->_parseResponse(334))) {
+ return $error;
+ }
+
+ $challenge = base64_decode($this->_arguments[0]);
+ $auth_str = base64_encode($uid . ' ' .
+ $this->_HMAC_MD5($pwd, $challenge));
+ if (PEAR::isError($error = $this->_put($auth_str))) {
+ return $error;
+ }
+ if (PEAR::isError($error = $this->_parseResponse(235))) {
+ return $error;
+ }
}
/**
Index: pear/Net_SMTP/package.xml
diff -u pear/Net_SMTP/package.xml:1.11 pear/Net_SMTP/package.xml:1.12
--- pear/Net_SMTP/package.xml:1.11 Fri Jan 10 16:44:35 2003
+++ pear/Net_SMTP/package.xml Sun Jan 12 18:21:00 2003
@@ -27,7 +27,7 @@
<date>2003-XX-XX</date>
<notes>
- The SMTP server's SIZE capability is now honored.
-- Improved support for SMTP authentication (LOGIN, PLAIN).
+- Improved support for SMTP authentication (LOGIN, PLAIN, CRAM-MD5).
- Overhauled the server response parsing system.
- Added optional debugging output (enabled via setDebug()).
- A timeout value can now be specified for the socket connection.