Debug School

rakesh kumar
rakesh kumar

Posted on

Laravel Error:stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:

yesterday i got error

Image description

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;
        }
    }
Enter fullscreen mode Exit fullscreen mode

Solution

$context = stream_context_create([
    "ssl" => [
        "capture_peer_cert" => true,
        "verify_peer" => false,
        "verify_peer_name" => false,
    ],
]);
Enter fullscreen mode Exit fullscreen mode

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;
        }
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)