Example #1
0
/**
 * {@link Auth_OpenID_getMathLib} checks for the presence of long
 * number extension modules and returns an instance of
 * {@link Auth_OpenID_MathWrapper} which exposes the module's
 * functionality.
 *
 * Checks for the existence of an extension module described by the
 * result of {@link Auth_OpenID_math_extensions()} and returns an
 * instance of a wrapper for that extension module.  If no extension
 * module is found, an instance of {@link Auth_OpenID_MathWrapper} is
 * returned, which wraps the native PHP integer implementation.  The
 * proper calling convention for this method is $lib =
 * Auth_OpenID_getMathLib().
 *
 * This function checks for the existence of specific long number
 * implementations in the following order: GMP followed by BCmath.
 *
 * @return Auth_OpenID_MathWrapper $instance An instance of
 * {@link Auth_OpenID_MathWrapper} or one of its subclasses
 *
 * @package OpenID
 */
function Auth_OpenID_getMathLib()
{
    // The instance of Auth_OpenID_MathWrapper that we choose to
    // supply will be stored here, so that subseqent calls to this
    // method will return a reference to the same object.
    static $lib = null;
    if (isset($lib)) {
        return $lib;
    }
    if (Auth_OpenID_noMathSupport()) {
        $null = null;
        return $null;
    }
    // If this method has not been called before, look at
    // Auth_OpenID_math_extensions and try to find an extension that
    // works.
    $ext = Auth_OpenID_detectMathLibrary(Auth_OpenID_math_extensions());
    if ($ext === false) {
        $tried = array();
        foreach (Auth_OpenID_math_extensions() as $extinfo) {
            $tried[] = $extinfo['extension'];
        }
        $triedstr = implode(", ", $tried);
        Auth_OpenID_setNoMathSupport();
        $result = null;
        return $result;
    }
    // Instantiate a new wrapper
    $class = $ext['class'];
    $lib = new $class();
    return $lib;
}
Example #2
0
function detect_math($r, &$out)
{
    $out .= $r->h2('Math support');
    $ext = Auth_OpenID_detectMathLibrary(Auth_OpenID_math_extensions());
    if (!isset($ext['extension']) || !isset($ext['class'])) {
        $out .= $r->p('Your PHP installation does not include big integer math ' . 'support. This support is required if you wish to run a ' . 'secure OpenID server without using SSL.');
        $out .= $r->p('To use this library, you have a few options:');
        $gmp_lnk = $r->link('http://www.php.net/manual/en/ref.gmp.php', 'GMP');
        $bc_lnk = $r->link('http://www.php.net/manual/en/ref.bc.php', 'bcmath');
        $out .= $r->ol(array('Install the ' . $gmp_lnk . ' PHP extension', 'Install the ' . $bc_lnk . ' PHP extension', 'If your site is low-security, call ' . 'Auth_OpenID_setNoMathSupport(), defined in Auth/OpenID/BigMath.php. ', 'The library will function, but ' . 'the security of your OpenID server will depend on the ' . 'security of the network links involved. If you are only ' . 'using consumer support, you should still be able to operate ' . 'securely when the users are communicating with a ' . 'well-implemented server.'));
        return false;
    } else {
        switch ($ext['extension']) {
            case 'bcmath':
                $out .= $r->p('Your PHP installation has bcmath support. This is ' . 'adequate for small-scale use, but can be CPU-intensive. ' . 'You may want to look into installing the GMP extension.');
                $lnk = $r->link('http://www.php.net/manual/en/ref.gmp.php');
                $out .= $r->p('See ' . $lnk . ' for more information ' . 'about the GMP extension.');
                break;
            case 'gmp':
                $out .= $r->p('Your PHP installation has gmp support. Good.');
                break;
            default:
                $class = $ext['class'];
                $lib = new $class();
                $one = $lib->init(1);
                $two = $lib->add($one, $one);
                $t = $lib->toString($two);
                $out .= $r->p('Uh-oh. I do not know about the ' . $ext['extension'] . ' extension!');
                if ($t != '2') {
                    $out .= $r->p('It looks like it is broken. 1 + 1 = ' . var_export($t, false));
                    return false;
                } else {
                    $out .= $r->p('But it seems to be able to add one and one.');
                }
        }
        return true;
        // Math library is OK
    }
}
Example #3
0
 /**
  * This method should handle any authentication and report back to the subject
  *
  * @access	public
  * @param   array 	$credentials Array holding the user credentials
  * @param 	array   $options     Array of extra options (return, entry_url)
  * @param	object	$response	Authentication response object
  * @return	boolean
  * @since 1.5
  */
 function onAuthenticate($credentials, $options, &$response)
 {
     global $mainframe;
     if (!defined('Auth_OpenID_RAND_SOURCE')) {
         define("Auth_OpenID_RAND_SOURCE", null);
     }
     require_once JPATH_LIBRARIES . DS . 'openid' . DS . 'consumer.php';
     jimport('joomla.filesystem.folder');
     // Access the session data
     $session =& JFactory::getSession();
     // Need to check for bcmath or gmp - if not, use the dumb mode.
     // TODO: Should dump an error to debug saying we are dumb
     global $_Auth_OpenID_math_extensions;
     $ext = Auth_OpenID_detectMathLibrary($_Auth_OpenID_math_extensions);
     if (!isset($ext['extension']) || !isset($ext['class'])) {
         define("Auth_OpenID_NO_MATH_SUPPORT", true);
     }
     // Create and/or start using the data store
     $store_path = JPATH_ROOT . '/tmp/_joomla_openid_store';
     if (!JFolder::exists($store_path) && !JFolder::create($store_path)) {
         $response->type = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = "Could not create the FileStore directory '{$store_path}'. " . " Please check the effective permissions.";
         return false;
     }
     // Create store object
     $store = new Auth_OpenID_FileStore($store_path);
     // Create a consumer object
     $consumer = new Auth_OpenID_Consumer($store);
     if (!isset($_SESSION['_openid_consumer_last_token'])) {
         // Begin the OpenID authentication process.
         if (!($request = $consumer->begin($credentials['username']))) {
             $response->type = JAUTHENTICATE_STATUS_FAILURE;
             $response->error_message = 'Authentication error : could not connect to the openid server';
             return false;
         }
         // Request simple registration information
         $request->addExtensionArg('sreg', 'required', 'email');
         $request->addExtensionArg('sreg', 'optional', 'fullname, language, timezone');
         //Create the entry url
         $entry_url = isset($options['entry_url']) ? $options['entry_url'] : JURI::base();
         $entry_url = JURI::getInstance($entry_url);
         unset($options['entry_url']);
         //We don't need this anymore
         //Create the url query information
         $options['return'] = isset($options['return']) ? base64_encode($options['return']) : base64_encode(JURI::base());
         $options[JUtility::getToken()] = 1;
         $process_url = sprintf($entry_url->toString() . "&username=%s", $credentials['username']);
         $process_url .= '&' . JURI::buildQuery($options);
         $trust_url = $entry_url->toString(array('path', 'host', 'port', 'scheme'));
         $redirect_url = $request->redirectURL($trust_url, $process_url);
         $session->set('trust_url', $trust_url);
         // Redirect the user to the OpenID server for authentication.  Store
         // the token for this authentication so we can verify the response.
         $mainframe->redirect($redirect_url);
         return false;
     }
     $result = $consumer->complete(JRequest::get('get'));
     switch ($result->status) {
         case Auth_OpenID_SUCCESS:
             $sreg = $result->extensionResponse('sreg');
             $response->status = JAUTHENTICATE_STATUS_SUCCESS;
             $response->error_message = '';
             $response->email = isset($sreg['email']) ? $sreg['email'] : "";
             $response->fullname = isset($sreg['fullname']) ? $sreg['fullname'] : "";
             $response->language = isset($sreg['language']) ? $sreg['language'] : "";
             $response->timezone = isset($sreg['timezone']) ? $sreg['timezone'] : "";
             break;
         case Auth_OpenID_CANCEL:
             $response->status = JAUTHENTICATE_STATUS_CANCEL;
             $response->error_message = 'Authentication cancelled';
             break;
         case Auth_OpenID_FAILURE:
             $response->status = JAUTHENTICATE_STATUS_FAILURE;
             $response->error_message = 'Authentication failed';
             break;
     }
 }
