Search code examples
phpcurlhttpsrhelvimeo-api

Using the Vimeo api gives intermittent ssl error when getting video list


I am having issues using the PHP API here. It works but every 2nd or 3rd request I get the following error:

Unable to complete request.[SSL connect error]

This is happening on Vimeo.php:154. This is right after curl has executed. I tried using curl on its own at the command line and have gotten:

curl: (35) SSL connect error

This references:

A problem occurred somewhere in the SSL/TLS handshake. You really want the error buffer and read the message there as it pinpoints the problem slightly more. Could be certificates (file formats, paths, permissions), passwords, and others.

So I tried it with PHP file_get_contents and the warning I get is

Warning: file_get_contents(): SSL: Connection reset by peer

I am kind of at a loss for where this comming from and don't know if this is VImeo rejecting my request sometimes or the server losing the connection sometimes. I am trying to find out if someone has had this issue before or has some steps I can use to go about getting more of a clue as to what is causing the issue. Here is my code

Using file_Gets_contents

$opts = array(
                'http'=>array(
                        'method'=>"GET",
                        'header'=>"Authorization: bearer <Personal access token>\r\n"
                ),
                'ssl'=>array(
                        'allow_self_signed'=>false,
                        'verify_peer'=>false,
                )
        );
$context = stream_context_create($opts);
$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$unparsed_json = file_get_contents($url, false, $context);

$json_object = json_decode($unparsed_json);
var_dump($json_object);die();

Using CURL

$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$curlHeader = [
    'Authorization: bearer <Personal access token>',
    'Accept: ' . self::VERSION_STRING,
];
$ch = curl_init();
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$unparsed_json = curl_exec ($ch);
// Check if any error occurred
if(curl_errno($ch))
{
    $info = curl_getinfo($ch);
    var_dump('Curl error: ', curl_error($ch), ' Curl error no: ', curl_errno($ch), ' Unparsed json: ', $unparsed_json, ' Info: ', $info, 'DIR CERT: ', __DIR__ . '/CERT'); die();
}
curl_close ($ch);
$json_object = json_decode($unparsed_json);
var_dump($unparsed_json);die();

Using Vimeo.php

$userAccount = '<user account>';
$url = "https://api.vimeo.com/users/$userAccount/videos";
$client_id = '<Client ID>';
$client_secret = '<Secret>';
$lib = new Vimeo\Vimeo($client_id, $client_secret);

$lib->setToken('<Personal access token>');
$response = $lib->request($url, [], 'GET');
var_dump($response['body']);die();

I used verbose on curl at the Linux command line and saw this:

About to connect() to api.vimeo.com port 443 (#0)
Trying 104.156.85.217... connected
Connected to api.vimeo.com (104.156.85.217) port 443 (#0)
Initializing NSS with certpath: sql:/etc/pki/nssdb
CAfile: 'cert file location'
CApath: none
NSS error -5961
Closing connection #0
SSL connect error

curl: (35) SSL connect error


Solution

  • I found the issue was that the web filter was blocking. The way I found out was using openssl directly:

    [username@server username]$ openssl s_client -connect :443 -msg
    CONNECTED(00000003)
    '>>> TLS 1.2 Handshake [length 00f4], ClientHello
    write:errno=104
    ---
    no peer certificate available
    ---
    No client certificate CA names sent
    ---
    SSL handshake has read 0 bytes and written 249 bytes
    ---
    New, (NONE), Cipher is (NONE)
    Secure Renegotiation IS NOT supported
    Compression: NONE
    Expansion: NONE
    ---