summaryrefslogtreecommitdiffstats
path: root/Auth
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-09-08 22:56:12 +0000
committerJosh Hoyt <josh@janrain.com>2006-09-08 22:56:12 +0000
commit9371604f7b7e4a1691afc90a4f3ba9e83777d2af (patch)
tree0c5c813bc69deec509045ca42c9bf8449987adc9 /Auth
parent9588223f3465c362171cdcab5101feca2a3b0412 (diff)
downloadphp-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.zip
php-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.tar.gz
php-openid-9371604f7b7e4a1691afc90a4f3ba9e83777d2af.tar.bz2
[project @ Make MySQL and PostGreSQL store tests work; make NO_MATH_SUPPORT work]
Diffstat (limited to 'Auth')
-rw-r--r--Auth/OpenID/Consumer.php6
-rw-r--r--Auth/OpenID/PostgreSQLStore.php13
-rw-r--r--Auth/OpenID/SQLStore.php9
-rw-r--r--Auth/OpenID/Server.php12
4 files changed, 26 insertions, 14 deletions
diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php
index 86a0e0d..1655bff 100644
--- a/Auth/OpenID/Consumer.php
+++ b/Auth/OpenID/Consumer.php
@@ -501,9 +501,7 @@ class Auth_OpenID_GenericConsumer {
function Auth_OpenID_GenericConsumer(&$store)
{
$this->store =& $store;
- $this->_use_assocs =
- !(defined('Auth_OpenID_NO_MATH_SUPPORT') ||
- ($this->store && $this->store->isDumb()));
+ $this->_use_assocs = !($this->store && $this->store->isDumb());
$this->fetcher = Services_Yadis_Yadis::getHTTPFetcher();
}
@@ -836,7 +834,7 @@ class Auth_OpenID_GenericConsumer {
$proto = 'http';
}
- if ($proto == 'https') {
+ if ($proto == 'https' || defined('Auth_OpenID_NO_MATH_SUPPORT')) {
$assoc_session = new Auth_OpenID_PlainTextConsumerSession();
} else {
$assoc_session = new Auth_OpenID_DiffieHellmanConsumerSession();
diff --git a/Auth/OpenID/PostgreSQLStore.php b/Auth/OpenID/PostgreSQLStore.php
index a5baef1..71270b7 100644
--- a/Auth/OpenID/PostgreSQLStore.php
+++ b/Auth/OpenID/PostgreSQLStore.php
@@ -24,7 +24,7 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore {
{
$this->sql['nonce_table'] =
"CREATE TABLE %s (server_url VARCHAR(2047), timestamp INTEGER, ".
- "salt CHAR(40), UNIQUE (server_url, timestamp, salt)";
+ "salt CHAR(40), UNIQUE (server_url, timestamp, salt))";
$this->sql['assoc_table'] =
"CREATE TABLE %s (server_url VARCHAR(2047), handle VARCHAR(255), ".
@@ -66,14 +66,9 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore {
"DELETE FROM %s WHERE server_url = ? AND handle = ?";
$this->sql['add_nonce'] =
- array(
- 'insert_nonce' => "INSERT INTO %s (nonce, expires) VALUES ".
- "(?, ?)",
- 'update_nonce' => "UPDATE %s SET expires = ? WHERE nonce = ?"
- );
-
- $this->sql['get_nonce'] =
- "SELECT * FROM %s WHERE nonce = ?";
+ "INSERT INTO %s (server_url, timestamp, salt) VALUES ".
+ "(?, ?, ?)"
+ ;
}
/**
diff --git a/Auth/OpenID/SQLStore.php b/Auth/OpenID/SQLStore.php
index 4b4fceb..6c23932 100644
--- a/Auth/OpenID/SQLStore.php
+++ b/Auth/OpenID/SQLStore.php
@@ -371,6 +371,10 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore {
$auth_key_s = $this->blobEncode($auth_key);
$this->_create_auth($auth_key_s);
+ } elseif ($this->isError($value)) {
+ trigger_error("Database error: " . $value->userinfo,
+ E_USER_WARNING);
+ return null;
} else {
$auth_key_s = $value;
$auth_key = $this->blobDecode($auth_key_s);
@@ -530,6 +534,11 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore {
$result = $this->connection->query($sql, array($server_url,
$timestamp,
$salt));
+ if ($this->isError($result)) {
+ $this->connection->rollback();
+ } else {
+ $this->connection->commit();
+ }
return $this->resultToBool($result);
}
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index b82bb4a..0297156 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -377,6 +377,7 @@ class Auth_OpenID_PlainTextServerSession {
* session type.
*/
var $session_type = 'plaintext';
+ var $needs_math = false;
function fromQuery($unused_request)
{
@@ -396,6 +397,7 @@ class Auth_OpenID_DiffieHellmanServerSession {
*/
var $session_type = 'DH-SHA1';
+ var $needs_math = true;
function Auth_OpenID_DiffieHellmanServerSession($dh, $consumer_pubkey)
{
@@ -506,9 +508,18 @@ class Auth_OpenID_AssociateRequest extends Auth_OpenID_Request {
}
$session_cls = $session_classes[$session_type];
+
+ // Fall back to null session if there is no math support
+ if (defined('Auth_OpenID_NO_MATH_SUPPORT')) {
+ $vars = get_class_vars($session_cls);
+ if ($vars['needs_math']) {
+ $session_cls = $session_classes[null];
+ }
+ }
$session = call_user_func_array(array($session_cls, 'fromQuery'),
array($query));
+
if (($session === null) || (_isError($session))) {
return new Auth_OpenID_ServerError($query,
"Error parsing $session_type session");
@@ -519,7 +530,6 @@ class Auth_OpenID_AssociateRequest extends Auth_OpenID_Request {
function answer($assoc)
{
- $ml =& Auth_OpenID_getMathLib();
$response = new Auth_OpenID_ServerResponse($this);
$response->fields = array('expires_in' => $assoc->getExpiresIn(),