From a1d064129a9b8ae5bbd739885db2180f08554a55 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 17 Jun 2016 23:21:34 +0200 Subject: [PATCH] Handle namespaces for new phpseclib --- plugins/OStatus/OStatusPlugin.php | 10 ++++------ plugins/OStatus/classes/Magicsig.php | 24 ++++++++++++------------ plugins/OStatus/lib/magicenvelope.php | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 72f246d68f..d877dd37c6 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -85,12 +85,10 @@ class OStatusPlugin extends Plugin public function onAutoload($cls) { - switch ($cls) { - case 'Crypt_AES': - case 'Crypt_RSA': - // Crypt_AES becomes Crypt/AES.php which is found in extlib/phpseclib/ - // which has been added to our include_path before - require_once str_replace('_', '/', $cls) . '.php'; + if (mb_substr($cls, 0, 10) === 'phpseclib\\') { + // These are saved under extlib/phpseclib with \ as /, + // phpseclib has already been added to our include_path + require_once str_replace('\\', '/', str_replace('phpseclib\\', '', $cls) . '.php'); return false; } diff --git a/plugins/OStatus/classes/Magicsig.php b/plugins/OStatus/classes/Magicsig.php index f5a5733dcb..42a1ff1319 100644 --- a/plugins/OStatus/classes/Magicsig.php +++ b/plugins/OStatus/classes/Magicsig.php @@ -52,7 +52,7 @@ class Magicsig extends Managed_DataObject /** * Flattened string representation of the key pair; callers should * usually use $this->publicKey and $this->privateKey directly, - * which hold live Crypt_RSA key objects. + * which hold live \phpseclib\Crypt\RSA key objects. * * @var string */ @@ -68,14 +68,14 @@ class Magicsig extends Managed_DataObject /** * Public RSA key; gets serialized in/out via $this->keypair string. * - * @var Crypt_RSA + * @var \phpseclib\Crypt\RSA */ public $publicKey; /** * PrivateRSA key; gets serialized in/out via $this->keypair string. * - * @var Crypt_RSA + * @var \phpseclib\Crypt\RSA */ public $privateKey; @@ -95,7 +95,7 @@ class Magicsig extends Managed_DataObject { $obj = parent::getKV($k, $v); if ($obj instanceof Magicsig) { - $obj->importKeys(); // Loads Crypt_RSA objects etc. + $obj->importKeys(); // Loads \phpseclib\Crypt\RSA objects etc. // Throw out a big fat warning for keys of less than 1024 bits. ( // The only case these show up in would be imported or @@ -156,14 +156,14 @@ class Magicsig extends Managed_DataObject $magicsig = new Magicsig($alg); $magicsig->user_id = $user->id; - $rsa = new Crypt_RSA(); + $rsa = new \phpseclib\Crypt\RSA(); $keypair = $rsa->createKey($bits); - $magicsig->privateKey = new Crypt_RSA(); + $magicsig->privateKey = new \phpseclib\Crypt\RSA(); $magicsig->privateKey->loadKey($keypair['privatekey']); - $magicsig->publicKey = new Crypt_RSA(); + $magicsig->publicKey = new \phpseclib\Crypt\RSA(); $magicsig->publicKey->loadKey($keypair['publickey']); $magicsig->insert(); // will do $this->keypair = $this->toString(true); @@ -185,7 +185,7 @@ class Magicsig extends Managed_DataObject $exp = call_user_func($base64_func, $this->publicKey->exponent->toBytes()); $private_exp = ''; - if ($full_pair && $this->privateKey instanceof Crypt_RSA && $this->privateKey->exponent->toBytes()) { + if ($full_pair && $this->privateKey instanceof \phpseclib\Crypt\RSA && $this->privateKey->exponent->toBytes()) { $private_exp = '.' . call_user_func($base64_func, $this->privateKey->exponent->toBytes()); } @@ -211,7 +211,7 @@ class Magicsig extends Managed_DataObject /** * importKeys will load the object's keypair string, which initiates - * loadKey() and configures Crypt_RSA objects. + * loadKey() and configures \phpseclib\Crypt\RSA objects. * * @param string $keypair optional, otherwise the object's "keypair" property will be used */ @@ -240,7 +240,7 @@ class Magicsig extends Managed_DataObject } /** - * Fill out $this->privateKey or $this->publicKey with a Crypt_RSA object + * Fill out $this->privateKey or $this->publicKey with a \phpseclib\Crypt\RSA object * representing the give key (as mod/exponent pair). * * @param string $mod base64url-encoded @@ -249,7 +249,7 @@ class Magicsig extends Managed_DataObject */ public function loadKey($mod, $exp, $type = 'public') { - $rsa = new Crypt_RSA(); + $rsa = new \phpseclib\Crypt\RSA(); $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1); $rsa->setHash($this->getHash()); $rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256); @@ -265,7 +265,7 @@ class Magicsig extends Managed_DataObject public function loadPublicKeyPKCS1($key) { - $rsa = new Crypt_RSA(); + $rsa = new \phpseclib\Crypt\RSA(); if (!$rsa->setPublicKey($key, CRYPT_RSA_PUBLIC_FORMAT_PKCS1)) { throw new ServerException('Could not load PKCS1 public key. We probably got this from a remote Diaspora node as the profile public key.'); } diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php index 27ff0de5bf..48b88a2d5f 100644 --- a/plugins/OStatus/lib/magicenvelope.php +++ b/plugins/OStatus/lib/magicenvelope.php @@ -97,7 +97,7 @@ class MagicEnvelope throw new ServerException(sprintf('No public key found for profile (id==%d)', $profile->id)); } - assert($magicsig->publicKey instanceof Crypt_RSA); + assert($magicsig->publicKey instanceof \phpseclib\Crypt\RSA); return $magicsig; } @@ -203,7 +203,7 @@ class MagicEnvelope $magicsig = Magicsig::generate($this->actor->getUser()); } assert($magicsig instanceof Magicsig); - assert($magicsig->privateKey instanceof Crypt_RSA); + assert($magicsig->privateKey instanceof \phpseclib\Crypt\RSA); // Prepare text and metadata for signing $this->data = Magicsig::base64_url_encode($text);