Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEpnW-0002nq-81 for pgsql-committers@arkaria.postgresql.org; Mon, 30 Sep 2019 07:08:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iEpnU-000721-TL for pgsql-committers@arkaria.postgresql.org; Mon, 30 Sep 2019 07:08:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEpnU-00071u-Ll for pgsql-committers@lists.postgresql.org; Mon, 30 Sep 2019 07:08:40 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEpnN-0000if-CL for pgsql-committers@lists.postgresql.org; Mon, 30 Sep 2019 07:08:40 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 2FE2C20E54; Mon, 30 Sep 2019 03:08:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 30 Sep 2019 03:08:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=yXzDkjhsc7n1MANTU6JVJ5Gr0lF hFtuYilzi0WB7RQc=; b=Bl+32Z7wg8iJ1sGWWp914yUzUnRf++qCeNGJHeYHbB3 patnsx6ORsTUM0ci0W7n9uvGP55GxuO1cXF+iSXpTRy4vjSfyc13MC8beh49dyz4 CPMafouWLAENSdu2Ece8B9QExpZBuCMCoeoL43oxB7QC7826DxPdBjkrric9Wfmv 1arAeeszO0a5ypg1C/RGA1ggsZGJH0ABcp1jorvmThO/nEg3BTJYuXb2w+uyavf0 4QY8byG807j+P51IWQMrr3HXD9TCN8uRHzr3eOtpH5jrU9DI7F6+/nBCeXDH0XqE br4hJDNJk958XcIN11ffN30Jg/A4flofsHv6YqFILcA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=yXzDkj hsc7n1MANTU6JVJ5Gr0lFhFtuYilzi0WB7RQc=; b=y/Kt/Y6RMLpnRSqIhN9GZq UIOkBZ7sNhT5ehfrTrYjLfRz1+rmLSAZk0SC3j9jS/buFOF+xtlJq9m+U6ET5X59 484RdNLUKG3cnqAMhgGnuvDO/Ti08mSRiORWck52SNezrxt6dcjvUQyImMVAYeVx VRn3oV6Q/VAe7QQPem1YUUIV2p0VYmmTfkXdZvaleVlZa2duQueehB5w6/u1R/Q6 UY6kUwEdxmnTkfNkwttcaGrwrGQ5tDGzIFW9KqZ6+ZnIgbW6kdSqR1kI2kfHkLsD iWeJtcgrXiVdLnrj/HhhdCy1XJBE3Wq394+u7UjyLO3Z1ho305uEA6TRC6gGJcFA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrgedugdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepudduuddruddtvddrudektddrudekheenucfrrghr rghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 072CE8005A; Mon, 30 Sep 2019 03:08:29 -0400 (EDT) Date: Mon, 30 Sep 2019 16:08:26 +0900 From: Michael Paquier To: Tom Lane Cc: Jeff Davis , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Add libpq parameter 'channel_binding'. Message-ID: <20190930070826.GM2888@paquier.xyz> References: <24857.1569775891@sss.pgh.pa.us> <20190929234733.GA2888@paquier.xyz> <20190930064539.GK2888@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="oJAv8lSwuaQsYd0G" Content-Disposition: inline In-Reply-To: <20190930064539.GK2888@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --oJAv8lSwuaQsYd0G Content-Type: multipart/mixed; boundary="gWRamliw218YCZO9" Content-Disposition: inline --gWRamliw218YCZO9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 30, 2019 at 03:45:39PM +0900, Michael Paquier wrote: > If the server publishes SCRAM-SHA-256-PLUS and the server does not > support channel binding, then we get this error message: > "channel binding is required, but server did not offer an > authentication method that supports channel binding." > So that's the part which is wrong. >=20 > Now, I am not completely sure that the suggested change is completely > right either as we would get an error in this scenario when > channel_binding is "prefer" or "require". For "require", this error > message is fine. However, for "prefer", shouldn't we do what we do on > HEAD, aka *not* select SCRAM-SHA-256-PLUS and switch to SCRAM-SHA-256? > This would have the advantage to make the connection work with default > parameters. So, something like the attached looks better to me. Using a server which publishes SCRAM-SHA-256-PLUS, I get the following over SSL: 1) client supports channel binding: 1-1) channel_binding =3D disable =3D> OK, with SCRAM-SHA-256=20 1-2) channel_binding =3D prefer =3D> OK, with SCRAM-SHA-256-PLUS 1-3) channel_binding =3D require =3D> OK, with SCRAM-SHA-256-PLUS 2) client does not support channel binding 2-1) channel_binding =3D disable =3D> OK, with SCRAM-SHA-256 2-2) channel_binding =3D prefer =3D> OK, with SCRAM-SHA-256 2-3) channel_binding =3D require =3D> failure with new error message, instead of the confusing one. The bug is with 2-3, and Tom's suggestion would have switched 2-2 to a failure (2-2 works on HEAD). -- Michael --gWRamliw218YCZO9 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="channel-binding-fix-v1.patch" diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index 04118d54e2..d6e4036641 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -471,14 +471,28 @@ pg_SASL_init(PGconn *conn, int payloadlen) { if (conn->ssl_in_use) { - /* - * The server has offered SCRAM-SHA-256-PLUS, which is only - * supported by the client if a hash of the peer certificate - * can be created, and if channel_binding is not disabled. - */ + /* The server has offered SCRAM-SHA-256-PLUS */ + #ifdef HAVE_PGTLS_GET_PEER_CERTIFICATE_HASH + /* + * The client supports channel binding, which is chosen if + * channel_binding is not disabled. + */ if (conn->channel_binding[0] != 'd') /* disable */ selected_mechanism = SCRAM_SHA_256_PLUS_NAME; +#else + /* + * The client does not support channel binding. If it is + * required, complain immediately instead of the error below + * which would be confusing as the server is publishing + * SCRAM-SHA-256-PLUS. + */ + if (conn->channel_binding[0] == 'r') /* require */ + { + printfPQExpBuffer(&conn->errorMessage, + libpq_gettext("channel binding is required, but client does not support it\n")); + goto error; + } #endif } else --gWRamliw218YCZO9-- --oJAv8lSwuaQsYd0G Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl2RqeoACgkQnvQgOdby QH25gA//ZpUvDbz8je0kUVSg0x3RpHikzP/KE0tTynOpPFybIMDCfsXnEHYoMDWF noxSLKeLZW85xVF1dzNmYeEaPI4khPZnB85YK8sPleaLxp/uuDNbM8Z8ALL9TpYD izLxI2psUEfmTnVvnZ1bqrIDYssR5xTV41s6dzrGpbgFbaAxxPhbU7jPen31ENhs OF8N5q9wzpesiQzquqciTN9eZdhJEcLFoTtTMkA2yzOqcTGF6Jx3M4Lh7FV3atzA TZzqAKywHQ+bAyRyYsNEoAtLkpKdQ3NEGoxJGLLFd6Jb6UVVjHCJFEQjftlW1Esd 5c3Y9vdXubOvJLETg8n60JENtB2NUZB0hr1/TsDXJEizBe29iBhxanbCsfNoOe4/ YsJmyBaQ6P9mTYXoIKgcijTYp9g7Q3jvb1i0fFNLpRb2SEzYFeU+7HD6aS4j92x4 mXvDIvnO1tdfDiYRXoAQ90QhCG82B2O9Mv7cAYSbat24/bsZYHbajdY1aKEaJBWq jZt/X6jtmFfbla3jjlKGpM/ZxJvLS5D36+3Yzq+gro/ufndG+ObDe7WvN/vp9pjW LLzkZ7P+jZ++kb5i1dhy0QW7hwjhFaKBm/r/DWIB+k0t6Z47DIEK57E/NRBI+X1O FLwMLMMYllUAPHJE0kNXi5JLKmAHxUTNKN/AVZwSVWpcAsxv0Kw= =eA7M -----END PGP SIGNATURE----- --oJAv8lSwuaQsYd0G--