From: Alessandro Gherardi <alessandro.gherardi@yahoo.com>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: scram-sha-256 authentication broken in FIPS mode
Date: Mon, 17 Sep 2018 14:55:55 +0000 (UTC)
Message-ID: <1940555821.4092541.1537196155707@mail.yahoo.com> (raw)
In-Reply-To: <20180913031114.GA3578@paquier.xyz>
References: <898098721.1290085.1536118171911@mail.yahoo.com>
<20180905042717.GL20696@paquier.xyz>
<767499000.1481233.1536153579656@mail.yahoo.com>
<20180905181545.GC2726@paquier.xyz>
<1691863835.972001.1536301001998@mail.yahoo.com>
<1924578892.946938.1536301653576@mail.yahoo.com>
<1168852455.1352488.1536591120175@mail.yahoo.com>
<20180911030250.GA27115@paquier.xyz>
<5aeb058d-e32c-e3e0-e4b1-6469aeeadc2b@2ndquadrant.com>
<20180911222424.GB25160@paquier.xyz>
<20180913031114.GA3578@paquier.xyz>
Here's a patch for enabling FIPS in OpenSSL - by calling FIPS_mode_set(1) - on Windows if the FIPS registry entry HKLM\System\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy\Enabled is set to 1. That's the entry that the .NET crypto libraries look at to decide whether or not to operate in FIPS mode.
I thought of submitting a pull request for adding this logic to OpenSSL, however (1) https://www.openssl.org/source/ says they are working on a new FIPS module, so I doubt they would take a pull request for OpenSSL 1.0.X and (2) For Linux, this logic doesn't exist on the standard OpenSSL distribution but only on the RHEL-specific OpenSSL patch (See method init_fips_mode() in https://git.centos.org/raw/rpms/openssl.git/c7/SOURCES!openssl-1.0.2i-fips.patch ).
Therefore, I believe the best option, at least for now, is calling FIPS_mode_set(1) in the application.
Attachments:0001-On-Windows-call-FIPS_mode_set-1-if-FIPS-registry-ent.patch (application/octet-stream, 3.1K) download
From 38d6f522fcb1038df979bd26364d66e82f5f6d1f Mon Sep 17 00:00:00 2001
From: Alessandro Gherardi <alessandro.gherardi@yahoo.com>
Date: Sun, 16 Sep 2018 14:11:33 -0600
Subject: [PATCH] On Windows, call FIPS_mode_set(1) if FIPS registry entry
indicates that FIPS is enabled
---
src/backend/libpq/be-secure-openssl.c | 44 ++++++++++++++++++++++++++++++++
src/interfaces/libpq/fe-secure-openssl.c | 40 +++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.cindex 6a57657..f4dbef2 100644--- a/src/backend/libpq/be-secure-openssl.c+++ b/src/backend/libpq/be-secure-openssl.c@@ -81,6 +81,50 @@ be_tls_init(bool isServerStart)
/* This stuff need be done only once. */
if (!SSL_initialized)
{
+#ifdef WIN32+ HKEY rootKey;+ DWORD fipsEnabled = 0;+ DWORD fipsEnabledSize = sizeof(DWORD);++ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,+ "System\\CurrentControlSet\\Control\\Lsa\\FipsAlgorithmPolicy",+ 0,+ KEY_READ,+ &rootKey) != ERROR_SUCCESS)+ {+ ereport(isServerStart ? FATAL : LOG,+ (errmsg("could not open FIPS registry key")));+ goto error;+ }+ if (RegQueryValueEx(rootKey,+ "Enabled",+ 0,+ 0,+ (LPBYTE)&fipsEnabled,+ &fipsEnabledSize) != ERROR_SUCCESS)+ {+ RegCloseKey(rootKey);+ ereport(isServerStart ? FATAL : LOG,+ (errmsg("could not read FIPS registry entry")));+ goto error;+ }+ RegCloseKey(rootKey);++ if (fipsEnabled == 1 && FIPS_mode() == 0)+ {+ if (FIPS_mode_set(1) != 1)+ {+ ereport(isServerStart ? FATAL : LOG,+ (errmsg("could not enable FIPS mode")));+ goto error;+ }++ ereport(LOG,+ (errmsg("successfully enabled OpenSSL FIPS mode")));+ }++#endif+
#ifdef HAVE_OPENSSL_INIT_SSL
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL);
#else
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.cindex bbae8ef..6c1cf6c 100644--- a/src/interfaces/libpq/fe-secure-openssl.c+++ b/src/interfaces/libpq/fe-secure-openssl.c@@ -703,6 +703,46 @@ pgtls_init(PGconn *conn)
{
if (pq_init_ssl_lib)
{
+#ifdef WIN32+ HKEY rootKey;+ DWORD fipsEnabled = 0;+ DWORD fipsEnabledSize = sizeof(DWORD);++ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,+ "System\\CurrentControlSet\\Control\\Lsa\\FipsAlgorithmPolicy",+ 0,+ KEY_READ,+ &rootKey) != ERROR_SUCCESS)+ {+ printfPQExpBuffer(&conn->errorMessage,+ libpq_gettext("could not open FIPS registry key"));+ return -1;+ }+ if (RegQueryValueEx(rootKey,+ "Enabled",+ 0,+ 0,+ (LPBYTE) &fipsEnabled,+ &fipsEnabledSize) != ERROR_SUCCESS)+ {+ RegCloseKey(rootKey);+ printfPQExpBuffer(&conn->errorMessage,+ libpq_gettext("could not read FIPS registry entry"));+ return -1;+ }+ RegCloseKey(rootKey);++ if (fipsEnabled == 1 && FIPS_mode() == 0)+ {+ if (FIPS_mode_set(1) != 1)+ {+ printfPQExpBuffer(&conn->errorMessage,+ libpq_gettext("could not enable FIPS mode"));+ return -1;+ }+ }+#endif+
#ifdef HAVE_OPENSSL_INIT_SSL
OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL);
#else
--
2.7.4
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: alessandro.gherardi@yahoo.com, peter.eisentraut@2ndquadrant.com, michael@paquier.xyz
Subject: Re: scram-sha-256 authentication broken in FIPS mode
In-Reply-To: <1940555821.4092541.1537196155707@mail.yahoo.com>
References: <898098721.1290085.1536118171911@mail.yahoo.com> <20180905042717.GL20696@paquier.xyz> <767499000.1481233.1536153579656@mail.yahoo.com> <20180905181545.GC2726@paquier.xyz> <1691863835.972001.1536301001998@mail.yahoo.com> <1924578892.946938.1536301653576@mail.yahoo.com> <1168852455.1352488.1536591120175@mail.yahoo.com> <20180911030250.GA27115@paquier.xyz> <5aeb058d-e32c-e3e0-e4b1-6469aeeadc2b@2ndquadrant.com> <20180911222424.GB25160@paquier.xyz> <20180913031114.GA3578@paquier.xyz> <1940555821.4092541.1537196155707@mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox