Exemplo n.º 1
0
 function runTest()
 {
     $lib =& Auth_OpenID_getMathLib();
     $shared = $lib->init($this->shared);
     $dh1 = new Auth_OpenID_DiffieHellman(null, null, $this->p1);
     $dh2 = new Auth_OpenID_DiffieHellman(null, null, $this->p2);
     $sh1 = $dh1->getSharedSecret($dh2->getPublicKey());
     $sh2 = $dh2->getSharedSecret($dh1->getPublicKey());
     $this->assertEquals($lib->cmp($shared, $sh1), 0);
     $this->assertEquals($lib->cmp($shared, $sh2), 0);
 }
Exemplo n.º 2
0
function Auth_OpenID_associate($qs, $assoc_secret, $assoc_handle)
{
    $query_data = Auth_OpenID_parse($qs);
    assert(count($query_data) == 6 || count($query_data) == 4);
    assert($query_data['openid.mode'] == 'associate');
    assert($query_data['openid.assoc_type'] == 'HMAC-SHA1');
    assert($query_data['openid.session_type'] == 'DH-SHA1');
    $reply_dict = array('assoc_type' => 'HMAC-SHA1', 'assoc_handle' => $assoc_handle, 'expires_in' => '600');
    $dh_args = Auth_OpenID_DiffieHellman::serverAssociate($query_data, $assoc_secret);
    $reply_dict = array_merge($reply_dict, $dh_args);
    return Auth_OpenID_KVForm::fromArray($reply_dict);
}
Exemplo n.º 3
0
 /**
  * Perform the server side of the OpenID Diffie-Hellman association
  */
 function serverAssociate($consumer_args, $assoc_secret)
 {
     $lib =& Auth_OpenID_getMathLib();
     if (isset($consumer_args['openid.dh_modulus'])) {
         $mod = $lib->base64ToLong($consumer_args['openid.dh_modulus']);
     } else {
         $mod = null;
     }
     if (isset($consumer_args['openid.dh_gen'])) {
         $gen = $lib->base64ToLong($consumer_args['openid.dh_gen']);
     } else {
         $gen = null;
     }
     $cpub64 = @$consumer_args['openid.dh_consumer_public'];
     if (!isset($cpub64)) {
         return false;
     }
     $dh = new Auth_OpenID_DiffieHellman($mod, $gen);
     $cpub = $lib->base64ToLong($cpub64);
     $mac_key = $dh->xorSecret($cpub, $assoc_secret);
     $enc_mac_key = base64_encode($mac_key);
     $spub64 = $lib->longToBase64($dh->getPublicKey());
     $server_args = array('session_type' => 'DH-SHA1', 'dh_server_public' => $spub64, 'enc_mac_key' => $enc_mac_key);
     return $server_args;
 }
Exemplo n.º 4
0
 function test_dh()
 {
     if (!defined('Auth_OpenID_NO_MATH_SUPPORT')) {
         $dh = new Auth_OpenID_DiffieHellman();
         $ml =& Auth_OpenID_getMathLib();
         $cpub = $dh->public;
         $session = new Auth_OpenID_DiffieHellmanServerSession(new Auth_OpenID_DiffieHellman(), $cpub);
         $this->request = new Auth_OpenID_AssociateRequest($session);
         $response = $this->request->answer($this->assoc);
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "assoc_type"), "HMAC-SHA1");
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "assoc_handle"), $this->assoc->handle);
         $this->assertFalse(Auth_OpenID::arrayGet($response->fields, "mac_key"));
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "session_type"), "DH-SHA1");
         $this->assertTrue(Auth_OpenID::arrayGet($response->fields, "enc_mac_key"));
         $this->assertTrue(Auth_OpenID::arrayGet($response->fields, "dh_server_public"));
         $enc_key = base64_decode(Auth_OpenID::arrayGet($response->fields, "enc_mac_key"));
         $spub = $ml->base64ToLong(Auth_OpenID::arrayGet($response->fields, "dh_server_public"));
         $secret = $dh->xorSecret($spub, $enc_key);
         $this->assertEquals($secret, $this->assoc->secret);
     }
 }
Exemplo n.º 5
0
 function test_dhSHA256()
 {
     if (defined('Auth_OpenID_NO_MATH_SUPPORT') || !Auth_OpenID_SHA256_SUPPORTED) {
         print "(Skipping test_dhSHA256)";
         return;
     }
     $this->assoc = $this->signatory->createAssociation(false, 'HMAC-SHA256');
     $consumer_dh = new Auth_OpenID_DiffieHellman();
     $cpub = $consumer_dh->public;
     $server_dh = new Auth_OpenID_DiffieHellman();
     $session = new Auth_OpenID_DiffieHellmanSHA256ServerSession($server_dh, $cpub);
     $this->request = new Auth_OpenID_AssociateRequest($session, 'HMAC-SHA256');
     $response = $this->request->answer($this->assoc);
     $this->assertFalse($response->fields->getArg(Auth_OpenID_OPENID_NS, "mac_key"));
     $this->assertTrue($response->fields->getArg(Auth_OpenID_OPENID_NS, "enc_mac_key"));
     $this->assertTrue($response->fields->getArg(Auth_OpenID_OPENID_NS, "dh_server_public"));
     $fields = array('assoc_type' => 'HMAC-SHA256', 'assoc_handle' => $this->assoc->handle, 'session_type' => 'DH-SHA256');
     foreach ($fields as $k => $v) {
         $this->assertEquals($response->fields->getArg(Auth_OpenID_OPENID_NS, $k), $v);
     }
     $enc_key = base64_decode($response->fields->getArg(Auth_OpenID_OPENID_NS, "enc_mac_key"));
     $lib =& Auth_OpenID_getMathLib();
     $spub = $lib->base64ToLong($response->fields->getArg(Auth_OpenID_OPENID_NS, "dh_server_public"));
     $secret = $consumer_dh->xorSecret($spub, $enc_key, 'Auth_OpenID_SHA256');
     $s = base64_encode($secret);
     $assoc_s = base64_encode($this->assoc->secret);
     $this->assertEquals($s, $assoc_s);
 }