Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1keSG5-00080V-Nj for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Nov 2020 00:20:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1keSG2-0008GD-Ry for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Nov 2020 00:20:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1keSG1-0008G6-2T for pgsql-hackers@lists.postgresql.org; Mon, 16 Nov 2020 00:20:34 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1keSFs-0000QT-Ep for pgsql-hackers@lists.postgresql.org; Mon, 16 Nov 2020 00:20:32 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id ABE0E5C00B9; Sun, 15 Nov 2020 19:20:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 15 Nov 2020 19:20:21 -0500 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=fm3; bh=/Yeo6MYLgNnCtLEqznFEjg2eJHr ZFriwqia9vq8coN8=; b=RRmuv5CZh1+LORakHWGwAFvE41ft05LcOaD6DlbcU6o /cwcb//K7HGnl0klUp31qXSh5YbtBM86GBhD6SMaBfjdOaEpnIwkuu8Ky7F/BdXC PBIDeukV6QeywXK5+XJU/snbMw/I8NjwBdw25R49Zf/K44W/nw2wUSEeShQGGu9J 7qMWNdroVmneeJBum+2O13TefP0SUW2bLdeLjPlt4iN5uGB0RCDIimG8olvgMKgS UkUj1lGfv2NxpLJqA6RXXEOOsQsNIXLn+F/HnV8DTO9qic0B9AkD92y19OGPTXuN KsrrjlcRbO2SK0bu63Gb95jhJhmtlDO13N6Q38HuDTA== 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=fm1; bh=/Yeo6M YLgNnCtLEqznFEjg2eJHrZFriwqia9vq8coN8=; b=Wlci61PS2WPvHbDNhfp5YN WGVTDmeAEbPblcMqvMj12jY/xD3OdoVAgC/BON7it4/ylqF3waH1DvlaDGVdcyeK fUdUzAx/ONNoVENmC0l/3RjM+E6KmtfJTyxKr6ahyj+Oi2fRQSOTYncIItpk3xNp 12Pw65BAtefN+NacNGsxmxWSm4juWgVPgtMLZql4VId/w9foeMI814Auxac7QNE9 a54vVMJAzGC/vR8ybJUwmPaev81gi+/1NZcEpTU3REp1yeUiobFIKVy5jrdFxugQ iqhxX0nRoBqFH7fuhLNYfrIJxz17ht8ByteCkCH4SUTDcDZn6e0EXeNLqvxHHP1w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeftddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucfkphepudduuddruddtvddrudektd drudekheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehmihgthhgrvghlsehprghquhhivghrrdighiii 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 882F13064AB0; Sun, 15 Nov 2020 19:20:19 -0500 (EST) Date: Mon, 16 Nov 2020 09:20:16 +0900 From: Michael Paquier To: Tom Lane Cc: Magnus Hagander , Daniel Gustafsson , Postgres hackers Subject: Re: Move OpenSSL random under USE_OPENSSL_RANDOM Message-ID: <20201116002016.GA2656@paquier.xyz> References: <20201105034413.GE1632@paquier.xyz> <20201105121253.GA17513@paquier.xyz> <7001EB35-BF76-4DEA-A7AB-CA94BCAA64E3@yesql.se> <20201105122834.GB17513@paquier.xyz> <8D9C19AD-674D-4FD2-820E-9B429053719E@yesql.se> <20201105233632.GA21123@paquier.xyz> <53D01523-A458-4FC6-83F1-8A16266F54A0@yesql.se> <632623.1605460616@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="aVD9QWMuhilNxW9f" Content-Disposition: inline In-Reply-To: <632623.1605460616@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --aVD9QWMuhilNxW9f Content-Type: multipart/mixed; boundary="k1lZvvs/B4yU6o8G" Content-Disposition: inline --k1lZvvs/B4yU6o8G Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Nov 15, 2020 at 12:16:56PM -0500, Tom Lane wrote: > The obvious problem with this is that if !USE_OPENSSL, we will not have > pulled in openssl's headers. FWIW, I argued upthread against including this part because it is useless: if not building with OpenSSL, we'll never have the base to be able to use RAND_poll(). > However ... all these machines are pointing at line 96, which is not > that one but the one under "#if defined(USE_OPENSSL)". So I'm not sure > what to make of that, except that a bit more finesse seems required. The build scripts of src/tools/msvc/ choose to not use OpenSSL as strong random source even if building with OpenSSL. The top of the file only includes openssl/rand.h if using USE_OPENSSL_RANDOM. Thinking about that afresh, I think that we got that wrong here on three points: - If attempting to use OpenSSL on Windows, let's just bite the bullet and use OpenSSL as random source, using Windows as source only when not building with OpenSSL. - Instead of using a call to RAND_poll() that we know will never work, let's just issue a compilation failure if attempting to use USE_OPENSSL_RANDOM without USE_OPENSSL. - rand.h needs to be included under USE_OPENSSL. -- Michael --k1lZvvs/B4yU6o8G Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="win32-openssl.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/port/pg_strong_random.c b/src/port/pg_strong_random.c index 6d85f50b7c..c5dfe4b072 100644 --- a/src/port/pg_strong_random.c +++ b/src/port/pg_strong_random.c @@ -24,7 +24,7 @@ #include #include =20 -#ifdef USE_OPENSSL_RANDOM +#ifdef USE_OPENSSL #include #endif #ifdef USE_WIN32_RANDOM @@ -98,14 +98,11 @@ pg_strong_random_init(void) =20 #if defined(USE_OPENSSL_RANDOM) /* - * In case the backend is using the PRNG from OpenSSL without being built - * with support for OpenSSL, make sure to perform post-fork initializatio= n. - * If the backend is using OpenSSL then we have already performed this - * step. The same version caveat as discussed in the comment above applies - * here as well. + * If attempting to use OpenSSL as random source without support for it, + * consider this combination as invalid. */ #ifndef USE_OPENSSL - RAND_poll(); +#error cannot use OpenSSL as random source without building with it. #endif =20 #elif defined(USE_WIN32_RANDOM) diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 17e480546c..cb01902ae9 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -525,6 +525,7 @@ sub GenerateFiles if ($self->{options}->{openssl}) { $define{USE_OPENSSL} =3D 1; + $define{USE_OPENSSL_RANDOM} =3D 1; =20 my ($digit1, $digit2, $digit3) =3D $self->GetOpenSSLVersion(); =20 --k1lZvvs/B4yU6o8G-- --aVD9QWMuhilNxW9f Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl+xxcAACgkQnvQgOdby QH3mUA/+K+7lIKnOQ1gkAxjfdK00Kk+09q20/yq2ZiUT7bp3GMRNpxXle4h5pDCW f71F3ZUFKaw7vTfcoXUklbG2xtjd6AayjaItHUhTmGcsMKQ2bFN9g0j0vZQW/QNe Hs1rcW9ymPcDwVUmL9+VHpyBi4y6X2Il6ZGZ9iLkOIFysYwMnfidAk7bUsK/+g1i x+9xcqrTH+E9HlaC0/cv5L9U7RDctAueMk1Q+zFNqY2hqVmFmTtxjzL+f7sif33y GKtJys1wvW62ij/GjkbomDHlrA7K2ma6IbD/0bTMVTEa7G7ShwAJ6anaZegHnInY Zxh2/OMz9+ahP2ADVquCU+6sevgaDBQb0UEXF5LNf2cWb3rCpSc65k43YivbqvuG fcjVvH2gLykc3HI7CqgrYXfrBicielvEZCyxqLNnFEoHBa3BW8q8aBJvd+Y5Byn8 GkDRQD23thhLqp4+u0bPIQCsNF5CGg2Acw9oUl2hFFS9WSwhxnJa3zuPg1KfUTbg UPQt4EOb4+iX2fureosTmJKACvbdFe7KbMqoIYN/LCVxaDlToL0GyjDcNpKAxx6u KQ86hnOr39AqBI91gQbhJRNXvlo1rn2DRLi7EdmTnmf44wDhrwkz2UN8oVaI5Bx0 A9hx+6ccMDPh4Ku6KsQ17DkPev9NaTMw2ETKvLVb63lcMSzP8K8= =zGow -----END PGP SIGNATURE----- --aVD9QWMuhilNxW9f--