20 require_once
'Auth/OpenID/CryptUtil.php';
25 require_once
'Auth/OpenID/KVForm.php';
30 require_once
'Auth/OpenID/HMAC.php';
68 'HMAC-SHA1' =>
'Auth_OpenID_HMACSHA1',
69 'HMAC-SHA256' =>
'Auth_OpenID_HMACSHA256' 97 static function fromExpiresIn($expires_in, $handle, $secret, $assoc_type)
100 $lifetime = $expires_in;
102 $issued, $lifetime, $assoc_type);
132 $handle, $secret, $issued, $lifetime, $assoc_type)
134 if (!in_array($assoc_type,
136 $fmt =
'Unsupported association type (%s)';
137 trigger_error(sprintf($fmt, $assoc_type), E_USER_ERROR);
140 $this->handle = $handle;
141 $this->secret = $secret;
142 $this->issued = $issued;
143 $this->lifetime = $lifetime;
144 $this->assoc_type = $assoc_type;
160 return max(0, $this->issued + $this->lifetime - $now);
172 return ((gettype($this) == gettype($other))
173 && ($this->handle == $other->handle)
174 && ($this->secret == $other->secret)
175 && ($this->issued == $other->issued)
176 && ($this->lifetime == $other->lifetime)
177 && ($this->assoc_type == $other->assoc_type));
190 'handle' => $this->handle,
191 'secret' => base64_encode($this->secret),
192 'issued' => strval(intval($this->issued)),
193 'lifetime' => strval(intval($this->lifetime)),
194 'assoc_type' => $this->assoc_type
197 assert(array_keys(
$data) == $this->assoc_keys);
214 foreach ($pairs as $key => $value) {
215 if (is_array($value)) {
216 list($key, $value) = $value;
222 $class_vars = get_class_vars($class_name);
223 $class_assoc_keys = $class_vars[
'assoc_keys'];
226 sort($class_assoc_keys);
228 if ($keys != $class_assoc_keys) {
229 trigger_error(
'Unexpected key values: ' . var_export($keys,
true),
234 $version = $pairs[
'version'];
235 $handle = $pairs[
'handle'];
236 $secret = $pairs[
'secret'];
237 $issued = $pairs[
'issued'];
238 $lifetime = $pairs[
'lifetime'];
239 $assoc_type = $pairs[
'assoc_type'];
241 if ($version !=
'2') {
242 trigger_error(
'Unknown version: ' . $version, E_USER_WARNING);
246 $issued = intval($issued);
247 $lifetime = intval($lifetime);
248 $secret = base64_decode($secret);
250 return new $class_name(
251 $handle, $secret, $issued, $lifetime, $assoc_type);
268 $callback = $this->_macs[$this->assoc_type];
270 return call_user_func_array($callback, array($this->secret, $kv));
294 if ($extant_handle && ($extant_handle != $this->handle)) {
299 $signed_message = $message;
303 $message_keys = array_keys($signed_message->toPostArgs());
304 $signed_list = array();
305 $signed_prefix =
'openid.';
307 foreach ($message_keys as $k) {
308 if (strpos($k, $signed_prefix) === 0) {
309 $signed_list[] = substr($k, strlen($signed_prefix));
313 $signed_list[] =
'signed';
317 implode(
',', $signed_list));
320 return $signed_message;
338 $signed_list = explode(
',', $signed);
340 $data = $message->toPostArgs();
341 foreach ($signed_list as $field) {
358 return base64_encode($this->
sign($pairs));
377 return $calculated_sig == $sig;
383 if ($assoc_type ==
'HMAC-SHA1') {
385 }
else if ($assoc_type ==
'HMAC-SHA256') {
394 return array(
'HMAC-SHA1',
'HMAC-SHA256');
399 $a = array(
'HMAC-SHA1');
401 if (Auth_OpenID_HMACSHA256_SUPPORTED) {
402 $a[] =
'HMAC-SHA256';
410 $assoc_to_session = array(
411 'HMAC-SHA1' => array(
'DH-SHA1',
'no-encryption'));
413 if (Auth_OpenID_HMACSHA256_SUPPORTED) {
414 $assoc_to_session[
'HMAC-SHA256'] =
415 array(
'DH-SHA256',
'no-encryption');
423 if (!in_array($session_type,
436 $order[] = array(
'HMAC-SHA1',
'DH-SHA1');
438 if (Auth_OpenID_HMACSHA256_SUPPORTED) {
439 $order[] = array(
'HMAC-SHA256',
'DH-SHA256');
443 $order[] = array(
'HMAC-SHA1',
'no-encryption');
445 if (Auth_OpenID_HMACSHA256_SUPPORTED) {
446 $order[] = array(
'HMAC-SHA256',
'no-encryption');
457 list($assoc, $session) = $pair;
459 if ($session !=
'no-encryption') {
460 if (Auth_OpenID_HMACSHA256_SUPPORTED &&
461 ($assoc ==
'HMAC-SHA256')) {
463 }
else if ($assoc !=
'HMAC-SHA256') {
528 $this->allowed_types = array();
529 $this->setAllowedTypes($allowed_types);
540 foreach ($allowed_types as $pair) {
541 list($assoc_type, $session_type) = $pair;
547 $this->allowed_types = $allowed_types;
560 if ($this->allowed_types === null) {
561 $this->allowed_types = array();
564 if ($session_type === null) {
571 foreach ($available as $session_type) {
572 $this->addAllowedType($assoc_type, $session_type);
576 $this->allowed_types[] = array($assoc_type, $session_type);
588 $assoc_good = in_array(array($assoc_type, $session_type),
589 $this->allowed_types);
591 $matches = in_array($session_type,
594 return ($assoc_good && $matches);
603 if (!$this->allowed_types) {
604 return array(null, null);
607 return $this->allowed_types[0];
Auth_OpenID_getDefaultNegotiator()
setAllowedTypes($allowed_types)
Set the allowed association types, checking to make sure each combination is valid.
const Auth_OpenID_OPENID_NS
_makePairs($message)
Given a Auth_OpenID_Message, return the key/value pairs to be signed according to the signed list in ...
Auth_OpenID_getAllAssociationTypes()
static fromExpiresIn($expires_in, $handle, $secret, $assoc_type)
This is an alternate constructor (factory method) used by the OpenID consumer library to create assoc...
Auth_OpenID_getOnlyEncryptedOrder()
$SIG_LENGTH
This is a HMAC-SHA1 specific value.
isAllowed($assoc_type, $session_type)
sign($pairs)
Generate a signature for a sequence of (key, value) pairs.
Auth_OpenID_getSecretSize($assoc_type)
getExpiresIn($now=null)
This returns the number of seconds this association is still valid for, or 0 if the association is no...
checkMessageSignature($message)
Confirm that the signature of these fields matches the signature contained in the data...
Auth_OpenID_getSupportedAssociationTypes()
static deserialize($class_name, $assoc_s)
Parse an association as stored by serialize().
Auth_OpenID_Association( $handle, $secret, $issued, $lifetime, $assoc_type)
This is the standard constructor for creating an association.
getMessageSignature($message)
Given an Auth_OpenID_Message, return the signature for the signed list in the message.
signMessage($message)
Generate a signature for some fields in a dictionary.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
static arrayGet($arr, $key, $fallback=null)
Convenience function for getting array values.
addAllowedType($assoc_type, $session_type=null)
Add an association type and session type to the allowed types list.
equal($other)
This checks to see if two Auth_OpenID_Association instances represent the same association.
Auth_OpenID_getDefaultAssociationOrder()
getAllowedType()
Get a pair of assocation type and session type that are supported.
static isFailure($thing)
Return true if $thing is an Auth_OpenID_FailureResponse object; false if not.
serialize()
Convert an association to KV form.
Auth_OpenID_getSessionTypes($assoc_type)
$assoc_keys
The ordering and name of keys as stored by serialize.
Auth_OpenID_SessionNegotiator($allowed_types)
Auth_OpenID_noMathSupport()
Auth_OpenID_checkSessionType($assoc_type, $session_type)
Auth_OpenID_getEncryptedNegotiator()