Skip to content

Commit 383514b

Browse files
authored
Expose setting CURLSSLOPT_NATIVE_CA as an option (#1776)
1 parent 0ecfac5 commit 383514b

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ parameters:
125125
count: 1
126126
path: src/Options.php
127127

128+
-
129+
message: "#^Method Sentry\\\\Options\\:\\:getHttpSslNativeCa\\(\\) should return bool but returns mixed\\.$#"
130+
count: 1
131+
path: src/Options.php
132+
128133
-
129134
message: "#^Method Sentry\\\\Options\\:\\:getHttpSslVerifyPeer\\(\\) should return bool but returns mixed\\.$#"
130135
count: 1

src/HttpClient/HttpClient.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ public function sendRequest(Request $request, Options $options): Response
7878
curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false);
7979
}
8080

81+
$httpSslNativeCa = $options->getHttpSslNativeCa();
82+
if ($httpSslNativeCa) {
83+
if (
84+
\defined('CURLSSLOPT_NATIVE_CA')
85+
&& isset(curl_version()['version'])
86+
&& version_compare(curl_version()['version'], '7.71', '>=')
87+
) {
88+
curl_setopt($curlHandle, \CURLOPT_SSL_OPTIONS, \CURLSSLOPT_NATIVE_CA);
89+
}
90+
}
91+
8192
$httpProxy = $options->getHttpProxy();
8293
if ($httpProxy !== null) {
8394
curl_setopt($curlHandle, \CURLOPT_PROXY, $httpProxy);

src/Options.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,20 @@ public function setHttpSslVerifyPeer(bool $httpSslVerifyPeer): self
942942
return $this;
943943
}
944944

945+
public function getHttpSslNativeCa(): bool
946+
{
947+
return $this->options['http_ssl_native_ca'];
948+
}
949+
950+
public function setHttpSslNativeCa(bool $httpSslNativeCa): self
951+
{
952+
$options = array_merge($this->options, ['http_ssl_native_ca' => $httpSslNativeCa]);
953+
954+
$this->options = $this->resolver->resolve($options);
955+
956+
return $this;
957+
}
958+
945959
/**
946960
* Returns whether the requests should be compressed using GZIP or not.
947961
*/
@@ -1139,6 +1153,7 @@ private function configureOptions(OptionsResolver $resolver): void
11391153
'http_connect_timeout' => self::DEFAULT_HTTP_CONNECT_TIMEOUT,
11401154
'http_timeout' => self::DEFAULT_HTTP_TIMEOUT,
11411155
'http_ssl_verify_peer' => true,
1156+
'http_ssl_native_ca' => false,
11421157
'http_compression' => true,
11431158
'capture_silenced_errors' => false,
11441159
'max_request_body_size' => 'medium',

tests/OptionsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ static function (): void {},
362362
'setHttpSslVerifyPeer',
363363
];
364364

365+
yield [
366+
'http_ssl_native_ca',
367+
true,
368+
'getHttpSslNativeCa',
369+
'setHttpSslNativeCa',
370+
];
371+
365372
yield [
366373
'http_compression',
367374
false,

0 commit comments

Comments
 (0)