Re: User functions for building SCRAM secrets

From: "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: User functions for building SCRAM secrets
Date: 2022-11-27 05:21:58
Message-ID: 4e644f58-6510-fb35-e372-d86f56dcb61a@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/26/22 2:53 PM, Jonathan S. Katz wrote:
> On 11/16/22 10:09 PM, Michael Paquier wrote:

>> git diff --check reports some whitespaces.
>
> Ack. Will fix on the next pass. (I've been transitioning editors, which
> could have resulted in that),

Fixed (and have run that check subsequently).

>> scram_build_secret_sha256_internal() is missing SASLprep on the
>> password string.  Perhaps the best thing to do here is just to extend
>> pg_be_scram_build_secret() with more arguments so as callers can
>> optionally pass down a custom salt with its length, leaving the
>> responsibility to pg_be_scram_build_secret() to create a random salt
>> if nothing has been given?
>
> Ah, good catch!
>
> I think if we go with passing down the salt, we'd also have to allow for
> the passing down of the iterations, too, and we're close to rebuilding
> "scram_build_secret". I'll stare a bit at this on the next pass and
> either 1/ just SASLprep the string in the new
> "scram_build_secret_sha256_internal" func, or 2/ change the definition
> of "pg_be_scram_build_secret" to accommodate more overrides.

In the end I went with your suggested approach as it limited the amount
of code duplication. I did keep in all the permutations of the tests as
it did help me catch an error in my code that let to a panic.

As this seems to be closer to completion, I did include docs in this
patch. I added this function as part of the "string functions" section
of the docs as "md5" was already there. If we continue to add more
authentication helper functions, perhaps we should consider breaking
those out into their own documentation section.

Thanks,

Jonathan

Attachment Content-Type Size
scram-funcs-v3.patch text/plain 18.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Reid Thompson 2022-11-27 05:32:19 Re: Add tracking of backend memory allocated to pg_stat_activity
Previous Message Ian Lawrence Barwick 2022-11-27 05:15:46 Re: Reducing power consumption on idle servers