From 3b803db6d815a6d015d5fa013c8147d66a559973 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Aug 2015 06:39:53 +0200 Subject: [PATCH 1/2] Update phpseclib to 2.0 --- 3rdparty | 2 +- .../files_external/controller/ajaxcontroller.php | 5 +++-- apps/files_external/lib/config.php | 7 +++---- apps/files_external/lib/sftp.php | 16 ++++++++++------ apps/files_external/lib/sftp_key.php | 15 +++++++-------- lib/private/security/crypto.php | 10 +++++----- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/3rdparty b/3rdparty index c45d817921..3a6ccaefdf 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit c45d817921543d2f0562ac4f3be61404b1d4a35e +Subproject commit 3a6ccaefdf72f990a285743c069c303611444a14 diff --git a/apps/files_external/controller/ajaxcontroller.php b/apps/files_external/controller/ajaxcontroller.php index 6225cd0b61..cb2de43228 100644 --- a/apps/files_external/controller/ajaxcontroller.php +++ b/apps/files_external/controller/ajaxcontroller.php @@ -25,6 +25,7 @@ namespace OCA\Files_External\Controller; use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\AppFramework\Http\JSONResponse; +use phpseclib\Crypt\RSA; class AjaxController extends Controller { public function __construct($appName, IRequest $request) { @@ -32,8 +33,8 @@ class AjaxController extends Controller { } private function generateSshKeys() { - $rsa = new \Crypt_RSA(); - $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH); + $rsa = new RSA(); + $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setPassword(\OC::$server->getConfig()->getSystemValue('secret', '')); $key = $rsa->createKey(); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 5dc6d06ae0..91e1aa7d50 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -31,6 +31,8 @@ * */ +use phpseclib\Crypt\AES; + /** * Class to configure mount.json globally and for users */ @@ -895,10 +897,7 @@ class OC_Mount_Config { * Returns the encryption cipher */ private static function getCipher() { - if (!class_exists('Crypt_AES', false)) { - include('Crypt/AES.php'); - } - $cipher = new Crypt_AES(CRYPT_AES_MODE_CBC); + $cipher = new AES(AES::MODE_CBC); $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); return $cipher; } diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index cbe090311a..03ece9cb9d 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -30,8 +30,12 @@ */ namespace OC\Files\Storage; +use phpseclib\Net\RSA; +use phpseclib\Net\SFTP; +use phpseclib\Net\SFTP\Stream; + /** -* Uses phpseclib's Net_SFTP class and the Net_SFTP_Stream stream wrapper to +* Uses phpseclib's Net\SFTP class and the Net\SFTP\Stream stream wrapper to * provide access to SFTP servers. */ class SFTP extends \OC\Files\Storage\Common { @@ -42,7 +46,7 @@ class SFTP extends \OC\Files\Storage\Common { private $port = 22; /** - * @var \Net_SFTP + * @var SFTP */ protected $client; @@ -51,10 +55,10 @@ class SFTP extends \OC\Files\Storage\Common { */ public function __construct($params) { // Register sftp:// - \Net_SFTP_Stream::register(); + Stream::register(); $this->host = $params['host']; - + //deals with sftp://server example $proto = strpos($this->host, '://'); if ($proto != false) { @@ -87,7 +91,7 @@ class SFTP extends \OC\Files\Storage\Common { /** * Returns the connection. * - * @return \Net_SFTP connected client instance + * @return SFTP connected client instance * @throws \Exception when the connection failed */ public function getConnection() { @@ -96,7 +100,7 @@ class SFTP extends \OC\Files\Storage\Common { } $hostKeys = $this->readHostKeys(); - $this->client = new \Net_SFTP($this->host, $this->port); + $this->client = new SFTP($this->host, $this->port); // The SSH Host Key MUST be verified before login(). $currentHostKey = $this->client->getServerPublicHostKey(); diff --git a/apps/files_external/lib/sftp_key.php b/apps/files_external/lib/sftp_key.php index 1bcea6bc96..06771d57d2 100644 --- a/apps/files_external/lib/sftp_key.php +++ b/apps/files_external/lib/sftp_key.php @@ -22,10 +22,9 @@ */ namespace OC\Files\Storage; -/** -* Uses phpseclib's Net_SFTP class and the Net_SFTP_Stream stream wrapper to -* provide access to SFTP servers. -*/ +use phpseclib\Crypt\RSA; +use phpseclib\Net\SFTP; + class SFTP_Key extends \OC\Files\Storage\SFTP { private $publicKey; private $privateKey; @@ -39,7 +38,7 @@ class SFTP_Key extends \OC\Files\Storage\SFTP { /** * Returns the connection. * - * @return \Net_SFTP connected client instance + * @return SFTP connected client instance * @throws \Exception when the connection failed */ public function getConnection() { @@ -48,7 +47,7 @@ class SFTP_Key extends \OC\Files\Storage\SFTP { } $hostKeys = $this->readHostKeys(); - $this->client = new \Net_SFTP($this->getHost()); + $this->client = new SFTP($this->getHost()); // The SSH Host Key MUST be verified before login(). $currentHostKey = $this->client->getServerPublicHostKey(); @@ -74,10 +73,10 @@ class SFTP_Key extends \OC\Files\Storage\SFTP { /** * Returns the private key to be used for authentication to the remote server. * - * @return \Crypt_RSA instance or null in case of a failure to load the key. + * @return RSA instance or null in case of a failure to load the key. */ private function getPrivateKey() { - $key = new \Crypt_RSA(); + $key = new RSA(); $key->setPassword(\OC::$server->getConfig()->getSystemValue('secret', '')); if (!$key->loadKey($this->privateKey)) { // Should this exception rather than return null? diff --git a/lib/private/security/crypto.php b/lib/private/security/crypto.php index bca0f08090..5a7073e950 100644 --- a/lib/private/security/crypto.php +++ b/lib/private/security/crypto.php @@ -23,8 +23,8 @@ namespace OC\Security; -use Crypt_AES; -use Crypt_Hash; +use phpseclib\Crypt\AES; +use phpseclib\Crypt\Hash; use OCP\Security\ICrypto; use OCP\Security\ISecureRandom; use OCP\Security\StringUtils; @@ -41,7 +41,7 @@ use OCP\IConfig; * @package OC\Security */ class Crypto implements ICrypto { - /** @var Crypt_AES $cipher */ + /** @var AES $cipher */ private $cipher; /** @var int */ private $ivLength = 16; @@ -51,7 +51,7 @@ class Crypto implements ICrypto { private $random; function __construct(IConfig $config, ISecureRandom $random) { - $this->cipher = new Crypt_AES(); + $this->cipher = new AES(); $this->config = $config; $this->random = $random; } @@ -69,7 +69,7 @@ class Crypto implements ICrypto { // Append an "a" behind the password and hash it to prevent reusing the same password as for encryption $password = hash('sha512', $password . 'a'); - $hash = new Crypt_Hash('sha512'); + $hash = new Hash('sha512'); $hash->setKey($password); return $hash->hash($message); } From 3cd54cda24c6523e3ddfd77364c8b897c9e64421 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 4 Aug 2015 15:09:06 +0200 Subject: [PATCH 2/2] Rebase upon newest master --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 3a6ccaefdf..0590498b38 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 3a6ccaefdf72f990a285743c069c303611444a14 +Subproject commit 0590498b38aa0c760e2ad7af4fbd19787d62ed4e