flatiron / cradle

a high-level CouchDB client for Node.js
MIT License
1.38k stars 182 forks source link

SSL error on secure connection #151

Open jlporter opened 12 years ago

jlporter commented 12 years ago

I recently tried to update to cradle 0.6.1 from 0.5.8 and am getting SSL errors when attempting to connect to my Cloudant hosted DB. Here is the test program I am using.

var http = require('http');
var cradle = require('cradle');

var cradleService = new(cradle.Connection)('app1234567.heroku.cloudant.com', 443, {
    secure: true,
    auth: {username: 'app1234567.heroku', password: 'notreallymypassword'} 
});

cradleService.info(function (info) {
    console.log('callback');
    console.log(info);
});

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World');
}).listen(5000, '127.0.0.1');

When I run this, the callback from info (or any of the other cradle API function) has the following error message [Error: 140735330154848:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:683: ]

I am testing with node v0.6.10.

mrmarbles commented 12 years ago

I just got this same error. +1

deitch commented 12 years ago

+1 just got the same thing.

deitch commented 12 years ago

I found the problem. It ignores {secure:true}. In this._url (cradle.js L254), it sets the uri to https if the protocol was set, and it sets options.secure based on protocol in the initialization, but never the other way around.

If you explicitly set "https://" it should work.

deitch commented 12 years ago

CONFIRMED.

cedricmay commented 12 years ago

Same here.

adambreen commented 12 years ago

I was having this issue, until I realised that I wasn't working with the 0.6.x versions of Cradle.

If you're following the tutorial here: http://blog.nodejitsu.com/a-simple-webservice-in-nodejs (or http://ddewaele.blogspot.com.au/2012/04/nodejs-on-apple-os-x-lion.html)

... and you cloned the example code from https://github.com/indexzero/nodejs-intro.git

... then, using Cloudant, you'll get the above-reported issues.

The problem is that the example code's package.json sets Cradle to 0.5.x - obviously the Cloudant-friendly updates are contained somewhere in the 0.6.x stream.

How to test:

  1. npm install cradle # this will put the latest version of cradle in ./node_modules. Try it outside your example code folder.
  2. start node console

var cradle = require('cradle'); var conn = new (cradle.Connection)('appXXXXX.heroku.cloudant.com', 80, {auth:{username:"appXXXXXXX.heroku", password:"XXXXXXXXXXXX"}}); conn.databases(function(a,b){ console.log(a,b); });

output should be a list of the databases you have on your Cloudant host eg. for me it was: null [ 'basic', 'test' ]

jedrichards commented 11 years ago

Also having this error when attempting to connect to a Cloudant database over SSL from inside a Heroku app (Node 0.8.14, Cradle 0.6.4).

[Error: 139860364240672:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:683:]

As far as I can see @deitch is correct. Setting secure=true in your options isn't enough, you need to add https:// to the start of your hostname too.

ghost commented 11 years ago

Another thing that can cause this is asking to use port 80 on the end of a hostname with the protocol https :)