Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SCRAM using Postgres 15.1 #797

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eulerto
Copy link
Member

@eulerto eulerto commented Dec 23, 2022

Since SCRAM support as copied from Postgres 11.5, SCRAM infrastructure changed quite a bit. This update uses Postgres 15.1 as base. New files need to be added due to code rearrangement.

I split this work in 3 steps:

  1. update etc/import-common.sh. It adds additional files that needs to be copied for this update.
  2. copy the original files from PostgreSQL source code. It uses minor version 15.1 (latest stable minor version). As is, it overrides the changes made by previous commits. The required changes are reintroduced in the step 3.
  3. apply the required changes. Some previous logic was kept but a few were changed.

Although Postgres mixes some header files (such as sha2_int.h) with *.c files, I moved all header files to include/common and updated the references to them. The reason is that Makefile does not include the current directory.

After copying (over) the required files, a few changes are required to compile the code. The challenge was to apply minimal changes to make it work. system.h and postgres_compat.h does the trick plus changing some header file references that is now in the include/common directory. Makefile was updated to include the new required files.

TODO:

  • avoid new files if possible
  • fix compiler warnings
  • document that this update is based on Postgres 15.1
  • scram_XXX functions should use errstr for error handling

This commit copies the original files from PostgreSQL source code. It
uses minor version 15.1 (latest stable minor version). As is, it
overrides the changes made by previous commits. The required changes
are reintroduced in the next commit.

This SCRAM update requires additional files due to upstream changes.
Although some header files were mixed *.c files (such as md5_int.h), all
*.h files were added to include/common and the references were updated.
The reason is that Makefile does not include the current directory for
header files. No changes were made to these files yet. It is done in the
next commit.

THIS COMMIT DOES NOT COMPILE.
After copying (over) the required files, a few changes are required to
compile the code. The challenge was to apply minimal changes to make it
work.  system.h and postgres_compat.h does the trick plus changing some
references to header files that is now in the include/common directory.
Makefile included the new required files.
scram_SaltedPassword(password, salt, saltlen, iterations, salted_password);
scram_ServerKey(salted_password, computed_key);
scram_SaltedPassword(password, salt, saltlen, iterations, salted_password, &errstr);
scram_ServerKey(salted_password, computed_key, &errstr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be doing something with errstr?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I forgot to add a TODO. A few error/warning messages was added to these scram_XXX functions in Postgres and we should do the same in PgBouncer as well.

@JelteF
Copy link
Member

JelteF commented Feb 12, 2024

@eulerto Do you still want to work on this?

@eulerto
Copy link
Member Author

eulerto commented Feb 21, 2024

It is on my list for some time. I will post an updated PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants