From patchwork Thu Oct 13 09:32:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9374625 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 F1FBE60839 for ; Thu, 13 Oct 2016 09:41:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2BA229F3D for ; Thu, 13 Oct 2016 09:41:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7BDD29F59; Thu, 13 Oct 2016 09:41:52 +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 499CD29F3D for ; Thu, 13 Oct 2016 09:41:52 +0000 (UTC) Received: from localhost ([::1]:38899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bucWN-0006EK-FO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Oct 2016 05:41:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bucNw-00087S-77 for qemu-devel@nongnu.org; Thu, 13 Oct 2016 05:33:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bucNt-0002eG-9g for qemu-devel@nongnu.org; Thu, 13 Oct 2016 05:33:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bucNt-0002dc-0d for qemu-devel@nongnu.org; Thu, 13 Oct 2016 05:33:05 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89ADC3D94B for ; Thu, 13 Oct 2016 09:33:04 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-30.ams2.redhat.com [10.36.116.30]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9D9X2wD025485; Thu, 13 Oct 2016 05:33:03 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 050F880DA8; Thu, 13 Oct 2016 11:33:00 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 13 Oct 2016 11:32:53 +0200 Message-Id: <1476351178-32540-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1476351178-32540-1-git-send-email-kraxel@redhat.com> References: <1476351178-32540-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 13 Oct 2016 09:33:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/10] ui: refactor method for setting up VncDisplay auth types 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: Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: "Daniel P. Berrange" There is a lot of repeated code in the auth type setup method, particularly around checking TLS credential types. Refactor it to reduce duplication and instead of having one method do both plain and websockets at once, call it separately for each. Signed-off-by: Daniel P. Berrange Message-id: 1475163940-26094-6-git-send-email-berrange@redhat.com Signed-off-by: Gerd Hoffmann --- ui/vnc.c | 124 +++++++++++++++++++++++++++------------------------------------ ui/vnc.h | 1 + 2 files changed, 53 insertions(+), 72 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index 1104697..2f3ebdc 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3325,7 +3325,9 @@ static QemuOptsList qemu_vnc_opts = { static int -vnc_display_setup_auth(VncDisplay *vd, +vnc_display_setup_auth(int *auth, + int *subauth, + QCryptoTLSCreds *tlscreds, bool password, bool sasl, bool websocket, @@ -3378,86 +3380,56 @@ vnc_display_setup_auth(VncDisplay *vd, * VNC auth mechs for plain VNC vs websockets VNC, the end * result has the same security characteristics. */ - if (password) { - if (vd->tlscreds) { - vd->auth = VNC_AUTH_VENCRYPT; - if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_X509)) { + if (websocket || !tlscreds) { + if (password) { + VNC_DEBUG("Initializing VNC server with password auth\n"); + *auth = VNC_AUTH_VNC; + } else if (sasl) { + VNC_DEBUG("Initializing VNC server with SASL auth\n"); + *auth = VNC_AUTH_SASL; + } else { + VNC_DEBUG("Initializing VNC server with no auth\n"); + *auth = VNC_AUTH_NONE; + } + *subauth = VNC_AUTH_INVALID; + } else { + bool is_x509 = object_dynamic_cast(OBJECT(tlscreds), + TYPE_QCRYPTO_TLS_CREDS_X509) != NULL; + bool is_anon = object_dynamic_cast(OBJECT(tlscreds), + TYPE_QCRYPTO_TLS_CREDS_ANON) != NULL; + + if (!is_x509 && !is_anon) { + error_setg(errp, + "Unsupported TLS cred type %s", + object_get_typename(OBJECT(tlscreds))); + return -1; + } + *auth = VNC_AUTH_VENCRYPT; + if (password) { + if (is_x509) { VNC_DEBUG("Initializing VNC server with x509 password auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_X509VNC; - } else if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_ANON)) { + *subauth = VNC_AUTH_VENCRYPT_X509VNC; + } else { VNC_DEBUG("Initializing VNC server with TLS password auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_TLSVNC; - } else { - error_setg(errp, - "Unsupported TLS cred type %s", - object_get_typename(OBJECT(vd->tlscreds))); - return -1; + *subauth = VNC_AUTH_VENCRYPT_TLSVNC; } - } else { - VNC_DEBUG("Initializing VNC server with password auth\n"); - vd->auth = VNC_AUTH_VNC; - vd->subauth = VNC_AUTH_INVALID; - } - if (websocket) { - vd->ws_auth = VNC_AUTH_VNC; - } else { - vd->ws_auth = VNC_AUTH_INVALID; - } - } else if (sasl) { - if (vd->tlscreds) { - vd->auth = VNC_AUTH_VENCRYPT; - if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_X509)) { + + } else if (sasl) { + if (is_x509) { VNC_DEBUG("Initializing VNC server with x509 SASL auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_X509SASL; - } else if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_ANON)) { + *subauth = VNC_AUTH_VENCRYPT_X509SASL; + } else { VNC_DEBUG("Initializing VNC server with TLS SASL auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_TLSSASL; - } else { - error_setg(errp, - "Unsupported TLS cred type %s", - object_get_typename(OBJECT(vd->tlscreds))); - return -1; + *subauth = VNC_AUTH_VENCRYPT_TLSSASL; } } else { - VNC_DEBUG("Initializing VNC server with SASL auth\n"); - vd->auth = VNC_AUTH_SASL; - vd->subauth = VNC_AUTH_INVALID; - } - if (websocket) { - vd->ws_auth = VNC_AUTH_SASL; - } else { - vd->ws_auth = VNC_AUTH_INVALID; - } - } else { - if (vd->tlscreds) { - vd->auth = VNC_AUTH_VENCRYPT; - if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_X509)) { + if (is_x509) { VNC_DEBUG("Initializing VNC server with x509 no auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_X509NONE; - } else if (object_dynamic_cast(OBJECT(vd->tlscreds), - TYPE_QCRYPTO_TLS_CREDS_ANON)) { + *subauth = VNC_AUTH_VENCRYPT_X509NONE; + } else { VNC_DEBUG("Initializing VNC server with TLS no auth\n"); - vd->subauth = VNC_AUTH_VENCRYPT_TLSNONE; - } else { - error_setg(errp, - "Unsupported TLS cred type %s", - object_get_typename(OBJECT(vd->tlscreds))); - return -1; + *subauth = VNC_AUTH_VENCRYPT_TLSNONE; } - } else { - VNC_DEBUG("Initializing VNC server with no auth\n"); - vd->auth = VNC_AUTH_NONE; - vd->subauth = VNC_AUTH_INVALID; - } - if (websocket) { - vd->ws_auth = VNC_AUTH_NONE; - } else { - vd->ws_auth = VNC_AUTH_INVALID; } } return 0; @@ -3769,7 +3741,15 @@ void vnc_display_open(const char *id, Error **errp) } #endif - if (vnc_display_setup_auth(vd, password, sasl, ws_enabled, errp) < 0) { + if (vnc_display_setup_auth(&vd->auth, &vd->subauth, + vd->tlscreds, password, + sasl, false, errp) < 0) { + goto fail; + } + + if (vnc_display_setup_auth(&vd->ws_auth, &vd->ws_subauth, + vd->tlscreds, password, + sasl, true, errp) < 0) { goto fail; } diff --git a/ui/vnc.h b/ui/vnc.h index 223af38..d191d88 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -172,6 +172,7 @@ struct VncDisplay int auth; int subauth; /* Used by VeNCrypt */ int ws_auth; /* Used by websockets */ + int ws_subauth; /* Used by websockets */ bool lossy; bool non_adaptive; QCryptoTLSCreds *tlscreds;