Author: chabotc
Date: Tue Jun  3 11:08:00 2008
New Revision: 662851

URL: http://svn.apache.org/viewvc?rev=662851&view=rev
Log:
Fixed a few bugs introduced by SHINDIG-328 when the key was already formatted

Modified:
    incubator/shindig/trunk/php/src/gadgets/http/SigningFetcherFactory.php
    incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php

Modified: incubator/shindig/trunk/php/src/gadgets/http/SigningFetcherFactory.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/SigningFetcherFactory.php?rev=662851&r1=662850&r2=662851&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/SigningFetcherFactory.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/http/SigningFetcherFactory.php Tue 
Jun  3 11:08:00 2008
@@ -57,17 +57,21 @@
                                        if (! $rsa_private_key = 
@file_get_contents($keyFile)) {
                                                throw new Exception("Could not 
read keyfile ($keyFile), check the file name and permission");
                                        }
-                                       $phrase = 
Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : 
null;
-                                       $privateKey .= "-----BEGIN PRIVATE 
KEY-----\n";
-                                       $chunks = str_split($rsa_private_key, 
64);
-                                       foreach ($chunks as $chunk) {
-                                               $privateKey .= $chunk . "\n";
+                                       $phrase = 
Config::get('private_key_phrase') != '' ? (Config::get('private_key_phrase')) : 
null;
+                                       if (strpos($rsa_private_key, 
"-----BEGIN") === false) {
+                                               $privateKey .= "-----BEGIN 
PRIVATE KEY-----\n";
+                                               $chunks = 
str_split($rsa_private_key, 64);
+                                               foreach ($chunks as $chunk) {
+                                                       $privateKey .= $chunk . 
"\n";
+                                               }
+                                               $privateKey .= "-----END 
PRIVATE KEY-----";
+                                       } else {
+                                               $privateKey = $rsa_private_key;
                                        }
-                                       $privateKey .= "-----END PRIVATE 
KEY-----";
+                                       $cache->set(md5("RSA_PRIVATE_KEY_" . 
$this->keyName), $rsa_private_key);
                                        if (! $rsa_private_key = 
@openssl_pkey_get_private($privateKey, $phrase)) {
                                                throw new Exception("Could not 
create the key");
                                        }
-                                       $cache->set(md5("RSA_PRIVATE_KEY_" . 
$this->keyName), $rsa_private_key);
                                }
                        } catch (Exception $e) {
                                throw new Exception("Error loading private key: 
" . $e);

Modified: 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php?rev=662851&r1=662850&r2=662851&view=diff
==============================================================================
--- 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php 
(original)
+++ 
incubator/shindig/trunk/php/src/gadgets/oauth/BasicGadgetOAuthTokenStore.php 
Tue Jun  3 11:08:00 2008
@@ -91,16 +91,26 @@
                        if (($cachedRequest = $cache->get(md5("RSA_KEY_" . 
$serviceName))) !== false) {
                                $consumerSecret = $cachedRequest;
                        } else {
-                               $consumerSecret = "-----BEGIN PRIVATE 
KEY-----\n";
-                               $chunks = 
str_split($consumerInfo[$this->CONSUMER_SECRET_KEY], 64);
-                               foreach ($chunks as $chunk) {
-                                       $consumerSecret .= $chunk . "\n";
+                               $key = 
$consumerInfo[$this->CONSUMER_SECRET_KEY];
+                               if (empty($key)) {
+                                       throw new Exception("Invalid key");
+                               }
+                               if (strpos($key, "-----BEGIN") === false) {
+                                       $strip_this = array(" ", "\n", "\r");
+                                       //removes breaklines and trim.
+                                       $rsa_private_key = 
trim(str_replace($strip_this, "", $key));
+                                       $consumerSecret = 
OAuth::$BEGIN_PRIVATE_KEY . "\n";
+                                       $chunks = str_split($rsa_private_key, 
64);
+                                       foreach ($chunks as $chunk) {
+                                               $consumerSecret .= $chunk . 
"\n";
+                                       }
+                                       $consumerSecret .= 
OAuth::$END_PRIVATE_KEY;
+                               } else {
+                                       $consumerSecret = $key;
                                }
-                               $consumerSecret .= "-----END PRIVATE KEY-----";
                                $cache->set(md5("RSA_KEY_" . $serviceName), 
$consumerSecret);
                        }
                }
-               
                $kas = new ConsumerKeyAndSecret($consumerKey, $consumerSecret, 
$keyType);
                $this->storeConsumerKeyAndSecret($gadgetUri, $serviceName, 
$kas);
        }

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php?rev=662851&r1=662850&r2=662851&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuth.php Tue Jun  3 11:08:00 
2008
@@ -32,6 +32,8 @@
        public static $OAUTH_VERSION = "oauth_version";
        public static $HMAC_SHA1 = "HMAC_SHA1";
        public static $RSA_SHA1 = "RSA_SHA1";
+       public static $BEGIN_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----";
+       public static $END_PRIVATE_KEY = "-----END PRIVATE KEY-----";
 }
 
 /* Generic exception class
@@ -282,7 +284,7 @@
        {
                $parameters = is_array($parameters) ? $parameters : array();
                $defaults = array("oauth_nonce" => 
OAuthRequest::generate_nonce(), "oauth_timestamp" => 
OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key, // 
quick hack to make this demo'able
-               'synd' => 'partuza', 'container' => 'partuza');
+'synd' => 'partuza', 'container' => 'partuza');
                $parameters = array_merge($defaults, $parameters);
                if (isset($token)) {
                        $parameters['oauth_token'] = $token;


Reply via email to