2015-02-24 18:05:19 +00: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-24 21:29:10 +00:00
|
|
|
* @param $uid userid
|
|
|
|
* @param $password user password
|
2015-02-24 18:05:19 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-03-24 21:29:10 +00:00
|
|
|
public function setupUser($uid, $password) {
|
|
|
|
return $this->setupServerSide($uid, $password);
|
2015-02-24 18:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-24 21:29:10 +00:00
|
|
|
* @param $uid userid
|
|
|
|
* @param $password user password
|
2015-02-24 18:05:19 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2015-03-24 21:29:10 +00:00
|
|
|
public function setupServerSide($uid, $password) {
|
2015-02-24 18:05:19 +00:00
|
|
|
// Check if user already has keys
|
2015-03-24 21:29:10 +00:00
|
|
|
if (!$this->keyManager->userHasKeys($uid)) {
|
|
|
|
return $this->keyManager->storeKeyPair($uid, $password,
|
|
|
|
$this->crypt->createKeyPair());
|
2015-02-24 18:05:19 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|