From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6A1QI9jV62LWtgAAbAwnHQ (envelope-from ) for ; Thu, 04 Aug 2022 16:21:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WJtsItjV62IgQgEAG6o9tA (envelope-from ) for ; Thu, 04 Aug 2022 16:21:12 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F0AE3342 for ; Thu, 4 Aug 2022 16:21:11 +0200 (CEST) Received: from localhost ([::1]:47512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJbip-0001rk-2i for larch@yhetil.org; Thu, 04 Aug 2022 10:21:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJbig-0001q7-Ez for guix-patches@gnu.org; Thu, 04 Aug 2022 10:21:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:36213) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJbig-0005A4-60 for guix-patches@gnu.org; Thu, 04 Aug 2022 10:21:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oJbig-0001PV-1Y for guix-patches@gnu.org; Thu, 04 Aug 2022 10:21:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56867] [PATCH] download: Do not wrap TLS port on GnuTLS >= 3.7.7. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 04 Aug 2022 14:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56867 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56867@debbugs.gnu.org Cc: guile-devel@gnu.org Received: via spool by 56867-submit@debbugs.gnu.org id=B56867.16596228365365 (code B ref 56867); Thu, 04 Aug 2022 14:21:01 +0000 Received: (at 56867) by debbugs.gnu.org; 4 Aug 2022 14:20:36 +0000 Received: from localhost ([127.0.0.1]:54189 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oJbi3-0001OB-Nr for submit@debbugs.gnu.org; Thu, 04 Aug 2022 10:20:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oJbi1-0001Nq-VQ for 56867@debbugs.gnu.org; Thu, 04 Aug 2022 10:20:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:42100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJbhw-00052f-Ny; Thu, 04 Aug 2022 10:20:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=AJICttRZOaEGO+iSWH4Ghlg//5/JOxiOBH+4qG2JF6o=; b=EuarLm90E6finYUhMz2a 4ATot69akhOe6HId70PqwH9Pgbe4VmcPoBONGqh+eCVv+NHU7vDfp1HD8aq9yCn5tSpyg8VsAIfJM HdEQa7MCyLpW3SRJHGNTwQmo/WVCKDfKkUbfeZVLH/ji+4UhfCLxTyONU9eoMJHq8tbq35PQ+cCyZ IRe9VM+C11CjYlomY25pWN3Y7kzzZZhn/UWc+80ThaoXR4Vtq+a1lOrHGgm8kGjeK6LV+iRCOLjfA wCB81I0cxgU/QCfCjVU/j6G82Km+UIckfi9IZXbl7dnOlvY0J11eJ2gq/n8/FqVmsOR6CodGNAv2n QdFXPxByyF7iUQ==; Received: from [2001:660:6102:310:f6b5:dff0:8fea:f7c9] (port=42640 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJbhw-0005iU-B2; Thu, 04 Aug 2022 10:20:16 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20220801090749.11655-1-ludo@gnu.org> Date: Thu, 04 Aug 2022 16:20:12 +0200 In-Reply-To: <20220801090749.11655-1-ludo@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Mon, 1 Aug 2022 11:07:49 +0200") Message-ID: <87pmhgks4j.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659622872; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=AJICttRZOaEGO+iSWH4Ghlg//5/JOxiOBH+4qG2JF6o=; b=V2JtU+SHh+4Oo6t8/09WDM0fzPg3yjlJiQiTghlo6HxCUapxHf8UmbkU86gk1/hzMrZK2d DMons1ZIxWrrCNWj3URSoScv+LALXy/8r2Ixoaejtx0+o4fYARKElEJIaDysNIW9MUta1N 5K9+2YpAPZCL8M2bSVSNbaQE8bfIAXL9XepZDfFI3kKHKibgPAAeSWMzf07NQnKWXsS05H 1OLdhXhLPHg+OZPGEL2Rumjq6rbW4+ThHAe1m1h4nSZ3ae2Piygsu+lTKcqGs3vKOSkc6/ AUgJAX0xkRkFF30b328rAdU4/FjSwBCqgZpOqjh7W1epCDK/KNSD8Am0KT2SLQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659622872; a=rsa-sha256; cv=none; b=mdSJM6+RJ2dOIo1SrrT203KyQ9ylDz12PJtAssHoS2Ubz+jtUyVc5Ohq9RDm+bdxj/qdW8 HvbeP4/qMiU7qoO2NPuPC700MWdDSIIA4+gZxr3jx0BgRHdCi0ErsojwNTKoPsoYEoXdDX 6vBZC+mtifNaYZJ7g+OIdpayzS/OPkUPE0VvORxyxtbdnkjg4Em0/ZNxyT3bmtXFgEt2fy qLTib3j0E3QiPBvCWptW2mvDdTygyeMKMLfMdylM7C3G5jhrQ4m9U5vGGXkeUlKrFj0KbQ qAy+BcA14xwS+ocAsJ9r8tEG8no4Gu0LUnVdoormohHdC6OKDaRzZp1jGXbnMg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=EuarLm90; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.51 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=EuarLm90; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: F0AE3342 X-Spam-Score: -5.51 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9GaWHhFru8jU --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s skribis: > The custom input/output port wrapping the TLS session record port would > introduce overhead, and it would also prevent its uses in a non-blocking > context--e.g., with Fibers. The port close mechanism added in GnuTLS > 3.7.7 allows us to get rid of that wrapper. > > * guix/build/download.scm (wrap-record-port-for-gnutls<3.7.7): New > procedure, with code formerly in 'tls-wrap'. > (tls-wrap): Check for 'set-session-record-port-close!' and use it when > available; otherwise call 'wrap-record-port-for-gnutls<3.7.7'. I synchronized Guile's copy of this code: 317b06bf8 web: 'tls-wrap' retries handshake upon non-fatal errors. c01ca10b3 web: Do not wrap TLS port on GnuTLS >=3D 3.7.7. I realized that=E2=80=99s not enough to make it possible to use non-blocking ports though. First, I noticed that GnuTLS doesn=E2=80=99t implement =E2=80=98write_wait_= fd=E2=80=99, only =E2=80=98read_wait_fd=E2=80=99 (not sure how problematic that is): --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,use(web client) scheme@(guile-user)> (define p (open-socket-for-uri "https://guix.gnu.org")) scheme@(guile-user)> ((@@ (ice-9 suspendable-ports) wait-for-writable) p) ice-9/boot-9.scm:1685:16: In procedure raise-exception: In procedure write_wait_fd: unimplemented Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue. scheme@(guile-user) [1]> ,q scheme@(guile-user)> ,use(gnutls) scheme@(guile-user)> (gnutls-version) $1 =3D "3.7.7" scheme@(guile-user)> ((@@ (ice-9 suspendable-ports) wait-for-readable) p) $2 =3D 1 --8<---------------cut here---------------end--------------->8--- Second, =E2=80=98open-socket-for-uri=E2=80=99 creates a blocking socket and= uses that as the backing file descriptor of the TLS session. We=E2=80=99d need a way to pass flags for the =E2=80=98socket=E2=80=99 call= made by =E2=80=98open-socket-for-uri=E2=80=99 so we can pass O_NONBLOCK, maybe as s= how below: --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/module/web/client.scm b/module/web/client.scm index a08c4203c..9273a45ad 100644 --- a/module/web/client.scm +++ b/module/web/client.scm @@ -320,7 +320,8 @@ host name without trailing dot." (read-response port)) (define* (open-socket-for-uri uri-or-string - #:key (verify-certificate? #t)) + #:key (verify-certificate? #t) + (flags 0)) "Return an open input/output port for a connection to URI-OR-STRING. When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates." (define uri @@ -373,10 +374,18 @@ When VERIFY-CERTIFICATE? is true, verify HTTPS server certificates." (when (and https? (current-https-proxy)) (setup-http-tunnel s uri)) - (if https? - (tls-wrap s (uri-host uri) - #:verify-certificate? verify-certificate?) - s))) + (let ((port (if https? + (tls-wrap s (uri-host uri) + #:verify-certificate? verify-certificate?) + s))) + (unless (zero? flags) + ;; FLAGS might contain O_NONBLOCK. Thus, set it as a last step + ;; because 'handshake' otherwise throws an exception for + ;; GNUTLS_E_AGAIN. + (let ((initial-flags (fcntl s F_GETFL))) + (fcntl s F_SETFL (logior initial-flags flags)))) + + port))) (define (extend-request r k v . additional) (let ((r (set-field r (request-headers) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable =E2=80=A6 which lets us do that: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> ,use(web client) scheme@(guile-user)> (define p (open-socket-for-uri "https://guix.gnu.org" = #:flags O_NONBLOCK)) scheme@(guile-user)> (http-get "https://guix.gnu.org" #:port p) --8<---------------cut here---------------end--------------->8--- Thoughts? Ludo=E2=80=99. --=-=-=--