]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Math_BigInteger doesn't correctly handle serialization/deserialization for a value...
authorBrion Vibber <brion@pobox.com>
Mon, 22 Mar 2010 19:17:45 +0000 (12:17 -0700)
committerBrion Vibber <brion@pobox.com>
Mon, 22 Mar 2010 19:17:45 +0000 (12:17 -0700)
Worked around this with a subclass that fixes the wakeup, used for the stored 0 value in the subclassed Crypt_RSA.

plugins/OStatus/classes/Magicsig.php
plugins/OStatus/lib/safecrypt_rsa.php [new file with mode: 0644]
plugins/OStatus/lib/safemath_biginteger.php [new file with mode: 0644]

index 5705ecc1169a3b3abbd1b2a44d70238bc90f7d2a..87c684c93d87702eac562585797a0167070c4ad9 100644 (file)
@@ -27,8 +27,6 @@
  * @link      http://status.net/
  */
 
-require_once 'Crypt/RSA.php';
-
 class Magicsig extends Memcached_DataObject
 {
 
@@ -102,16 +100,16 @@ class Magicsig extends Memcached_DataObject
 
     public function generate($user_id)
     {
-        $rsa = new Crypt_RSA();
+        $rsa = new SafeCrypt_RSA();
         
         $keypair = $rsa->createKey();
 
         $rsa->loadKey($keypair['privatekey']);
 
-        $this->privateKey = new Crypt_RSA();
+        $this->privateKey = new SafeCrypt_RSA();
         $this->privateKey->loadKey($keypair['privatekey']);
 
-        $this->publicKey = new Crypt_RSA();
+        $this->publicKey = new SafeCrypt_RSA();
         $this->publicKey->loadKey($keypair['publickey']);
         
         $this->user_id = $user_id;
@@ -163,7 +161,7 @@ class Magicsig extends Memcached_DataObject
     {
         common_log(LOG_DEBUG, "Adding ".$type." key: (".$mod .', '. $exp .")");
 
-        $rsa = new Crypt_RSA();
+        $rsa = new SafeCrypt_RSA();
         $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
         $rsa->setHash('sha256');
         $rsa->modulus = new Math_BigInteger(base64_url_decode($mod), 256);
diff --git a/plugins/OStatus/lib/safecrypt_rsa.php b/plugins/OStatus/lib/safecrypt_rsa.php
new file mode 100644 (file)
index 0000000..f3aa2c9
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+
+require_once 'Crypt/RSA.php';
+
+/**
+ * Crypt_RSA stores a Math_BigInteger with value 0, which triggers a bug
+ * in Math_BigInteger's wakeup function which spews notices to log or output.
+ * This wrapper replaces it with a version that survives serialization.
+ */
+class SafeCrypt_RSA extends Crypt_RSA
+{
+    function __construct()
+    {
+        parent::__construct();
+        $this->zero = new SafeMath_BigInteger();
+    }
+}
+
diff --git a/plugins/OStatus/lib/safemath_biginteger.php b/plugins/OStatus/lib/safemath_biginteger.php
new file mode 100644 (file)
index 0000000..c05e24d
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+require_once 'Math/BigInteger.php';
+
+/**
+ * Crypt_RSA stores a Math_BigInteger with value 0, which triggers a bug
+ * in Math_BigInteger's wakeup function which spews notices to log or output.
+ * This wrapper replaces it with a version that survives serialization.
+ */
+class SafeMath_BigInteger extends Math_BigInteger
+{
+    function __wakeup()
+    {
+        if ($this->hex == '') {
+            $this->hex = '0';
+        }
+        parent::__wakeup();
+    }
+}
+