Source for file Association.php
Documentation is available at Association.php
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID/Association/Exception.php';
require_once 'OpenID.php';
require_once 'OpenID/Message.php';
require_once 'Validate.php';
* A class that represents an association. This class can be serialized for
* storage. It also allows you to add and check signatures of an OpenID_Message.
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
* @see OpenID_Association_Request::buildRequest()
* expires_in paramater of the association. Time is in seconds.
* Unix timestamp of when this association was created.
* assoc_type parameter of the association. Should be one of HMAC-SHA1 or
* assoc_handle parameter of the association.
* In the association response, this is also referred to as the "mac_key", or is
* derived from the "enc_mac_key" if the session used encryption.
* Required parameters for storing an association.
* Local list of supported association types.
OpenID::ASSOC_TYPE_HMAC_SHA1,
OpenID::ASSOC_TYPE_HMAC_SHA256
* Validates some association values before setting them as member variables.
* @param array $params Array of relevant parameters from the association
* @throws OpenID_Association_Exception if the response is not valid
// Make sure required params are present
foreach ($this->requiredParams as $key) {
if (!isset
($params[$key])) {
"Missing parameter: $key"
if (!Validate::uri($params['uri'])) {
throw
new OpenID_Association_Exception(
"Invalid uri: " .
$params['uri']
"Invalid association type: " .
$params['assocType']
$this->$key =
$params[$key];
* Allows access to association data via $assoc->name
* @param string $name Name of the item to get
public function __get($name)
* Gets the algo part of the assoc_type (strips 'HMAC-')
* @return string Algorithm part of the assoc_type handle
* Checks the signature of an OpenID_Message using this association
* @param OpenID_Message $message Instance of OpenID_Message
* @throws OpenID_Association_Exception if the handles don't match
* @return bool true if the signatures match, false otherwise
// Make sure the handles match for this OP and response
if ($this->assocHandle !=
$message->get('openid.assoc_handle')) {
'Association handles do not match'
// Make sure the OP Endpoints match for this association and response
if ($this->uri !=
$message->get('openid.op_endpoint')) {
'Endpoint URLs do not match'
if (!strlen($message->get('openid.signed'))) {
$list =
explode(',', $message->get('openid.signed'));
// Create a message with only keys in the signature
'openid.sig' =>
$message->get('openid.sig'),
'signature' =>
$signedOnlyDigest,
'SignedKVFormat' =>
$signedOnly,
'MessageHTTPFormat' =>
$message->getHTTPFormat(),
return $signedOnlyDigest ==
$message->get('openid.sig');
* Returns a KV formatted message for signing based on the contents of the
* openid.signed key. This allows for duplicate entries, which
* OpenID_Message::getKVFormat() doesn't. (Yahoo! uses duplicates)
* @param OpenID_Message $message An instance of the OpenID_Message you want to
* @return string The openid.signed items in KV form
$list =
explode(',', $message->get('openid.signed'));
foreach ($list as $key) {
$signedOnly .=
"$key:" .
$message->get('openid.' .
$key) .
"\n";
* Signs an OpenID_Message instance
* @param OpenID_Message $message Message to be signed
* @throws OpenID_Association_Exception if the message is already signed,
or the association handles do not match
if ($message->get('openid.sig') !==
null ||
$message->get('openid.signed') !==
null) {
'This message appears to be already signed'
// Make sure the handles match for this OP and response
if ($this->assocHandle !=
$message->get('openid.assoc_handle')) {
'Association handles do not match'
foreach ($message->getArrayFormat() as $key =>
$val) {
if (strncmp('openid.', $key, 7) ==
0) {
$message->set('openid.signed', implode(',', $keys));
foreach ($keys as $key) {
$signedMessage->set($key, $message->get('openid.' .
$key));
$rawSignature =
$this->hashHMAC($signedMessage->getKVFormat());
* Gets a an HMAC hash of an OpenID_Message using this association.
* @param OpenID_Message $message The message format of the items to hash
* @return string The HMAC hash
Documentation generated on Tue, 15 Dec 2009 19:00:51 -0800 by phpDocumentor 1.4.3