ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
Auth_OpenID_TrustRoot Class Reference

A wrapper for trust-root related functions. More...

+ Collaboration diagram for Auth_OpenID_TrustRoot:

Static Public Member Functions

static buildDiscoveryURL ($realm)
static _parse ($trust_root)
 Parse a URL into its trust_root parts.
static isSane ($trust_root)
 Is this trust root sane?
static match ($trust_root, $url)
 Does this URL match the given trust root?

Detailed Description

A wrapper for trust-root related functions.

Definition at line 47 of file TrustRoot.php.

Member Function Documentation

static Auth_OpenID_TrustRoot::_parse (   $trust_root)
static

Parse a URL into its trust_root parts.

private

Parameters
string$trust_rootThe url to parse
Returns
mixed $parsed Either an associative array of trust root parts or false if parsing failed.

Definition at line 94 of file TrustRoot.php.

Referenced by Auth_OpenID_returnToMatches(), buildDiscoveryURL(), Auth_OpenID_CheckIDRequest\make(), and Auth_OpenID_CheckIDRequest\trustRootValid().

{
$trust_root = Auth_OpenID_urinorm($trust_root);
if ($trust_root === null) {
return false;
}
if (preg_match("/:\/\/[^:]+(:\d+){2,}(\/|$)/", $trust_root)) {
return false;
}
$parts = @parse_url($trust_root);
if ($parts === false) {
return false;
}
$required_parts = array('scheme', 'host');
$forbidden_parts = array('user', 'pass', 'fragment');
$keys = array_keys($parts);
if (array_intersect($keys, $required_parts) != $required_parts) {
return false;
}
if (array_intersect($keys, $forbidden_parts) != array()) {
return false;
}
if (!preg_match(Auth_OpenID___HostSegmentRe, $parts['host'])) {
return false;
}
$scheme = strtolower($parts['scheme']);
$allowed_schemes = array('http', 'https');
if (!in_array($scheme, $allowed_schemes)) {
return false;
}
$parts['scheme'] = $scheme;
$host = strtolower($parts['host']);
$hostparts = explode('*', $host);
switch (count($hostparts)) {
case 1:
$parts['wildcard'] = false;
break;
case 2:
if ($hostparts[0] ||
($hostparts[1] && substr($hostparts[1], 0, 1) != '.')) {
return false;
}
$host = $hostparts[1];
$parts['wildcard'] = true;
break;
default:
return false;
}
if (strpos($host, ':') !== false) {
return false;
}
$parts['host'] = $host;
if (isset($parts['path'])) {
$path = strtolower($parts['path']);
if (substr($path, 0, 1) != '/') {
return false;
}
} else {
$path = '/';
}
$parts['path'] = $path;
if (!isset($parts['port'])) {
$parts['port'] = false;
}
$parts['unparsed'] = $trust_root;

+ Here is the caller graph for this function:

static Auth_OpenID_TrustRoot::buildDiscoveryURL (   $realm)
static

Definition at line 59 of file TrustRoot.php.

References _parse().

Referenced by Auth_OpenID_verifyReturnTo().

{
$parsed = Auth_OpenID_TrustRoot::_parse($realm);
if ($parsed === false) {
return false;
}
if ($parsed['wildcard']) {
// Use "www." in place of the star
if ($parsed['host'][0] != '.') {
return false;
}
$www_domain = 'www' . $parsed['host'];
return sprintf('%s://%s%s', $parsed['scheme'],
$www_domain, $parsed['path']);
} else {
return $parsed['unparsed'];

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Auth_OpenID_TrustRoot::isSane (   $trust_root)
static

Is this trust root sane?

A trust root is sane if it is syntactically valid and it has a reasonable domain name. Specifically, the domain name must be more than one level below a standard TLD or more than two levels below a two-letter tld.

For example, '*.com' is not a sane trust root, but '*.foo.com' is. '*.co.uk' is not sane, but '*.bbc.co.uk' is.

This check is not always correct, but it attempts to err on the side of marking sane trust roots insane instead of marking insane trust roots sane. For example, 'kink.fm' is marked as insane even though it "should" (for some meaning of should) be marked sane.

This function should be used when creating OpenID servers to alert the users of the server when a consumer attempts to get the user to accept a suspicious trust root.

Parameters
string$trust_rootThe trust root to check
Returns
bool $sanity Whether the trust root looks OK

Definition at line 200 of file TrustRoot.php.

{
$parts = Auth_OpenID_TrustRoot::_parse($trust_root);
if ($parts === false) {
return false;
}
// Localhost is a special case
if ($parts['host'] == 'localhost') {
return true;
}
$host_parts = explode('.', $parts['host']);
if ($parts['wildcard']) {
// Remove the empty string from the beginning of the array
array_shift($host_parts);
}
if ($host_parts && !$host_parts[count($host_parts) - 1]) {
array_pop($host_parts);
}
if (!$host_parts) {
return false;
}
// Don't allow adjacent dots
if (in_array('', $host_parts, true)) {
return false;
}
// Get the top-level domain of the host. If it is not a valid TLD,
// it's not sane.
preg_match(Auth_OpenID___TLDs, $parts['host'], $matches);
if (!$matches) {
return false;
}
$tld = $matches[1];
if (count($host_parts) == 1) {
return false;
}
if ($parts['wildcard']) {
// It's a 2-letter tld with a short second to last segment
// so there needs to be more than two segments specified
// (e.g. *.co.uk is insane)
$second_level = $host_parts[count($host_parts) - 2];
if (strlen($tld) == 2 && strlen($second_level) <= 3) {
return count($host_parts) > 2;
}
}
static Auth_OpenID_TrustRoot::match (   $trust_root,
  $url 
)
static

Does this URL match the given trust root?

Return whether the URL falls under the given trust root. This does not check whether the trust root is sane. If the URL or trust root do not parse, this function will return false.

Parameters
string$trust_rootThe trust root to match against
string$urlThe URL to check
Returns
bool $matches Whether the URL matches against the trust root

Definition at line 270 of file TrustRoot.php.

Referenced by Auth_OpenID_returnToMatches(), and Auth_OpenID_CheckIDRequest\trustRootValid().

{
$trust_root_parsed = Auth_OpenID_TrustRoot::_parse($trust_root);
$url_parsed = Auth_OpenID_TrustRoot::_parse($url);
if (!$trust_root_parsed || !$url_parsed) {
return false;
}
// Check hosts matching
if ($url_parsed['wildcard']) {
return false;
}
if ($trust_root_parsed['wildcard']) {
$host_tail = $trust_root_parsed['host'];
$host = $url_parsed['host'];
if ($host_tail &&
substr($host, -(strlen($host_tail))) != $host_tail &&
substr($host_tail, 1) != $host) {
return false;
}
} else {
if ($trust_root_parsed['host'] != $url_parsed['host']) {
return false;
}
}
// Check path and query matching
$base_path = $trust_root_parsed['path'];
$path = $url_parsed['path'];
if (!isset($trust_root_parsed['query'])) {
if ($base_path != $path) {
if (substr($path, 0, strlen($base_path)) != $base_path) {
return false;
}
if (substr($base_path, strlen($base_path) - 1, 1) != '/' &&
substr($path, strlen($base_path), 1) != '/') {
return false;
}
}
} else {
$base_query = $trust_root_parsed['query'];
$query = @$url_parsed['query'];
$qplus = substr($query, 0, strlen($base_query) + 1);
$bqplus = $base_query . '&';
if ($base_path != $path ||
($base_query != $query && $qplus != $bqplus)) {
return false;
}
}
// The port and scheme need to match exactly
return ($trust_root_parsed['scheme'] == $url_parsed['scheme'] &&

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: