diff options
Diffstat (limited to 'Auth/OpenID/FileStore.php')
-rw-r--r-- | Auth/OpenID/FileStore.php | 102 |
1 files changed, 3 insertions, 99 deletions
diff --git a/Auth/OpenID/FileStore.php b/Auth/OpenID/FileStore.php index 84f6332..9a24030 100644 --- a/Auth/OpenID/FileStore.php +++ b/Auth/OpenID/FileStore.php @@ -63,11 +63,9 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { 'associations'; // Temp dir must be on the same filesystem as the assciations - // $directory and the $directory containing the auth key file. + // $directory. $this->temp_dir = $directory . DIRECTORY_SEPARATOR . 'temp'; - $this->auth_key_name = $directory . DIRECTORY_SEPARATOR . 'auth_key'; - $this->max_nonce_age = 6 * 60 * 60; // Six hours, in seconds if (!$this->_setup()) { @@ -90,15 +88,14 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { */ function _setup() { - return (Auth_OpenID::ensureDir(dirname($this->auth_key_name)) && - Auth_OpenID::ensureDir($this->nonce_dir) && + return (Auth_OpenID::ensureDir($this->nonce_dir) && Auth_OpenID::ensureDir($this->association_dir) && Auth_OpenID::ensureDir($this->temp_dir)); } /** * Create a temporary file on the same filesystem as - * $this->auth_key_name and $this->association_dir. + * $this->association_dir. * * The temporary directory should not be cleaned if there are any * processes using the store. If there is no active process using @@ -120,99 +117,6 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { } /** - * Read the auth key from the auth key file. Will return None if - * there is currently no key. - * - * @return mixed - */ - function readAuthKey() - { - if (!$this->active) { - trigger_error("FileStore no longer active", E_USER_ERROR); - return null; - } - - $auth_key_file = @fopen($this->auth_key_name, 'rb'); - if ($auth_key_file === false) { - return null; - } - - $key = fread($auth_key_file, filesize($this->auth_key_name)); - fclose($auth_key_file); - - return $key; - } - - /** - * Generate a new random auth key and safely store it in the - * location specified by $this->auth_key_name. - * - * @return string $key - */ - function createAuthKey() - { - if (!$this->active) { - trigger_error("FileStore no longer active", E_USER_ERROR); - return null; - } - - $auth_key = Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN); - - list($file_obj, $tmp) = $this->_mktemp(); - - fwrite($file_obj, $auth_key); - fflush($file_obj); - fclose($file_obj); - - if (function_exists('link')) { - // Posix filesystem - $saved = link($tmp, $this->auth_key_name); - Auth_OpenID_FileStore::_removeIfPresent($tmp); - } else { - // Windows filesystem - $saved = rename($tmp, $this->auth_key_name); - } - - if (!$saved) { - // The link failed, either because we lack the permission, - // or because the file already exists; try to read the key - // in case the file already existed. - $auth_key = $this->readAuthKey(); - } - - return $auth_key; - } - - /** - * Retrieve the auth key from the file specified by - * $this->auth_key_name, creating it if it does not exist. - * - * @return string $key - */ - function getAuthKey() - { - if (!$this->active) { - trigger_error("FileStore no longer active", E_USER_ERROR); - return null; - } - - $auth_key = $this->readAuthKey(); - if ($auth_key === null) { - $auth_key = $this->createAuthKey(); - - if (strlen($auth_key) != $this->AUTH_KEY_LEN) { - $fmt = 'Got an invalid auth key from %s. Expected '. - '%d-byte string. Got: %s'; - $msg = sprintf($fmt, $this->auth_key_name, $this->AUTH_KEY_LEN, - $auth_key); - trigger_error($msg, E_USER_WARNING); - return null; - } - } - return $auth_key; - } - - /** * Create a unique filename for a given server url and * handle. This implementation does not assume anything about the * format of the handle. The filename that is returned will |