Re: pgcrypto support for bcrypt $2b$ hashes

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Daniel Fone <daniel(at)fone(dot)net(dot)nz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgcrypto support for bcrypt $2b$ hashes
Date: 2021-09-25 12:09:10
Message-ID: 161723B5-4F9A-45EB-8C65-C016F8ADB7F8@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 24 Sep 2021, at 04:12, Daniel Fone <daniel(at)fone(dot)net(dot)nz> wrote:

> At the moment, pgcrypto’s `crypt` doesn’t recognise this prefix. However, simply `replace`ing the prefix with $2a$ allows crypt to validate the hashes. This patch simply adds recognition for the prefix and treats the hash identically to the $2a$ hashes.

But 2b and 2a hashes aren't equal, although very similar. 2a should have the
many-buggy to one-correct collision safety and 2b hashes shouldn't. The fact
that your hashes work isn't conclusive evidence.

> Is this a reasonable change to pgcrypto?

I think it's reasonable to support 2b hashes, but not like how this patch does
it.

> I note that the last upstream change brought into crypt-blowfish.c was in 2011, predating this prefix. [5] Are there deeper concerns or other upstream changes that need to be addressed alongside this?

Upgrading our crypt_blowfish.c to the upstream 1.3 version would be the correct
fix IMO, but since we have a few local modifications it's not a drop-in. I
don't think it would be too hairy, but one needs to be very careful when
dealing with crypto.

> Is there a better approach to this?

Compile with OpenSSL support, then pgcrypto will use the libcrypto implementation.

> At the moment, the $2x$ variant is supported but not mentioned in the docs, so I haven’t included any documentation updates.

Actually it is, in table F.16 in the below documentation page we refer to our
supported level as "Blowfish-based, variant 2a".

https://www.postgresql.org/docs/devel/pgcrypto.html

--
Daniel Gustafsson https://vmware.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-09-25 13:45:29 Re: OpenSSL 3.0.0 compatibility
Previous Message Alvaro Herrera 2021-09-25 11:51:36 Re: prevent immature WAL streaming