AjaxController uses RSA auth mechanism

This commit is contained in:
Robin McCorkell 2015-08-19 21:13:16 +01:00
parent 1084e3adc7
commit 080fafe63a
3 changed files with 22 additions and 20 deletions

View File

@ -24,7 +24,6 @@
namespace OCA\Files_External\AppInfo;
use \OCA\Files_External\Controller\AjaxController;
use \OCP\AppFramework\App;
use \OCP\IContainer;
use \OCA\Files_External\Service\BackendService;
@ -36,18 +35,6 @@ class Application extends App {
public function __construct(array $urlParams=array()) {
parent::__construct('files_external', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('AjaxController', function (IContainer $c) {
return new AjaxController(
$c->query('AppName'),
$c->query('Request')
);
});
$this->loadBackends();
$this->loadAuthMechanisms();
}

View File

@ -25,19 +25,19 @@ namespace OCA\Files_External\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\JSONResponse;
use phpseclib\Crypt\RSA;
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
class AjaxController extends Controller {
public function __construct($appName, IRequest $request) {
/** @var RSA */
private $rsaMechanism;
public function __construct($appName, IRequest $request, RSA $rsaMechanism) {
parent::__construct($appName, $request);
$this->rsaMechanism = $rsaMechanism;
}
private function generateSshKeys() {
$rsa = new RSA();
$rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
$rsa->setPassword(\OC::$server->getConfig()->getSystemValue('secret', ''));
$key = $rsa->createKey();
$key = $this->rsaMechanism->createKey();
// Replace the placeholder label with a more meaningful one
$key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);

View File

@ -33,6 +33,8 @@ use \phpseclib\Crypt\RSA as RSACrypt;
*/
class RSA extends AuthMechanism {
const CREATE_KEY_BITS = 1024;
/** @var IConfig */
private $config;
@ -62,4 +64,17 @@ class RSA extends AuthMechanism {
$storage->setBackendOption('public_key_auth', $auth);
}
/**
* Generate a keypair
*
* @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
*/
public function createKey() {
$rsa = new RSACrypt();
$rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
$rsa->setPassword($this->config->getSystemValue('secret', ''));
return $rsa->createKey(self::CREATE_KEY_BITS);
}
}