Skip to content

Commit 0b1ec4d

Browse files
committed
Update extlibs
y
1 parent fc4fe19 commit 0b1ec4d

20 files changed

+162
-115
lines changed

extlib/Auth/OpenID/Association.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -374,42 +374,7 @@ function checkMessageSignature($message)
374374
}
375375

376376
$calculated_sig = $this->getMessageSignature($message);
377-
378-
return $this->constantTimeCompare($calculated_sig, $sig);
379-
}
380-
381-
/**
382-
* String comparison function which will complete in a constant time
383-
* for strings of any given matching length, to help prevent an attacker
384-
* from distinguishing how much of a signature token they have guessed
385-
* correctly.
386-
*
387-
* For this usage, it's assumed that the length of the string is known,
388-
* so we may safely short-circuit on mismatched lengths which will be known
389-
* to be invalid by the attacker.
390-
*
391-
* http://lists.openid.net/pipermail/openid-security/2010-July/001156.html
392-
* http://rdist.root.org/2010/01/07/timing-independent-array-comparison/
393-
*/
394-
private function constantTimeCompare($a, $b)
395-
{
396-
$len = strlen($a);
397-
if (strlen($b) !== $len) {
398-
// Short-circuit on length mismatch; attackers will already know
399-
// the correct target length so this is safe.
400-
return false;
401-
}
402-
if ($len == 0) {
403-
// 0-length valid input shouldn't really happen. :)
404-
return true;
405-
}
406-
$result = 0;
407-
for ($i = 0; $i < strlen($a); $i++) {
408-
// We use scary bitwise operations to avoid logical short-circuits
409-
// in lower-level code.
410-
$result |= ord($a{$i}) ^ ord($b{$i});
411-
}
412-
return ($result == 0);
377+
return Auth_OpenID_CryptUtil::constEq($calculated_sig, $sig);
413378
}
414379
}
415380

