20 require_once
'Auth/OpenID.php';
21 require_once
'Auth/OpenID/Interface.php';
22 require_once
'Auth/OpenID/HMAC.php';
23 require_once
'Auth/OpenID/Nonce.php';
52 trigger_error(
'Not a directory and failed to create: ' 55 $directory = realpath($directory);
57 $this->directory = $directory;
60 $this->nonce_dir = $directory . DIRECTORY_SEPARATOR .
'nonces';
62 $this->association_dir = $directory . DIRECTORY_SEPARATOR .
67 $this->temp_dir = $directory . DIRECTORY_SEPARATOR .
'temp';
69 $this->max_nonce_age = 6 * 60 * 60;
72 trigger_error(
'Failed to initialize OpenID file store in ' .
80 $this->active =
false;
111 $file_obj = @fopen($name,
'wb');
112 if ($file_obj !==
false) {
113 return array($file_obj, $name);
128 foreach ($nonces as $nonce_fname) {
129 $base = basename($nonce_fname);
130 $parts = explode(
'-', $base, 2);
131 $timestamp = $parts[0];
132 $timestamp = intval($timestamp, 16);
133 if (abs($timestamp - $now) > $Auth_OpenID_SKEW) {
152 if (!$this->active) {
153 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
157 if (strpos($server_url,
'://') ===
false) {
158 trigger_error(sprintf(
"Bad server URL: %s", $server_url),
163 list($proto, $rest) = explode(
'://', $server_url, 2);
164 $parts = explode(
'/', $rest);
173 $filename = sprintf(
'%s-%s-%s-%s', $proto, $domain, $url_hash,
176 return $this->association_dir. DIRECTORY_SEPARATOR . $filename;
184 if (!$this->active) {
185 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
189 $association_s = $association->serialize();
191 $association->handle);
192 list($tmp_file, $tmp) = $this->
_mktemp();
195 trigger_error(
"_mktemp didn't return a valid file descriptor",
200 fwrite($tmp_file, $association_s);
206 if (@rename($tmp, $filename)) {
215 if (@rename($tmp, $filename)) {
234 if (!$this->active) {
235 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
239 if ($handle === null) {
252 $matching_files = array();
255 $name = basename($filename);
256 foreach ($association_files as $association_file) {
257 $base = basename($association_file);
258 if (strpos($base, $name) === 0) {
259 $matching_files[] = $association_file;
263 $matching_associations = array();
265 foreach ($matching_files as $full_name) {
267 if ($association !== null) {
268 $matching_associations[] = array($association->issued,
275 foreach ($matching_associations as $key => $assoc) {
276 $issued[$key] = $assoc[0];
277 $assocs[$key] = $assoc[1];
280 array_multisort($issued, SORT_DESC, $assocs, SORT_DESC,
281 $matching_associations);
284 if ($matching_associations) {
285 list($issued, $assoc) = $matching_associations[0];
298 if (!$this->active) {
299 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
303 if (file_exists($filename) !==
true) {
307 $assoc_file = @fopen($filename,
'rb');
309 if ($assoc_file ===
false) {
313 $filesize = filesize($filename);
314 if ($filesize ===
false || $filesize <= 0) {
318 $assoc_s = fread($assoc_file, $filesize);
334 if ($association->getExpiresIn() == 0) {
349 if (!$this->active) {
350 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
355 if ($assoc === null) {
373 if (!$this->active) {
374 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
378 if ( abs($timestamp - time()) > $Auth_OpenID_SKEW ) {
383 list($proto, $rest) = explode(
'://', $server_url, 2);
389 $parts = explode(
'/', $rest, 2);
391 $url_hash = $this->
_safe64($server_url);
392 $salt_hash = $this->
_safe64($salt);
394 $filename = sprintf(
'%08x-%s-%s-%s-%s', $timestamp, $proto,
395 $domain, $url_hash, $salt_hash);
396 $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $filename;
398 $result = @fopen($filename,
'x');
416 $all_associations = array();
418 $association_filenames =
421 foreach ($association_filenames as $association_filename) {
422 $association_file = fopen($association_filename,
'rb');
424 if ($association_file !==
false) {
425 $assoc_s = fread($association_file,
426 filesize($association_filename));
427 fclose($association_file);
432 'Auth_OpenID_Association', $assoc_s);
434 if ($association === null) {
436 $association_filename);
438 if ($association->getExpiresIn() == 0) {
439 $all_associations[] = array($association_filename,
446 return $all_associations;
451 if (!$this->active) {
452 trigger_error(
"FileStore no longer active",
E_USER_ERROR);
460 foreach ($nonces as $nonce) {
462 $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $nonce;
468 list($assoc_filename, $assoc) = $pair;
469 if ($assoc->getExpiresIn() == 0) {
480 if ($dir[strlen($dir) - 1] != DIRECTORY_SEPARATOR) {
481 $dir .= DIRECTORY_SEPARATOR;
484 if ($handle = opendir($dir)) {
485 while ($item = readdir($handle)) {
486 if (!in_array($item, array(
'.',
'..'))) {
487 if (is_dir($dir . $item)) {
492 }
else if (is_file($dir . $item)) {
493 if (!unlink($dir . $item)) {
518 foreach (range(0, 4) as $i) {
519 $name = tempnam($dir,
"php_openid_filestore_");
521 if ($name !==
false) {
533 foreach (range(0, 4) as $i) {
534 $name = $dir . strval(DIRECTORY_SEPARATOR) . strval(getmypid()) .
535 "-" . strval(rand(1, time()));
536 if (!mkdir($name, 0700)) {
550 $handle = opendir($dir);
552 while (
false !== ($filename = readdir($handle))) {
553 if (!in_array($filename, array(
'.',
'..'))) {
554 $files[] = $dir . DIRECTORY_SEPARATOR . $filename;
567 return (strpos($_Auth_OpenID_filename_allowed, $char) !==
false);
576 $h64 = str_replace(
'+',
'_', $h64);
577 $h64 = str_replace(
'/',
'.', $h64);
578 $h64 = str_replace(
'=',
'', $h64);
590 for ($i = 0; $i < count($b); $i++) {
595 $filename .= sprintf(
"_%02X", ord($c));
610 return @unlink($filename);
617 list($assoc_filename, $assoc) = $pair;
618 if ($assoc->getExpiresIn() == 0) {
Auth_OpenID_FileStore($directory)
Auth_OpenID_checkTimestamp($nonce_string, $allowed_skew=null, $now=null)
getAssociation($server_url, $handle=null)
storeAssociation($server_url, $association)
if(!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE' E_USER_ERROR
_getAssociation($filename)
removeAssociation($server_url, $handle)
useNonce($server_url, $timestamp, $salt)
static deserialize($class_name, $assoc_s)
_removeIfPresent($filename)
getAssociationFilename($server_url, $handle)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
const Auth_OpenID_letters
static ensureDir($dir_name)