Example #4
0
/**
 * {@link Auth_OpenID_getMathLib} checks for the presence of long
 * number extension modules and returns an instance of
 * {@link Auth_OpenID_MathWrapper} which exposes the module's
 * functionality.
 *
 * Checks for the existence of an extension module described by the
 * local {@link Auth_OpenID_math_extensions} array and returns an
 * instance of a wrapper for that extension module.  If no extension
 * module is found, an instance of {@link Auth_OpenID_MathWrapper} is
 * returned, which wraps the native PHP integer implementation.  The
 * proper calling convention for this method is $lib =&
 * Auth_OpenID_getMathLib().
 *
 * This function checks for the existence of specific long number
 * implementations in the following order: GMP followed by BCmath.
 *
 * @return Auth_OpenID_MathWrapper $instance An instance of
 * {@link Auth_OpenID_MathWrapper} or one of its subclasses
 *
 * @package OpenID
 */
function &Auth_OpenID_getMathLib()
{
    // The instance of Auth_OpenID_MathWrapper that we choose to
    // supply will be stored here, so that subseqent calls to this
    // method will return a reference to the same object.
    static $lib = null;
    if (isset($lib)) {
        return $lib;
    }
    if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
        $null = null;
        return $null;
    }
    // If this method has not been called before, look at
    // $Auth_OpenID_math_extensions and try to find an extension that
    // works.
    global $_Auth_OpenID_math_extensions;
    $ext = Auth_OpenID_detectMathLibrary($_Auth_OpenID_math_extensions);
    if ($ext === false) {
        $tried = array();
        foreach ($_Auth_OpenID_math_extensions as $extinfo) {
            $tried[] = $extinfo['extension'];
        }
        $triedstr = implode(", ", $tried);
        $msg = 'This PHP installation has no big integer math ' . 'library. Define Auth_OpenID_NO_MATH_SUPPORT to use ' . 'this library in dumb mode. Tried: ' . $triedstr;
        trigger_error($msg, E_USER_ERROR);
    }
    // Instantiate a new wrapper
    $class = $ext['class'];
    $lib = new $class();
    return $lib;
}
Example #5
0
/**
 * {@link Auth_OpenID_getMathLib} checks for the presence of long
 * number extension modules and returns an instance of
 * {@link Auth_OpenID_MathWrapper} which exposes the module's
 * functionality.
 *
 * Checks for the existence of an extension module described by the
 * local {@link Auth_OpenID_math_extensions} array and returns an
 * instance of a wrapper for that extension module.  If no extension
 * module is found, an instance of {@link Auth_OpenID_MathWrapper} is
 * returned, which wraps the native PHP integer implementation.  The
 * proper calling convention for this method is $lib =&
 * Auth_OpenID_getMathLib().
 *
 * This function checks for the existence of specific long number
 * implementations in the following order: GMP followed by BCmath.
 *
 * @return Auth_OpenID_MathWrapper $instance An instance of
 * {@link Auth_OpenID_MathWrapper} or one of its subclasses
 *
 * @package OpenID
 */
function &Auth_OpenID_getMathLib()
{
    // The instance of Auth_OpenID_MathWrapper that we choose to
    // supply will be stored here, so that subseqent calls to this
    // method will return a reference to the same object.
    static $lib = null;
    if (isset($lib)) {
        return $lib;
    }
    if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
        $null = null;
        return $null;
    }
    // If this method has not been called before, look at
    // $Auth_OpenID_math_extensions and try to find an extension that
    // works.
    global $_Auth_OpenID_math_extensions;
    $ext = Auth_OpenID_detectMathLibrary($_Auth_OpenID_math_extensions);
    if ($ext === false) {
        $tried = array();
        foreach ($_Auth_OpenID_math_extensions as $extinfo) {
            $tried[] = $extinfo['extension'];
        }
        $triedstr = implode(", ", $tried);
        define('Auth_OpenID_NO_MATH_SUPPORT', true);
        $null = null;
        return $null;
    }
    // Instantiate a new wrapper
    $class = $ext['class'];
    $lib = new $class();
    return $lib;
}