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

Fix pgcrypto to support OpenSSL >= 3.0.0 #973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion contrib/pgcrypto/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/rand.h>
/*
* OPENSSL_VERSION_MAJOR isn't defined at all until OpenSSL 3.0.0, but since
* OPENSSL_VERSION_NUMBER is used by both OpenSSL and LibreSSL it's safer to
* check for the new macro rather than the overloaded old one.
*/
#if OPENSSL_VERSION_MAJOR >= 3
#include <openssl/provider.h>
#endif

#include "px.h"
#include "utils/memutils.h"
Expand Down Expand Up @@ -67,6 +75,10 @@ typedef struct OSSLDigest
struct OSSLDigest *prev;
} OSSLDigest;

#if OPENSSL_VERSION_MAJOR >= 3
static OSSL_PROVIDER *legacy_provider = NULL;
static OSSL_PROVIDER *default_provider = NULL;
#endif
static OSSLDigest *open_digests = NULL;
static bool digest_resowner_callback_registered = false;

Expand Down Expand Up @@ -193,8 +205,20 @@ px_find_digest(const char *name, PX_MD **res)

if (!px_openssl_initialized)
{
px_openssl_initialized = 1;
#if OPENSSL_VERSION_MAJOR >= 3
if (legacy_provider == NULL)
legacy_provider = OSSL_PROVIDER_load(NULL, "legacy");
if (default_provider == NULL)
default_provider = OSSL_PROVIDER_load(NULL, "default");
#endif

/*
* OpenSSL_add_all_algorithms is deprecated in OpenSSL 1.1.0 and no
* longer required in 1.1.0 and later versions as initialization is
* performed automatically.
*/
OpenSSL_add_all_algorithms();
px_openssl_initialized = 1;
}

if (!digest_resowner_callback_registered)
Expand Down Expand Up @@ -776,6 +800,13 @@ px_find_cipher(const char *name, PX_Cipher **res)
EVP_CIPHER_CTX *ctx;
OSSLCipher *od;

#if OPENSSL_VERSION_MAJOR >= 3
if (legacy_provider == NULL)
legacy_provider = OSSL_PROVIDER_load(NULL, "legacy");
if (default_provider == NULL)
default_provider = OSSL_PROVIDER_load(NULL, "default");
#endif

name = px_resolve_alias(ossl_aliases, name);
#ifdef OPENSSL_ALLOW_REDIRECT
if (px_find_cipher_support_redirect(name)) {
Expand Down
6 changes: 6 additions & 0 deletions doc/src/sgml/pgcrypto.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ gen_salt(type text [, iter_count integer ]) returns text
</tgroup>
</table>

<para>
When compiled against <productname>OpenSSL</productname> 3.0.0, the legacy
provider will be automatically loaded in order to support the ciphers in
the above table.
</para>

<para>
Notes:
</para>
Expand Down
Loading