diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index 8ddb3afaf33aa..084c33b5fed42 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -49,6 +49,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; @@ -72,7 +73,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), ); }); diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index ff4781eba0f8f..4bc58ab94f05b 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -22,6 +22,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; @@ -55,6 +56,7 @@ public function __construct( IUserSession $userSession, private IEventDispatcher $eventDispatcher, private LoggerInterface $logger, + private IConfig $config, ) { $user = $userSession->getUser(); $this->uid = $user ? $user->getUID() : null; @@ -124,7 +126,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, $user); } diff --git a/apps/files_sharing/lib/External/MountProvider.php b/apps/files_sharing/lib/External/MountProvider.php index a5781d5d35ac5..ca98d47a36b45 100644 --- a/apps/files_sharing/lib/External/MountProvider.php +++ b/apps/files_sharing/lib/External/MountProvider.php @@ -12,6 +12,7 @@ use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; use OCP\Http\Client\IClientService; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IUser; use OCP\Server; @@ -33,6 +34,7 @@ public function __construct( private IDBConnection $connection, callable $managerProvider, private ICloudIdManager $cloudIdManager, + private IConfig $config, ) { $this->managerProvider = $managerProvider; } @@ -46,6 +48,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'] = Server::get(IClientService::class); + $data['verify'] = !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates'); return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory); } diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index 14c6afec4d8f8..e4b2cf0a94382 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -24,6 +24,7 @@ use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; use OCP\IGroupManager; @@ -61,6 +62,7 @@ class ManagerTest extends TestCase { protected ICloudFederationFactory&MockObject $cloudFederationFactory; protected IGroupManager&MockObject $groupManager; protected IUserManager&MockObject $userManager; + private IConfig $config; protected function setUp(): void { parent::setUp(); @@ -72,6 +74,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); @@ -95,7 +98,7 @@ protected function setUp(): void { $this->contactsManager, $this->createMock(IURLGenerator::class), $this->userManager, - )); + ), $this->config); $group1 = $this->createMock(IGroup::class); $group1->expects($this->any())->method('getGID')->willReturn('group1'); @@ -147,6 +150,7 @@ private function createManagerForUser($userId) { $userSession, $this->eventDispatcher, $this->logger, + $this->config, ] )->onlyMethods(['tryOCMEndPoint'])->getMock(); } diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 1721c6d25db5b..df87b1b98f5e0 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -52,6 +52,7 @@ class DAV extends Common { protected $host; /** @var bool */ protected $secure; + protected bool $verify; /** @var string */ protected $root; /** @var string */ @@ -106,12 +107,14 @@ public function __construct(array $parameters) { $this->authType = $parameters['authType']; } if (isset($parameters['secure'])) { + $this->verify = $parameters['verify'] ?? true; if (is_string($parameters['secure'])) { $this->secure = ($parameters['secure'] === 'true'); } else { $this->secure = (bool)$parameters['secure']; } } else { + $this->verify = false; $this->secure = false; } if ($this->secure === true) { @@ -155,6 +158,9 @@ protected function init(): void { $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; @@ -361,7 +367,8 @@ public function fopen(string $path, string $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 @@ -511,7 +518,8 @@ protected function uploadFile(string $path, string $target): void { '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);