2015-02-24 21:05:19 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Clark Tomlinson <fallen013@gmail.com>
|
|
|
|
* @since 3/6/15, 11:36 AM
|
|
|
|
* @link http:/www.clarkt.com
|
|
|
|
* @copyright Clark Tomlinson © 2015
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Encryption\Users;
|
|
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Crypto\Crypt;
|
|
|
|
use OCA\Encryption\KeyManager;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
|
|
|
class Setup extends \OCA\Encryption\Setup {
|
|
|
|
/**
|
|
|
|
* @var Crypt
|
|
|
|
*/
|
|
|
|
private $crypt;
|
|
|
|
/**
|
|
|
|
* @var KeyManager
|
|
|
|
*/
|
|
|
|
private $keyManager;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ILogger $logger
|
|
|
|
* @param IUserSession $userSession
|
|
|
|
* @param Crypt $crypt
|
|
|
|
* @param KeyManager $keyManager
|
|
|
|
*/
|
|
|
|
public function __construct(ILogger $logger, IUserSession $userSession, Crypt $crypt, KeyManager $keyManager) {
|
|
|
|
parent::__construct($logger, $userSession);
|
|
|
|
$this->crypt = $crypt;
|
|
|
|
$this->keyManager = $keyManager;
|
2015-03-27 20:10:32 +03:00
|
|
|
}
|
2015-02-24 21:05:19 +03:00
|
|
|
|
|
|
|
/**
|
2015-03-25 00:29:10 +03:00
|
|
|
* @param $uid userid
|
|
|
|
* @param $password user password
|
2015-02-24 21:05:19 +03:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-03-25 00:29:10 +03:00
|
|
|
public function setupUser($uid, $password) {
|
|
|
|
return $this->setupServerSide($uid, $password);
|
2015-02-24 21:05:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-25 00:29:10 +03:00
|
|
|
* @param $uid userid
|
|
|
|
* @param $password user password
|
2015-02-24 21:05:19 +03:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-03-25 00:29:10 +03:00
|
|
|
public function setupServerSide($uid, $password) {
|
2015-02-24 21:05:19 +03:00
|
|
|
// Check if user already has keys
|
2015-03-25 00:29:10 +03:00
|
|
|
if (!$this->keyManager->userHasKeys($uid)) {
|
|
|
|
return $this->keyManager->storeKeyPair($uid, $password,
|
|
|
|
$this->crypt->createKeyPair());
|
2015-02-24 21:05:19 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|