Exemple #1
0
 function OpenID_MemcStore($prefix_part = null)
 {
     global $wgMemc, $wgDBname;
     if (isset($prefix_part)) {
         $this->prefix = $prefix_part . ':';
     }
     $auth_key = Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN);
     $k = $this->_authKeyKey();
     $res = $wgMemc->add($k, $auth_key);
 }
Exemple #2
0
function Auth_OpenID_mkNonce($when = null)
{
    // Generate a nonce with the current timestamp
    $salt = Auth_OpenID_CryptUtil::randomString(6, Auth_OpenID_Nonce_CHRS);
    if ($when === null) {
        $when = gmmktime();
    }
    $time_str = gmstrftime(Auth_OpenID_Nonce_TIME_FMT, $when);
    return $time_str . $salt;
}
Exemple #3
0
function Auth_OpenID_mkNonce($when = null)
{
    // Generate a nonce with the current timestamp
    $salt = Auth_OpenID_CryptUtil::randomString(6, Auth_OpenID_Nonce_CHRS);
    if ($when === null) {
        // It's safe to call time() with no arguments; it returns a
        // GMT unix timestamp on PHP 4 and PHP 5.  gmmktime() with no
        // args returns a local unix timestamp on PHP 4, so don't use
        // that.
        $when = time();
    }
    $time_str = gmstrftime(Auth_OpenID_Nonce_TIME_FMT, $when);
    return $time_str . $salt;
}
Exemple #4
0
	/**
	 * util function: current nonce
	 */
	private static function generate_nonce() {
		$mt = microtime();
		$rand = mt_rand();
		$md5 = md5($mt . $rand);

		$r = Auth_OpenID_CryptUtil::randomString(32,"abcdef01234567890");
		//print '<h1>microtime:: '.$mt.'  random:: '.$rand.'  md5:: '.$md5.'</h1>';

		return  $r;// md5s look nicer than numbers
	}
 /**
  * Generates an association with the specified parameters.
  */
 function genAssoc($now, $issued = 0, $lifetime = 600)
 {
     $sec = Auth_OpenID_CryptUtil::randomString(20);
     $hdl = Auth_OpenID_CryptUtil::randomString(128, $this->allowed_handle);
     return new Auth_OpenID_Association($hdl, $sec, $now + $issued, $lifetime, 'HMAC-SHA1');
 }
Exemple #6
0
 function setUp()
 {
     // Pre-compute DH with small prime so tests run quickly.
     $this->server_dh = new Auth_OpenID_DiffieHellman(100389557, 2);
     $this->consumer_dh = new Auth_OpenID_DiffieHellman(100389557, 2);
     $lib =& Auth_OpenID_getMathLib();
     $cls = $this->session_cls;
     $this->consumer_session = new $cls($this->consumer_dh);
     // base64(btwoc(g ^ xb mod p))
     $this->dh_server_public = $lib->longToBase64($this->server_dh->public);
     $this->secret = Auth_OpenID_CryptUtil::randomString($this->consumer_session->secret_size);
     $this->enc_mac_key = base64_encode($this->server_dh->xorSecret($this->consumer_dh->public, $this->secret, $this->consumer_session->hash_func));
     $this->msg = new Auth_OpenID_Message($this->message_namespace);
 }
Exemple #7
0
 /**
  * @access private
  */
 function _createNonce()
 {
     $nonce = Auth_OpenID_CryptUtil::randomString($this->nonce_len, $this->nonce_chrs);
     $this->store->storeNonce($nonce);
     return $nonce;
 }
 function getAuthKey()
 {
     $value = $this->_get_auth();
     if (!$value) {
         $auth_key = Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN);
         $auth_key_s = $this->blobEncode($auth_key);
         $this->_create_auth($auth_key_s);
     } else {
         $auth_key_s = $value;
         $auth_key = $this->blobDecode($auth_key_s);
     }
     $this->connection->commit();
     if (strlen($auth_key) != $this->AUTH_KEY_LEN) {
         $fmt = "Expected %d-byte string for auth key. Got key of length %d";
         trigger_error(sprintf($fmt, $this->AUTH_KEY_LEN, strlen($auth_key)), E_USER_WARNING);
         return null;
     }
     return $auth_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;
 }