Skip to content

Commit 1791b7e

Browse files
committed
Fix SSL certificate check errors by using the OS certificate authorities instead of PHP's configuration (which can be unset or out of date).
1 parent 9a01b60 commit 1791b7e

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/Supporting/CommunicationProvider.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,21 @@ public function callRestAPI($params, $isAddToken, $method = 'GET', $request = nu
596596
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
597597
if ($methodLower == 'post') {
598598
curl_setopt($ch, CURLOPT_POST, 1);
599-
} else
600-
if ($methodLower == 'put') {
601-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
602-
} else if ($methodLower == 'patch') {
603-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
604-
} else if ($methodLower == 'delete') {
605-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
606-
} else {
607-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
608-
}
599+
} elseif (in_array($methodLower, ['put', 'patch', 'delete', 'get'], true)) {
600+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($methodLower));
601+
}
609602
if ($this->isCertVaridating) {
610603
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
611604
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
605+
// Use the OS native certificate authorities, if possible.
606+
// This fixes SSL validation errors if `php.ini` doesn't have
607+
// [curl] `curl.cainfo` set properly of if this PEM file isn't
608+
// up to date. Better rely on the OS certificate authorities, which
609+
// is maintained automatically.
610+
if (defined('CURLSSLOPT_NATIVE_CA')
611+
&& version_compare(curl_version()['version'], '7.71', '>=')) {
612+
curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
613+
}
612614
} else {
613615
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
614616
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

0 commit comments

Comments
 (0)