use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
use OCP\Security\StringUtils;
/** @var DbHandler */
private $dbHandler;
+ /** @var ILogger */
+ private $logger;
+
/**
* OCSAuthAPI constructor.
*
* @param IJobList $jobList
* @param TrustedServers $trustedServers
* @param DbHandler $dbHandler
+ * @param ILogger $logger
*/
public function __construct(
IRequest $request,
ISecureRandom $secureRandom,
IJobList $jobList,
TrustedServers $trustedServers,
- DbHandler $dbHandler
+ DbHandler $dbHandler,
+ ILogger $logger
) {
$this->request = $request;
$this->secureRandom = $secureRandom;
$this->jobList = $jobList;
$this->trustedServers = $trustedServers;
$this->dbHandler = $dbHandler;
+ $this->logger = $logger;
}
/**
$token = $this->request->getParam('token');
if ($this->trustedServers->isTrustedServer($url) === false) {
+ $this->logger->log(\OCP\Util::ERROR, 'remote server not trusted (' . $url . ') while requesting shared secret');
return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
}
// token wins
$localToken = $this->dbHandler->getToken($url);
if (strcmp($localToken, $token) > 0) {
+ $this->logger->log(\OCP\Util::ERROR, 'remote server (' . $url . ') presented lower token');
return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
}
$url = $this->request->getParam('url');
$token = $this->request->getParam('token');
- if (
- $this->trustedServers->isTrustedServer($url) === false
- || $this->isValidToken($url, $token) === false
- ) {
+ if ($this->trustedServers->isTrustedServer($url) === false) {
+ $this->logger->log(\OCP\Util::ERROR, 'remote server not trusted (' . $url . ') while getting shared secret');
+ return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
+ }
+
+ if ($this->isValidToken($url, $token) === false) {
+ $this->logger->log(\OCP\Util::ERROR, 'remote server (' . $url . ') didn\'t send a valid token (got ' . $token . ') while getting shared secret');
return new \OC_OCS_Result(null, HTTP::STATUS_FORBIDDEN);
}
$this->trustedServers = new TrustedServers(
$this->dbHandler,
\OC::$server->getHTTPClientService(),
- \OC::$server->getLogger(),
+ $this->logger,
$this->jobList,
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
} catch (ClientException $e) {
$status = $e->getCode();
+ $this->logger->logException($e);
}
// if we received a unexpected response we try again later
private $endPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json';
+ /** @var ILogger */
+ private $logger;
+
/**
* RequestSharedSecret constructor.
*
$this->jobList = $jobList ? $jobList : \OC::$server->getJobList();
$this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator();
$this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation'));
+ $this->logger = \OC::$server->getLogger();
if ($trustedServers) {
$this->trustedServers = $trustedServers;
} else {
$this->trustedServers = new TrustedServers(
$this->dbHandler,
\OC::$server->getHTTPClientService(),
- \OC::$server->getLogger(),
+ $this->logger,
$this->jobList,
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
} catch (ClientException $e) {
$status = $e->getCode();
+ $this->logger->logException($e);
}
// if we received a unexpected response we try again later
use OCA\Federation\DbHandler;
use OCA\Federation\TrustedServers;
use OCP\AppFramework\Http;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\Security\ISecureRandom;
use Test\TestCase;
/** @var \PHPUnit_Framework_MockObject_MockObject | DbHandler */
private $dbHandler;
+ /** @var \PHPUnit_Framework_MockObject_MockObject | ILogger */
+ private $logger;
+
/** @var OCSAuthApi */
private $ocsAuthApi;
->disableOriginalConstructor()->getMock();
$this->jobList = $this->getMockBuilder('OC\BackgroundJob\JobList')
->disableOriginalConstructor()->getMock();
+ $this->logger = $this->getMockBuilder('OCP\ILogger')
+ ->disableOriginalConstructor()->getMock();
$this->ocsAuthApi = new OCSAuthAPI(
$this->request,
$this->secureRandom,
$this->jobList,
$this->trustedServers,
- $this->dbHandler
+ $this->dbHandler,
+ $this->logger
);
}
$this->secureRandom,
$this->jobList,
$this->trustedServers,
- $this->dbHandler
+ $this->dbHandler,
+ $this->logger
]
)->setMethods(['isValidToken'])->getMock();