Exemplo n.º 1
0
 function associate($server_url)
 {
     list($p, $g) = $this->get_mod_gen();
     $dh = new DiffieHellman($p, $g, $this->srand);
     $cpub = $dh->createKeyExchange();
     $args = array('openid.mode' => 'associate', 'openid.assoc_type' => 'HMAC-SHA1', 'openid.session_type' => 'DH-SHA1', 'openid.dh_modulus' => oidUtil::to_b64(oidUtil::long2a($dh->p)), 'openid.dh_gen' => oidUtil::to_b64(oidUtil::long2a($dh->g)), 'openid.dh_consumer_public' => oidUtil::to_b64(oidUtil::long2a($cpub)));
     $body = http_build_query($args);
     list($url, $data) = $this->http_client->post($server_url, $body);
     $results = oidUtil::parsekv($data);
     $assoc_type = $this->getResult($results, 'assoc_type');
     if ($assoc_type != 'HMAC-SHA1') {
         trigger_error(sprintf('runtime error : Unknown association type %s', $assoc_type), E_USER_WARNING);
     }
     $assoc_handle = $this->getResult($results, 'assoc_handle');
     $expires_in = isset($results['expires_in']) ? $results['expires_in'] : 0;
     $session_type = isset($results['session_type']) ? $results['session_type'] : 0;
     if (!$session_type) {
         $secret = oidUtil::from_b64($this->getResult($results, 'mac_key'));
     } else {
         if ($session_type != 'DH-SHA1') {
             trigger_error(sprintf('runtime error : Unknown Session Type: %s', $session_type), E_USER_WARNING);
         }
         $spub = oidUtil::a2long(oidUtil::from_b64($this->getResult($results, 'dh_server_public')));
         $dh_shared = $dh->decryptKeyExchange($spub);
         $enc_mac_key = $this->getResult($results, 'enc_mac_key');
         // print "enc_mac_key: " . $enc_mac_key;
         $secret = oidUtil::strxor(oidUtil::from_b64($enc_mac_key), oidUtil::sha1(oidUtil::long2a($dh_shared)));
     }
     return ConsumerAssociation::from_expires_in($expires_in, $server_url, $assoc_handle, $secret);
 }