/** * testSetMessage * * @return void */ public function testSetMessage() { // KV $kv = "openid.foo:foo bar\nopenid.bar:foo bar\n"; // Test constructor setting $this->object = new OpenID_Message($kv, OpenID_Message::FORMAT_KV); $this->assertSame($kv, $this->object->getKVFormat()); // HTTP $http = "openid.foo=foo+bar&openid.bar=foo+bar"; $this->object->setMessage($http, OpenID_Message::FORMAT_HTTP); $this->assertSame($http, $this->object->getHTTPFormat()); // Array $array = array('openid.foo' => 'foo bar', 'openid.bar' => 'foo bar'); $this->object->setMessage($array, OpenID_Message::FORMAT_ARRAY); $this->assertSame($array, $this->object->getArrayFormat()); }
/** * 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 * @return void */ public function signMessage(OpenID_Message $message) { if ($message->get('openid.sig') !== null || $message->get('openid.signed') !== null) { throw new OpenID_Association_Exception('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')) { throw new OpenID_Association_Exception('Association handles do not match'); } $keys = array('signed'); foreach ($message->getArrayFormat() as $key => $val) { if (strncmp('openid.', $key, 7) == 0) { $keys[] = substr($key, 7); } } sort($keys); $message->set('openid.signed', implode(',', $keys)); $signedMessage = new OpenID_Message(); foreach ($keys as $key) { $signedMessage->set($key, $message->get('openid.' . $key)); } $rawSignature = $this->hashHMAC($signedMessage->getKVFormat()); $message->set('openid.sig', base64_encode($rawSignature)); }