Re: Replace current implementations in crypt() and gen_salt() to OpenSSL

From: Joe Conway <mail(at)joeconway(dot)com>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>, Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "Koshi Shibagaki (Fujitsu)" <shibagaki(dot)koshi(at)fujitsu(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Replace current implementations in crypt() and gen_salt() to OpenSSL
Date: 2024-10-26 18:10:29
Message-ID: 16b4a157-9ea1-44d0-b7b3-4c85df5de97b@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>> On 20 Feb 2024, at 13:40, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>> On 20.02.24 12:39, Daniel Gustafsson wrote:
>>> A fifth option is to throw away our in-tree implementations and use the OpenSSL
>>> API's for everything, which is where this thread started. If the effort to
>>> payoff ratio is palatable to anyone then patches are for sure welcome.
>> The problem is that, as I understand it, these crypt routines are
>> not designed in a way that you can just plug in a crypto library
>> underneath. Effectively, the definition of what, say, blowfish
>> crypt does, is whatever is in that source file, and transitively,
>> whatever OpenBSD does.

Someone asked me about this issue a few days ago which led me back to
this unresolved thread.

> diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
> index 96447c5757..3d4391ebe1 100644
> --- a/contrib/pgcrypto/pgcrypto.c
> +++ b/contrib/pgcrypto/pgcrypto.c
> @@ -187,6 +187,14 @@ pg_crypt(PG_FUNCTION_ARGS)
> *resbuf;
> text *res;
>
> +#if defined FIPS_mode
> + if (FIPS_mode())
> +#else
> + if (EVP_default_properties_is_fips_enabled(OSSL_LIB_CTX_get0_global_default()))
> +#endif
> + ereport(ERROR,
> + (errmsg("not available when using OpenSSL in FIPS mode")));
> +
> buf0 = text_to_cstring(arg0);
> buf1 = text_to_cstring(arg1);
>
>
> Greenplum implemented similar functionality but with a GUC, fips_mode=<bool>.
> The problem with that is that it gives the illusion that enabling such a GUC
> gives any guarantees about FIPS which isn't really the case since postgres
> isn't FIPS certified.

Rather than depend on figuring out if we are in FIPS_mode in a portable
way, I think the GUC is simpler and sufficient. Why not do that and just
use a better name, e.g. legacy_crypto_enabled or something similar
(bike-shedding welcomed) as in the attached.

--
Joe Conway
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v1-0001-pgcrypto.patch text/x-patch 4.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2024-10-26 18:49:36 heap_inplace_lock vs. autovacuum w/ LOCKTAG_TUPLE
Previous Message Nathan Bossart 2024-10-26 16:14:38 Re: Assertion failure when autovacuum drops orphan temp indexes.