Skip to content

Commit

Permalink
Fix Bug #2143 and Bug #2154.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/Auth_SASL/trunk@209855 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Anish Mistry committed Mar 22, 2006
1 parent 5a675d5 commit f6e2ad6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion SASL.php
Expand Up @@ -91,7 +91,8 @@ function &factory($type)
}

require_once($filename);
return new $classname();
$obj = new $classname();
return $obj;
}
}

Expand Down
24 changes: 14 additions & 10 deletions SASL/DigestMD5.php
Expand Up @@ -74,7 +74,12 @@ function getResponse($authcid, $pass, $challenge, $hostname, $service, $authzid
$digest_uri = sprintf('%s/%s', $service, $hostname);
$response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid);

return sprintf('username="%s",realm="%s"' . $authzid_string . ',nonce="%s",cnonce="%s",nc="00000001",qop=auth,digest-uri="%s",response=%s,%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
if ($challenge['realm']) {
return sprintf('username="%s",realm="%s"' . $authzid_string .
',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
} else {
return sprintf('username="%s"' . $authzid_string . ',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']);
}
} else {
return PEAR::raiseError('Invalid digest challenge');
}
Expand Down Expand Up @@ -125,20 +130,19 @@ function _parseChallenge($challenge)
*/
// Realm
if (empty($tokens['realm'])) {
$uname = posix_uname();
$tokens['realm'] = $uname['nodename'];
$tokens['realm'] = "";
}

// Maxbuf
if (empty($tokens['maxbuf'])) {
$tokens['maxbuf'] = 65536;
}

// Required: nonce, algorithm
if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) {
return array();
}

return $tokens;
}

Expand Down Expand Up @@ -174,11 +178,11 @@ function _getResponseValue($authcid, $pass, $realm, $nonce, $cnonce, $digest_uri
*/
function _getCnonce()
{
if (file_exists('/dev/urandom')) {
return base64_encode(fread(fopen('/dev/urandom', 'r'), 32));
if (file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) {
return base64_encode(fread($fd, 32));

} elseif (file_exists('/dev/random')) {
return base64_encode(fread(fopen('/dev/random', 'r'), 32));
} elseif (file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) {
return base64_encode(fread($fd, 32));

} else {
$str = '';
Expand Down

0 comments on commit f6e2ad6

Please sign in to comment.