Completed
Push — master ( 097cba...398505 )
by Lukas
10:38
created

AjaxController::generateSshKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Morris Jobke <[email protected]>
4
 * @author Robin Appelman <[email protected]>
5
 * @author Robin McCorkell <[email protected]>
6
 * @author Ross Nicoll <[email protected]>
7
 *
8
 * @copyright Copyright (c) 2016, ownCloud, Inc.
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OCA\Files_External\Controller;
26
27
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
28
use OCP\AppFramework\Controller;
29
use OCP\IRequest;
30
use OCP\AppFramework\Http\JSONResponse;
31
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
32
33
class AjaxController extends Controller {
34
	/** @var RSA */
35
	private $rsaMechanism;
36
	/** @var GlobalAuth  */
37
	private $globalAuth;
38
39
	public function __construct($appName,
40
								IRequest $request,
41
								RSA $rsaMechanism,
42
								GlobalAuth $globalAuth) {
43
		parent::__construct($appName, $request);
44
		$this->rsaMechanism = $rsaMechanism;
45
		$this->globalAuth = $globalAuth;
46
	}
47
48
	private function generateSshKeys() {
49
		$key = $this->rsaMechanism->createKey();
50
		// Replace the placeholder label with a more meaningful one
51
		$key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
52
53
		return $key;
54
	}
55
56
	/**
57
	 * Generates an SSH public/private key pair.
58
	 *
59
	 * @NoAdminRequired
60
	 */
61
	public function getSshKeys() {
62
		$key = $this->generateSshKeys();
63
		return new JSONResponse(
64
			array('data' => array(
65
				'private_key' => $key['privatekey'],
66
				'public_key' => $key['publickey']
67
			),
68
			'status' => 'success'
69
		));
70
	}
71
72
	/**
73
	 * @param string $uid
74
	 * @param string $user
75
	 * @param string $password
76
	 * @return bool
77
	 */
78
	public function saveGlobalCredentials($uid, $user, $password) {
79
		$this->globalAuth->saveAuth($uid, $user, $password);
80
		return true;
81
	}
82
}
83