Skip to content

Commit 2e1971e

Browse files
Merge pull request phpmyadmin#17143 from mauriciofauth/ca-bundle
Use `composer/ca-bundle` to manage the CA cert file
2 parents 9d8b873 + e5f9012 commit 2e1971e

File tree

10 files changed

+27
-216
lines changed

10 files changed

+27
-216
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ phpMyAdmin - ChangeLog
2121
- issue #16425 Add "DELETE FROM" table on table operations page
2222
- issue #16482 Add a select all link for table-specific privileges
2323
- issue #14276 Add support for account locking
24+
- issue #17143 Use composer/ca-bundle to manage the CA cert file
25+
- issue #17143 Require the openssl PHP extension
2426

2527
5.1.2 (not yet released)
2628
- issue Replaced MySQL documentation redirected links

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
"ext-iconv": "*",
4545
"ext-json": "*",
4646
"ext-mysqli": "*",
47+
"ext-openssl": "*",
4748
"ext-pcre": "*",
4849
"ext-xml": "*",
50+
"composer/ca-bundle": "^1.2",
4951
"google/recaptcha": "^1.1",
5052
"nikic/fast-route": "^1.3",
5153
"phpmyadmin/motranslator": "^5.0",
@@ -73,7 +75,6 @@
7375
"tecnickcom/tcpdf": "<6.2"
7476
},
7577
"suggest": {
76-
"ext-openssl": "Cookie encryption",
7778
"ext-curl": "Updates checking",
7879
"ext-opcache": "Better performance",
7980
"ext-zlib": "For gz import and export",

libraries/certs/12d55845.0

Lines changed: 0 additions & 20 deletions
This file was deleted.

libraries/certs/2e5ac55d.0

Lines changed: 0 additions & 20 deletions
This file was deleted.

libraries/certs/4042bcee.0

Lines changed: 0 additions & 31 deletions
This file was deleted.

libraries/certs/6187b673.0

Lines changed: 0 additions & 31 deletions
This file was deleted.

libraries/certs/README.rst

Lines changed: 0 additions & 16 deletions
This file was deleted.

libraries/certs/cacert.pem

Lines changed: 0 additions & 51 deletions
This file was deleted.

libraries/classes/Utils/HttpRequest.php

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace PhpMyAdmin\Utils;
66

7+
use Composer\CaBundle\CaBundle;
8+
79
use function base64_encode;
810
use function curl_exec;
911
use function curl_getinfo;
@@ -15,14 +17,14 @@
1517
use function ini_get;
1618
use function intval;
1719
use function is_array;
20+
use function is_dir;
1821
use function parse_url;
1922
use function preg_match;
2023
use function stream_context_create;
2124
use function strlen;
2225

2326
use const CURL_IPRESOLVE_V4;
2427
use const CURLINFO_HTTP_CODE;
25-
use const CURLINFO_SSL_VERIFYRESULT;
2628
use const CURLOPT_CAINFO;
2729
use const CURLOPT_CAPATH;
2830
use const CURLOPT_CONNECTTIMEOUT;
@@ -145,7 +147,6 @@ private function response(
145147
* @param bool $returnOnlyStatus If set to true, the method would only return response status
146148
* @param mixed $content Content to be sent with HTTP request
147149
* @param string $header Header to be set for the HTTP request
148-
* @param int $ssl SSL mode to use
149150
*
150151
* @return string|bool|null
151152
*/
@@ -154,8 +155,7 @@ private function curl(
154155
$method,
155156
$returnOnlyStatus = false,
156157
$content = null,
157-
$header = '',
158-
$ssl = 0
158+
$header = ''
159159
) {
160160
$curlHandle = curl_init($url);
161161
if ($curlHandle === false) {
@@ -188,21 +188,14 @@ private function curl(
188188
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $content);
189189
}
190190

191-
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, '2');
192-
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, '1');
193-
194-
/**
195-
* Configure ISRG Root X1 to be able to verify Let's Encrypt SSL
196-
* certificates even without properly configured curl in PHP.
197-
*
198-
* See https://letsencrypt.org/certificates/
199-
*/
200-
$certsDir = ROOT_PATH . 'libraries/certs/';
201-
/* See code below for logic */
202-
if ($ssl == CURLOPT_CAPATH) {
203-
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAPATH, $certsDir);
204-
} elseif ($ssl == CURLOPT_CAINFO) {
205-
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAINFO, $certsDir . 'cacert.pem');
191+
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, 2);
192+
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, true);
193+
194+
$caPathOrFile = CaBundle::getSystemCaRootBundlePath();
195+
if (is_dir($caPathOrFile)) {
196+
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAPATH, $caPathOrFile);
197+
} else {
198+
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_CAINFO, $caPathOrFile);
206199
}
207200

208201
$curlStatus &= (int) curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
@@ -217,28 +210,6 @@ private function curl(
217210

218211
$response = @curl_exec($curlHandle);
219212
if ($response === false) {
220-
/*
221-
* In case of SSL verification failure let's try configuring curl
222-
* certificate verification. Unfortunately it is tricky as setting
223-
* options incompatible with PHP build settings can lead to failure.
224-
*
225-
* So let's rather try the options one by one.
226-
*
227-
* 1. Try using system SSL storage.
228-
* 2. Try setting CURLOPT_CAINFO.
229-
* 3. Try setting CURLOPT_CAPATH.
230-
* 4. Fail.
231-
*/
232-
if (curl_getinfo($curlHandle, CURLINFO_SSL_VERIFYRESULT) != 0) {
233-
if ($ssl == 0) {
234-
return $this->curl($url, $method, $returnOnlyStatus, $content, $header, CURLOPT_CAINFO);
235-
}
236-
237-
if ($ssl == CURLOPT_CAINFO) {
238-
return $this->curl($url, $method, $returnOnlyStatus, $content, $header, CURLOPT_CAPATH);
239-
}
240-
}
241-
242213
return null;
243214
}
244215

@@ -273,6 +244,10 @@ private function fopen(
273244
'user_agent' => 'phpMyAdmin',
274245
'header' => 'Accept: */*',
275246
],
247+
'ssl' => [
248+
'verify_peer' => true,
249+
'verify_peer_name' => true,
250+
],
276251
];
277252
if ($header) {
278253
$context['http']['header'] .= "\n" . $header;
@@ -282,6 +257,13 @@ private function fopen(
282257
$context['http']['content'] = $content;
283258
}
284259

260+
$caPathOrFile = CaBundle::getSystemCaRootBundlePath();
261+
if (is_dir($caPathOrFile)) {
262+
$context['ssl']['capath'] = $caPathOrFile;
263+
} else {
264+
$context['ssl']['cafile'] = $caPathOrFile;
265+
}
266+
285267
$context = $this->handleContext($context);
286268
$response = @file_get_contents(
287269
$url,

scripts/check-release-excludes.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ validateExtension() {
100100
foundFileExt
101101
fi
102102
;;
103-
libraries/certs/*)
104-
if [ "${extension}" != "0" -a "${extension}" != "rst" -a "${extension}" != "pem" ]; then
105-
foundFileExt
106-
fi
107-
;;
108103
libraries/*)
109104
if [ \
110105
"${extension}" != "php" -a "${extension}" != "md" \

0 commit comments

Comments
 (0)