| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | namespace SimpleID\Protocols\OpenID\Extensions; |
| 24: | |
| 25: | use SimpleID\Auth\AuthManager; |
| 26: | use SimpleID\Module; |
| 27: | use SimpleID\Protocols\ProtocolResult; |
| 28: | use SimpleID\Protocols\OpenID\OpenIDCheckEvent; |
| 29: | use SimpleID\Protocols\OpenID\OpenIDModule; |
| 30: | use SimpleID\Protocols\OpenID\Message; |
| 31: | use SimpleID\Protocols\OpenID\Request; |
| 32: | use SimpleID\Protocols\OpenID\OpenIDResponseBuildEvent; |
| 33: | use SimpleID\Store\StoreManager; |
| 34: | use SimpleID\Util\OpaqueIdentifier; |
| 35: | use SimpleID\Util\Events\BaseDataCollectionEvent; |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | class PAPEOpenIDExtensionModule extends Module implements ProtocolResult { |
| 41: | |
| 42: | |
| 43: | const OPENID_NS_PAPE = 'http://specs.openid.net/extensions/pape/1.0'; |
| 44: | |
| 45: | |
| 46: | const PAPE_POLICY_NONE = 'http://schemas.openid.net/pape/policies/2007/06/none'; |
| 47: | |
| 48: | |
| 49: | const PAPE_LEVEL_NIST800_63 = 'http://csrc.nist.gov/publications/nistpubs/800-63/SP800-63V1_0_2.pdf'; |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function onXrdsTypes(BaseDataCollectionEvent $event) { |
| 58: | $event->addResult([ |
| 59: | self::OPENID_NS_PAPE, |
| 60: | self::PAPE_LEVEL_NIST800_63 |
| 61: | ]); |
| 62: | } |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public function onOpenIDCheckEvent(OpenIDCheckEvent $event) { |
| 69: | $request = $event->getRequest(); |
| 70: | |
| 71: | |
| 72: | if (!$request->hasExtension(self::OPENID_NS_PAPE)) return; |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | $pape_request = $request->getParamsForExtension(self::OPENID_NS_PAPE); |
| 79: | |
| 80: | |
| 81: | if (isset($pape_request['max_auth_age'])) { |
| 82: | $auth = AuthManager::instance(); |
| 83: | |
| 84: | |
| 85: | if (!$auth->isLoggedIn()) return; |
| 86: | |
| 87: | $auth_level = $auth->getAuthLevel(); |
| 88: | if ($auth_level == null) $auth_level = AuthManager::AUTH_LEVEL_SESSION; |
| 89: | |
| 90: | $auth_time = $auth->getAuthTime(); |
| 91: | if ($auth_time == null) $auth_time = 0; |
| 92: | |
| 93: | |
| 94: | |
| 95: | if (($auth_level < AuthManager::AUTH_LEVEL_CREDENTIALS) |
| 96: | || ((time() - $auth->getAuthTime()) > $pape_request['max_auth_age'])) { |
| 97: | $this->f3->set('message', $this->f3->get('intl.common.reenter_credentials')); |
| 98: | $event->setResult(self::CHECKID_REENTER_CREDENTIALS); |
| 99: | } |
| 100: | } |
| 101: | } |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | |
| 107: | public function onOpenIDResponseBuildEvent(OpenIDResponseBuildEvent $event) { |
| 108: | $auth = AuthManager::instance(); |
| 109: | |
| 110: | |
| 111: | if (!$event->isPositiveAssertion()) return; |
| 112: | |
| 113: | |
| 114: | $request = $event->getRequest(); |
| 115: | $response = $event->getResponse(); |
| 116: | |
| 117: | if ($request->getVersion() < Message::OPENID_VERSION_2) return; |
| 118: | |
| 119: | |
| 120: | $pape_request = $request->getParamsForExtension(self::OPENID_NS_PAPE); |
| 121: | |
| 122: | |
| 123: | |
| 124: | $alias = $response->getAliasForExtension(self::OPENID_NS_PAPE, 'pape'); |
| 125: | |
| 126: | |
| 127: | |
| 128: | $response['ns.' . $alias] = self::OPENID_NS_PAPE; |
| 129: | |
| 130: | |
| 131: | $response[$alias . '.auth_time'] = gmdate('Y-m-d\TH:i:s\Z', $auth->getAuthTime()); |
| 132: | |
| 133: | |
| 134: | $response[$alias . '.auth_level.ns.nist'] = self::PAPE_LEVEL_NIST800_63; |
| 135: | $response[$alias . '.auth_level.nist'] = 0; |
| 136: | |
| 137: | |
| 138: | $response[$alias . '.auth_policies'] = self::PAPE_POLICY_NONE; |
| 139: | } |
| 140: | } |
| 141: | |
| 142: | ?> |
| 143: | |