1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

pgcrypto: Make it possible to disable built-in crypto

When using OpenSSL and/or the underlying operating system in FIPS
mode no non-FIPS certified crypto implementations should be used.
While that is already possible by just not invoking the built-in
crypto in pgcrypto, this adds a GUC which prohibit the code from
being called.  This doesn't change the FIPS status of PostgreSQL
but can make it easier for sites which target FIPS compliance to
ensure that violations cannot occur.

Author: Daniel Gustafsson <daniel@yesql.se>
Author: Joe Conway <mail@joeconway.com>
Reviewed-by: Joe Conway <mail@joeconway.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/16b4a157-9ea1-44d0-b7b3-4c85df5de97b@joeconway.com
This commit is contained in:
Daniel Gustafsson
2025-01-24 14:25:08 +01:00
parent 924d89a354
commit 035f99cbeb
7 changed files with 121 additions and 0 deletions

View File

@ -38,16 +38,47 @@
#include "px-crypt.h"
#include "px.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "varatt.h"
PG_MODULE_MAGIC;
/* private stuff */
static const struct config_enum_entry builtin_crypto_options[] = {
{"on", BC_ON, false},
{"off", BC_OFF, false},
{"fips", BC_FIPS, false},
{NULL, 0, false}
};
typedef int (*PFN) (const char *name, void **res);
static void *find_provider(text *name, PFN provider_lookup, const char *desc,
int silent);
int builtin_crypto_enabled = BC_ON;
/*
* Entrypoint of this module.
*/
void
_PG_init(void)
{
DefineCustomEnumVariable("pgcrypto.builtin_crypto_enabled",
"Sets if builtin crypto functions are enabled.",
"\"on\" enables builtin crypto, \"off\" unconditionally disables and \"fips\" "
"will disable builtin crypto if OpenSSL is in FIPS mode",
&builtin_crypto_enabled,
BC_ON,
builtin_crypto_options,
PGC_SUSET,
0,
NULL,
NULL,
NULL);
MarkGUCPrefixReserved("pgcrypto");
}
/* SQL function: hash(bytea, text) returns bytea */
PG_FUNCTION_INFO_V1(pg_digest);