Exemplo n.º 1
0
 function do_associate($req)
 {
     // Performs the actions needed for openid.mode=associate.  If
     // srand was provided when constructing this server instance,
     // this method supports the DH-SHA1 openid.session_type when
     // requested.  This function requires that $this->get_new_secret be
     // overriden to function properly.  Returns a Response object
     // indicating what should be sent back to the consumer.
     $reply = array();
     $assoc_type = $req->get('openid.assoc_type', 'HMAC-SHA1');
     $assoc = $this->estore->get($assoc_type);
     $session_type = $req->get('session_type');
     if ($session_type) {
         if ($session_type == 'DH-SHA1') {
             $p = $req->get('dh_modulus');
             $g = $req->get('dh_gen');
             $dh = DiffieHellman::fromBase64($p, $g, $this->srand);
             $cpub = oidUtil::a2long(oidUtil::from_b64($req->get('dh_consumer_public')));
             $dh_shared = $dh->decryptKeyExchange($cpub);
             $mac_key = oidUtil::strxor($assoc->secret, oidUtil::sha1(oidUtil::long2a($dh_shared)));
             $spub = $dh->createKeyExchange();
             $reply['session_type'] = $session_type;
             $reply['dh_server_public'] = oidUtil::to_b64(oidUtil::long2a($spub));
             $reply['enc_mac_key'] = oidUtil::to_b64($mac_key);
             // error_log( "assoc.secret: " . $assoc->secret );
             // error_log( "dh_server_public: " . $reply['dh_server_public'] );
             // error_log( "dh_server_public_raw: " . $spub );
             // error_log( "enc_mac_key: " . $reply['enc_mac_key'] );
         } else {
             // raise ProtocolError('session_type must be DH-SHA1');
             $error = 'session_type must be DH-SHA1';
             return OpenIDServer::_error_page($error);
         }
     } else {
         $reply['mac_key'] = oidUtil::to_b64($assoc->secret);
     }
     $reply['assoc_type'] = $assoc_type;
     $reply['assoc_handle'] = $assoc->handle;
     $reply['expires_in'] = $assoc->get_expires_in();
     return response_page(oidUtil::kvform($reply));
 }