Skip to content

Commit 4ef906b

Browse files
Update src/Appwrite/Platform/Modules/Health/Http/Health/Certificate/Get.php
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 28aa4e8 commit 4ef906b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

  • src/Appwrite/Platform/Modules/Health/Http/Health/Certificate

src/Appwrite/Platform/Modules/Health/Http/Health/Certificate/Get.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public function action(string $domain, Response $response): void
7272
$streamContextParams = stream_context_get_params($sslSocket);
7373
$peerCertificate = $streamContextParams['options']['ssl']['peer_certificate'];
7474
$certificatePayload = openssl_x509_parse($peerCertificate);
75+
76+
fclose($sslSocket); // Close the socket to prevent resource leak
77+
78+
if ($certificatePayload === false) {
79+
throw new Exception(Exception::HEALTH_INVALID_HOST);
80+
}
7581

7682
$sslExpiration = $certificatePayload['validTo_time_t'];
7783
$status = $sslExpiration < time() ? 'fail' : 'pass';
@@ -81,12 +87,11 @@ public function action(string $domain, Response $response): void
8187
}
8288

8389
$response->dynamic(new Document([
84-
'name' => $certificatePayload['name'],
85-
'subjectSN' => $certificatePayload['subject']['CN'],
86-
'issuerOrganisation' => $certificatePayload['issuer']['O'],
90+
'name' => $certificatePayload['name'] ?? '',
91+
'subjectCN' => $certificatePayload['subject']['CN'] ?? '',
92+
'issuerOrganisation' => $certificatePayload['issuer']['O'] ?? '',
8793
'validFrom' => $certificatePayload['validFrom_time_t'],
8894
'validTo' => $certificatePayload['validTo_time_t'],
89-
'signatureTypeSN' => $certificatePayload['signatureTypeSN'],
95+
'signatureTypeSN' => $certificatePayload['signatureTypeSN'] ?? '',
9096
]), Response::MODEL_HEALTH_CERTIFICATE);
91-
}
9297
}

0 commit comments

Comments
 (0)