Kayako wget OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

We are using Kayako for our support ticket system. I just updated our server from Ubuntu 12.04 to Ubuntu 14.04. We started to see a problem with some crons which automate the importing and processing of emails.

This is the error that we got:

Resolving support.oursite.com (support.oursite.com)... 127.0.1.1
Connecting to support.oursite.com (support.oursite.com)|127.0.1.1|:443... connected.
OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Unable to establish SSL connection.

There are several possible SSL problems that this could be:

1 – The destination site does not like the protocol – this could be caused but CURL / WGET not using a compatible version of SSL as the server. So you can try setting the version of ssl like so:

wget -secure-protocol=SSLv2 https://example.com
curl --sslv2 https://example.com

2 – The destination site does not like the cipher. This can be caused by a poor cipher configuration in Apache or anonymous ciphers is disabled on the server.

Finally – and this was my problem…

The php script that was making the request was located on the same server as the Kayako support ticket system. The url for the server was something like support.randomhacks.co.uk and the hostname of the server was also support.randomhacks.co.uk . So, when looking up the DNS record for support.randomhacks.co.uk the computer went to /etc/hosts and returned 127.0.0.1 rather than the public ip address. So, when the script tried to connect to Apache at 127.0.0.1 using https it failed because SSL certificates a limited to one ip address only and this was the public IP address.

I hope help solve you problem. I would be great to hear if you have another solution.
I hope this helps someone.

Request Entity Too Large – php curl error

I have been trying to make curl post request to a script like so:

    $ch = curl_init('http://my.server/api.php');                     
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => 'hello' ));
    curl_setopt($ch, CURLOPT_POST, true);                                         
    $response = curl_exec($ch);   

It keep failing with an Apache 213 error like this:

The requested resource
/api.php
does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.

It turns out that you need to set the curl options in the correct order and CURLOPT_POST needs to be before CURLOPT_POSTFIELDS. Like so:

    $ch = curl_init('http://my.server/api.php');                     
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
    curl_setopt($ch, CURLOPT_POST, 
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => 'hello' ));
true);                                         
    $response = curl_exec($ch);