Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxXin-00015f-Fn for pgsql-general@arkaria.postgresql.org; Wed, 05 Sep 2018 13:19:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fxXil-0005T2-92 for pgsql-general@arkaria.postgresql.org; Wed, 05 Sep 2018 13:19:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxXik-0005Sm-5F for pgsql-general@lists.postgresql.org; Wed, 05 Sep 2018 13:19:47 +0000 Received: from sonic310-13.consmr.mail.bf2.yahoo.com ([74.6.135.123]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxXig-0002iY-Iw for pgsql-general@lists.postgresql.org; Wed, 05 Sep 2018 13:19:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1536153581; bh=aSny50Ect5GUCrS4apFUDGBSRv3bl9NMwXw/Skomodk=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=qMDQH9rf3YhFQ3fG6N30ONxvWY0JG30TWJmuR9m4UPWstOuo4wpS3ir2gpioxNqC1Fv+QAvPRSnaTpfl4CpKIZoTFJ7Ix57Bk5rgzQvaYq158R5dp/8kaSz/pCulU8ejqXHzRBs51vrBTY899BfSEtw4GBI2+koywpOUX1dn06/smrR74brud4srbdMJsPS2xqZc//5kCTSmVb8R4/5bHdZgWyyTxkBtFc/p7I0mfhzn3OsYO4VfamEL5BtgPU4+HToQCl1MbDNbU8jLDlQ2yQ1f1lZaI7+AJZszlOsrsEaA7ZOAHOJlm6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iHb6w-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.bf2.yahoo.com with HTTP; Wed, 5 Sep 2018 13:19:41 +0000 Date: Wed, 5 Sep 2018 13:19:39 +0000 (UTC) From: Alessandro Gherardi To: Michael Paquier Cc: "pgsql-general@lists.postgresql.org" Message-ID: <767499000.1481233.1536153579656@mail.yahoo.com> In-Reply-To: <20180905042717.GL20696@paquier.xyz> References: <898098721.1290085.1536118171911.ref@mail.yahoo.com> <898098721.1290085.1536118171911@mail.yahoo.com> <20180905042717.GL20696@paquier.xyz> Subject: Re: scram-sha-256 authentication broken in FIPS mode MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1481232_47182775.1536153579652" X-Mailer: WebService/1.1.12403 YMailNorrin Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Content-Length: 11024 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1481232_47182775.1536153579652 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Michael,I'm actually running postgres on Windows. I added code to fe-secure-openssl.c and be-secure-openssl.c that reads the = Windows "standard" FIPS registry entry, and if FIPS is enabled calls FIPS_m= ode_set(1). This is to mimic to behavior of the .NET framework. Below is the code I added to fe-secure-openssl.c, the code in be-secure-ope= nssl.c is similar: Thoughts? I can try to fix the scram-sha-256 issue by using EVP and send yo= u a merge request for the patch and the code below if you think my approach= is correct. Thanks,Alessandro intpgtls_init(PGconn *conn){... =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!ssl_lib_initialized) { if (pq_init_ssl_lib= ) { #ifdef WIN32 HKEY rootKey; DWORD fipsEnabled =3D 0; DWORD fipsEnabledSize =3D sizeof(DWORD); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Control\\= Lsa\\FipsAlgorithmPolicy", 0, KEY_READ, &rootKey) !=3D ERROR_SUCCESS) { pri= ntfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open FIPS regi= stry key")); return -1; } if (RegQueryValueEx(rootKey, "Enabled", 0, 0, (LP= BYTE) &fipsEnabled, &fipsEnabledSize) !=3D ERROR_SUCCESS) { RegCloseKey(roo= tKey); printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not read= FIPS registry entry")); return -1; } RegCloseKey(rootKey); if (fipsEnabled =3D=3D 1 && FIPS_mode() =3D=3D 0) { if (FIPS_mode_set(1) != =3D 1) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not en= able FIPS mode")); return -1; } }#endif #ifdef HAVE_OPENSSL_INIT_SSL OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NUL= L);#else OPENSSL_config(NULL); SSL_library_init(); SSL_load_error_strings()= ;#endif On Tuesday, September 4, 2018, 10:27:22 PM MDT, Michael Paquier wrote: =20 =20 On Wed, Sep 05, 2018 at 03:29:31AM +0000, Alessandro Gherardi wrote: > It looks like scram-sha-256 doesn't work when postgres is linked > against FIPS-enabled OpenSSL and FIPS mode is turned on. >=20 > Specifically, all login attempts fail with an OpenSSL error saying > something along the lines of "Low level API call to digest SHA256 > forbidden in fips mode". The error comes from libc, right?=C2=A0 Postgres can of course be configure= d to work with FIPS without patching it, it just needs to be enabled system-wide, which is what RedHat does, and what you are doing I guess? > I think this issue could be solved by refactoring the code in > sha2_openssl.c to use the OpenSSL EVP interface > (see https://wiki.openssl.org/index.php/EVP_Message_Digests=C2=A0).=20 > Any thoughts? Is this a known issue? This report is the first of this kind since Postgres 10, which is where the SHA2 interface for OpenSSL has been introduced.=C2=A0 So likely we'd ne= ed to look into that more deeply..=C2=A0 This has the strong smell of a bug.= =C2=A0 If your system is new enough, you should have sha256() & co as system functions, so you would see the failure as well?=C2=A0 The regression tests would have likely complained. -- Michael =20 ------=_Part_1481232_47182775.1536153579652 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Michael,
I'm actually ru= nning postgres on Windows.

I added code to fe-secu= re-openssl.c and be-secure-openssl.c that reads the Windows "standard" FIPS= registry entry, and if FIPS is enabled calls FIPS_mode_set(1). This is to = mimic to behavior of the .NET framework.

Below is = the code I added to fe-secure-openssl.c, the code in be-secure-openssl.c is= similar:

Thoughts? I can try to fix the scram-sha= -256 issue by using EVP and send you a merge request for the patch and the = code below if you think my approach is correct.

Th= anks,
Alessandro

int
pgtls_init(PGconn *conn)
{
...

        if (!ssl_lib_initialized)
=09{
=09=09if (pq_init_ssl_lib)
=09=09{

#ifdef WIN32
=09=09=09HKEY rootKey;
=09=09=09DWORD fipsEnabled =3D 0;
=09=09=09DWORD fipsEnabledSize =3D sizeof(DW= ORD);

=09= =09=09if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
=09=09=09=09"System\\CurrentControlSet\\Cont= rol\\Lsa\\FipsAlgorithmPolicy",
=09=09=09=090,
=09=09=09=09&rootKey) !=3D ERROR_SUCCESS)
=09=09=09{
=09=09=09=09printfPQExpBuffer(&conn->= errorMessage,
=09=09=09=09= =09libpq_gettext("could not open FIPS registry key"));
=09=09=09=09return -1;
=09=09=09}
=09=09=09if (RegQueryValueEx(rootKey= ,
=09=09=09=09"Enab= led",
=09=09=09=090= ,
=09=09=09=090,
=09=09=09=09(LPBYTE) = &fipsEnabled,
=09=09= =09=09&fipsEnabledSize) !=3D ERROR_SUCCESS)
=09=09=09{
=09=09=09=09RegCloseKey(rootKey);
=09=09=09=09printfPQExpBuffer(&a= mp;conn->errorMessage,
= =09=09=09=09=09libpq_gettext("could not read FIPS registry entry"));=
=09=09=09=09return= -1;
=09=09=09}
=09=09=09RegCloseKey(r= ootKey);

= =09=09=09if (fipsEnabled =3D=3D 1 && FIPS_mode() =3D=3D 0)
=09=09=09{
=09=09=09=09if (FIPS_mode_se= t(1) !=3D 1)
=09=09=09=09<= /span>{
=09=09=09=09=09printfPQExpBuffer(&conn->errorMessage,
=09=09=09=09=09=09libpq_gettext("could not e= nable FIPS mode"));
=09=09= =09=09=09return -1;
=09=09=09=09}
=09= =09=09}
#endif

#ifde= f HAVE_OPENSSL_INIT_SSL
= =09=09=09OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL);
#else
=09=09=09OPE= NSSL_config(NULL);
=09=09= =09SSL_library_init();
=09=09=09SSL_load_error_strings();
#endif


=20
On Tuesday, September 4, 2018, 10:27:22 PM MDT, Michael= Paquier <michael@paquier.xyz> wrote:


On Wed, Sep 05, 2018 at 03:29:31AM +0000, Alessandro G= herardi wrote:
> It looks like scram-sha-256 doesn't w= ork when postgres is linked
> against FIPS-enabled Ope= nSSL and FIPS mode is turned on.
>
= > Specifically, all login attempts fail with an OpenSSL error saying
> something along the lines of "Low level API call to dig= est SHA256
> forbidden in fips mode".

The error comes from libc, right?  Postgres can o= f course be configured
to work with FIPS without patching= it, it just needs to be enabled
system-wide, which is wh= at RedHat does, and what you are doing I guess?


> I think this issue could be solved by refactoring the code in
> sha2_openssl.c to use the OpenSSL EVP interface
> (see https:/= /wiki.openssl.org/index.php/EVP_Message_Digests ).
> Any thoughts? Is this a known issue?


This report is the first of this kind since Postgres 10, whic= h is where
the SHA2 interface for OpenSSL has been introd= uced.  So likely we'd need
to look into that more de= eply..  This has the strong smell of a bug.  If
your system is new enough, you should have sha256() & co as system
functions, so you would see the failure as well?  The r= egression tests
would have likely complained.
--
Michael
------=_Part_1481232_47182775.1536153579652--