Skip to content

Commit f97d6b5

Browse files
committed
refactor: verify SSL peer and host when using client certificates
1 parent 3b46225 commit f97d6b5

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/PrefillGravityForms/Controllers/BaseController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ protected function handleCurl(array $args, string $transientKey): array
311311
curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $this->settings->getPassphrase());
312312
}
313313

314-
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->settings->getSupplierCertificate() ? true : false);
315-
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->settings->getSupplierCertificate() ? 2 : 0);
314+
$shouldVerifyPeerHost = $this->shouldVerifyPeerHost();
315+
316+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $shouldVerifyPeerHost);
317+
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $shouldVerifyPeerHost ? 2 : 0);
316318
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeoutOptionCURL());
317319

318320
$output = curl_exec($curl);
@@ -346,6 +348,15 @@ protected function handleCurl(array $args, string $transientKey): array
346348
}
347349
}
348350

351+
/**
352+
* Verification of the peer's SSL certificate and host is only necessary when
353+
* SSL certificates are used and a supplier certificate is provided.
354+
*/
355+
private function shouldVerifyPeerHost(): bool
356+
{
357+
return $this->settings->useSSLCertificates() && $this->settings->getSupplierCertificate();
358+
}
359+
349360
/**
350361
* Extracts the burgerservicenummer (BSN) from the API response.
351362
*/

0 commit comments

Comments
 (0)