Skip to content

Commit b396704

Browse files
authored
Merge pull request nextcloud#1319 from nextcloud/sslHandlerFunction
refactor: Add SSL verification handling function
2 parents 72d9c5e + 03775b7 commit b396704

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

lib/Helper/HttpClientHelper.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
/**
56
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
67
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -23,34 +24,41 @@ public function __construct(
2324
}
2425

2526
public function get($url, array $headers = [], array $options = []) {
26-
$oidcConfig = $this->config->getSystemValue('user_oidc', []);
27-
28-
$client = $this->clientService->newClient();
29-
30-
$debugModeEnabled = $this->config->getSystemValueBool('debug', false);
31-
if ($debugModeEnabled
32-
|| (isset($oidcConfig['httpclient.allowselfsigned'])
33-
&& !in_array($oidcConfig['httpclient.allowselfsigned'], [false, 'false', 0, '0'], true))) {
27+
if ($this->shouldDisableSSLVerification()) {
3428
$options['verify'] = false;
3529
}
3630

37-
return $client->get($url, $options)->getBody();
31+
return $this->clientService->newClient()->get($url, $options)->getBody();
3832
}
3933

4034
public function post($url, $body, array $headers = []) {
41-
$oidcConfig = $this->config->getSystemValue('user_oidc', []);
42-
$client = $this->clientService->newClient();
43-
4435
$options = [
4536
'headers' => $headers,
4637
'body' => $body,
4738
];
4839

49-
if (isset($oidcConfig['httpclient.allowselfsigned'])
50-
&& !in_array($oidcConfig['httpclient.allowselfsigned'], [false, 'false', 0, '0'], true)) {
40+
if ($this->shouldDisableSSLVerification()) {
5141
$options['verify'] = false;
5242
}
5343

54-
return $client->post($url, $options)->getBody();
44+
return $this->clientService->newClient()->post($url, $options)->getBody();
45+
}
46+
47+
private function shouldDisableSSLVerification(): bool {
48+
if ($this->config->getSystemValueBool('debug', false)) {
49+
return true;
50+
}
51+
52+
$oidcConfig = $this->config->getSystemValue('user_oidc', []);
53+
if (!isset($oidcConfig['httpclient.allowselfsigned'])) {
54+
return false;
55+
}
56+
57+
$allowSelfSigned = $oidcConfig['httpclient.allowselfsigned'];
58+
59+
return !($allowSelfSigned === false
60+
|| $allowSelfSigned === 'false'
61+
|| $allowSelfSigned === 0
62+
|| $allowSelfSigned === '0');
5563
}
5664
}

0 commit comments

Comments
 (0)