diff --git a/app/Libraries/Abdm/EAtriaBridgeConnector.php b/app/Libraries/Abdm/EAtriaBridgeConnector.php index e316674..483f352 100644 --- a/app/Libraries/Abdm/EAtriaBridgeConnector.php +++ b/app/Libraries/Abdm/EAtriaBridgeConnector.php @@ -305,13 +305,22 @@ class EAtriaBridgeConnector implements AbdmConnectorInterface . ' | token_source=' . $tokenSource . ' | body=' . json_encode($safeRequestBody)); + // SSL verification stays ON by default. Some local WAMP/XAMPP + // installs ship a stale bundled cacert.pem, causing cURL error 60 + // on outbound HTTPS calls. Fix that by updating curl.cainfo in + // php.ini on the affected machine; only as a last resort can a + // specific deployment opt out via ABDM_BRIDGE_SSL_VERIFY=false. + $sslVerifyRaw = strtolower(trim((string) (getenv('ABDM_BRIDGE_SSL_VERIFY') ?: ''))); + $sslVerify = ! in_array($sslVerifyRaw, ['0', 'false', 'no', 'off'], true); + $ch = curl_init(); $curlOptions = [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->timeoutSec, CURLOPT_HTTPHEADER => $headers, - CURLOPT_SSL_VERIFYPEER => true, + CURLOPT_SSL_VERIFYPEER => $sslVerify, + CURLOPT_SSL_VERIFYHOST => $sslVerify ? 2 : 0, CURLOPT_CUSTOMREQUEST => $method, ]; diff --git a/app/Libraries/Abdm/M3HiuGatewayClient.php b/app/Libraries/Abdm/M3HiuGatewayClient.php index df25ebc..826dfe3 100644 --- a/app/Libraries/Abdm/M3HiuGatewayClient.php +++ b/app/Libraries/Abdm/M3HiuGatewayClient.php @@ -14,6 +14,23 @@ class M3HiuGatewayClient $this->baseUrl = rtrim((string) (getenv('EATRIA_BRIDGE_URL') ?: 'https://abdm-bridge.e-atria.in/api'), '/'); } + /** + * SSL peer/host verification is ON by default (secure). Some local + * WAMP/XAMPP/Laragon installs ship a stale bundled cacert.pem which makes + * outbound HTTPS calls fail with cURL error 60 (SSL certificate problem). + * Rather than disabling verification for everyone, allow an explicit, + * per-deployment opt-out via env for that specific broken environment: + * ABDM_BRIDGE_SSL_VERIFY=false + * The correct long-term fix on the affected machine is to update PHP's + * CA bundle (curl.cainfo in php.ini), not to disable verification. + */ + private function sslVerifyEnabled(): bool + { + $raw = strtolower(trim((string) (getenv('ABDM_BRIDGE_SSL_VERIFY') ?: ''))); + + return ! in_array($raw, ['0', 'false', 'no', 'off'], true); + } + private function sanitizeBearerToken(string $token): string { $token = trim($token); @@ -88,12 +105,14 @@ class M3HiuGatewayClient $headers[] = 'X-Hospital-Id: ' . $hospitalId; } + $sslVerify = $this->sslVerifyEnabled(); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->timeoutSec, - CURLOPT_SSL_VERIFYPEER => true, + CURLOPT_SSL_VERIFYPEER => $sslVerify, + CURLOPT_SSL_VERIFYHOST => $sslVerify ? 2 : 0, CURLOPT_HTTPHEADER => $headers, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), @@ -266,12 +285,14 @@ class M3HiuGatewayClient $url .= '?' . http_build_query($cleanQuery); } + $sslVerify = $this->sslVerifyEnabled(); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->timeoutSec, - CURLOPT_SSL_VERIFYPEER => true, + CURLOPT_SSL_VERIFYPEER => $sslVerify, + CURLOPT_SSL_VERIFYHOST => $sslVerify ? 2 : 0, CURLOPT_HTTPHEADER => $headers, CURLOPT_CUSTOMREQUEST => 'GET', ]); diff --git a/check_new_docs.php b/check_new_docs.php new file mode 100644 index 0000000..7bccb85 --- /dev/null +++ b/check_new_docs.php @@ -0,0 +1,6 @@ +query("SELECT id, document_title, document_date, care_context_reference, created_at FROM abdm_hiu_documents WHERE abha_address = '{$abha}' ORDER BY id DESC LIMIT 5"); +while ($row = $res->fetch_assoc()) { print_r($row); } +$db->close();