diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-07-04 17:37:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 17:37:25 +0200 |
commit | 711d861d8ba0486a0262cff45dd124bba1da1f2e (patch) | |
tree | 2a24db7a78de457ee2420163e42eea7b9ae7fe00 /apps/files_external/lib | |
parent | f3c25e177f428d0438d73505915e4bf110c835b7 (diff) | |
parent | e3127b8899575ead3c256d09657898bc0fc13a82 (diff) | |
download | nextcloud-server-711d861d8ba0486a0262cff45dd124bba1da1f2e.tar.gz nextcloud-server-711d861d8ba0486a0262cff45dd124bba1da1f2e.zip |
Merge pull request #5556 from nextcloud/files_external_sftp_2048_4096
[Files external] Add support for 2048 and 4096 bit RSA key generation
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/Controller/AjaxController.php | 10 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Auth/PublicKey/RSA.php | 11 |
2 files changed, 13 insertions, 8 deletions
diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php index f12f8450973..5f5b32cffb6 100644 --- a/apps/files_external/lib/Controller/AjaxController.php +++ b/apps/files_external/lib/Controller/AjaxController.php @@ -68,10 +68,11 @@ class AjaxController extends Controller { } /** + * @param int $keyLength * @return array */ - private function generateSshKeys() { - $key = $this->rsaMechanism->createKey(); + private function generateSshKeys($keyLength) { + $key = $this->rsaMechanism->createKey($keyLength); // Replace the placeholder label with a more meaningful one $key['publickey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']); @@ -82,9 +83,10 @@ class AjaxController extends Controller { * Generates an SSH public/private key pair. * * @NoAdminRequired + * @param int $keyLength */ - public function getSshKeys() { - $key = $this->generateSshKeys(); + public function getSshKeys($keyLength = 1024) { + $key = $this->generateSshKeys($keyLength); return new JSONResponse( array('data' => array( 'private_key' => $key['privatekey'], diff --git a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php index cb387b22012..8dedf8c5196 100644 --- a/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php +++ b/apps/files_external/lib/Lib/Auth/PublicKey/RSA.php @@ -35,8 +35,6 @@ use \phpseclib\Crypt\RSA as RSACrypt; */ class RSA extends AuthMechanism { - const CREATE_KEY_BITS = 1024; - /** @var IConfig */ private $config; @@ -69,14 +67,19 @@ class RSA extends AuthMechanism { /** * Generate a keypair * + * @param int $keyLenth * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey] */ - public function createKey() { + public function createKey($keyLength) { $rsa = new RSACrypt(); $rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH); $rsa->setPassword($this->config->getSystemValue('secret', '')); - return $rsa->createKey(self::CREATE_KEY_BITS); + if ($keyLength !== 1024 && $keyLength !== 2048 && $keyLength !== 4096) { + $keyLength = 1024; + } + + return $rsa->createKey($keyLength); } } |