A wrapper for trust-root related functions.
More...
A wrapper for trust-root related functions.
Definition at line 47 of file TrustRoot.php.
◆ _parse()
static Auth_OpenID_TrustRoot::_parse |
( |
|
$trust_root | ) |
|
|
static |
Parse a URL into its trust_root parts.
private
- Parameters
-
string | $trust_root | The 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().
99 if ($trust_root === null) {
103 if (preg_match(
"/:\/\/[^:]+(:\d+){2,}(\/|$)/", $trust_root)) {
107 $parts = @parse_url($trust_root);
108 if ($parts ===
false) {
112 $required_parts = array(
'scheme',
'host');
113 $forbidden_parts = array(
'user',
'pass',
'fragment');
114 $keys = array_keys($parts);
115 if (array_intersect($keys, $required_parts) != $required_parts) {
119 if (array_intersect($keys, $forbidden_parts) != array()) {
127 $scheme = strtolower($parts[
'scheme']);
128 $allowed_schemes = array(
'http',
'https');
129 if (!in_array($scheme, $allowed_schemes)) {
132 $parts[
'scheme'] = $scheme;
134 $host = strtolower($parts[
'host']);
135 $hostparts = explode(
'*', $host);
136 switch (count($hostparts)) {
138 $parts[
'wildcard'] =
false;
142 ($hostparts[1] && substr($hostparts[1], 0, 1) !=
'.')) {
145 $host = $hostparts[1];
146 $parts[
'wildcard'] =
true;
151 if (strpos($host,
':') !==
false) {
155 $parts[
'host'] = $host;
157 if (isset($parts[
'path'])) {
158 $path = strtolower($parts[
'path']);
159 if (substr(
$path, 0, 1) !=
'/') {
166 $parts[
'path'] =
$path;
167 if (!isset($parts[
'port'])) {
168 $parts[
'port'] =
false;
172 $parts[
'unparsed'] = $trust_root;
Auth_OpenID_urinorm($uri)
const Auth_OpenID___HostSegmentRe
◆ buildDiscoveryURL()
static Auth_OpenID_TrustRoot::buildDiscoveryURL |
( |
|
$realm | ) |
|
|
static |
Definition at line 59 of file TrustRoot.php.
References $path, $query, _parse(), Auth_OpenID___HostSegmentRe, Auth_OpenID___TLDs, Auth_OpenID_urinorm(), isSane(), and match().
Referenced by Auth_OpenID_verifyReturnTo().
65 if ($parsed ===
false) {
69 if ($parsed[
'wildcard']) {
71 if ($parsed[
'host'][0] !=
'.') {
75 $www_domain =
'www' . $parsed[
'host'];
77 return sprintf(
'%s://%s%s', $parsed[
'scheme'],
78 $www_domain, $parsed[
'path']);
80 return $parsed[
'unparsed'];
static _parse($trust_root)
Parse a URL into its trust_root parts.
◆ isSane()
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_root | The trust root to check |
- Returns
- bool $sanity Whether the trust root looks OK
Definition at line 200 of file TrustRoot.php.
Referenced by buildDiscoveryURL().
205 if ($parts ===
false) {
210 if ($parts[
'host'] ==
'localhost') {
214 $host_parts = explode(
'.', $parts[
'host']);
215 if ($parts[
'wildcard']) {
217 array_shift($host_parts);
220 if ($host_parts && !$host_parts[count($host_parts) - 1]) {
221 array_pop($host_parts);
229 if (in_array(
'', $host_parts,
true)) {
241 if (count($host_parts) == 1) {
245 if ($parts[
'wildcard']) {
249 $second_level = $host_parts[count($host_parts) - 2];
250 if (strlen($tld) == 2 && strlen($second_level) <= 3) {
251 return count($host_parts) > 2;
static _parse($trust_root)
Parse a URL into its trust_root parts.
const Auth_OpenID___TLDs
A regular expression that matches a domain ending in a top-level domains.
◆ match()
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_root | The trust root to match against |
string | $url | The 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_AX_FetchRequest\Auth_OpenID_AX_FetchRequest(), Auth_OpenID_returnToMatches(), buildDiscoveryURL(), and Auth_OpenID_CheckIDRequest\trustRootValid().
276 if (!$trust_root_parsed || !$url_parsed) {
281 if ($url_parsed[
'wildcard']) {
284 if ($trust_root_parsed[
'wildcard']) {
285 $host_tail = $trust_root_parsed[
'host'];
286 $host = $url_parsed[
'host'];
288 substr($host, -(strlen($host_tail))) != $host_tail &&
289 substr($host_tail, 1) != $host) {
293 if ($trust_root_parsed[
'host'] != $url_parsed[
'host']) {
299 $base_path = $trust_root_parsed[
'path'];
300 $path = $url_parsed[
'path'];
301 if (!isset($trust_root_parsed[
'query'])) {
302 if ($base_path !=
$path) {
303 if (substr(
$path, 0, strlen($base_path)) != $base_path) {
306 if (substr($base_path, strlen($base_path) - 1, 1) !=
'/' &&
307 substr(
$path, strlen($base_path), 1) !=
'/') {
312 $base_query = $trust_root_parsed[
'query'];
313 $query = @$url_parsed[
'query'];
314 $qplus = substr(
$query, 0, strlen($base_query) + 1);
315 $bqplus = $base_query .
'&';
316 if ($base_path !=
$path ||
317 ($base_query !=
$query && $qplus != $bqplus)) {
323 return ($trust_root_parsed[
'scheme'] == $url_parsed[
'scheme'] &&
static _parse($trust_root)
Parse a URL into its trust_root parts.
The documentation for this class was generated from the following file: