Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PostgreSQL in Ruby with SSL connections

33 views
Skip to first unread message

Kevin Brown

unread,
Jan 20, 2006, 4:41:59 PM1/20/06
to
Is SSL supported with the ruby postgres adapter? I'd like to SSL the
connections, but looking at the rdoc, I'm not seeing anything about
it, though there is a mysterious "options" parameter. I can already
connect to my postgres server with pgadmin3, so I know everything is
set up correctly, so how to I tell the ruby code to get on board?


Dick Davies

unread,
Jan 21, 2006, 2:28:22 AM1/21/06
to
It's handled transparently by libpq. If you're using the C library,
you don't need to worry about it.


--
Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/


Kevin Brown

unread,
Jan 24, 2006, 9:00:16 PM1/24/06
to
I'd like to use SSL certificate authentication, and that happens
transparently? Don't I need to supply a cert? It's not looking in the
~/.postgresql directory for it like psql does...?

Dick Davies

unread,
Jan 25, 2006, 6:30:03 AM1/25/06
to
Sorry, you didn't mention client auth. Haven't tried that
(but server auth worked fine for me before now).

Dave Lee

unread,
Jan 25, 2006, 10:56:30 AM1/25/06
to
On 1/24/06, Kevin Brown <blar...@gmail.com> wrote:
> I'd like to use SSL certificate authentication, and that happens
> transparently? Don't I need to supply a cert? It's not looking in the
> ~/.postgresql directory for it like psql does...?

If you are using postgres-pr, than I can't comment. If you are using
the ruby-postgres extension, then it too should be looking in the
~/.postgresql directory because, as mentioned by Dick Davies,
ruby-postgres makes use of libpq, which is what psql uses. The
documentation regarding ssl support in libpq is at:

http://www.postgresql.org/docs/current/interactive/libpq-ssl.html

which states:

"If the server demands a client certificate, libpq will send the
certificate stored in file ~/.postgresql/postgresql.crt within the
user's home directory. A matching private key file
~/.postgresql/postgresql.key must also be present, and must not be
world-readable."

Having said this, I haven't actually used ssl for postgresql
connections. The documentation regarding ssl with libpq is very
simple, I'm not sure what could be going wrong in your case. Which
OS? Which ruby? Which version of ruby-postgres? Maybe you're
actually using postgres-pr?

Dave


Kevin Brown

unread,
Jan 26, 2006, 2:23:22 AM1/26/06
to
I'm using the compiled C extension on Linux. I'll do some more
playing and see what I can make out. Could very well have been world
readable.

Thanks for your help, and I'll post the result when I've played some more.

Kevin Brown

unread,
Jan 26, 2006, 4:25:27 AM1/26/06
to
Alright, here it is. I'm not even client authing yet. Psql connects
just fine and lets me know it's SSLing the connection. Ruby code from
the same machine to the same machine says:

#<PGError: SSL error: sslv3 alert handshake failure>

which I can't find anything about using Google.

Kevin Brown

unread,
Jan 26, 2006, 4:48:08 AM1/26/06
to
Ok, I've nailed it down further.

Without client authing, everything now works fine.

I turn on client authing, and psql connects just fine, while the ruby
code does not, reporting the same #<PGError: SSL error> stuff.

Dave Lee

unread,
Jan 26, 2006, 9:57:11 AM1/26/06
to
On 1/26/06, Kevin Brown <blar...@gmail.com> wrote:
> Alright, here it is. I'm not even client authing yet. Psql connects
> just fine and lets me know it's SSLing the connection. Ruby code from
> the same machine to the same machine says:
>
> #<PGError: SSL error: sslv3 alert handshake failure>
>
> which I can't find anything about using Google.

I googled "sslv3 alert handshake failure" which resulted in almost 12k
hits. I don't think you'd find much if you include PGError in the
search. In any case, the fact that psql is working while
ruby-postgres is not, is confusing. The thing is, the ruby-postgres
extension contains no SSL logic, it leaves it all in the hands of
libpq.

is your ruby process and psql process being run under the same user?

Dave


Kevin Brown

unread,
Jan 28, 2006, 6:32:19 AM1/28/06
to

Yes. And the postgres server reports in the logs that the ruby code
is not supplying a cert, hence the ssl handshake failure, while psql,
from the exact same user account, and terminal window, 2 seconds
apart, connects beautifully.

Did they link against an older version (7 point something) of lib-pq?
I'm on newest everything for psql and the server...


Dave Lee

unread,
Jan 28, 2006, 11:01:28 AM1/28/06
to
On 1/28/06, Kevin Brown <blar...@gmail.com> wrote:
> Yes. And the postgres server reports in the logs that the ruby code
> is not supplying a cert, hence the ssl handshake failure, while psql,
> from the exact same user account, and terminal window, 2 seconds
> apart, connects beautifully.
>
> Did they link against an older version (7 point something) of lib-pq?
> I'm on newest everything for psql and the server...

are you running on windows?

Dave


Kevin Brown

unread,
Jan 28, 2006, 6:56:50 PM1/28/06
to
No. Server is Debian Sarge with 8.1.2 installed from source. Client
is Kubuntu Breezy Badger with ruby and postgres ruby adapter installed
via apt-get.

Kevin Brown

unread,
Jan 30, 2006, 12:23:47 AM1/30/06
to
So, any idea what's going on here? I don't know the internals, and
haven't bothered to look, but should I?
0 new messages