Re: PQinitSSL broken in some use casesf

Lists: pgsql-hackers
From: Andrew Chernow <ac(at)esilo(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: PQinitSSL broken in some use cases
Date: 2009-01-29 20:11:41
Message-ID: 49820D7D.7030902@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I am using a library that links with and initializes libcrypto (ie.
CRYPTO_set_locking_callback) but not SSL. This causes problems even
when using PQinitSSL(FALSE) because things like SSL_library_init(); are
not called (unless I manually call them, copy and paste code from
fe-secure.c which may change). If libpq does init ssl, it overwrites
(and breaks) the other library's crypto.

Shouldn't crypto and ssl init be treated as two different things? If
not, how does one determine a version portable way of initializing SSL
in a manner required by libpq? Lots of apps using encryption but don't
necessarily use ssl, so they need to know how to init ssl for libpq.

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


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-01-30 21:52:38
Message-ID: 200901302152.n0ULqc205768@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Chernow wrote:
> I am using a library that links with and initializes libcrypto (ie.
> CRYPTO_set_locking_callback) but not SSL. This causes problems even
> when using PQinitSSL(FALSE) because things like SSL_library_init(); are
> not called (unless I manually call them, copy and paste code from
> fe-secure.c which may change). If libpq does init ssl, it overwrites
> (and breaks) the other library's crypto.
>
> Shouldn't crypto and ssl init be treated as two different things? If
> not, how does one determine a version portable way of initializing SSL
> in a manner required by libpq? Lots of apps using encryption but don't
> necessarily use ssl, so they need to know how to init ssl for libpq.

I didn't realize they were could be initialized separately, so we really
don't have an answer for you. This is the first time I have heard of
this requirement.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-02 14:48:12
Message-ID: 498707AC.70306@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Andrew Chernow wrote:
>> I am using a library that links with and initializes libcrypto (ie.
>> CRYPTO_set_locking_callback) but not SSL. This causes problems even
>> when using PQinitSSL(FALSE) because things like SSL_library_init(); are
>> not called (unless I manually call them, copy and paste code from
>> fe-secure.c which may change). If libpq does init ssl, it overwrites
>> (and breaks) the other library's crypto.
>>
>> Shouldn't crypto and ssl init be treated as two different things? If
>> not, how does one determine a version portable way of initializing SSL
>> in a manner required by libpq? Lots of apps using encryption but don't
>> necessarily use ssl, so they need to know how to init ssl for libpq.
>
> I didn't realize they were could be initialized separately, so we really
> don't have an answer for you. This is the first time I have heard of
> this requirement.
>

Just bringing it to everyones attention. I have no idea how common this
use case is or if it deserves a patch. From your comments, it sounds
uncommon.

How we came across this:
We have an internal library that links with libcrypto.so but not
libssl.so. The library uses digests and ciphers from libcrypto. It
initializes libcrypto for thread safety and seeds the PRNG. So, one of
our applications is linking with both libpq and this library; which
caused the conflict.

How we worked around it:
We solved it by copying the SSL init sequence from fe-secure.c. Doesn't
seem like something that would change very often. So we
init_our_library(), PQinitSSL(0) and then do a few lines of SSL init stuff.

--
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: Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 14:32:50
Message-ID: 49919012.9040207@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Chernow wrote:
> Bruce Momjian wrote:
>> Andrew Chernow wrote:
>>> I am using a library that links with and initializes libcrypto (ie.
>>> CRYPTO_set_locking_callback) but not SSL. This causes problems even
>>> when using PQinitSSL(FALSE) because things like SSL_library_init();
>>> are not called (unless I manually call them, copy and paste code from
>>> fe-secure.c which may change). If libpq does init ssl, it overwrites
>>> (and breaks) the other library's crypto.
>>>
>>> Shouldn't crypto and ssl init be treated as two different things? If
>>> not, how does one determine a version portable way of initializing
>>> SSL in a manner required by libpq? Lots of apps using encryption but
>>> don't necessarily use ssl, so they need to know how to init ssl for
>>> libpq.
>>
>> I didn't realize they were could be initialized separately, so we really
>> don't have an answer for you. This is the first time I have heard of
>> this requirement.
>>
>
> Just bringing it to everyones attention. I have no idea how common this
> use case is or if it deserves a patch. From your comments, it sounds
> uncommon.
>
> How we came across this:
> We have an internal library that links with libcrypto.so but not
> libssl.so. The library uses digests and ciphers from libcrypto. It
> initializes libcrypto for thread safety and seeds the PRNG. So, one of
> our applications is linking with both libpq and this library; which
> caused the conflict.
>
> How we worked around it:
> We solved it by copying the SSL init sequence from fe-secure.c. Doesn't
> seem like something that would change very often. So we
> init_our_library(), PQinitSSL(0) and then do a few lines of SSL init stuff.

Seems unusual, but certainly not "nearly impossible". But we're back to
the discussions around the WSA code - our API provides no really good
place to do this, so perhaps we should just clearly document how it's
done and how to work around it?

//Magnus


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 15:13:24
Message-ID: b42b73150902100713mdbfd64ah706ced5170897a59@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 9:32 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>> How we worked around it:
>> We solved it by copying the SSL init sequence from fe-secure.c. Doesn't
>> seem like something that would change very often. So we
>> init_our_library(), PQinitSSL(0) and then do a few lines of SSL init stuff.
>
> Seems unusual, but certainly not "nearly impossible". But we're back to
> the discussions around the WSA code - our API provides no really good
> place to do this, so perhaps we should just clearly document how it's
> done and how to work around it?

I'm not so sure that's appropriate in this case. I think the existing
libpq behavior is simply wrong...crypto and ssl are two separate
libraries and PQinitSSL does not expose the necessary detail. This is
going to break apps in isolated but spectacular fashion when they link
to both pq and crypto for different reasons.

maybe invent a special value to PQinitSSL for ssl only init?

merlin


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 15:18:14
Message-ID: 49919AB6.4020501@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Tue, Feb 10, 2009 at 9:32 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
>>> How we worked around it:
>>> We solved it by copying the SSL init sequence from fe-secure.c. Doesn't
>>> seem like something that would change very often. So we
>>> init_our_library(), PQinitSSL(0) and then do a few lines of SSL init stuff.
>> Seems unusual, but certainly not "nearly impossible". But we're back to
>> the discussions around the WSA code - our API provides no really good
>> place to do this, so perhaps we should just clearly document how it's
>> done and how to work around it?
>
> I'm not so sure that's appropriate in this case. I think the existing
> libpq behavior is simply wrong...crypto and ssl are two separate
> libraries and PQinitSSL does not expose the necessary detail. This is
> going to break apps in isolated but spectacular fashion when they link
> to both pq and crypto for different reasons.

They could, but nobody has reported it yet, so it's not a common scenario.

> maybe invent a special value to PQinitSSL for ssl only init?

We could do that, I guess. However, if an application passes this in to
an old version of libpq, there is no way to know that it didn't know
about it.

//Magnus


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 15:39:47
Message-ID: 603c8f070902100739s31b31bf1r252c0eff9226534d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> maybe invent a special value to PQinitSSL for ssl only init?
>
> We could do that, I guess. However, if an application passes this in to
> an old version of libpq, there is no way to know that it didn't know
> about it.

Well, you could create PQinitSSLExtended, but, as you say, the use
case is pretty narrow...

It would help if there were a PQgetLibraryVersion() function.

...Robert


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 15:54:53
Message-ID: 7476.1234281293@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> We could do that, I guess. However, if an application passes this in to
>> an old version of libpq, there is no way to know that it didn't know
>> about it.

> Well, you could create PQinitSSLExtended, but, as you say, the use
> case is pretty narrow...

> It would help if there were a PQgetLibraryVersion() function.

Help how? There is nothing an app can do to work around the problem
AFAICS. Or if there were, we should just document it and not change
the code --- the use case for this is evidently too narrow to justify
complicating libpq's API even more.

regards, tom lane


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:03:50
Message-ID: 4991A566.6000905@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>> We could do that, I guess. However, if an application passes this in to
>>> an old version of libpq, there is no way to know that it didn't know
>>> about it.
>
>> Well, you could create PQinitSSLExtended, but, as you say, the use
>> case is pretty narrow...
>
>> It would help if there were a PQgetLibraryVersion() function.
>
> Help how? There is nothing an app can do to work around the problem
> AFAICS. Or if there were, we should just document it and not change
> the code --- the use case for this is evidently too narrow to justify
> complicating libpq's API even more.

Sure, there is a way to work around it in this case. By manually
initializing ssl+crypto even though you only need crypto, and then tell
libpq you have taken care of the initialization.

//Magnus


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:06:48
Message-ID: 603c8f070902100806mbd4023av4561284e36ef655f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 10:54 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>> We could do that, I guess. However, if an application passes this in to
>>> an old version of libpq, there is no way to know that it didn't know
>>> about it.
>
>> Well, you could create PQinitSSLExtended, but, as you say, the use
>> case is pretty narrow...
>
>> It would help if there were a PQgetLibraryVersion() function.
>
> Help how? There is nothing an app can do to work around the problem
> AFAICS. Or if there were, we should just document it and not change
> the code --- the use case for this is evidently too narrow to justify
> complicating libpq's API even more.

It would let you assert that you were running against a version of
libpq that has the functionality that you are attempting to use, thus
eliminating the risk of silent failure.

...Robert


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:14:42
Message-ID: 7782.1234282482@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>> Well, you could create PQinitSSLExtended, but, as you say, the use
>>> case is pretty narrow...
>>> It would help if there were a PQgetLibraryVersion() function.
>>
>> Help how? There is nothing an app can do to work around the problem
>> AFAICS. Or if there were, we should just document it and not change
>> the code --- the use case for this is evidently too narrow to justify
>> complicating libpq's API even more.

> It would let you assert that you were running against a version of
> libpq that has the functionality that you are attempting to use, thus
> eliminating the risk of silent failure.

If that's all you want, then PQinitSSLExtended is a perfectly good
answer. Your app will fail to link if you try to use a library
version that hasn't got it.

I think documenting the workaround is a sufficient answer though.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:31:59
Message-ID: 200902101631.n1AGVxO18550@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
> Merlin Moncure wrote:
> > On Tue, Feb 10, 2009 at 9:32 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> >>> How we worked around it:
> >>> We solved it by copying the SSL init sequence from fe-secure.c. Doesn't
> >>> seem like something that would change very often. So we
> >>> init_our_library(), PQinitSSL(0) and then do a few lines of SSL init stuff.
> >> Seems unusual, but certainly not "nearly impossible". But we're back to
> >> the discussions around the WSA code - our API provides no really good
> >> place to do this, so perhaps we should just clearly document how it's
> >> done and how to work around it?
> >
> > I'm not so sure that's appropriate in this case. I think the existing
> > libpq behavior is simply wrong...crypto and ssl are two separate
> > libraries and PQinitSSL does not expose the necessary detail. This is
> > going to break apps in isolated but spectacular fashion when they link
> > to both pq and crypto for different reasons.
>
> They could, but nobody has reported it yet, so it's not a common scenario.

Agreed.

Would someone remind me why turning off ssl initialization in libpq does
not work for this case?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:34:36
Message-ID: 603c8f070902100834g500a606bu12914fa2b04c73a5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 11:14 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>>> Well, you could create PQinitSSLExtended, but, as you say, the use
>>>> case is pretty narrow...
>>>> It would help if there were a PQgetLibraryVersion() function.
>>>
>>> Help how? There is nothing an app can do to work around the problem
>>> AFAICS. Or if there were, we should just document it and not change
>>> the code --- the use case for this is evidently too narrow to justify
>>> complicating libpq's API even more.
>
>> It would let you assert that you were running against a version of
>> libpq that has the functionality that you are attempting to use, thus
>> eliminating the risk of silent failure.
>
> If that's all you want, then PQinitSSLExtended is a perfectly good
> answer. Your app will fail to link if you try to use a library
> version that hasn't got it.

I agree. I was thinking that there might not be enough interest in
this feature to add an API call just to support it, but I thought
PQgetVersion() might be a more general solution.

> I think documenting the workaround is a sufficient answer though.

I don't have a strong opinion on that one way or the other, but Andrew
seemed to be concerned that he was cut-and-pasting a fair amount of
code.

...Robert


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:49:15
Message-ID: 603c8f070902100849n44034028p5423f18e6e1b9317@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Would someone remind me why turning off ssl initialization in libpq does
> not work for this case?

That initializes both libcrypto and libssl. The problem arises when
libcrypto has been initialized but libssl has not.

...Robert


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:49:24
Message-ID: 4991B014.7040503@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
>
> If that's all you want, then PQinitSSLExtended is a perfectly good
> answer.
>

How about PQinitCrypto(bool do_init), which would default to TRUE if
never called. PQinitSSL already handles the SSL part, just need control
over initializing crypto.

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


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:52:13
Message-ID: 200902101652.n1AGqDJ21891@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andrew Chernow wrote:
> Tom Lane wrote:
> >
> > If that's all you want, then PQinitSSLExtended is a perfectly good
> > answer.
> >
>
> How about PQinitCrypto(bool do_init), which would default to TRUE if
> never called. PQinitSSL already handles the SSL part, just need control
> over initializing crypto.

Folks, we need a lot more demand before we add functions to libpq.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:52:52
Message-ID: 200902101652.n1AGqqF22096@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas wrote:
> > Would someone remind me why turning off ssl initialization in libpq does
> > not work for this case?
>
> That initializes both libcrypto and libssl. The problem arises when
> libcrypto has been initialized but libssl has not.

So initialize ssl in your application? What is the problem?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:53:13
Message-ID: b42b73150902100853j76f8e269o778cd4fb1fd296ca@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 11:52 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Robert Haas wrote:
>> > Would someone remind me why turning off ssl initialization in libpq does
>> > not work for this case?
>>
>> That initializes both libcrypto and libssl. The problem arises when
>> libcrypto has been initialized but libssl has not.
>
> So initialize ssl in your application? What is the problem?

then libpq doesn't work.

merlin


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:54:28
Message-ID: 200902101654.n1AGsSI22568@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Tue, Feb 10, 2009 at 11:52 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> > Robert Haas wrote:
> >> > Would someone remind me why turning off ssl initialization in libpq does
> >> > not work for this case?
> >>
> >> That initializes both libcrypto and libssl. The problem arises when
> >> libcrypto has been initialized but libssl has not.
> >
> > So initialize ssl in your application? What is the problem?
>
> then libpq doesn't work.

Why?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 16:57:17
Message-ID: b42b73150902100857l3377bf8geafccb6392f6d129@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 11:14 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>>>> Well, you could create PQinitSSLExtended, but, as you say, the use
>>>> case is pretty narrow...
>>>> It would help if there were a PQgetLibraryVersion() function.
>>>
>>> Help how? There is nothing an app can do to work around the problem
>>> AFAICS. Or if there were, we should just document it and not change
>>> the code --- the use case for this is evidently too narrow to justify
>>> complicating libpq's API even more.
>
>> It would let you assert that you were running against a version of
>> libpq that has the functionality that you are attempting to use, thus
>> eliminating the risk of silent failure.
>
> If that's all you want, then PQinitSSLExtended is a perfectly good
> answer. Your app will fail to link if you try to use a library
> version that hasn't got it.
>
> I think documenting the workaround is a sufficient answer though.

I don't think you can get way with that this time. wsa cleanup was a
mainly harmless side effect. This is a nasty 'maybe it works, maybe
it doesn't' virtually impossible to debug problem. We caught it on a
particular platform (windows, iirc) when deep in our code a mutex call
deadlocked when it shouldn't have, after weeks of working ok.
debugging nightmare.

PQinitSSL is *broken*. It's always been broken. Since it already
takes a parameter, I say add a special switch...the backwards
compatibility danger doesn't seem too bad.

merlin


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:03:29
Message-ID: b42b73150902100903w433bcefax49229f3a96566b46@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 11:54 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> Merlin Moncure wrote:
>> On Tue, Feb 10, 2009 at 11:52 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> > Robert Haas wrote:
>> >> > Would someone remind me why turning off ssl initialization in libpq does
>> >> > not work for this case?
>> >>
>> >> That initializes both libcrypto and libssl. The problem arises when
>> >> libcrypto has been initialized but libssl has not.
>> >
>> > So initialize ssl in your application? What is the problem?
>>
>> then libpq doesn't work.

PQinitSSL is required if you want to make any ssl calls (it does some
libpq setup beyond the ssl library initialization).

merlin


From: Dave Page <dpage(at)pgadmin(dot)org>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:03:34
Message-ID: 937d27e10902100903u2ea7fbe6if992cfa54aa24a78@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 4:57 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:

> PQinitSSL is *broken*. It's always been broken. Since it already
> takes a parameter, I say add a special switch...the backwards
> compatibility danger doesn't seem too bad.

Add a switch to what? I get very nervous for our Windows users when
people start talking about changing the libpq API (for those that
don't know, Windows doesn't have DLL versioning like Unix - so any
non-backwards compatible API change really needs a corresponding
filename change to avoid pain and suffering).

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:05:20
Message-ID: 4991B3D0.7020604@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Andrew Chernow wrote:
>> Tom Lane wrote:
>>> If that's all you want, then PQinitSSLExtended is a perfectly good
>>> answer.
>>>
>> How about PQinitCrypto(bool do_init), which would default to TRUE if
>> never called. PQinitSSL already handles the SSL part, just need control
>> over initializing crypto.
>
> Folks, we need a lot more demand before we add functions to libpq.
>

Honestly, I'm not suggesting that a function is added. If others decide
to do that, I think the function's purpose should be to init crypto. We
don't need another way to init ssl.

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


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Dave Page <dpage(at)pgadmin(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:05:50
Message-ID: b42b73150902100905x7fe00974sd2d01ee9a135ad05@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 12:03 PM, Dave Page <dpage(at)pgadmin(dot)org> wrote:
> On Tue, Feb 10, 2009 at 4:57 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>
>> PQinitSSL is *broken*. It's always been broken. Since it already
>> takes a parameter, I say add a special switch...the backwards
>> compatibility danger doesn't seem too bad.
>
> Add a switch to what? I get very nervous for our Windows users when
> people start talking about changing the libpq API (for those that
> don't know, Windows doesn't have DLL versioning like Unix - so any
> non-backwards compatible API change really needs a corresponding
> filename change to avoid pain and suffering).

PQinitSSL(SSL_ONLY) or something, where the constant is carefully
chosen to not be accidentally passed in by older libpq users.

merlin


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:10:52
Message-ID: b42b73150902100910y7721f44cyd69d1ca65440052a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 12:03 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Tue, Feb 10, 2009 at 11:54 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>> Merlin Moncure wrote:
>>> On Tue, Feb 10, 2009 at 11:52 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>>> > Robert Haas wrote:
>>> >> > Would someone remind me why turning off ssl initialization in libpq does
>>> >> > not work for this case?
>>> >>
>>> >> That initializes both libcrypto and libssl. The problem arises when
>>> >> libcrypto has been initialized but libssl has not.
>>> >
>>> > So initialize ssl in your application? What is the problem?
>>>
>>> then libpq doesn't work.
>
> PQinitSSL is required if you want to make any ssl calls (it does some
> libpq setup beyond the ssl library initialization).

that was worded badly. Rather, PQinitSSL is required if you need to
use ssl features withing libpq.

merlin


From: Dave Page <dpage(at)pgadmin(dot)org>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 17:20:41
Message-ID: 937d27e10902100920q769716e5kec67ad78455f8490@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 5:05 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:

> PQinitSSL(SSL_ONLY) or something, where the constant is carefully
> chosen to not be accidentally passed in by older libpq users.

Ahh, OK. That would be painless.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Dave Page <dpage(at)pgadmin(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 18:02:51
Message-ID: 4991C14B.6090601@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure wrote:
> On Tue, Feb 10, 2009 at 12:03 PM, Dave Page <dpage(at)pgadmin(dot)org> wrote:
>> On Tue, Feb 10, 2009 at 4:57 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>>
>>> PQinitSSL is *broken*. It's always been broken. Since it already
>>> takes a parameter, I say add a special switch...the backwards
>>> compatibility danger doesn't seem too bad.
>> Add a switch to what? I get very nervous for our Windows users when
>> people start talking about changing the libpq API (for those that
>> don't know, Windows doesn't have DLL versioning like Unix - so any
>> non-backwards compatible API change really needs a corresponding
>> filename change to avoid pain and suffering).
>
> PQinitSSL(SSL_ONLY) or something, where the constant is carefully
> chosen to not be accidentally passed in by older libpq users.

So how are you planinng to deal with it when your application passes
that to a version of libpq that doesn't support it?

//Magnus


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Dave Page <dpage(at)pgadmin(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Chernow <ac(at)esilo(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PQinitSSL broken in some use casesf
Date: 2009-02-10 18:06:23
Message-ID: b42b73150902101006n4e20e851l167cbb66b9b96b4c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 10, 2009 at 1:02 PM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> Merlin Moncure wrote:
>> On Tue, Feb 10, 2009 at 12:03 PM, Dave Page <dpage(at)pgadmin(dot)org> wrote:
>>> On Tue, Feb 10, 2009 at 4:57 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>>>
>>>> PQinitSSL is *broken*. It's always been broken. Since it already
>>>> takes a parameter, I say add a special switch...the backwards
>>>> compatibility danger doesn't seem too bad.
>>> Add a switch to what? I get very nervous for our Windows users when
>>> people start talking about changing the libpq API (for those that
>>> don't know, Windows doesn't have DLL versioning like Unix - so any
>>> non-backwards compatible API change really needs a corresponding
>>> filename change to avoid pain and suffering).
>>
>> PQinitSSL(SSL_ONLY) or something, where the constant is carefully
>> chosen to not be accidentally passed in by older libpq users.
>
> So how are you planinng to deal with it when your application passes
> that to a version of libpq that doesn't support it?

well, either nothing, which is no worse off than we are now, or
backpatch the fix. probably nothing :-)

merlin