From patchwork Wed Mar 7 11:25:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 10263845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9A78260211 for ; Wed, 7 Mar 2018 11:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B79429491 for ; Wed, 7 Mar 2018 11:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F79D2949F; Wed, 7 Mar 2018 11:27:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D201C29491 for ; Wed, 7 Mar 2018 11:27:19 +0000 (UTC) Received: from localhost ([::1]:60916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etXE7-0003ZR-0Y for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Mar 2018 06:27:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etXCj-0002KW-5P for qemu-devel@nongnu.org; Wed, 07 Mar 2018 06:25:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etXCh-0000QM-Sa for qemu-devel@nongnu.org; Wed, 07 Mar 2018 06:25:53 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44520 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etXCe-0000Mz-2a; Wed, 07 Mar 2018 06:25:48 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A743E40252F4; Wed, 7 Mar 2018 11:25:47 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63870215CDA7; Wed, 7 Mar 2018 11:25:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 7 Mar 2018 11:25:32 +0000 Message-Id: <20180307112532.24248-7-berrange@redhat.com> In-Reply-To: <20180307112532.24248-1-berrange@redhat.com> References: <20180307112532.24248-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 07 Mar 2018 11:25:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 07 Mar 2018 11:25:47 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'berrange@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 6/6] qio: non-default context for TLS handshake X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Peter Xu , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Xu A new parameter "context" is added to qio_channel_tls_handshake() is to allow the TLS to be run on a non-default context. Still, no functional change. Signed-off-by: Peter Xu Signed-off-by: Daniel P. Berrangé --- chardev/char-socket.c | 1 + include/io/channel-tls.h | 5 ++++- io/channel-tls.c | 45 ++++++++++++++++++++++++++++++++++----------- migration/tls.c | 2 ++ nbd/client.c | 1 + nbd/server.c | 1 + tests/test-io-channel-tls.c | 2 ++ ui/vnc-auth-vencrypt.c | 1 + ui/vnc-ws.c | 1 + 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index b0d11387f3..58e11c6f4c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -703,6 +703,7 @@ static void tcp_chr_tls_init(Chardev *chr) qio_channel_tls_handshake(tioc, tcp_chr_tls_handshake, chr, + NULL, NULL); } diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h index d157eb10e8..87fcaf9146 100644 --- a/include/io/channel-tls.h +++ b/include/io/channel-tls.h @@ -116,6 +116,8 @@ qio_channel_tls_new_client(QIOChannel *master, * @func: the callback to invoke when completed * @opaque: opaque data to pass to @func * @destroy: optional callback to free @opaque + * @context: the context that TLS handshake will run with. If %NULL, + * the default context will be used * * Perform the TLS session handshake. This method * will return immediately and the handshake will @@ -126,7 +128,8 @@ qio_channel_tls_new_client(QIOChannel *master, void qio_channel_tls_handshake(QIOChannelTLS *ioc, QIOTaskFunc func, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); /** * qio_channel_tls_get_session: diff --git a/io/channel-tls.c b/io/channel-tls.c index 6182702dab..9628e6fa47 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -140,13 +140,19 @@ qio_channel_tls_new_client(QIOChannel *master, return NULL; } +struct QIOChannelTLSData { + QIOTask *task; + GMainContext *context; +}; +typedef struct QIOChannelTLSData QIOChannelTLSData; static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, GIOCondition condition, gpointer user_data); static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, - QIOTask *task) + QIOTask *task, + GMainContext *context) { Error *err = NULL; QCryptoTLSSessionHandshakeStatus status; @@ -171,6 +177,15 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, qio_task_complete(task); } else { GIOCondition condition; + QIOChannelTLSData *data = g_new0(typeof(*data), 1); + + data->task = task; + data->context = context; + + if (context) { + g_main_context_ref(context); + } + if (status == QCRYPTO_TLS_HANDSHAKE_SENDING) { condition = G_IO_OUT; } else { @@ -178,11 +193,12 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, } trace_qio_channel_tls_handshake_pending(ioc, status); - qio_channel_add_watch(ioc->master, - condition, - qio_channel_tls_handshake_io, - task, - NULL); + qio_channel_add_watch_full(ioc->master, + condition, + qio_channel_tls_handshake_io, + data, + NULL, + context); } } @@ -191,12 +207,18 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, GIOCondition condition, gpointer user_data) { - QIOTask *task = user_data; + QIOChannelTLSData *data = user_data; + QIOTask *task = data->task; + GMainContext *context = data->context; QIOChannelTLS *tioc = QIO_CHANNEL_TLS( qio_task_get_source(task)); - qio_channel_tls_handshake_task( - tioc, task); + g_free(data); + qio_channel_tls_handshake_task(tioc, task, context); + + if (context) { + g_main_context_unref(context); + } return FALSE; } @@ -204,7 +226,8 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, void qio_channel_tls_handshake(QIOChannelTLS *ioc, QIOTaskFunc func, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task; @@ -212,7 +235,7 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc, func, opaque, destroy); trace_qio_channel_tls_handshake_start(ioc); - qio_channel_tls_handshake_task(ioc, task); + qio_channel_tls_handshake_task(ioc, task, context); } diff --git a/migration/tls.c b/migration/tls.c index a29b35b33c..3b9e8c9263 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -105,6 +105,7 @@ void migration_tls_channel_process_incoming(MigrationState *s, qio_channel_tls_handshake(tioc, migration_tls_incoming_handshake, NULL, + NULL, NULL); } @@ -159,5 +160,6 @@ void migration_tls_channel_connect(MigrationState *s, qio_channel_tls_handshake(tioc, migration_tls_outgoing_handshake, s, + NULL, NULL); } diff --git a/nbd/client.c b/nbd/client.c index 9c3fe4aaa6..dcad23a053 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -579,6 +579,7 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc, qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, + NULL, NULL); if (!data.complete) { diff --git a/nbd/server.c b/nbd/server.c index 4990a5826e..e714bfe6a1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -599,6 +599,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client, qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, + NULL, NULL); if (!data.complete) { diff --git a/tests/test-io-channel-tls.c b/tests/test-io-channel-tls.c index a210d01ba5..32743b2c96 100644 --- a/tests/test-io-channel-tls.c +++ b/tests/test-io-channel-tls.c @@ -203,10 +203,12 @@ static void test_io_channel_tls(const void *opaque) qio_channel_tls_handshake(clientChanTLS, test_tls_handshake_done, &clientHandshake, + NULL, NULL); qio_channel_tls_handshake(serverChanTLS, test_tls_handshake_done, &serverHandshake, + NULL, NULL); /* diff --git a/ui/vnc-auth-vencrypt.c b/ui/vnc-auth-vencrypt.c index 7833631275..d99ea362c1 100644 --- a/ui/vnc-auth-vencrypt.c +++ b/ui/vnc-auth-vencrypt.c @@ -128,6 +128,7 @@ static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len qio_channel_tls_handshake(tls, vnc_tls_handshake_done, vs, + NULL, NULL); } return 0; diff --git a/ui/vnc-ws.c b/ui/vnc-ws.c index 6ccad22cef..950f1cd2ac 100644 --- a/ui/vnc-ws.c +++ b/ui/vnc-ws.c @@ -81,6 +81,7 @@ gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED, qio_channel_tls_handshake(tls, vncws_tls_handshake_done, vs, + NULL, NULL); return TRUE;