yesterday i got error
stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000086:SSL routines::certificate verify failed {"exception":"object
my code is
private function getSSLInfo($url)
{
$parsedUrl = parse_url($url);
$host = $parsedUrl["host"];
$port = isset($parsedUrl["port"]) ? $parsedUrl["port"] : 443;
$context = stream_context_create(["ssl" => ["capture_peer_cert" => true]]);
$client = stream_socket_client("ssl://$host:$port", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($client) {
$sslInfo = stream_context_get_params($client)["options"]["ssl"]["peer_certificate"];
return openssl_x509_parse($sslInfo);
} else {
return false;
}
}
Solution
$context = stream_context_create([
"ssl" => [
"capture_peer_cert" => true,
"verify_peer" => false,
"verify_peer_name" => false,
],
]);
Full Code Solution
private function getSSLInfo($url)
{
$parsedUrl = parse_url($url);
$host = $parsedUrl["host"];
$port = isset($parsedUrl["port"]) ? $parsedUrl["port"] : 443;
$context = stream_context_create([
"ssl" => [
"capture_peer_cert" => true,
"verify_peer" => false,
"verify_peer_name" => false,
],
]);
$client = stream_socket_client("ssl://$host:$port", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if ($client) {
$sslInfo = stream_context_get_params($client)["options"]["ssl"]["peer_certificate"];
return openssl_x509_parse($sslInfo);
} else {
return false;
}
}
Top comments (0)