is NOT OK # Anything else is OK # List from: http://www.iana.org/gtld/gtld.htm $tld_list = array( "aero" => 1, "biz" => 1, "com" => 1, "coop" => 1, "edu" => 1, "gov" => 1, "info" => 1, "int" => 1, "mil" => 1, "museum" => 1, "name" => 1, "net" => 1, "org" => 1, "pro" => 1); function valid_wildcard($h) { switch (strrpos($h, "*")) { case false: # Not wildcard return true; case 0: # Wildcard break; default: # * not at start return false; } $h = explode(".", $h); if ($h[0] != "*") return false; # *xyz.stuff is bad switch (count($h)) { case 0: case 1: case 2: return false; case 3: return array_key_exists($h[-1], $tld_list); default: return true; } } function valid_root($root, $ret) { $root = parse_url($root); if (isset($root["fragment"])) return false; $ret = parse_url($ret); if ($root["scheme"] != $ret["scheme"]) return false; if ($root["port"] != $ret["port"]) return false; if (isset($root["user"]) && $root["user"] != $ret["user"]) return false; if (isset($root["pass"]) && $root["pass"] != $ret["pass"]) return false; if (isset($root["query"]) && $root["query"] != $ret["query"]) return false; $h = $root["host"]; if (!valid_wildcard($h)) return false; if ($h[0] == "*") { $hn = strlen($h) - 1; if (substr($h, 2) != substr($ret["host"], -$hn, $hn)) return false; } else { if ($h != $ret["host"]) return false; } $p1 = explode("/", rtrim($root["path"], "/")); $p2 = explode("/", rtrim($ret["path"], "/")); foreach ($p1 as $k => $v) { if ($p2[$k] != $v) return false; } return true; } function randbytes($n) { /*$r = fopen("/dev/urandom", "rb"); $s = fread($r, $n); fclose($r); */ $s=""; for ($i=0; $i<$n; $i++) { $s.=chr(rand(0,255)); } return $s; } function xtea_block($k, $v) { list(, $v0, $v1) = unpack("N*", $v); $sum = 0; $delta = 0x9E3779B9; for ($i = 0; $i < 32; $i++) { $v0 = intval($v0 + ($v1 << 4 ^ $v1 >> 5) + $v1 ^ $sum + $k[$sum & 3]); $sum = intval($sum + $delta); $v1 = intval($v1 + ($v0 << 4 ^ $v0 >> 5) + $v0 ^ $sum + $k[$sum >> 11 & 3]); } return pack("N2", $v0, $v1); } function xtea_encrypt($key, $data) { $key = array_merge(unpack("N*", str_pad($key, 16, chr(0)))); $v = randbytes(8); $out = $v; $i = 0; $l = strlen($data); while ($i < $l) { $v = xtea_block($key, $v); $p = substr($data, $i, 8); $i += 8; $v ^= $p; $out .= $v; } return $out; } function xtea_decrypt($key, $data) { $key = array_merge(unpack("N*", str_pad($key, 16, chr(0)))); $v = substr($data, 0, 8); $i = 8; $l = strlen($data); $out = ""; while ($i < $l) { $v = xtea_block($key, $v); $c = substr($data, $i, 8); $i += 8; $out .= $v ^ $c; $v = $c; } return $out; } define("HASH_LEN", 20); function hmac($key, $str) { $key = str_pad($key, 64, chr(0)); $ipad = $key ^ str_repeat(chr(0x36), 64); $opad = $key ^ str_repeat(chr(0x5C), 64); return pack("H*", sha1($opad . pack("H*", sha1($ipad . $str)))); } function sign_array($key, $data) { $token = ""; foreach (explode(",", $data["signed"]) as $f) { $token .= "$f:$data[$f]\n"; } return base64_encode(hmac($key, $token)); } function make_handle($expiry, $exposed, $key) { $token = pack("lc", $expiry, $exposed ? 1 : 0) . $key; return base64_encode(xtea_encrypt(SIGKEY, hmac(SIGKEY, $token) . $token)); } function check_handle($bh, $exposed_ok) { $handle = base64_decode($bh); # IV + HMAC + expiry + exposed if (!$handle || strlen($handle) < 8 + HASH_LEN + 5) return false; $handle = xtea_decrypt(SIGKEY, $handle); $data = substr($handle, HASH_LEN); if (hmac(SIGKEY, $data) != substr($handle, 0, HASH_LEN)) return false; $t = unpack("lexpiry/cexposed", $data); if ($t["expiry"] < time() || $t["exposed"] && !$exposed_ok) return false; return substr($data, 5); } function make_args($prefix, $data) { $url = ""; foreach ($data as $k => $v) { $url .= "$prefix$k=" . urlencode($v) . "&"; } return rtrim($url, "&"); } function continuation() { $url = ""; foreach ($_REQUEST as $k => $v) { if (strncmp($k, "openid_", 7) || $k == "openid_mode") continue; $url .= "&openid." . substr($k, 7) . "=" . urlencode($v); } return $url; } $ret = $_REQUEST["openid_return_to"]; if ($ret) { if (!preg_match("/^https?:/", $ret)) { header("HTTP/1.0 400 Bad Request"); ?> Bad Request

The OpenID endpoint received an invalid request.

Error

An error occurred processing your request: This is an OpenID server endpoint, not a human-readable resource. For more information, see http://www.openid.net/."; ?>

Login

Your password is incorrect. Please try again.':'You must login to OpenID to continue.'?>

Password:

Login required

You need to log in to be authenticated.

"id_res", "identity" => $id, "issued" => t2utc($t), # COMPAT "valid_to" => t2utc($t + VALID_TIME), "return_to" => $ret, "signed" => "mode,issued,valid_to,identity,return_to"); $handle = $_REQUEST["openid_assoc_handle"]; if ($handle) { $key = check_handle($handle, true); if ($key == false) $resp["invalidate_handle"] = $handle; } if (!$key) { $key = randbytes(KEY_LEN); $handle = make_handle($t + ASSOC_TIME, false, $key); } $resp["sig"] = sign_array($key, $resp); $resp["assoc_handle"] = $handle; $url = $retp . make_args("openid.", $resp); header("Location: $url"); ?> Authentication OK

Authentication complete. Click here to proceed

OpenID<?echo $title?": $title":''?>

OpenID

Logout

You are now logged out. Have a nice day.

Log in again

Trust Site'; echo '
'.$root.'
'; global $retp; echo '
This site has been added to your trusted site list.
Continue


'; } else if ( $root && $_REQUEST['del_site'] ) { if ( is_trusted($root) ) { $trusted = list_trusted_sites(); $out = fopen("openid_trust","w"); foreach ( $trusted as $cs ) { if ( trim($cs) != trim($root) ) { fwrite($out,$cs."\n"); } } fclose($out); } echo '

Trusted Sites

'; echo '
'.$root.'
'; echo '
This site has been removed from your trusted site list.
Done

'; } else if ( $root ) { echo '

Trust Site

'; echo '
'; echo '
'.$root.'
'; if ( is_trusted($root) ) echo '
This site is already in your trusted site list.

'; else echo '
This site is not in your trusted site list. Do you want to add this site to your list?

'; } else if ( $_REQUEST['ui'] == 'trust' ) { echo '

Trusted Sites

'; $trusted = list_trusted_sites(); if ( count($trusted) ) { echo 'There are '.count($trusted).' sites on your trusted sites list.'; echo '"; } else { echo "You do not have any sites on your trusted sites list"; } } else {?>

Welcome

Welcome to your OpenID server. To manage your trusted sites, click "Trust" on the menu above.