summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/auth
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/auth')
-rw-r--r--apps/files_external/lib/auth/authmechanism.php6
-rw-r--r--apps/files_external/lib/auth/openstack/openstack.php48
-rw-r--r--apps/files_external/lib/auth/openstack/rackspace.php46
-rw-r--r--apps/files_external/lib/auth/publickey/rsa.php80
4 files changed, 177 insertions, 3 deletions
diff --git a/apps/files_external/lib/auth/authmechanism.php b/apps/files_external/lib/auth/authmechanism.php
index 11d99bb330d..ddc0c6a4dca 100644
--- a/apps/files_external/lib/auth/authmechanism.php
+++ b/apps/files_external/lib/auth/authmechanism.php
@@ -22,7 +22,7 @@
namespace OCA\Files_External\Lib\Auth;
use \OCA\Files_External\Lib\StorageConfig;
-use \OCA\Files_External\Lib\VisibilityTrait;
+use \OCA\Files_External\Lib\PermissionsTrait;
use \OCA\Files_External\Lib\IdentifierTrait;
use \OCA\Files_External\Lib\FrontendDefinitionTrait;
use \OCA\Files_External\Lib\StorageModifierTrait;
@@ -40,7 +40,7 @@ use \OCA\Files_External\Lib\StorageModifierTrait;
* scheme, which are provided from the authentication mechanism.
*
* This class uses the following traits:
- * - VisibilityTrait
+ * - PermissionsTrait
* Restrict usage to admin-only/none
* - FrontendDefinitionTrait
* Specify configuration parameters and other definitions
@@ -58,7 +58,7 @@ class AuthMechanism implements \JsonSerializable {
const SCHEME_PUBLICKEY = 'publickey';
const SCHEME_OPENSTACK = 'openstack';
- use VisibilityTrait;
+ use PermissionsTrait;
use FrontendDefinitionTrait;
use StorageModifierTrait;
use IdentifierTrait;
diff --git a/apps/files_external/lib/auth/openstack/openstack.php b/apps/files_external/lib/auth/openstack/openstack.php
new file mode 100644
index 00000000000..faf356bcf2e
--- /dev/null
+++ b/apps/files_external/lib/auth/openstack/openstack.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * @author Robin McCorkell <rmccorkell@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib\Auth\OpenStack;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+
+/**
+ * OpenStack Keystone authentication
+ */
+class OpenStack extends AuthMechanism {
+
+ public function __construct(IL10N $l) {
+ $this
+ ->setIdentifier('openstack::openstack')
+ ->setScheme(self::SCHEME_OPENSTACK)
+ ->setText($l->t('OpenStack'))
+ ->addParameters([
+ (new DefinitionParameter('user', $l->t('Username'))),
+ (new DefinitionParameter('password', $l->t('Password')))
+ ->setType(DefinitionParameter::VALUE_PASSWORD),
+ (new DefinitionParameter('tenant', $l->t('Tenant name'))),
+ (new DefinitionParameter('url', $l->t('Identity endpoint URL'))),
+ ])
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/auth/openstack/rackspace.php b/apps/files_external/lib/auth/openstack/rackspace.php
new file mode 100644
index 00000000000..9268f3aad87
--- /dev/null
+++ b/apps/files_external/lib/auth/openstack/rackspace.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @author Robin McCorkell <rmccorkell@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib\Auth\OpenStack;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+
+/**
+ * Rackspace authentication
+ */
+class Rackspace extends AuthMechanism {
+
+ public function __construct(IL10N $l) {
+ $this
+ ->setIdentifier('openstack::rackspace')
+ ->setScheme(self::SCHEME_OPENSTACK)
+ ->setText($l->t('Rackspace'))
+ ->addParameters([
+ (new DefinitionParameter('user', $l->t('Username'))),
+ (new DefinitionParameter('key', $l->t('API key')))
+ ->setType(DefinitionParameter::VALUE_PASSWORD),
+ ])
+ ;
+ }
+
+}
diff --git a/apps/files_external/lib/auth/publickey/rsa.php b/apps/files_external/lib/auth/publickey/rsa.php
new file mode 100644
index 00000000000..f40136dda01
--- /dev/null
+++ b/apps/files_external/lib/auth/publickey/rsa.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * @author Robin McCorkell <rmccorkell@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib\Auth\PublicKey;
+
+use \OCP\IL10N;
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCP\IConfig;
+use \phpseclib\Crypt\RSA as RSACrypt;
+
+/**
+ * RSA public key authentication
+ */
+class RSA extends AuthMechanism {
+
+ const CREATE_KEY_BITS = 1024;
+
+ /** @var IConfig */
+ private $config;
+
+ public function __construct(IL10N $l, IConfig $config) {
+ $this->config = $config;
+
+ $this
+ ->setIdentifier('publickey::rsa')
+ ->setScheme(self::SCHEME_PUBLICKEY)
+ ->setText($l->t('RSA public key'))
+ ->addParameters([
+ (new DefinitionParameter('user', $l->t('Username'))),
+ (new DefinitionParameter('public_key', $l->t('Public key'))),
+ (new DefinitionParameter('private_key', 'private_key'))
+ ->setType(DefinitionParameter::VALUE_HIDDEN),
+ ])
+ ->setCustomJs('public_key')
+ ;
+ }
+
+ public function manipulateStorageConfig(StorageConfig &$storage) {
+ $auth = new RSACrypt();
+ $auth->setPassword($this->config->getSystemValue('secret', ''));
+ if (!$auth->loadKey($storage->getBackendOption('private_key'))) {
+ throw new \RuntimeException('unable to load private key');
+ }
+ $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);
+ }
+
+}