Skip to content

Commit 8b235c8

Browse files
committed
fix(files_sharing): respect config to skip certificate verification
This is important especially for local development, as certificate are self-signed. Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent c29c702 commit 8b235c8

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
use OCP\Group\Events\GroupDeletedEvent;
5353
use OCP\Group\Events\UserAddedEvent;
5454
use OCP\Group\Events\UserRemovedEvent;
55+
use OCP\IConfig;
5556
use OCP\IDBConnection;
5657
use OCP\IGroup;
5758
use OCP\Share\Events\BeforeShareDeletedEvent;
@@ -77,7 +78,8 @@ public function register(IRegistrationContext $context): void {
7778
function () use ($c) {
7879
return $c->get(Manager::class);
7980
},
80-
$c->get(ICloudIdManager::class)
81+
$c->get(ICloudIdManager::class),
82+
$c->get(IConfig::class),
8183
);
8284
});
8385

apps/files_sharing/lib/External/Manager.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\Files\Storage\IStorageFactory;
2727
use OCP\Http\Client\IClientService;
2828
use OCP\ICertificateManager;
29+
use OCP\IConfig;
2930
use OCP\IDBConnection;
3031
use OCP\IGroup;
3132
use OCP\IGroupManager;
@@ -56,6 +57,7 @@ public function __construct(
5657
private ISetupManager $setupManager,
5758
private ICertificateManager $certificateManager,
5859
private ExternalShareMapper $externalShareMapper,
60+
private IConfig $config,
5961
) {
6062
$this->user = $userSession->getUser();
6163
}
@@ -113,6 +115,7 @@ public function addShare(ExternalShare $externalShare, IUser|IGroup|null $shareW
113115
'password' => $externalShare->getPassword(),
114116
'mountpoint' => $externalShare->getMountpoint(),
115117
'owner' => $externalShare->getOwner(),
118+
'verify' => !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates'),
116119
];
117120
return $this->mountShare($options, $user);
118121
}

apps/files_sharing/lib/External/MountProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCP\Files\Storage\IStorageFactory;
1818
use OCP\Http\Client\IClientService;
1919
use OCP\ICertificateManager;
20+
use OCP\IConfig;
2021
use OCP\IDBConnection;
2122
use OCP\IUser;
2223
use OCP\Server;
@@ -37,6 +38,7 @@ public function __construct(
3738
private readonly IDBConnection $connection,
3839
callable $managerProvider,
3940
private readonly ICloudIdManager $cloudIdManager,
41+
private IConfig $config,
4042
) {
4143
$this->managerProvider = $managerProvider;
4244
}
@@ -50,6 +52,7 @@ private function getMount(IUser $user, array $data, IStorageFactory $storageFact
5052
$data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']);
5153
$data['certificateManager'] = Server::get(ICertificateManager::class);
5254
$data['HttpClientService'] = Server::get(IClientService::class);
55+
$data['verify'] = !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates');
5356

5457
return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory);
5558
}

apps/files_sharing/tests/External/ManagerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\Http\Client\IResponse;
3131
use OCP\ICacheFactory;
3232
use OCP\ICertificateManager;
33+
use OCP\IConfig;
3334
use OCP\IDBConnection;
3435
use OCP\IGroup;
3536
use OCP\IGroupManager;
@@ -71,6 +72,7 @@ class ManagerTest extends TestCase {
7172
protected ISetupManager&MockObject $setupManager;
7273
protected ICertificateManager&MockObject $certificateManager;
7374
private ExternalShareMapper $externalShareMapper;
75+
private IConfig $config;
7476

7577
protected function setUp(): void {
7678
parent::setUp();
@@ -81,6 +83,7 @@ protected function setUp(): void {
8183
->disableOriginalConstructor()->getMock();
8284
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
8385
$this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class);
86+
$this->config = $this->createMock(IConfig::class);
8487
$this->groupManager = $this->createMock(IGroupManager::class);
8588
$this->userManager = $this->createMock(IUserManager::class);
8689
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
@@ -119,7 +122,7 @@ protected function setUp(): void {
119122
$this->contactsManager,
120123
$this->createMock(IURLGenerator::class),
121124
$this->userManager,
122-
));
125+
), $this->config);
123126

124127
$this->group1 = $this->createMock(IGroup::class);
125128
$this->group1->expects($this->any())->method('getGID')->willReturn('group1');
@@ -169,6 +172,7 @@ private function createManagerForUser(IUser $user): Manager&MockObject {
169172
$this->setupManager,
170173
$this->certificateManager,
171174
$this->externalShareMapper,
175+
$this->config,
172176
]
173177
)->onlyMethods(['tryOCMEndPoint'])->getMock();
174178
}

lib/private/Files/Storage/DAV.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class DAV extends Common {
5454
protected $host;
5555
/** @var bool */
5656
protected $secure;
57+
protected bool $verify;
5758
/** @var string */
5859
protected $root;
5960
/** @var string */
@@ -108,12 +109,14 @@ public function __construct(array $parameters) {
108109
$this->authType = $parameters['authType'];
109110
}
110111
if (isset($parameters['secure'])) {
112+
$this->verify = $parameters['verify'] ?? true;
111113
if (is_string($parameters['secure'])) {
112114
$this->secure = ($parameters['secure'] === 'true');
113115
} else {
114116
$this->secure = (bool)$parameters['secure'];
115117
}
116118
} else {
119+
$this->verify = false;
117120
$this->secure = false;
118121
}
119122
if ($this->secure === true) {
@@ -157,6 +160,9 @@ protected function init(): void {
157160
$this->client->setThrowExceptions(true);
158161

159162
if ($this->secure === true) {
163+
if ($this->verify === false) {
164+
$this->client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
165+
}
160166
$certPath = $this->certManager->getAbsoluteBundlePath();
161167
if (file_exists($certPath)) {
162168
$this->certPath = $certPath;
@@ -363,7 +369,8 @@ public function fopen(string $path, string $mode) {
363369
'auth' => [$this->user, $this->password],
364370
'stream' => true,
365371
// set download timeout for users with slow connections or large files
366-
'timeout' => $this->timeout
372+
'timeout' => $this->timeout,
373+
'verify' => $this->verify,
367374
]);
368375
} catch (\GuzzleHttp\Exception\ClientException $e) {
369376
if ($e->getResponse() instanceof ResponseInterface
@@ -513,7 +520,8 @@ protected function uploadFile(string $path, string $target): void {
513520
'body' => $source,
514521
'auth' => [$this->user, $this->password],
515522
// set upload timeout for users with slow connections or large files
516-
'timeout' => $this->timeout
523+
'timeout' => $this->timeout,
524+
'verify' => $this->verify,
517525
]);
518526

519527
$this->removeCachedFile($target);

0 commit comments

Comments
 (0)