Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzinY-005hzz-CZ for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Apr 2025 21:05:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tzinW-006bWe-Po for pgsql-hackers@arkaria.postgresql.org; Tue, 01 Apr 2025 21:05:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tzinW-006bWW-3R for pgsql-hackers@lists.postgresql.org; Tue, 01 Apr 2025 21:05:26 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzinS-002pTh-1b for pgsql-hackers@postgresql.org; Tue, 01 Apr 2025 21:05:25 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id E3DBD11400A3 for ; Tue, 1 Apr 2025 17:05:19 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 01 Apr 2025 17:05:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mackerron.co.uk; h=cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1743541519; x=1743627919; bh=zjeyQPRAdhkEY74adEs+DYdU15n4+sJO 9EwBqllqRHo=; b=NtXqRoaD+/v3TdiuHL1hH/wxf9YCEhUNtf9D9Y2/0IdhBJ6B FOZmTojY5U0LTMtqpaE5AtbJXRb39mRGI6xbeE3zK6k5kYomga3b5F8J5IbwAWCB xX+YAkLdF+rtWLXVSG/WnNRsAi0+MAP8Wp5XJUmCAq9O3zhlYg/8m4KiJDx+lh7m MEeRIOE2eoUa6ApW7CvAJAUls8AG9ior08ZagNFDIN4ALzg1CJAhZpEvSVUNmcsg y0PC4yhn6Degou7sd54bRHaABM2G0ORL0Y5RV5Iu/NtQxcMoSpWIZiijbvkkGZTq rRRyB/kwFn/o2YXePu48fjm61xVARBsTsWMjig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1743541519; x= 1743627919; bh=zjeyQPRAdhkEY74adEs+DYdU15n4+sJO9EwBqllqRHo=; b=q 7X833UxX6qLmf1ISEXjOIz/9Xy8k4nGga6KETRdOK4gV6nz5Ytt1kdWbjk4Q78y9 WbvqtJO8car2Ut8t07f/C2ZYNbNR89d+bio6Llgr6i38uwUaBsRD5xkfdJh2PPz1 oCKp8BrelEmXThq/zAdwNI0PEPYqm0RZoReiuF4eFtDOrLv5Hc1ABFucscKDslBB bip9tp9coIXkw2IvQPubEMWTbXR9yp/KqPtYXniijUoq57e7iDC+7k20s1xBgaxR cIjTTll7GE8JdrhgP+SIlIpFmEX/5uDY8JMSPCyIoiQVdKNMqxqXeg7qwZ/vVpCZ xCM7ev2veQ3SB8LVYADuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeefkeduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhtg gguffkfffvofesmhdtmherhhdtjeenucfhrhhomhepifgvohhrghgvucforggtmfgvrhhr ohhnuceoghgvohhrghgvsehmrggtkhgvrhhrohhnrdgtohdruhhkqeenucggtffrrghtth gvrhhnpeeigfejieelteeikeefheevveejfeeihefhhedtudduheevvdfgteekhfejudei ueenucffohhmrghinhepnhgvohhnrdhtvggthhdpghhithhhuhgsrdgtohhmpdifihhnsh htohhrvgdrihhmpdhsthgrtghkohhvvghrfhhlohifrdgtohhmpdhophgvnhhsshhlrdho rhhgpdhmrggtphhorhhtshdrohhrghdpuggvsghirghnrdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghgvohhrghgvsehmrggtkhgv rhhrohhnrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuth dprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhr gh X-ME-Proxy: Feedback-ID: ic18c41fa:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 1 Apr 2025 17:05:19 -0400 (EDT) From: George MacKerron Content-Type: multipart/mixed; boundary="Apple-Mail=_E4B2C119-5F0E-436F-8791-802979C9FF73" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.400.131.1.6\)) Subject: Making sslrootcert=system work on Windows psql Message-Id: <6C7CE7B4-0565-4840-96FA-A1BE5C8D53AB@mackerron.co.uk> Date: Tue, 1 Apr 2025 22:05:08 +0100 To: pgsql-hackers@postgresql.org X-Mailer: Apple Mail (2.3826.400.131.1.6) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_E4B2C119-5F0E-436F-8791-802979C9FF73 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I was very pleased to see the sslrootcert=3Dsystem connection option = added in Postgres 16 (I even blogged about it: = https://neon.tech/blog/avoid-mitm-attacks-with-psql-postgres-16). But = sslrootcert=3Dsystem has not been widely supported by psql = installations, perhaps because people compiling Postgres haven=E2=80=99t = always been aware of the requirement to point OpenSSL in the direction = of the system=E2=80=99s root CA certificates. I=E2=80=99ve recently been trying to get it more widely supported, with = some success (details at end of this message). However, psql via the EnterpriseDB Windows installer still doesn=E2=80=99t= support sslrootcert=3Dsystem, and I think a tiny patch is needed. The = diff is attached, and can be seen in context here: = https://github.com/postgres/postgres/compare/master...jawj:postgres:jawj-s= slrootcert-system-windows Essentially, on Windows with OpenSSL 3.2+, it replaces = SSL_CTX_set_default_verify_paths(SSL_context) with = SSL_CTX_load_verify_store(SSL_context, "org.openssl.winstore:=E2=80=9D). I=E2=80=99m not a Windows or OpenSSL expert, but so far the patched code = seems to work in theory and in practice (sources below, and I=E2=80=99ve = compiled and tested it working on Windows 11 x64). # Sources https://stackoverflow.com/a/79461864/338196 https://docs.openssl.org/master/man7/OSSL_STORE-winstore/ https://docs.openssl.org/master/man3/SSL_CTX_load_verify_locations/ # Status of sslrootcert=3Dsystem in various packages providing psql ## Mac Postgres.app =E2=80=94 now fixed = (https://github.com/PostgresApp/PostgresApp/issues/801) MacPorts =E2=80=94 now fixed (https://trac.macports.org/ticket/72080) EDB installer =E2=80=94 now fixed = (https://github.com/EnterpriseDB/edb-installers/issues/264) homebrew =E2=80=94 was working already ## Linux Debian/Ubuntu =E2=80=94 now Recommends ca-certificates = (https://salsa.debian.org/postgresql/postgresql/-/commit/96077ad61c3638664= 6cdd9b5ce0e423a357ce73b) ## Windows EDB installer =E2=80=94 in progress WSL1, WSL2 (Ubuntu, openSUSE) =E2=80=94 was working already --Apple-Mail=_E4B2C119-5F0E-436F-8791-802979C9FF73 Content-Disposition: attachment; filename=sslrootcert-system-win.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="sslrootcert-system-win.diff" Content-Transfer-Encoding: 7bit diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 5bb9d9779d828..ec5d87773df08 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -840,7 +840,11 @@ initialize_SSL(PGconn *conn) * further overridden by the SSL_CERT_DIR and SSL_CERT_FILE * environment variables. */ +#if defined(WIN32) && OPENSSL_VERSION_PREREQ(3, 2) + if (SSL_CTX_load_verify_store(SSL_context, "org.openssl.winstore:") != 1) +#else if (SSL_CTX_set_default_verify_paths(SSL_context) != 1) +#endif { char *err = SSLerrmessage(ERR_get_error()); --Apple-Mail=_E4B2C119-5F0E-436F-8791-802979C9FF73--