summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-02-05 21:13:20 +0000
committertailor <cygnus@janrain.com>2007-02-05 21:13:20 +0000
commitb71f297b3c7ef13e1ae2f608ad47c65b3312e629 (patch)
treee177996a030c60ae17f593b3ee64b80ca814483f
parent7760fc9051c6be78f74620383253bd4108d525f8 (diff)
downloadphp-openid-b71f297b3c7ef13e1ae2f608ad47c65b3312e629.zip
php-openid-b71f297b3c7ef13e1ae2f608ad47c65b3312e629.tar.gz
php-openid-b71f297b3c7ef13e1ae2f608ad47c65b3312e629.tar.bz2
[project @ Added two tests for SHA256 assocations]
-rw-r--r--Tests/Auth/OpenID/Server.php87
1 files changed, 85 insertions, 2 deletions
diff --git a/Tests/Auth/OpenID/Server.php b/Tests/Auth/OpenID/Server.php
index e6271e3..bf810b7 100644
--- a/Tests/Auth/OpenID/Server.php
+++ b/Tests/Auth/OpenID/Server.php
@@ -9,6 +9,8 @@ require_once "Tests/Auth/OpenID/MemStore.php";
require_once "Auth/OpenID.php";
require_once "Auth/OpenID/DiffieHellman.php";
require_once "Auth/OpenID/Server.php";
+require_once "Auth/OpenID/HMACSHA1.php";
+require_once "Auth/OpenID/Consumer.php";
function altModulus()
{
@@ -1293,12 +1295,14 @@ class Tests_Auth_OpenID_Associate extends PHPUnit_TestCase {
$this->request = Auth_OpenID_AssociateRequest::fromMessage($message);
$this->store = new Tests_Auth_OpenID_MemStore();
$this->signatory = new Auth_OpenID_Signatory($this->store);
- $this->assoc = $this->signatory->createAssociation(false);
}
- function test_dh()
+ function test_dhSHA1()
{
if (!defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ $this->assoc = $this->signatory->createAssociation(false,
+ 'HMAC-SHA1');
+
$dh = new Auth_OpenID_DiffieHellman();
$ml =& Auth_OpenID_getMathLib();
@@ -1346,8 +1350,87 @@ class Tests_Auth_OpenID_Associate extends PHPUnit_TestCase {
}
}
+ function test_dhSHA256()
+ {
+ if (!Auth_OpenID_SHA256_SUPPORTED) {
+ print "SHA256 not supported; not running SHA256 tests.";
+ 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);
+
+ // $rfg = lambda f: response->fields->getArg(OPENID_NS, f)
+ $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);
+ }
+
+ function test_protoError256()
+ {
+ if (!Auth_OpenID_HMACSHA256_SUPPORTED) {
+ print "SHA256 not supported; not running SHA256 tests.";
+ return;
+ }
+
+ $s256_session = new Auth_OpenID_DiffieHellmanSHA256ConsumerSession();
+
+ $invalid_s256 = array('openid.assoc_type' => 'HMAC-SHA1',
+ 'openid.session_type' => 'DH-SHA256');
+
+ $invalid_s256 = array_merge($invalid_s256, $s256_session->getRequest());
+
+ $invalid_s256_2 = array('openid.assoc_type' => 'MONKEY-PIRATE',
+ 'openid.session_type' => 'DH-SHA256');
+
+ $invalid_s256_2 = array_merge($invalid_s256_2, $s256_session->getRequest());
+
+ $bad_request_argss = array(
+ $invalid_s256,
+ $invalid_s256_2);
+
+ foreach ($bad_request_argss as $request_args) {
+ $message = Auth_OpenID_Message::fromPostArgs($request_args);
+ $result = Auth_OpenID_Associaterequest::fromMessage($message);
+ $this->assertTrue(is_a($result, 'Auth_OpenID_ServerError'));
+ }
+ }
+
function test_plaintext()
{
+ $this->assoc = $this->signatory->createAssociation(false,
+ 'HMAC-SHA1');
$response = $this->request->answer($this->assoc);
$this->assertEquals(