Re: new libpq SSL connection option

Lists: pgsql-hackers
From: Andrew Chernow <ac(at)esilo(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: new libpq SSL connection option
Date: 2008-12-05 20:58:58
Message-ID: 49399612.8040001@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Who anyone be opposed to "ssldir = path" as a connection option?
Currently, there is no way to change the homedir method ~/.postgresql
... or am I missing something? I am willing to supply a patch.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: "Alex Hunsaker" <badalex(at)gmail(dot)com>
To: "Andrew Chernow" <ac(at)esilo(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-05 21:11:37
Message-ID: 34d269d40812051311p2a368e25ra7bf2242b94d32fc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Dec 5, 2008 at 13:58, Andrew Chernow <ac(at)esilo(dot)com> wrote:
> Who anyone be opposed to "ssldir = path" as a connection option? Currently,
> there is no way to change the homedir method ~/.postgresql ... or am I
> missing something? I am willing to supply a patch.

You mean something like the
http://archives.postgresql.org/message-id/34d269d40811202107q489e2be0h771762398dd9fcdb@mail.gmail.com.

?


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Alex Hunsaker <badalex(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Magnus Hagander <magnus(at)hagander(dot)net>
Subject: Re: new libpq SSL connection option
Date: 2008-12-05 21:22:42
Message-ID: 49399BA2.5090801@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alex Hunsaker wrote:
> On Fri, Dec 5, 2008 at 13:58, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>> Who anyone be opposed to "ssldir = path" as a connection option? Currently,
>> there is no way to change the homedir method ~/.postgresql ... or am I
>> missing something? I am willing to supply a patch.
>
> You mean something like the
> http://archives.postgresql.org/message-id/34d269d40811202107q489e2be0h771762398dd9fcdb@mail.gmail.com.
>
> ?
>

yes, excately like that; apparently missed it. What is the status of
that patch? I see it was left in pending review .. is the fest is over?

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: "Alex Hunsaker" <badalex(at)gmail(dot)com>
To: "Andrew Chernow" <ac(at)esilo(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, "Magnus Hagander" <magnus(at)hagander(dot)net>
Subject: Re: new libpq SSL connection option
Date: 2008-12-05 21:32:57
Message-ID: 34d269d40812051332v2588698fv3fa3e8924365fdf4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Dec 5, 2008 at 14:22, Andrew Chernow <ac(at)esilo(dot)com> wrote:
> Alex Hunsaker wrote:
>>
>> On Fri, Dec 5, 2008 at 13:58, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>>>
>>> Who anyone be opposed to "ssldir = path" as a connection option?
>>> Currently,
>>> there is no way to change the homedir method ~/.postgresql ... or am I
>>> missing something? I am willing to supply a patch.
>>
>> You mean something like the
>>
>> http://archives.postgresql.org/message-id/34d269d40811202107q489e2be0h771762398dd9fcdb@mail.gmail.com.
>>
>> ?
>>
>
> yes, excately like that; apparently missed it. What is the status of that
> patch? I see it was left in pending review .. is the fest is over?

I think all that is left is changing PGROOTCERT to PGSSLROOTCERT,
agreeing to IFDEF the params out or not oh
and this little bit:

> Magnus Hagander escribió:
> > On Fri, Aug 1, 2008 at 13:31, Alvaro Herrera <alvherre(at)commandprompt(dot)com> wrote:
> >> Something that's bothering me is that PGSSLKEY is inconsistent with the
> >> sslkey conninfo parameter. PGSSLKEY specifies an engine (basically a
> >> driver for specialized hardware AFAICT) from which the key is to be
> >> loaded, but sslkey is a simple filename. This means that there's no way
> >> to load a key from hardware if you want to specify it per connection.
> >> Not that I have any such hardware, but it looks bogus.

>I think the above consideration needs some discussion too. Committing
>it as-is doesn't seem OK because you can't change it later -- it's
>user-visible.


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Alex Hunsaker <badalex(at)gmail(dot)com>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-09 14:11:09
Message-ID: 493E7C7D.3000403@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alex Hunsaker wrote:
> On Fri, Dec 5, 2008 at 14:22, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>> Alex Hunsaker wrote:
>>> On Fri, Dec 5, 2008 at 13:58, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>>>> Who anyone be opposed to "ssldir = path" as a connection option?
>>>> Currently,
>>>> there is no way to change the homedir method ~/.postgresql ... or am I
>>>> missing something? I am willing to supply a patch.
>>> You mean something like the
>>>
>>> http://archives.postgresql.org/message-id/34d269d40811202107q489e2be0h771762398dd9fcdb@mail.gmail.com.
>>>
>>> ?
>>>
>> yes, excately like that; apparently missed it. What is the status of that
>> patch? I see it was left in pending review .. is the fest is over?
>
> I think all that is left is changing PGROOTCERT to PGSSLROOTCERT,
> agreeing to IFDEF the params out or not oh
> and this little bit:
>
>> Magnus Hagander escribió:
>>> On Fri, Aug 1, 2008 at 13:31, Alvaro Herrera <alvherre(at)commandprompt(dot)com> wrote:
>>>> Something that's bothering me is that PGSSLKEY is inconsistent with the
>>>> sslkey conninfo parameter. PGSSLKEY specifies an engine (basically a
>>>> driver for specialized hardware AFAICT) from which the key is to be
>>>> loaded, but sslkey is a simple filename. This means that there's no way
>>>> to load a key from hardware if you want to specify it per connection.
>>>> Not that I have any such hardware, but it looks bogus.
>
>> I think the above consideration needs some discussion too. Committing
>> it as-is doesn't seem OK because you can't change it later -- it's
>> user-visible.

Here's a suggested update, which does *not* yet have documentation
updates. Changes from previous patch:

* Made all parameters available always and ignored for non-SSL connections
* Renamed PGROOTCERT to PGSSLROOTCERT
* Changes the way PGSSLKEY/sslkey is handled to this: When the string
does not contain a colon, it's treated as a filename. If it does contain
a colon (and on windows, if this colon is not in the second position
indicating a drive letter), it's treated as engine:key as before.

This should keep backwards compatibility.

I would also like to look this over completely - we only support loading
the KEY from the smartcard, but you still have to manually copy the
certificate to your machine. I don't know exactly how you're supposed to
do this in OpenSSL - some googling shows almost nobody else uses the
functions quite the way we do. So I'd like to look over if we need to do
more around this later, but this patch should make it possible to use
keys from different files without breaking backwards compatibility with
what we had before. So I'm considering that a separate step, that may
not be done in time for 8.4.

So. Comments?

//Magnus

Attachment Content-Type Size
sslkey_4.patch text/x-diff 12.4 KB

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-09 14:34:54
Message-ID: 493E820E.8090105@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
> * Renamed PGROOTCERT to PGSSLROOTCERT
>
> + <primary><envar>PGROOTCERT</envar></primary>

Looks like the old env name is still being used in the sgml docs.

I like the flexibility this patch offers.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-09 14:36:35
Message-ID: 493E8273.3000008@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Chernow wrote:
> Magnus Hagander wrote:
>> * Renamed PGROOTCERT to PGSSLROOTCERT
>>
>> + <primary><envar>PGROOTCERT</envar></primary>
>
> Looks like the old env name is still being used in the sgml docs.

Yes - I did say I hadn't updated the docs yet :-)

//Magnus


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-09 15:17:29
Message-ID: 15055.1228835849@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> I would also like to look this over completely - we only support loading
> the KEY from the smartcard, but you still have to manually copy the
> certificate to your machine. I don't know exactly how you're supposed to
> do this in OpenSSL - some googling shows almost nobody else uses the
> functions quite the way we do. So I'd like to look over if we need to do
> more around this later, but this patch should make it possible to use
> keys from different files without breaking backwards compatibility with
> what we had before. So I'm considering that a separate step, that may
> not be done in time for 8.4.

I'm confused here. Are you proposing user-visible changes that might
not get done in time for 8.4? I don't much like the idea that the API
is going to remain a moving target --- once 8.4 is out you will have
backwards compatibility constraints with whatever it does. It would
be better to avoid extending the feature set beyond what 8.3 can do
until you are certain it's right.

regards, tom lane


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-09 15:23:09
Message-ID: 493E8D5D.1080309@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>> I would also like to look this over completely - we only support loading
>> the KEY from the smartcard, but you still have to manually copy the
>> certificate to your machine. I don't know exactly how you're supposed to
>> do this in OpenSSL - some googling shows almost nobody else uses the
>> functions quite the way we do. So I'd like to look over if we need to do
>> more around this later, but this patch should make it possible to use
>> keys from different files without breaking backwards compatibility with
>> what we had before. So I'm considering that a separate step, that may
>> not be done in time for 8.4.
>
> I'm confused here. Are you proposing user-visible changes that might
> not get done in time for 8.4? I don't much like the idea that the API
> is going to remain a moving target --- once 8.4 is out you will have
> backwards compatibility constraints with whatever it does. It would
> be better to avoid extending the feature set beyond what 8.3 can do
> until you are certain it's right.

I'm not proposing anything yet - I haven't read up on it.

If it does change, though, only the engine-specific stuff would change
AFAICT. The new functionality in this patch is all around specifying
filenames, so that would not change.

And most likely it would not be a change in visible behavior if I get
the time to "fix" that - it'll either just be an under-the-hood change,
or more likely an extension to the parameters. I see no reason why it
should have any user-visible change at all on the stuff that's in this
patch.

//Magnus


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alex Hunsaker <badalex(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-27 18:50:13
Message-ID: 495678E5.7080804@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Why does pqGetHomeDirectory have to succeed to use conn->sslrootcert.
Maybe this should be an OR of the two since sslrootcert is not dependent
on homedir?

around line 970 src/interfaces/libpq/fe-secure.c

if (conn->sslrootcert || pqGetHomeDirectory(homedir, sizeof(homedir)))

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: "Alex Hunsaker" <badalex(at)gmail(dot)com>
To: "Andrew Chernow" <ac(at)esilo(dot)com>
Cc: "Magnus Hagander" <magnus(at)hagander(dot)net>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-29 22:25:54
Message-ID: 34d269d40812291425k36634efdj8d89adc3ebfb24e4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Dec 27, 2008 at 11:50, Andrew Chernow <ac(at)esilo(dot)com> wrote:
> Why does pqGetHomeDirectory have to succeed to use conn->sslrootcert. Maybe
> this should be an OR of the two since sslrootcert is not dependent on
> homedir?
>
> around line 970 src/interfaces/libpq/fe-secure.c
>
> if (conn->sslrootcert || pqGetHomeDirectory(homedir, sizeof(homedir)))

Certainly, did we miss anywhere else?


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Alex Hunsaker <badalex(at)gmail(dot)com>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-29 23:25:17
Message-ID: 49595C5D.5050006@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alex Hunsaker wrote:
> On Sat, Dec 27, 2008 at 11:50, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>> Why does pqGetHomeDirectory have to succeed to use conn->sslrootcert. Maybe
>> this should be an OR of the two since sslrootcert is not dependent on
>> homedir?
>>
>> around line 970 src/interfaces/libpq/fe-secure.c
>>
>> if (conn->sslrootcert || pqGetHomeDirectory(homedir, sizeof(homedir)))
>
> Certainly, did we miss anywhere else?

I agree it looks strange.

That said, have you actually seen a case where pqGetHomeDirectory()
fails? Or did you just notice the code?

//Magnus


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2008-12-30 01:46:04
Message-ID: 49597D5C.9090301@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
> Alex Hunsaker wrote:
>> On Sat, Dec 27, 2008 at 11:50, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>>> Why does pqGetHomeDirectory have to succeed to use conn->sslrootcert. Maybe
>>> this should be an OR of the two since sslrootcert is not dependent on
>>> homedir?
>>>
>>> around line 970 src/interfaces/libpq/fe-secure.c
>>>
>>> if (conn->sslrootcert || pqGetHomeDirectory(homedir, sizeof(homedir)))
>>
>> Certainly, did we miss anywhere else?
>>

Yes, the homedir variable is used again later in the function. homedir could be
invalid since pqGetHomeDirectory might not get called. Maybe something like
below would do the trick:

/* when used, it can't be an empty string. */
*homedir = 0;

/* If either are NULL, homedir is needed */
if (!conn->sslrootcert || !conn->sslcrl)
pqGetHomeDirectory(homedir, sizeof(homedir));

/* one of them must be valid */
if (conn->sslrootcert || *homedir)

> I agree it looks strange.
>
> That said, have you actually seen a case where pqGetHomeDirectory()
> fails? Or did you just notice the code?
>

It can fail. For non-windows systems, it can fail on pqGetpwuid; which equates
to getpwuid or getpwuid_r failing. On windows, it can fail on SHGetFolderPath.
I really have no idea how likely either failure case is.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2009-01-02 10:13:10
Message-ID: 495DE8B6.4040505@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Chernow wrote:
> Magnus Hagander wrote:
>> Alex Hunsaker wrote:
>>> On Sat, Dec 27, 2008 at 11:50, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>>>> Why does pqGetHomeDirectory have to succeed to use
>>>> conn->sslrootcert. Maybe
>>>> this should be an OR of the two since sslrootcert is not dependent on
>>>> homedir?
>>>>
>>>> around line 970 src/interfaces/libpq/fe-secure.c
>>>>
>>>> if (conn->sslrootcert || pqGetHomeDirectory(homedir, sizeof(homedir)))
>>>
>>> Certainly, did we miss anywhere else?
>>>
>
> Yes, the homedir variable is used again later in the function. homedir
> could be invalid since pqGetHomeDirectory might not get called. Maybe
> something like below would do the trick:
>
> /* when used, it can't be an empty string. */
> *homedir = 0;
>
> /* If either are NULL, homedir is needed */
> if (!conn->sslrootcert || !conn->sslcrl)
> pqGetHomeDirectory(homedir, sizeof(homedir));
>
> /* one of them must be valid */
> if (conn->sslrootcert || *homedir)

How about this patch?

There's a lot of whitespace change due to indentation change, so I've
included a version without it for reference.

Also, it looks like we have the same problem with the private key, in
client_cert_cb(), agreed?

//Magnus

Attachment Content-Type Size
libpq_gethomedir.diff text/x-diff 4.3 KB
libpq_gethomedir_nospace.diff text/x-diff 1.8 KB

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Alex Hunsaker <badalex(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2009-01-02 14:23:15
Message-ID: 495E2353.9000201@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>
> Also, it looks like we have the same problem with the private key, in
> client_cert_cb(), agreed?
>
>
> //Magnus
>

Yeah, same issue in that function. I missed that. My grep'n was
obviously brain dead.

It almost feels like there should be some util functions like
get_sslrootcert(conn, path_buf, buf_size) for each of the SSL files.
Isolate the logic behind a function with a success or failure return
value. It would probably make the current code easier to read/follow.
Only downside is that pqGetHomeDirectory would be called twice in some
cases, but I really don't think that makes any noticeable performance
difference.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/


From: "Alex Hunsaker" <badalex(at)gmail(dot)com>
To: "Magnus Hagander" <magnus(at)hagander(dot)net>
Cc: "Andrew Chernow" <ac(at)esilo(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2009-01-03 01:37:28
Message-ID: 34d269d40901021737m76110383l58aa8903ce835a2a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 2, 2009 at 03:13, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> Andrew Chernow wrote:
>> Yes, the homedir variable is used again later in the function. homedir
>> could be invalid since pqGetHomeDirectory might not get called. Maybe
>> something like below would do the trick:

> How about this patch?

looks good to me (btw it was almost hard to believe the non-white
space one was the same patch! lol)


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Alex Hunsaker <badalex(at)gmail(dot)com>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: new libpq SSL connection option
Date: 2009-01-07 12:02:56
Message-ID: 496499F0.8050102@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alex Hunsaker wrote:
> On Fri, Jan 2, 2009 at 03:13, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> Andrew Chernow wrote:
>>> Yes, the homedir variable is used again later in the function. homedir
>>> could be invalid since pqGetHomeDirectory might not get called. Maybe
>>> something like below would do the trick:
>
>> How about this patch?
>
> looks good to me (btw it was almost hard to believe the non-white
> space one was the same patch! lol)

Applied, along with a fix for the second place that had the issue.

//Magnus