Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose setting CURLSSLOPT_NATIVE_CA as an option #1776

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ parameters:
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getHttpSslNativeCa\\(\\) should return bool but returns mixed\\.$#"
count: 1
path: src/Options.php

-
message: "#^Method Sentry\\\\Options\\:\\:getHttpSslVerifyPeer\\(\\) should return bool but returns mixed\\.$#"
count: 1
Expand Down
11 changes: 11 additions & 0 deletions src/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ public function sendRequest(Request $request, Options $options): Response
curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, false);
}

$httpSslNativeCa = $options->getHttpSslNativeCa();
if ($httpSslNativeCa) {
if (
\defined('CURLSSLOPT_NATIVE_CA')
&& isset(curl_version()['version'])
&& version_compare(curl_version()['version'], '7.71', '>=')
) {
curl_setopt($curlHandle, \CURLOPT_SSL_OPTIONS, \CURLSSLOPT_NATIVE_CA);
}
}

$httpProxy = $options->getHttpProxy();
if ($httpProxy !== null) {
curl_setopt($curlHandle, \CURLOPT_PROXY, $httpProxy);
Expand Down
15 changes: 15 additions & 0 deletions src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,20 @@ public function setHttpSslVerifyPeer(bool $httpSslVerifyPeer): self
return $this;
}

public function getHttpSslNativeCa(): bool
{
return $this->options['http_ssl_native_ca'];
}

public function setHttpSslNativeCa(bool $httpSslNativeCa): self
{
$options = array_merge($this->options, ['http_ssl_native_ca' => $httpSslNativeCa]);

$this->options = $this->resolver->resolve($options);

return $this;
}

/**
* Returns whether the requests should be compressed using GZIP or not.
*/
Expand Down Expand Up @@ -1139,6 +1153,7 @@ private function configureOptions(OptionsResolver $resolver): void
'http_connect_timeout' => self::DEFAULT_HTTP_CONNECT_TIMEOUT,
'http_timeout' => self::DEFAULT_HTTP_TIMEOUT,
'http_ssl_verify_peer' => true,
'http_ssl_native_ca' => false,
'http_compression' => true,
'capture_silenced_errors' => false,
'max_request_body_size' => 'medium',
Expand Down
7 changes: 7 additions & 0 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ static function (): void {},
'setHttpSslVerifyPeer',
];

yield [
'http_ssl_native_ca',
true,
'getHttpSslNativeCa',
'setHttpSslNativeCa',
];

yield [
'http_compression',
false,
Expand Down
Loading