@@ -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