extlib/Auth/OpenID/BigMath.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ function Auth_OpenID_detectMathLibrary($exts)
365365
{
366366
$loaded = false;
367367

368-
$hasDl = function_exists('dl');
369368
foreach ($exts as $extension) {
370369
if (extension_loaded($extension['extension'])) {
371370
return $extension;

extlib/Auth/OpenID/Consumer.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* identity check.
3030
*
3131
* LIBRARY DESIGN
32-
*
32+
*
3333
* This consumer library is designed with that flow in mind. The goal
3434
* is to make it as easy as possible to perform the above steps
3535
* securely.
@@ -427,7 +427,7 @@ function complete($current_url, $query=null)
427427
$loader->fromSession($endpoint_data);
428428

429429
$message = Auth_OpenID_Message::fromPostArgs($query);
430-
$response = $this->consumer->complete($message, $endpoint,
430+
$response = $this->consumer->complete($message, $endpoint,
431431
$current_url);
432432
$this->session->del($this->_token_key);
433433

@@ -616,6 +616,9 @@ function Auth_OpenID_GenericConsumer($store)
616616
$this->store = $store;
617617
$this->negotiator = Auth_OpenID_getDefaultNegotiator();
618618
$this->_use_assocs = (is_null($this->store) ? false : true);
619+
if (get_class($this->store) == "Auth_OpenID_DumbStore") {
620+
$this->_use_assocs = false;
621+
}
619622

620623
$this->fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
621624

@@ -666,7 +669,7 @@ function complete($message, $endpoint, $return_to)
666669
'_completeInvalid');
667670

668671
return call_user_func_array(array($this, $method),
669-
array($message, &$endpoint, $return_to));
672+
array($message, $endpoint, $return_to));
670673
}
671674

672675
/**
@@ -957,6 +960,10 @@ function _idResCheckSignature($message, $server_url)
957960
}
958961

959962
if (!$assoc->checkMessageSignature($message)) {
963+
// If we get a "bad signature" here, it means that the association
964+
// is unrecoverabley corrupted in some way. Any futher attempts
965+
// to login with this association is likely to fail. Drop it.
966+
$this->store->removeAssociation($server_url, $assoc_handle);
960967
return new Auth_OpenID_FailureResponse(null,
961968
"Bad signature");
962969
}
@@ -1179,9 +1186,11 @@ function _verifyDiscoveryResultsOpenID2($message, $endpoint)
11791186
function _discoverAndVerify($claimed_id, $to_match_endpoints)
11801187
{
11811188
// oidutil.log('Performing discovery on %s' % (claimed_id,))
1182-
list($unused, $services) = call_user_func($this->discoverMethod,
1183-
$claimed_id,
1184-
&$this->fetcher);
1189+
list($unused, $services) = call_user_func_array($this->discoverMethod,
1190+
array(
1191+
$claimed_id,
1192+
$this->fetcher,
1193+
));
11851194

11861195
if (!$services) {
11871196
return new Auth_OpenID_FailureResponse(null,
@@ -1196,15 +1205,15 @@ function _discoverAndVerify($claimed_id, $to_match_endpoints)
11961205
/**
11971206
* @access private
11981207
*/
1199-
function _verifyDiscoveryServices($claimed_id,
1208+
function _verifyDiscoveryServices($claimed_id,
12001209
$services, $to_match_endpoints)
12011210
{
12021211
// Search the services resulting from discovery to find one
12031212
// that matches the information from the assertion
12041213

12051214
foreach ($services as $endpoint) {
12061215
foreach ($to_match_endpoints as $to_match_endpoint) {
1207-
$result = $this->_verifyDiscoverySingle($endpoint,
1216+
$result = $this->_verifyDiscoverySingle($endpoint,
12081217
$to_match_endpoint);
12091218

12101219
if (!Auth_OpenID::isFailure($result)) {
@@ -1362,7 +1371,7 @@ function _createCheckAuthRequest($message)
13621371
}
13631372
}
13641373
$ca_message = $message->copy();
1365-
$ca_message->setArg(Auth_OpenID_OPENID_NS, 'mode',
1374+
$ca_message->setArg(Auth_OpenID_OPENID_NS, 'mode',
13661375
'check_authentication');
13671376
return $ca_message;
13681377
}
@@ -1600,7 +1609,7 @@ function _extractAssociation($assoc_response, $assoc_session)
16001609

16011610
$expires_in = Auth_OpenID::intval($expires_in_str);
16021611
if ($expires_in === false) {
1603-
1612+
16041613
$err = sprintf("Could not parse expires_in from association ".
16051614
"response %s", print_r($assoc_response, true));
16061615
return new Auth_OpenID_FailureResponse(null, $err);
@@ -1947,7 +1956,7 @@ function formMarkup($realm, $return_to=null, $immediate=false,
19471956
function htmlMarkup($realm, $return_to=null, $immediate=false,
19481957
$form_tag_attrs=null)
19491958
{
1950-
$form = $this->formMarkup($realm, $return_to, $immediate,
1959+
$form = $this->formMarkup($realm, $return_to, $immediate,
19511960
$form_tag_attrs);
19521961

19531962
if (Auth_OpenID::isFailure($form)) {

extlib/Auth/OpenID/CryptUtil.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* The filename for a source of random bytes. Define this yourself
2121
* if you have a different source of randomness.
2222
*/
23-
define('Auth_OpenID_RAND_SOURCE', '/dev/urandom');
23+
define('Auth_OpenID_RAND_SOURCE', '/dev/urandom');
2424
}
2525

2626
class Auth_OpenID_CryptUtil {
@@ -104,5 +104,19 @@ static function randomString($length, $population = null)
104104

105105
return $str;
106106
}
107+
108+
static function constEq($s1, $s2)
109+
{
110+
if (strlen($s1) != strlen($s2)) {
111+
return false;
112+
}
113+
114+
$result = true;
115+
$length = strlen($s1);
116+
for ($i = 0; $i < $length; $i++) {
117+
$result &= ($s1[$i] == $s2[$i]);
118+
}
119+
return $result;
120+
}
107121
}
108122

extlib/Auth/OpenID/Extension.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function getExtensionArgs()
3939
*
4040
* Returns the message with the extension arguments added.
4141
*/
42-
function toMessage($message)
42+
function toMessage($message, $request = null)
4343
{
4444
$implicit = $message->isOpenID1();
4545
$added = $message->namespaces->addAlias($this->ns_uri,
@@ -53,8 +53,13 @@ function toMessage($message)
5353
}
5454
}
5555

56-
$message->updateArgs($this->ns_uri,
57-
$this->getExtensionArgs());
56+
if ($request !== null) {
57+
$message->updateArgs($this->ns_uri,
58+
$this->getExtensionArgs($request));
59+
} else {
60+
$message->updateArgs($this->ns_uri,
61+
$this->getExtensionArgs());
62+
}
5863
return $message;
5964
}
6065
}

extlib/Auth/OpenID/FileStore.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,22 @@ function _getAssociation($filename)
300300
return null;
301301
}
302302

303+
if (file_exists($filename) !== true) {
304+
return null;
305+
}
306+
303307
$assoc_file = @fopen($filename, 'rb');
304308

305309
if ($assoc_file === false) {
306310
return null;
307311
}
308312

309-
$assoc_s = fread($assoc_file, filesize($filename));
313+
$filesize = filesize($filename);
314+
if ($filesize === false || $filesize <= 0) {
315+
return null;
316+
}
317+
318+
$assoc_s = fread($assoc_file, $filesize);
310319
fclose($assoc_file);
311320

312321
if (!$assoc_s) {
@@ -473,7 +482,7 @@ function _rmtree($dir)
473482
}
474483

475484
if ($handle = opendir($dir)) {
476-
while ($item = readdir($handle)) {
485+
while (false !== ($item = readdir($handle))) {
477486
if (!in_array($item, array('.', '..'))) {
478487
if (is_dir($dir . $item)) {
479488

extlib/Auth/OpenID/HMAC.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ function Auth_OpenID_HMACSHA1($key, $text)
6060
$key = Auth_OpenID_SHA1($key, true);
6161
}
6262

63+
if (function_exists('hash_hmac') &&
64+
function_exists('hash_algos') &&
65+
(in_array('sha1', hash_algos()))) {
66+
return hash_hmac('sha1', $text, $key, true);
67+
}
68+
// Home-made solution
69+
6370
$key = str_pad($key, Auth_OpenID_SHA1_BLOCKSIZE, chr(0x00));
6471
$ipad = str_repeat(chr(0x36), Auth_OpenID_SHA1_BLOCKSIZE);
6572
$opad = str_repeat(chr(0x5c), Auth_OpenID_SHA1_BLOCKSIZE);

extlib/Auth/OpenID/Message.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ function toFormMarkup($action_url, $form_tag_attrs = null,
675675

676676
if ($form_tag_attrs) {
677677
foreach ($form_tag_attrs as $name => $attr) {
678-
$form .= sprintf(" %s=\"%s\"", $name, $attr);
678+
$form .= sprintf(" %s=\"%s\"", $name, htmlspecialchars($attr));
679679
}
680680
}
681681

@@ -684,11 +684,11 @@ function toFormMarkup($action_url, $form_tag_attrs = null,
684684
foreach ($this->toPostArgs() as $name => $value) {
685685
$form .= sprintf(
686686
"<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
687-
$name, $value);
687+
htmlspecialchars($name), htmlspecialchars($value));
688688
}
689689

690690
$form .= sprintf("<input type=\"submit\" value=\"%s\" />\n",
691-
$submit_text);
691+
htmlspecialchars($submit_text));
692692

693693
$form .= "</form>\n";
694694

extlib/Auth/OpenID/MySQLStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function setSQL()
3232

3333
$this->sql['assoc_table'] =
3434
"CREATE TABLE %s (\n".
35-
" server_url BLOB NOT NULL,\n".
35+
" server_url VARCHAR(2047) NOT NULL,\n".
3636
" handle VARCHAR(255) NOT NULL,\n".
3737
" secret BLOB NOT NULL,\n".
3838
" issued INTEGER NOT NULL,\n".

extlib/Auth/OpenID/Parse.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,19 @@ function removeQuotes($str)
219219
function match($regexp, $text, &$match)
220220
{
221221
if (!is_callable('mb_ereg_search_init')) {
222-
return preg_match($regexp, $text, $match);
222+
if (!preg_match($regexp, $text, $match)) {
223+
return false;
224+
}
225+
$match = $match[0];
226+
return true;
223227
}
224228

225229
$regexp = substr($regexp, 1, strlen($regexp) - 2 - strlen($this->_re_flags));
226230
mb_ereg_search_init($text);
227231
if (!mb_ereg_search($regexp)) {
228232
return false;
229233
}
230-
list($match) = mb_ereg_search_getregs();
234+
$match = mb_ereg_search_getregs();
231235
return true;
232236
}
233237

@@ -269,7 +273,7 @@ function parseLinkAttrs($html)
269273

270274
// Try to find the <HEAD> tag.
271275
$head_re = $this->headFind();
272-
$head_match = '';
276+
$head_match = array();
273277
if (!$this->match($head_re, $stripped, $head_match)) {
274278
ini_set( 'pcre.backtrack_limit', $old_btlimit );
275279
return array();
@@ -278,7 +282,7 @@ function parseLinkAttrs($html)
278282
$link_data = array();
279283
$link_matches = array();
280284

281-
if (!preg_match_all($this->_link_find, $head_match,
285+
if (!preg_match_all($this->_link_find, $head_match[0],
282286
$link_matches)) {
283287
ini_set( 'pcre.backtrack_limit', $old_btlimit );
284288
return array();

extlib/Auth/OpenID/SQLStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function tableExists($table_name)
166166
*/
167167
function isError($value)
168168
{
169-
return PEAR::isError($value);
169+
return @PEAR::isError($value);
170170
}
171171

172172
/**

extlib/Auth/OpenID/Server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,11 @@ function equals($other)
817817
*/
818818
function returnToVerified()
819819
{
820-
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
820+
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
821821
return call_user_func_array($this->verifyReturnTo,
822822
array($this->trust_root, $this->return_to, $fetcher));
823823
}
824-
824+
825825
static function fromMessage($message, $server)
826826
{
827827
$mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode');
@@ -1704,7 +1704,7 @@ function handleRequest($request)
17041704
{
17051705
if (method_exists($this, "openid_" . $request->mode)) {
17061706
$handler = array($this, "openid_" . $request->mode);
1707-
return call_user_func($handler, &$request);
1707+
return call_user_func_array($handler, array($request));
17081708
}
17091709
return null;
17101710
}

extlib/Auth/OpenID/TrustRoot.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static function isSane($trust_root)
210210
if ($parts['host'] == 'localhost') {
211211
return true;
212212
}
213-
213+
214214
$host_parts = explode('.', $parts['host']);
215215
if ($parts['wildcard']) {
216216
// Remove the empty string from the beginning of the array
@@ -413,7 +413,7 @@ function Auth_OpenID_getAllowedReturnURLs($relying_party_url, $fetcher,
413413
}
414414

415415
call_user_func_array($discover_function,
416-
array($relying_party_url, &$fetcher));
416+
array($relying_party_url, $fetcher));
417417

418418
$return_to_urls = array();
419419
$matching_endpoints = Auth_OpenID_extractReturnURL($endpoints);

0 commit comments

Comments
 (0)