Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/files_sharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\Group\Events\GroupChangedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
use OCP\Share\Events\ShareCreatedEvent;
Expand All @@ -69,7 +70,8 @@ public function register(IRegistrationContext $context): void {
function () use ($c) {
return $c->get(Manager::class);
},
$c->get(ICloudIdManager::class)
$c->get(ICloudIdManager::class),
$c->get(IConfig::class),
);
});

Expand Down
33 changes: 20 additions & 13 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
Expand Down Expand Up @@ -72,20 +73,24 @@ class Manager {
/** @var LoggerInterface */
private $logger;

/** @var IConfig */
private $config;

public function __construct(
IDBConnection $connection,
\OC\Files\Mount\Manager $mountManager,
IStorageFactory $storageLoader,
IClientService $clientService,
IManager $notificationManager,
IDiscoveryService $discoveryService,
IDBConnection $connection,
\OC\Files\Mount\Manager $mountManager,
IStorageFactory $storageLoader,
IClientService $clientService,
IManager $notificationManager,
IDiscoveryService $discoveryService,
ICloudFederationProviderManager $cloudFederationProviderManager,
ICloudFederationFactory $cloudFederationFactory,
IGroupManager $groupManager,
IUserManager $userManager,
IUserSession $userSession,
IEventDispatcher $eventDispatcher,
LoggerInterface $logger
ICloudFederationFactory $cloudFederationFactory,
IGroupManager $groupManager,
IUserManager $userManager,
IUserSession $userSession,
IEventDispatcher $eventDispatcher,
LoggerInterface $logger,
IConfig $config,
) {
$user = $userSession->getUser();
$this->connection = $connection;
Expand All @@ -101,6 +106,7 @@ public function __construct(
$this->userManager = $userManager;
$this->eventDispatcher = $eventDispatcher;
$this->logger = $logger;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -167,7 +173,8 @@ public function addShare($remote, $token, $password, $name, $owner, $shareType,
'token' => $token,
'password' => $password,
'mountpoint' => $mountPoint,
'owner' => $owner
'owner' => $owner,
'verify' => !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates'),
];
return $this->mountShare($options);
}
Expand Down
10 changes: 9 additions & 1 deletion apps/files_sharing/lib/External/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use OCP\Federation\ICloudIdManager;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IUser;

Expand All @@ -32,15 +33,21 @@ class MountProvider implements IMountProvider {
*/
private $cloudIdManager;

/**
* @var IConfig
*/
private $config;

/**
* @param \OCP\IDBConnection $connection
* @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself
* @param ICloudIdManager $cloudIdManager
*/
public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) {
public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager, IConfig $config) {
$this->connection = $connection;
$this->managerProvider = $managerProvider;
$this->cloudIdManager = $cloudIdManager;
$this->config = $config;
}

public function getMount(IUser $user, $data, IStorageFactory $storageFactory) {
Expand All @@ -52,6 +59,7 @@ public function getMount(IUser $user, $data, IStorageFactory $storageFactory) {
$data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']);
$data['certificateManager'] = \OC::$server->getCertificateManager();
$data['HttpClientService'] = \OC::$server->getHTTPClientService();
$data['verify'] = !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates');
return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory);
}

Expand Down
6 changes: 5 additions & 1 deletion apps/files_sharing/tests/External/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -79,6 +80,7 @@ class ManagerTest extends TestCase {
private $testMountProvider;
/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;
private IConfig $config;

protected function setUp(): void {
parent::setUp();
Expand All @@ -90,6 +92,7 @@ protected function setUp(): void {
->disableOriginalConstructor()->getMock();
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
$this->config = $this->createMock(IConfig::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
Expand All @@ -113,7 +116,7 @@ protected function setUp(): void {
$this->userManager,
$this->createMock(ICacheFactory::class),
$this->createMock(IEventDispatcher::class)
));
), $this->config);

$group1 = $this->createMock(IGroup::class);
$group1->expects($this->any())->method('getGID')->willReturn('group1');
Expand Down Expand Up @@ -165,6 +168,7 @@ private function createManagerForUser($userId) {
$userSession,
$this->eventDispatcher,
$this->logger,
$this->config,
]
)->setMethods(['tryOCMEndPoint'])->getMock();
}
Expand Down
16 changes: 12 additions & 4 deletions lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DAV extends Common {
protected $host;
/** @var bool */
protected $secure;
protected bool $verify;
/** @var string */
protected $root;
/** @var string */
Expand Down Expand Up @@ -102,12 +103,14 @@ public function __construct($params) {
$this->authType = $params['authType'];
}
if (isset($params['secure'])) {
$this->verify = $params['verify'] ?? true;
if (is_string($params['secure'])) {
$this->secure = ($params['secure'] === 'true');
} else {
$this->secure = (bool) $params['secure'];
}
} else {
$this->verify = false;
$this->secure = false;
}
if ($this->secure === true) {
Expand Down Expand Up @@ -151,6 +154,9 @@ protected function init() {
$this->client->setThrowExceptions(true);

if ($this->secure === true) {
if ($this->verify === false) {
$this->client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
}
$certPath = $this->certManager->getAbsoluteBundlePath();
if (file_exists($certPath)) {
$this->certPath = $certPath;
Expand All @@ -162,13 +168,13 @@ protected function init() {

$lastRequestStart = 0;
$this->client->on('beforeRequest', function (RequestInterface $request) use (&$lastRequestStart) {
$this->logger->debug('sending dav ' . $request->getMethod() . ' request to external storage: ' . $request->getAbsoluteUrl(), ['app' => 'dav']);
$this->logger->debug('sending dav ' . $request->getMethod() . ' request to external storage: ' . $request->getAbsoluteUrl(), ['app' => 'dav']);
$lastRequestStart = microtime(true);
$this->eventLogger->start('fs:storage:dav:request', 'Sending dav request to external storage');
});
$this->client->on('afterRequest', function (RequestInterface $request) use (&$lastRequestStart) {
$elapsed = microtime(true) - $lastRequestStart;
$this->logger->debug('dav ' . $request->getMethod() . ' request to external storage: ' . $request->getAbsoluteUrl() . ' took ' . round($elapsed * 1000, 1) . 'ms', ['app' => 'dav']);
$this->logger->debug('dav ' . $request->getMethod() . ' request to external storage: ' . $request->getAbsoluteUrl() . ' took ' . round($elapsed * 1000, 1) . 'ms', ['app' => 'dav']);
$this->eventLogger->end('fs:storage:dav:request');
});
}
Expand Down Expand Up @@ -338,7 +344,8 @@ public function fopen($path, $mode) {
'auth' => [$this->user, $this->password],
'stream' => true,
// set download timeout for users with slow connections or large files
'timeout' => $this->timeout
'timeout' => $this->timeout,
'verify' => $this->verify,
]);
} catch (\GuzzleHttp\Exception\ClientException $e) {
if ($e->getResponse() instanceof ResponseInterface
Expand Down Expand Up @@ -494,7 +501,8 @@ protected function uploadFile($path, $target) {
'body' => $source,
'auth' => [$this->user, $this->password],
// set upload timeout for users with slow connections or large files
'timeout' => $this->timeout
'timeout' => $this->timeout,
'verify' => $this->verify,
]);

$this->removeCachedFile($target);
Expand Down
Loading