Skip to content

Commit c94641b

Browse files
committed
ext/curl: Use default native CA
1 parent 4bf4c24 commit c94641b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

ext/curl/interface.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,15 @@ static void _php_curl_set_default_options(php_curl *ch)
11991199
if (cainfo && cainfo[0] != '\0') {
12001200
curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo);
12011201
}
1202+
#if LIBCURL_VERSION_NUM >= 0x075400 /* Available since 7.71.0 */
1203+
/* Curl supports falling back to the native/OS root certificates
1204+
* if cainfo is not provided. When the php.ini cainfo is empty,
1205+
* setting CURLSSLOPT_NATIVE_CA enables this behavior.
1206+
*/
1207+
else {
1208+
curl_easy_setopt(ch->cp, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
1209+
}
1210+
#endif
12021211

12031212
#ifdef ZTS
12041213
curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1);

ext/curl/tests/curl_native_ca.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Curl defaulting to default CA root store, especially in Windows
3+
--EXTENSIONS--
4+
curl
5+
--DESCRIPTION--
6+
On Windows, there is no fallback root CA store, so all HTTPS requests that require validation (default)
7+
fail by default. Curl >= 7.71.0 has a CURLOPT_SSL_OPTIONS = CURLSSLOPT_NATIVE_CA option that falls back
8+
to Windows root CA store.
9+
--SKIPIF--
10+
<?php
11+
if (getenv("SKIP_ONLINE_TESTS")) die("skip online test");
12+
$curl_version = curl_version();
13+
if ($curl_version['version_number'] < 0x074700) {
14+
die("skip: test works only with curl >= 7.71.0");
15+
}
16+
?>
17+
--INI--
18+
19+
--FILE--
20+
<?php
21+
$ch = curl_init('https://sha256.badssl.com/');
22+
$cert = curl_getinfo($ch, CURLINFO_CAINFO);
23+
var_dump($cert);
24+
curl_setopt_array($ch, [
25+
CURLOPT_RETURNTRANSFER => true,
26+
CURLOPT_SSL_VERIFYHOST => 2,
27+
CURLOPT_SSL_VERIFYPEER => 1,
28+
]);
29+
30+
curl_exec($ch);
31+
var_dump(curl_getinfo($ch, CURLINFO_SSL_VERIFYRESULT));
32+
33+
?>
34+
--EXPECT--
35+
int(0)

0 commit comments

Comments
 (0)